/swap
Overview
Unlike most DEX aggregators, our swap endpoint provides graph-based routing plans with optional on-demand calldata generation. Each routing plan specifies the exact amounts and tokens to trade with various liquidity sources, including AMMs and market maker liquidity.
When calldata is not requested, clients can use an encoder to convert the routing plans into transaction calldata for any compatible router contract. This flexibility allows you to choose the most suitable router for your specific use case.
By establishing a standardized format for routing plans, our approach decouples the aggregator API from specific router contracts. This standardization enables seamless encoding and settlement of routing results from any compatible aggregator using any supported router contract.
API schema
Swap endpoint
https://app.swap-net.xyz/api/v1.0/swapParameters
sellToken
Yes
Address of sell token¹
Blockchain addresses
buyToken
Yes
Address of buy token¹
Blockchain addresses
sellAmount
Yes²
Amount of sellToken to sell (in base units)
Positive integers
buyAmount
Yes²
Amount of buyToken to buy (in base units)
Positive integers
useRfq
No (default: false)
Whether to use market maker RFQ liquidity
boolean
includeCalldata
No (default: false)
Whether to include calldata in the response
boolean
userAddress
Yes if includeCalldata=true
User's wallet address
Blockchain addresses
recipientAddress
No
The address to receive buyToken³
Blockchain addresses
slippageTolerance
Yes if includeCalldata=true
Slippage tolerance (0.01 = 1%)
Decimal numbers between 0 and 1
apiKey
Yes
Your API key
string
¹ For native tokens, use either 0x0000000000000000000000000000000000000000 or 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee as the token address.
² Exactly one of sellAmount or buyAmount must be provided, but not both. Specify sellAmount for exact-input swaps or buyAmount for exact-output swaps.
³ If not set, buyToken will be sent to msg.sender.
Simple query example
Response includes:
tokens
Metadata of a list of tokens involved in the routing result. Including token's address, name, symbol, decimals, usdPrice, and a referenceId used to refer to the token.
sell
Contains referenceId and amount of the token the user wants to sell, and may include a wrapFromNative boolean field if the sell token is native token.
buy
Contains referenceId and amount of the token the user wants to buy, and may include an unwrapToNative boolean field if the buy token is native token.
nativeTokenUsdPrice
Current price of the native token on this chain.
routes
A collection of swaps forming a directed acyclic graph that converts all sell tokens into buy tokens. Note that the order of the routes is not guaranteed.
route.name
Name of the liquidity source used by this route (swap).
route.address
Address of the liquidity pool.
route.fromTokens
Array containing referenceId and amount of tokens to swap from.
route.toTokens
Array containing referenceId and amount of tokens to swap to.
route.details
Additional information about this route (swap) which is used during encoding.
Example with includeCalldata=true
includeCalldata=trueResponse includes three more fields:
routerAddress
Address of router contract
calldata
Calldata to settle the trade with the router contract
gasLimit
An estimated upper bound of gas consumption, used to config the TX
Last updated