Trading

Initializing the TradeModule:

All modules need to be added to the SetToken as the first step. Learn how to add a module to your SetToken in this section.

Once you have added the TradeModule to the SetToken, you must initialize the SetToken on the TradeModule:

/**
* Initializes this module to the SetToken. Only callable by the SetToken's manager.
*
* @param _setToken Instance of the SetToken to initialize
*/
function initialize(ISetToken _setToken);

Simply input the SetToken address in the TradeModule.

Trading:

In order to trade components, you must be operating as the manager of your SetToken. Call the trade function with inputs as follows:

/**
* Executes a trade on a supported DEX. Only callable by the SetToken's manager.
* @dev Although the SetToken units are passed in for the send and receive quantities, the total quantity
* sent and received is the quantity of SetToken units multiplied by the SetToken totalSupply.
*
* @param _setToken Instance of the SetToken to trade
* @param _exchangeName Human readable name of the exchange in the integrations registry
* @param _sendToken Address of the token to be sent to the exchange
* @param _sendQuantity Units of token in SetToken sent to the exchange
* @param _receiveToken Address of the token that will be received from the exchange
* @param _minReceiveQuantity Min units of token in SetToken to be received from the exchange
* @param _data Arbitrary bytes to be used to construct trade call data
*/
function trade(
ISetToken _setToken,
string memory _exchangeName,
address _sendToken,
uint256 _sendQuantity,
address _receiveToken,
uint256 _minReceiveQuantity,
bytes memory _data
);

It is important to not that units passed into the trade function are in position units (NOT the total 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 1 * 10^18) into the sendQuantity.

The exchange name is a string specifying which decentralized exchange to execute the trade. The exchange name is registered in the IntegrationRegistry. Exchanges supported by the TradeModule are:

Mainnet
Mainnet

Contract

Exchange Name

1Inch

"OneInchExchangeAdapter"

Uniswap

Coming Soon 👀

SushiSwap

Coming Soon 👀

Kyber

Coming Soon 👀

Synthetix

Coming Soon 👀

The _data parameter is optional on various exchanges and required for others. For example, you will need to input the trade calldata fetched from the 1inch API to execute an 1Inch trade.