Bebop JAM

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

  • tx

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>;

struct Transaction {
  address to;
  bytes data;
}

// RFQ Quote level payload sample returned from the Liquorice API
struct LiquoriceRFQQuoteLevel {
  address baseToken;
  uint256 baseTokenAmount;
  Transaction tx;
}

function getJamInteractions(LiquoriceRFQQuoteLevel calldata quoteLevel) 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[](2);

  // JamSettlement gives approval to LIQUORICE_BALANCE_MANAGER
  JamInteraction.Data memory approval = JamInteraction.Data(
    true,
    quoteLevel.baseToken,
    0,
    abi.encodeWithSelector(IERC20.approve.selector, LIQUORICE_BALANCE_MANAGER, quoteLevel.baseTokenAmount)
  );
  interactions[0] = approval;
  // And executes LiquoriceSettlement calldata   
  interactions[1] = JamInteraction.Data(true, quoteLevel.tx.to, 0, quoteLevel.tx.data);

  return interactions;
}

2.3 Rest arguments

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

Last updated