Bebop JAM API

The following guide explains how to use Liquorice together with Bebop JAM API

1. Providing JamSettlement address in the RFQ

From the perspective of Liquorice, trade is performed with the JamSettlement contract, not directly with the trader.

Therefore, a solver must first and foremost provide the address of the JamSettlement smart contract in both trader and effectiveTrader fields of the RFQ message.

2. Calling JamSettlement.settle function

2.1 Solver data argument

During the settlement process, funds from the trader must first be transferred to the JamSettlement contract.

For this reason, balanceRecipient of the ExecInfo.SolverData has to be set to the address of the JamSettlement contract.

Solidity example

ExecInfo.SolverData memory solverData = ExecInfo.SolverData(<jam-settlement>, 10_000);

2.2. Jam Interactions argument

To assemble Jam Interactions, solver would need to use following fields from the Quote payload

  • baseToken

  • baseTokenAmount

  • market

  • interactions

Reference

Approval

When performing the trade, Liquorice Balance Manager contract must have a baseToken approval given by the JamSettlement contract.

Quote interactions

The rest of the interactions must be assembled from the interactions and market fields.

Solidity example

address public constant LIQUORICE_BALANCE_MANAGER = <liquorice-balance-manager>;

// RFQ Quote payload sample returned from the Liquorice API
struct LiquoriceRFQQuote {
  address market;
  address baseToken;
  uint256 baseTokenAmount;
  bytes[] interactions;
}

function getJamInteractions(LiquoriceRFQQuote calldata quote) public returns (JamInteraction.Data[] memory interactions) {
  // Types can be found in https://github.com/bebop-dex/bebop-jam-contracts

  JamInteraction.Data[] memory interactions = new JamInteraction.Data[](quote.interactions.length + 1);

  // JamSettlement gives approval to LIQUORICE_BALANCE_MANAGER
  JamInteraction.Data memory approval = JamInteraction.Data(
    true,
    quote.baseToken,
    0,
    abi.encodeWithSelector(IERC20.approve.selector, LIQUORICE_BALANCE_MANAGER, quote.baseTokenAmount)
  );
  interactions[0] = approval;

  // And executes interactions
  for (uint256 i = 0; i < quote.interactions.length; i++) {
    interactions[i + 1] = JamInteraction.Data(false, quote.market, 0, quote.interactions[i]);
  }

  return interactions;
}

2.3 Rest arguments

Remaining arguments such as hooks, signature and order provided as is.

Last updated