Via 0x

Getting the Trade Calldata from 0x API:

The current 0x API adapter supports the 0xv4 exchange proxy. In order to execute a rebalance using 0x, you must fetch the trade calldata from the 0x /swap/v1/quote endpoint found here.

It is important to remember that the parameters passed into the TradeModule trade function is in position units. However, parameters you pass into the 0x API must be in total notional units instead. Refer to 0x Documentation for examples on receiving trade quotes.

Sample 0x API response:

{
"price": "108.2609065500801642",
"guaranteedPrice": "102.8478612225761558",
"to": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
"data": "0xd9627aa40000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000e45e3d944cda116000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000954906da0bf32d5479e25f46056d22f08464cab869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000000000003e67d7ea31600e8c94",
"value": "0",
"gas": "171000",
"estimatedGas": "171000",
"from": "0x1c5eeb49ddd0203444f9b4b6600226f78873cd4d",
"gasPrice": "79000000000",
"protocolFee": "0",
"minimumProtocolFee": "0",
"buyTokenAddress": "0x0954906da0bf32d5479e25f46056d22f08464cab",
"sellTokenAddress": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9",
"buyAmount": "1082609065500801642",
"sellAmount": "10000000000000000",
"sources": [
{
"name": "0x",
"proportion": "0"
},
{
"name": "Uniswap",
"proportion": "0"
},
{
"name": "Uniswap_V2",
"proportion": "1"
},
{
"name": "Eth2Dai",
"proportion": "0"
},
{
"name": "Kyber",
"proportion": "0"
},
{
"name": "Curve",
"proportion": "0"
},
{
"name": "LiquidityProvider",
"proportion": "0"
},
{
"name": "MultiBridge",
"proportion": "0"
},
{
"name": "Balancer",
"proportion": "0"
},
{
"name": "CREAM",
"proportion": "0"
},
{
"name": "Bancor",
"proportion": "0"
},
{
"name": "mStable",
"proportion": "0"
},
{
"name": "Mooniswap",
"proportion": "0"
},
{
"name": "MultiHop",
"proportion": "0"
},
{
"name": "Shell",
"proportion": "0"
},
{
"name": "Swerve",
"proportion": "0"
},
{
"name": "SnowSwap",
"proportion": "0"
},
{
"name": "SushiSwap",
"proportion": "0"
},
{
"name": "DODO",
"proportion": "0"
},
{
"name": "CryptoCom",
"proportion": "0"
}
],
"orders": [
{
"chainId": 1,
"exchangeAddress": "0x61935cbdd02287b511119ddb11aeb42f1593b7ef",
"makerAddress": "0xdcd6011f4c6b80e470d9487f5871a0cba7c93f48",
"takerAddress": "0x0000000000000000000000000000000000000000",
"feeRecipientAddress": "0x1000000000000000000000000000000000000011",
"senderAddress": "0x0000000000000000000000000000000000000000",
"makerAssetAmount": "1028478612225761559",
"takerAssetAmount": "10000000000000000",
"makerFee": "0",
"takerFee": "0",
"expirationTimeSeconds": "1611573427",
"salt": "13296217963886828288287121507227614217710859303974535612166126598723404635862",
"makerAssetData": "0xdc1600f30000000000000000000000000954906da0bf32d5479e25f46056d22f08464cab000000000000000000000000dcd6011f4c6b80e470d9487f5871a0cba7c93f48000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000954906da0bf32d5479e25f46056d22f08464cab",
"takerAssetData": "0xf47261b00000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9",
"makerFeeAssetData": "0x",
"takerFeeAssetData": "0x",
"signature": "0x04"
}
],
"allowanceTarget": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
"sellTokenToEthRate": "5.408199990410548256",
"buyTokenToEthRate": "114.15627671612326308"
}

Convenience API

We have provided a quick API for querying for a 0x trade quote through the 0x API (documented above)

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 (0x)

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
optional
string
Address of the token to receive
amount
optional
string
Notional amount of the from token to sell
exchange_type
optional
string
"zero_ex"
Response
200: OK
{
"trade_quote": {
"from": "0x430a35baa51ddeaccf89092a5edbda47aaae78e4",
"from_token_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"to_token_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"exchange_adapter_name": "ZeroExApiAdapter",
"calldata": "0xd9627aa4000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000002540babdb0000000000000000000000000000000000000000000000005d203f138e643c4200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2869584cd00000000000000000000000010000000000000000000000000000000000000110000000000000000000000000000000000000000000000f275edf373600e805a",
"gas": "379219",
"gas_price": "86000000015",
"from_token_amount": "649207",
"to_token_amount": "412717851179285",
"display": {
"input_amount": "10000000000",
"quote_amount": "9999985627",
"from_token_display_amount": "9999.985627",
"to_token_display_amount": "7.063613",
"from_token_price_usd": "$9,986.03",
"to_token_price_usd": "$9,978.77",
"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": "$46.07",
"gas_costs_eth": "0.0326128 ETH",
"fee_percentage": "0%",
"slippage": "0.07%"
}
}
}