统一返回结果格式
- code:返回错误码、200为正常返回
- msg:错误信息
- data:返回的数据
具体:
{
code : 200,
msg : "Success",
data : {
}
}
请求方式
- POST
- 通过 body传参
- network 通过url 传入,其实就是网络id,eth 传入1
协议名称(name)
- compound-v2
- aave-v2
- aave-v3
- lidosteth
操作名称(method)
-
deposit : 存款/质押
-
withraw:赎回/提现
-
claim: 领取奖励
参数描述
报价
Url:
/v1/defi/quote?nework=1
参数:
ApiWrapperQuoteParam
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
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[] | 是 | 直接传空数组[] ,报价后会有值 |
ApiQuoteParams
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
partnerFee | 手续费: 和swap 类似 | string | 是 | 如果不收手续费就只为0 |
wrappers | 协议 | ApiWrapperQuoteParam[] | 是 | 至少要传入一个 |
返回结果:
ApiWrapperQuoteResult
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
name | 协议名称: 参照协议名称列表 | string | 是 | 根据输入返回 |
method | 协议,参照 | string | 是 | 根据输入返回 |
args | 协议对应的参数:参考给wrapper的abi文档 | string[] | 是 | 根据输入返回 |
srcTokens | 输入Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 根据输入返回 |
srcDecimals | 输入Tokens 的精度 | number[] | 是 | 根据输入返回 |
srcAmounts | 输入Token的数量 | string[] | 是 | 根据输入返回 |
destTokens | 输出Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 根据输入返回 |
destDecimals | 输出 Tokens 的精度 | number[] | 是 | 根据输入返回 |
destAmounts | 输出Token的数量 | string[] | 是 | 根据报价返回结果 |
feeType | 手续费类型 | number | 是 | 0:无,1:从输入收取,2:从输出收取 |
directUser | 是否原路返回资金 | boolean | 是 | 是否输出token是直接到用户的地址还是可以经过jeton原路返回给用户 |
feeTokens | 手续费 Tokens(ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | string[] | 是 | 直接传空数组[] ,报价后会有值 |
feeAmounts | 手续费数量 | string[] | 是 | 直接传空数组[] ,报价后会有值 |
data | 辅助信息 | json | 是 | 目前就返回个{} 空对象 |
ApiQuoteResult
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
allowanceTarget | 授权合约 | string | 是 | 和swap一样 |
contractAddress | jetonRouter | String | 是 | jeton入口合约地址 |
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[] | 是 | 会根据计算得出 |
results | 协议报价的结果 | ApiWrapperQuoteResult[] | 是 | 会根据计算得出 |
例如:以aave-v3 存入 eth 为例子
请求地址: /v1/defi/quote?network=1
入参:
{
"partnerFee": "2147565568030",
"wrappers": [
{
"name": "aave-v3",
"method": "withdraw",
"args": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"0"
],
"srcTokens": [
"0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8"
],
"srcDecimals": [
18
],
"srcAmounts": [
"997008973080757726"
],
"destTokens": [
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
],
"destDecimals": [
18
],
"feeTokens": [],
"feeAmounts": []
}
]
}
出参:
{
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.编码
Url:
/v1/defi/encode?network=1
参数:
ApiPermitData
字段名称 | 描述 | 字段类型 | 是否非空 | 备注 |
---|---|---|---|---|
token | 要授权的token地址 | string | 是 | Erc20 地址 |
permit | permit 授权编码数据 | string | 是 |
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
]
}