Via Uniswap or Sushiswap

Getting the Trade Calldata from Uniswap or Sushiswap:

In order to execute a rebalance using Uniswap or Sushiswap, input the parameters into the trade function. If no data is provided, the adapter will attempt to trade directly on a pool between the two assets. This is rarely the highest liquidity path.

For example, your Set currently has a position for KNC and you wish to trade for WBTC. The KNC/WBTC pool is not very deep so trading against it will result in high slippage. The optimal trade path involves trading through the KNC/WETH and WETH/WBTC pairs. To specify this, you must pass in the custom path encoded in bytes into the _data field. To generate the bytes, you can use use an ABI coder.

If no _data is provided, it will automatically trade against the pool specified by the _sendTokenAddress and _receiveTokenAddress.

If you do not know or are unsure, drop in our Discord and ask us a question. Incorrectly supplying trade data can result in significant loss for your Set.

Sample ABI coder from ethers.js for generating a trade path:

import { defaultAbiCoder } from "ethers/lib/utils";
const path = [
"0xdd974d5c2e2928dea5f71b9825b8b646686bd200",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
];
const tradeData = defaultAbiCoder.encode(
["address[]"],
[path]
);
// Sample return data:
// tradeData = 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000dd974d5c2e2928dea5f71b9825b8b646686bd200000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599

Sample ABI coder online:

Alternatively, you can use an ABI encoder online.

Convenience API:

We have provided a quick API for querying for a Uniswap or Sushiswap trade quote. This will trade through the most common pairs including USDC, USDT, DAI, WETH, and WBTC.

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
Fetch Trade Quote (Uniswap or Sushiswap)

https://api.tokensets.com/public/v2/trade_quotes/:set_address
Request
Response
Request
Path Parameters
set_address
required
string
Address of the SetToken contract to trade from
Query Parameters
from_token_address
optional
string
Address of the position token in the Set to trade
to_token_address
required
string
Address of the token to receive
amount
required
string
Notional amount of the from token to sell
exchange_type
required
string
"uniswap" or "sushiswap"
Response
200: OK
The amounts returned in the API response reflect the position units of the tokens traded. They do not need to be converted.
{
"trade_quote": {
"from": "0x430a35baa51ddeaccf89092a5edbda47aaae78e4",
"from_token_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"to_token_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"exchange_adapter_name": "UniswapV2ExchangeAdapter",
"calldata": "0x",
"gas": "379807",
"gas_price": "71579375831",
"slippage_percentage": "10%",
"from_token_amount": "649526",
"to_token_amount": "411657654051506",
"display": {
"input_amount": "10000000000",
"quote_amount": "9999998982",
"from_token_display_amount": "9999.998982",
"to_token_display_amount": "7.042018",
"from_token_price_usd": "$9,998.27",
"to_token_price_usd": "$10,005.65",
"to_token": {
"symbol": "WETH",
"name": "Wrapped Ethereum",
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"decimals": 18
},
"from_token": {
"symbol": "USDC",
"name": "USD Coin",
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"decimals": 6
},
"gas_costs_usd": "$38.63",
"gas_costs_eth": "0.0271863 ETH",
"fee_percentage": "0%",
"slippage": "-0.07%"
}
}
}