Batch Trading

Note: For sets are NOT using Delegated Manager system and have not migrated to the Batch Trading system, please refer to the 'Trading' section on how to execute trades manually via BscScan

Initializing the BatchTradingExtension:

Note: You MUST have TradeModule initialized and the Set Manager set to your DelegatedManager address to use the BatchTradingExtension.

Due to the complexities of initializing, if you have not initialized the batch trading extension already, we recommend using the TradeModule directly.

Batch Trading:

Only the operator will be able to trade. Call the trade function with inputs as follows:

Important: sendQuantity and _minReceiveQuantity are denominated in position units and not the notional quantity. For example, if 1 SetToken contains 1 WETH, and there are 10 supply of SetTokens (10 WETH locked in total), trading 100% of the ETH to DAI requires passing in 1 (more accurately 10**18) into the sendQuantity.

struct TradeInfo {
    string exchangeName;             // Human readable name of the exchange in the integrations registry
    address sendToken;               // Address of the token to be sent to the exchange
    uint256 sendQuantity;            // Max units of `sendToken` sent to the exchange
    address receiveToken;            // Address of the token that will be received from the exchange
    uint256 receiveQuantity;         // Min units of `receiveToken` to be received from the exchange
    bytes data;                      // Arbitrary bytes to be used to construct trade call data
}

/**
 * ONLY OPERATOR: Executes a batch of trades on a supported DEX. If any individual trades fail, events are emitted.
 * @dev Although the SetToken units are passed in for the send and receive quantities, the total quantity
 * sent and received is the quantity of component units multiplied by the SetToken totalSupply.
 *
 * @param _setToken             Instance of the SetToken to trade
 * @param _trades               Array of TradeInfo structs containing information about trades
 */
function batchTrade(
    ISetToken _setToken,
    TradeInfo[] memory _trades
)

The exchange name is a string specifying which exchange adapter to execute the trade. The exchange name is registered in the IntegrationRegistry contract. Exchanges and aggregators currently supported by the TradeModule are:

Exchange

Adaptor

0x

ZeroExApiAdapterV5

Uniswap V3 (BNB-Chain)

UniswapV3ExchangeAdapter

Pancakeswap V2

PancakeswapV2ExchangeAdapter

Pancakeswap V3

PancakeswapV3ExchangeAdapter

AMMSplitter

AMMSplitterExchangeAdapter

The _data parameter is optional on some exchanges and required for others. For example, you will need to input the trade calldata fetched from the 0x API or 1inch API to execute an 1Inch trade or custom path to route the trade through Uniswap or Sushiswap. For information on how to generate the custom _data parameter, check out the next few sections.

Batch Trading on Etherscan using 0x

  1. Notice: For sets are NOT using Delegated Manager system and have not migrated to the Batch Trading system, please refer to the 'Trading' section on how to execute trades manually via BscScan

  2. Navigate to the BatchTradingExtension (Ethereum, Polygon) that you have already initialized on your Set

  3. Connect your web3 wallet

  4. Fill in the batchTrade() details and click submit

    1. The TradeInfo struct looks exactly like the inputs into the TradeModule directly. You can format the struct like this in bscscan

    2. [
          {
              "exchangeName: "ZeroExApiAdapterV4",
              "sendToken": "0xUSDC",
              "sendQuantity": "10000000",
              "receiveToken": "0xWETH",
              "receiveQuantity":"100000000000000",
              "data": "0xd9627aa40000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000e45e3d944cda116000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000954906da0bf32d5479e25f46056d22f08464cab869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000000000003e67d7ea31600e8c94"
          },{
              "exchangeName: "ZeroExApiAdapterV4",
              "sendToken": "0xUSDC",
              "sendQuantity": "10000000",
              "receiveToken": "0xWETH",
              "receiveQuantity":"100000000000000",
              "data": "0xd9627aa40000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000e45e3d944cda116000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000954906da0bf32d5479e25f46056d22f08464cab869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000000000003e67d7ea31600e8c94"
          }
      ]
    3. tradeData is pulled from the data field from 0x API. Refer to 0x API section to fetch a quote

    4. {
          "price": "108.2609065500801642",
          "guaranteedPrice": "102.8478612225761558",
          "to": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
          "data": "0xd9627aa40000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000e45e3d944cda116000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000954906da0bf32d5479e25f46056d22f08464cab869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000000000003e67d7ea31600e8c94",
      ...

Last updated