1️⃣Get Quote
This endpoint will return currently available routes with estimated target token amount for your quote. You can also designate specific bridges or aggregator to customize the route. If there is no available route, it will return an error_code, which you can reference here to get error detail.
Source chain ID.
Source chain quote token address.
Source chain quote token amount.
Destination chain ID.
Destination chain quote token address.
Percentage of slippage tolerance.
Affiliate address.
Commission rate of affiliate, denominator is 1000000. Affiliate must be provided when passing commissionRate.
Designated providers for source chain swap. Separate by comma. Will use all available providers if empty.
Designated providers for bridge operation. Separate by comma. Will use all available providers if empty.
Designated providers for destination chain swap. Separate by comma. Will use all available providers if empty.
GET /v1/quote HTTP/1.1
Host: aggregator-api.xy.finance
Accept: */*
Successful Response
{
"success": true,
"routes": [
{
"srcChainId": 42161,
"srcQuoteTokenAddress": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"srcQuoteTokenAmount": "999000000",
"dstChainId": 59144,
"dstQuoteTokenAddress": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"slippage": 1,
"bridgeDescription": {
"provider": "yBridge",
"srcChainId": 42161,
"srcBridgeTokenAddress": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"dstChainId": 59144,
"dstBridgeTokenAddress": "0x176211869cA2b568f2A7D4EE941E073a821EE1ff",
"srcBridgeTokenAmount": "999000000",
"dstBridgeTokenAmount": "997500000",
"bridgeContractAddress": "0x33383265290421C704c6b09F4BF27ce574DC4203",
"bridgeFeeAmount": "1500000",
"bridgeFeeToken": {
"chainId": 42161,
"address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"decimals": 6,
"symbol": "USDC"
},
"srcBridgeToken": {
"chainId": 42161,
"address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"decimals": 6,
"symbol": "USDC"
},
"dstBridgeToken": {
"chainId": 59144,
"address": "0x176211869cA2b568f2A7D4EE941E073a821EE1ff",
"decimals": 6,
"symbol": "USDC"
}
},
"dstSwapDescription": {
"chainId": "59144",
"provider": "OpenOcean V3 DexAggregator",
"srcTokenAddress": "0x176211869cA2b568f2A7D4EE941E073a821EE1ff",
"dstTokenAddress": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"srcTokenAmount": "997500000",
"dstTokenAmount": "609954227563476606",
"dexNames": [
"Horizon"
]
},
"dstQuoteTokenAmount": "609954227563476606",
"minReceiveAmount": "603854685287841839",
"affiliateFeeAmount": "1000000",
"withholdingFeeAmount": "0",
"routeType": "xy_router_cross_chain",
"tags": [],
"contractAddress": "0xd6FEbBCCBc78d89B63ee539d497eF530270FD3f7",
"withholdingFeeToken": {
"chainId": 42161,
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"decimals": 18,
"symbol": "ETH"
},
"srcQuoteToken": {
"chainId": 42161,
"address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"decimals": 6,
"symbol": "USDC"
},
"dstQuoteToken": {
"chainId": 59144,
"address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"decimals": 18,
"symbol": "ETH"
},
"srcQuoteTokenUsdValue": "999",
"dstQuoteTokenUsdValue": "999.1355224603528544583",
"transactionCounts": 2,
"estimatedGas": "400000",
"estimatedTransferTime": 180
}
]
}
Parameter/Response Details
Use
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
as the address for the native token in your parameter.If you would like to know more about commissionRate fields and fee collection function, please refer to Monetization / Take Fees
If you would like to know latest supported bridge provider and swap provider, please refer to Supported Blockchains/Bridges/DEXs
The
estimatedGas
field in the API response is an estimated value. For now, please use a method similar to RPC, such as eth_estimateGas, to re-estimate the actual gas limit. You can refer to the following sample code to do that:
from web3 import Web3
import requests
if __name__ == "__main__":
# 1st: get tx data from xy aggregator api
endpoint = 'https://aggregator-api.xy.finance/v1/buildTx?srcChainId=137&srcQuoteTokenAddress=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&srcQuoteTokenAmount=9000000000000000000&dstChainId=56&dstQuoteTokenAddress=0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d&slippage=1&receiver=0x9cEEEbdF49cF5DEa891C9D74f8ea03af2aCf284F&bridgeProvider=yBridge&srcBridgeTokenAddress=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174&dstBridgeTokenAddress=0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d&srcSwapProvider=OneInch%20V4%20DexAggregator&affiliate=0x512E00f66217714BAee5F0736428b026e8c30AF5'
resp = requests.get(endpoint)
resp_json = resp.json()
# 2nd: get estimateGas by calling web3 rpc
rpc_endpoint = 'https://polygon.llamarpc.com'
w3 = Web3(Web3.HTTPProvider(rpc_endpoint))
estimate_gas = w3.eth.estimate_gas(resp_json["tx"])
# 3rd: Combine the estimateGas with the tx data
tx = resp_json["tx"]
tx["gas"] = estimate_gas
# 4th: sign the tx & send it
priv_key = "0x"
tx_signed = w3.eth.account.sign_transaction(tx, priv_key)
tx_hash = w3.eth.send_raw_transaction(tx_signed.rawTransaction)
Example Request
$ curl "https://aggregator-api.xy.finance/v1/quote?srcChainId=10&srcQuoteTokenAddress=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&srcQuoteTokenAmount=1000000000000000000&dstChainId=56&dstQuoteTokenAddress=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&slippage=1&bridgeProviders=yBridge
This request is asking a quote of 1 ETH on Optimism to ETH on Arbitrum Chain and designate yBridge as bridgeProvider.
IMPORTANT:
Note that the amount parameter should be padded with zeroes. For example, pass
100000000
instead of
100
if the decimals of the token is 6.
Last updated
Was this helpful?