💻获取ETH/Base交易可用的路由

该接口分为2个,一个是精确指定输入,获得输出币种数量; 另外一个是精确指定输出,获得输入币种最小数量。

1. 精确输入

接入点:/defi/router/v1/tx/available_routes_exact_in

请求方式:GET

输入参数:

参数名字

参数说明

是否必须

举例

token_in_chain

网络代号,比如eth/polygon/arb等

eth

token_out_chain

网络代号,比如eth/polygon/arb等

arb

token_in_address

输入token的合约地址

0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

token_out_address

输出token的合约地址

0xb44C0A4624eaEd2C41EB8437d0Fb5A28F91E7335

in_amount

输入token的数量,以最小单位计

100000000

src

来源,可以选择gmgn或者swapx,默认gmgn

swapx

返回参数:

参数名字

参数说明

举例

msg

出错信息

amountIn is required

code

正确0,错误-1

0

data

返回跨链交易的基本信息,主要包含以下信息:

来源链ID:chain_id,

合约地址:to,

源币种数量:amount_in,

源币种USD价值:amount_in_usd,

获得币种数量:amount_out,

获得币种USD价值:amount_out_usd,

购买币种地址:buy_token_address,

卖出币种地址:sell_token_address,

经过步骤列表:steps,

(其中steps有id/type/tool三个字段)

{"routes": [{"chain_id": 1,"to": "0x4313C378Cc91eA583C91387B9216e2c03096b27f","amount_in": "10000000000000000","amount_out": "299609399139476657","input_token_address": "0x0000000000000000000000000000000000000000","output_token_address": "0x81de6d37439afb8c5c0a6d6e39e764c89e81d6b5","type": "v2","path": ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x81de6d37439afb8c5c0a6d6e39e764c89e81d6b5"],"pool_address": "0xc8d39a869dee360e19d2a2f189c5b87f013d9f85","factory_address": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f","fee": 3000,"steps": [{"id": 1,"type": "swap","tool": "uniswapv2"}],"token_in_usd_price": "2246.46","amount_in_usd": "22.4646","token_out_usd_price": "0.00000008532060895067131","amount_out_usd": "25.56285638192488514528660222461067","value": "10000000000000000","price_impact": "0.01","gas_limit": "221343"}],"volatilities": {"token_in": 0,"token_out": 10}

返回data的routes字段说明

字段名字

类型

模拟是否用到

举例

字段名字

类型

模拟是否用到

举例

chain_id

number

1

to

string

0xb2C435F236AE7697341beb0D98EceD5AB7d35052

amount_in

string

129470074265000000

amount_in2

string

1232343

amount_out

string

1000000000

input_token_address

string

0x0c48250eb1f29491f1efbeec0261eb556f0973c7

output_token_address

string

0x75c97384ca209f915381755c582ec0e2ce88c1ba

type

string

v0, v2, v3, v2-v2, v2-v3, v3-v2

path

string | string[]

[

'0x0c48250eb1f29491f1efbeec0261eb556f0973c7',

'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',

'0x75c97384ca209f915381755c582ec0e2ce88c1ba'

]

path_bytes

string

是,V3多跳用

pool_address

string | string[]

[

'0xe05d099bfd7f4aa9f2e696f6c3ebe181479961a5',

'0xb54ce26f2e30f64c5b684b141311ce138ab5e00e'

]

factory_address

string | string[]

是,V2多跳用

0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f

fee

string | string[]

是,V3用

3000

steps

array

[ { id: 1, type: 'swap', tool: 'uniswapv2' } ]

token_in_usd_price

string

10.3099800923283

amount_in_usd

string

1.334833

token_out_usd_price

string

0.00000000474642715895

amount_out_usd

string

1.3226

value

string

10000

gas_limit

string

21000

返回data的volatilities字段说明:

字段名字

类型

举例

token_in

Int, 5分钟价格波动率%上面的部分

5

token_out

Int,5分钟价格波动率%上面的部分

10

is_fomo

bool, true or false

true

2. 精确输出

接入点:/defi/router/v1/tx/available_routes_exact_out

请求方式:GET

输入参数:

参数名字

参数说明

是否必须

举例

token_in_chain

网络代号,比如eth/polygon/arb等

eth

token_out_chain

网络代号,比如eth/polygon/arb等

arb

token_in_address

输入token的合约地址

0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

token_out_address

输出token的合约地址

0xb44C0A4624eaEd2C41EB8437d0Fb5A28F91E7335

out_amount

输出token的数量,以最小单位计

100000000

src

来源,可以选择gmgn或者swapx,默认gmgn

swapx

返回参数:

参数名字

参数说明

举例

参数名字

参数说明

举例

msg

出错信息

amountIn is required

code

正确0,错误-1

0

data

返回跨链交易的基本信息,主要包含以下信息:

来源链ID:chain_id,

合约地址:to,

源币种数量:amount_in,

源币种USD价值:amount_in_usd,

输出币种数量:amount_out,

获得币种USD价值:amount_out_usd,

购买币种地址:buy_token_address,

卖出币种地址:sell_token_address,

经过步骤列表:steps,

(其中steps有id/type/tool三个字段)

{"routes":[{"chain_id":1,"to":"0x2abbEAf73456b6c0b1a1E7e32Dbd63Bf4fafAC40","amount_in":"987855194221161593","amount_out":"100000000000000000","input_token_address":"0x481c4572e017e636177920D79db157c0Cf3A4697","output_token_address":"0x2C3Bc638031AAbB701EA5f30c522379dEE5c2B22","type":"v3","path":["0x481c4572e017e636177920D79db157c0Cf3A4697","0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6","0x2C3Bc638031AAbB701EA5f30c522379dEE5c2B22"],"pool_address":["0x717BFacEBD23A5505b061Cf15a9C0fB2Ac1CABE4","0x20A741900D8b8Fcd10b4Af1822EE07622aF165C3"],"fee":[3000,3000],"steps":[{"id":1,"type":"swap","tool":"uniswapv3"}],"token_in_usd_price":0,"amount_in_usd":"0","token_out_usd_price":0,"amount_out_usd":"0","value":0}]}

Last updated