Unified return result format
- code: return error code, 200 is normal return
- msg: error message
- data: the returned data
specific:
{
code : 200,
msg : "Success",
data : {
}
}
request method
- POST
- Pass parameters through body
- The network is passed in through url, which is actually the network id, and eth is passed in 1
protocol name (name)
- compound-v2
- aave-v2
- aave-v3
- lidosteth
operation name (method)
-
deposit : deposit/stake
-
withraw: redemption/withdrawal
-
claim: claim the reward
Parameter Description
quotation
Url:
/v1/defi/quote?nework=1
parameter:
ApiWrapperQuoteParam
Field Name | describe | Field Type | Is it non-empty | Remark |
---|---|---|---|---|
name | Protocol name: Refer to the list of protocol names | string | yes | compound-v2、aave-v2、aave-v3、lido-steth |
method | protocol, see | string | yes | deposit、withdraw、claim |
args | Parameters corresponding to the protocol: refer to the abi document for the wrapper | string[] | yes | None: directly pass [] an empty array |
srcTokens | InputTokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | None: directly pass [] an empty array |
srcDecimals | Input the precision of Tokens | number[] | yes | None: directly pass [] an empty array |
srcAmounts | Enter the number of tokens | string[] | yes | None: directly pass [] an empty array |
destTokens | OutputTokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | None: directly pass [] an empty array |
destDecimals | The precision of the output Tokens | number[] | yes | None: directly pass [] an empty array |
feeTokens | 最新费 Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | Directly pass an empty array [], there will be a value after the quotation |
feeAmounts | Fee amount | string[] | yes | Directly pass an empty array [], there will be a value after the quotation |
ApiQuoteParams
Field Name | describe | Field Type | Is it non-empty | Remark |
---|---|---|---|---|
partnerFee | Handling fee: similar to swap | string | yes | If no handling fee is charged, it is only 0 |
wrappers | protocol | ApiWrapperQuoteParam[] | yes | Pass in at least one |
return result:
ApiWrapperQuoteResult
Field Name | describe | Field Type | Is it non-empty | Remark |
---|---|---|---|---|
name | Protocol name: Refer to the list of protocol names | string | yes | return based on input |
method | protocol, see | string | yes | return based on input |
args | Parameters corresponding to the protocol: refer to the abi document for the wrapper | string[] | yes | return based on input |
srcTokens | InputTokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | return based on input |
srcDecimals | Input the precision of Tokens | number[] | yes | return based on input |
srcAmounts | Enter the number of tokens | string[] | yes | return based on input |
destTokens | OutputTokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | return based on input |
destDecimals | The precision of the output Tokens | number[] | yes | return based on input |
destAmounts | The number of output tokens | string[] | yes | Return results based on quotes |
feeType | Fee Type | number | yes | 0: None, 1: Receive from input, 2: Receive from output |
directUser | Whether to return funds in the original way | boolean | yes | Whether the output token is directly to the user's address or can be returned to the user through jeton |
feeTokens | 最新费 Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | Directly pass an empty array [], there will be a value after the quotation |
feeAmounts | Fee amount | string[] | yes | Directly pass an empty array [], there will be a value after the quotation |
data | Supplementary information | json | yes | Currently returns an {} empty object |
ApiQuoteResult
Field Name | describe | Field Type | Is it non-empty | Remark |
---|---|---|---|---|
allowanceTarget | Licensing contract | string | yes | same as swap |
contractAddress | jetonRouter | String | yes | jeton entry contract address |
partnerFee | Handling fee: similar to swap | string | yes | Same as the incoming parameters, used to calculate the handling fee |
srcTokens | InputTokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | will be calculated based on |
srcDecimals | Input the precision of Tokens | number[] | yes | will be calculated based on |
srcAmounts | Enter the number of tokens | string[] | yes | will be calculated based on |
destTokens | OutputTokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeEEeE) | string[] | yes | will be calculated based on |
destDecimals | The precision of the output Tokens | number[] | yes | will be calculated based on |
destAmounts | The number of output tokens | string[] | yes | will be calculated based on |
results | The result of the agreement quotation | ApiWrapperQuoteResult[] | yes | will be calculated based on |
For example: take aave-v3 as an example
Request address: /v1/defi/quote?network=1
Enter:
{
"partnerFee": "2147565568030",
"wrappers": [
{
"name": "aave-v3",
"method": "withdraw",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"0"
],
"srcTokens": [
"0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8"
],
"srcDecimals": [
18
],
"srcAmounts": [
"997008973080757726"
],
"destTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"destDecimals": [
18
],
"feeTokens": [],
"feeAmounts": []
}
]
}
Out of parameters:
{
code : 200,
msg : "Success",
data : {
"allowanceTarget": "0x49149a233de6E4cD6835971506F47EE5862289c1",
"contractAddress": "0x4CF4dd3f71B67a7622ac250f8b10d266Dc5aEbcE",
"partnerFee": "2147565568030",
"srcAmounts": [
"997008973080757726"
],
"srcDecimals": [
18
],
"srcTokens": [
"0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8"
],
"destAmounts": [
"994017946161515453"
],
"destDecimals": [
18
],
"destTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"results": [
{
"name": "aave-v3",
"method": "withdraw",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"997008973080757726"
],
"srcTokens": [
"0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8"
],
"srcDecimals": [
18
],
"srcAmounts": [
"997008973080757726"
],
"destTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"destDecimals": [
18
],
"feeTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"feeAmounts": [
"2991026919242273"
],
"destAmounts": [
"994017946161515453"
],
"data": {},
"directUser": false,
"feeType": 2
}
]
}
}
2. Coding
Url:
/v1/defi/encode?network=1
parameter:
ApiPermitData
Field Name | describe | Field Type | Is it non-empty | Remark |
---|---|---|---|---|
token | The token address to be authorized | string | yes | Erc20 address |
permit | permit authorization coded data | string | yes |
ApiWrapperEncodeParam
说明:与报价结果ApiWrapperQuoteResult保持一致,这个对象和ApiWrapperQuoteResult 的定义是一样的)
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
name | 协议名称: 参照协议名称列表 | string | 是 | compound-v2、aave-v2、aave-v3、lido-steth |
method | 协议,参照 | string | 是 | deposit、withdraw、claim |
args | 协议对应的参数:参考给wrapper的abi文档 | string[] | 是 | 没有:直接传[] 空数组 |
srcTokens | 输入Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 没有:直接传[] 空数组 |
srcDecimals | 输入Tokens 的精度 | number[] | 是 | 没有:直接传[] 空数组 |
srcAmounts | 输入Token的数量 | string[] | 是 | 没有:直接传[] 空数组 |
destTokens | 输出Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 没有:直接传[] 空数组 |
destDecimals | 输出Tokens 的精度 | number[] | 是 | 没有:直接传[] 空数组 |
feeTokens | 手续费 Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 直接传空数组[] ,报价后会有值 |
feeAmounts | 手续费数量 | string[] | 是 | 直接传空数组[] ,报价后会有值 |
ApiEncodeParams
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
userAddress | 用户地址 | string | 是 | 操作用户,eoa 或者relayer用户 |
referrerAddress | 渠道地址 | string | 是 | 渠道地址 |
permits | permit 授权列表 | ApiPermitData[] | 是 | 没有数据请传入空的列表 [] |
beneficiary | 资产接受地址 | string | 否 | 如果不设置就是userAddress |
partnerFee | 手续费: 和swap 类似 | string | 是 | 与报价结果保持一致 |
srcTokens | 输入Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 与报价结果保持一致 |
srcDecimals | 输入Tokens 的精度 | number[] | 是 | 与报价结果保持一致 |
srcAmounts | 输入Token的数量 | string[] | 是 | 与报价结果保持一致 |
destTokens | 输出Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 与报价结果保持一致 |
destDecimals | 输出 Tokens 的精度 | number[] | 是 | 与报价结果保持一致 |
destAmounts | 输出Token的数量 | string[] | 是 | 与报价结果保持一致 |
wapperParams | 协议 | ApiWrapperQuoteParam[] | 是 | 至少要传入一个 |
返回结果:
ApiEncodeResult
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
from | 发起用户 | string | 是 | 如果eoa用户,那么就是用户自己,如果是relayer, 那么就是relayer |
to | 交互的合约地址 | string | 是 | |
value | 交易的eth 金额 | string | 是 | |
data | 编码数据 | string | 是 |
以lido 存入 eth 为例子
请求地址: /v1/defi/encode?network=1
body:
{
"partnerFee": "2147565568030",
"srcTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"srcDecimals": [
18
],
"srcAmounts": [
"1000000000000000000"
],
"destTokens": [
"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"
],
"destDecimals": [
18
],
"destAmounts": [
"996999002991026918"
],
"wapperParams": [
{
"name": "lidosteth",
"method": "deposit",
"args": [
"997008973080757726"
],
"srcTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"srcDecimals": [
18
],
"srcAmounts": [
"1000000000000000000"
],
"destTokens": [
"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"
],
"destDecimals": [
18
],
"feeTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"feeAmounts": [
"2991026919242273"
],
"destAmounts": [
"996999002991026918"
],
"data": {
},
"directUser": false,
"feeType": 1
}
],
"userAddress": "0xb6CcdceC81C531124eE6D565cd0231dd764ae192",
"referrerAddress": "0x4EFc83725CF33cDa2ad47fBe2cC30B3836647E27",
"permits": [
]
}
返回结果
{
code : 200,
msg : "Success",
data: {
"from": "0xb6CcdceC81C531124eE6D565cd0231dd764ae192",
"to": "0x4CF4dd3f71B67a7622ac250f8b10d266Dc5aEbcE",
"value": "1000000000000000000",
"data": "0xb42e09a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000004efc83725cf33cda2ad47fbe2cc30b3836647e27000000000000000000000000b6ccdcec81c531124ee6d565cd0231dd764ae192000000000000000000000000000000000000000000000000000001f404e2001e000000000000000000000000000000000000000000000000000000006485d08631500bb62ff34093887ae46e8eb2a33900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000dd60d4f96b2e2e6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000fae849108f2a63abe3bab17e21be077d07e7a9a200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024b6b55f250000000000000000000000000000000000000000000000000dd61660ee5b05de00000000000000000000000000000000000000000000000000000000"
}
}
Args (报价)
compound-v2
deposit
{
"name": "compound-v2",
"method": "deposit",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",// ETH, 要 srcTokens[0]保持一致
"0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5",// cEth, 要 destTokens[0] 保持一致
"0" //这个参数在报价的是填入0,报价完成后结果里面自动讲 srcAmounts[0] 填入
],
"srcTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"srcDecimals": [
18
],
"srcAmounts": [
"1000000000000000000"
],
"destTokens": [
"0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5"
],
"destDecimals": [
8
]
}
withdraw
{
"name": "compound-v2",
"method": "withdraw",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",// destTokens[0] 保持一致
"0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5",// srcTokens[0] 保持一致
"0" //cToken的数量,报价的时候填入0,报价后会自动填入(从 srcAmounts[0] 取)
],
"srcTokens": [
"0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5"
],
"srcDecimals": [
8
],
"srcAmounts": [
"4963958952"
],
"destTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"destDecimals": [
18
]
}
claim
{
"name": "compound-v2",
"method": "claim",
"args": [
"0x25f6E3Ed064Fc771AF0f22a8D24a1FB176ec5c53" //给那个用户领取收益,必须手动指定
],
"srcTokens": [],
"srcDecimals": [],
"srcAmounts": [],
"destTokens": [
"0xc00e94Cb662C3520282E6f5717214004A7f26888" //补贴token的地址 comp
],
"destDecimals": [
18
]
}
aave-v2
deposit
{
"name": "aave-v2",
"method": "deposit",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", //请与srcToken[0] 保持一致
"0" //请填写 0,报价服务会自动给 用srcAmounts[0]来进行填充
],
"srcTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" //ETH
],
"srcDecimals": [
18
],
"srcAmounts": [
"1000000000000000000"
],
"destTokens": [
"0x030bA81f1c18d280636F32af80b9AAd02Cf0854e" //AToken
],
"destDecimals": [
18
]
}
withdraw
{
"name": "aave-v2",
"method": "withdraw",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",//ETH 务必与destTokens[0] 保持一致
"0",//请填写0,报价服务会自动用srcAmounts[0] 进行填充
],
"srcTokens": [
"0x030bA81f1c18d280636F32af80b9AAd02Cf0854e"
],
"srcDecimals": [
8
],
"srcAmounts": [
"1000000000000000000"
],
"destTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"destDecimals": [
18
]
}
aave-v3(与v2版本相同)
lidosteth
deposit
{
"name": "lidosteth",
"method": "deposit",
"args": [
"0" //要存入的eth数量,请填入0,报价会自动用 srcAmounts[0] 进行填充
],
"srcTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" //eth
],
"srcDecimals": [
18
],
"srcAmounts": [
"1000000000000000000"
],
"destTokens": [
"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84" //lido
],
"destDecimals": [
18
]
}