Via 0x
Getting the Trade Calldata from 0x API:
In order to execute a rebalance using 0x, you must fetch the trade calldata
from the 0x /swap/v1/quote
endpoint found here.
0x supports BNB-chain and aggregates decentralized exchanges to return the best calldata
to the user. When querying the 0x quote endpoint, be sure to use the correct 0x subdomain based on network.
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"
}
Last updated