Set Documentation
Search…
Trading

What is the TradeModule:

The Trade Module enables managers of SetTokens to perform atomic trades using aggregators such as 0x and 1inch, and decentralized exchanges such as Sushiswap and Uniswap. This rebalances the Set for all Set holders.

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 by referring to the Adding a Module guide.
Once you have added the TradeModule to the SetToken, you must initialize the SetToken on the TradeModule:
1
/**
2
* Initializes this module to the SetToken. Only callable by the SetToken's manager.
3
*
4
* @param _setToken Instance of the SetToken to initialize
5
*/
6
function initialize(ISetToken _setToken);
Copied!

Trading:

Only the manager 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.
1
/**
2
* Executes a trade on a supported DEX. Only callable by the SetToken's manager.
3
* @dev Although the SetToken units are passed in for the send and receive quantities, the total quantity
4
* sent and received is the quantity of SetToken units multiplied by the SetToken totalSupply.
5
*
6
* @param _setToken Instance of the SetToken to trade
7
* @param _exchangeName Human readable name of the exchange in the integrations registry
8
* @param _sendToken Address of the token to be sent to the exchange
9
* @param _sendQuantity Units of token in SetToken sent to the exchange
10
* @param _receiveToken Address of the token that will be received from the exchange
11
* @param _minReceiveQuantity Min units of token in SetToken to be received from the exchange
12
* @param _data Arbitrary bytes to be used to construct trade call data
13
*/
14
function trade(
15
ISetToken _setToken,
16
string memory _exchangeName,
17
address _sendToken,
18
uint256 _sendQuantity,
19
address _receiveToken,
20
uint256 _minReceiveQuantity,
21
bytes memory _data
22
);
Copied!
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:
Mainnet
Contract
Exchange Name
0x
ZeroExApiAdapterV3
1Inch
OneInchExchangeAdapter
Uniswap V2
UniswapV2ExchangeAdapter
SushiSwap
SushiswapExchangeAdapter
Kyber
KyberExchangeAdapter
Uniswap V3
UniswapV3ExchangeAdapter
Kyber DMM
KyberV3ExchangeAdapter
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.

TokenSets UI

The easiest way to try a trade is to use the TokenSets UI, plugging in your own Set address in the path name in the URL.

Convenience API

We have provided a quick API for querying for a trade quote.
We assume no responsibility for any usage of the API. Always verify trade parameters returned by the API before use. Incorrect usage can result in significant losses.
get
https://api.tokensets.com/public/v2/trade_quotes/:set_address
Fetch Trade Quote
Last modified 3mo ago