Routes API
Last updated
Last updated
calculateMultiHopSwap
Calculates a multihop swap and returns the resulting amount and estimated gas. The gas estimate is only a rough estimate and may not match a swap's gas.
Copy
Parameters
path
bytes
The path of pools to swap through. Path is given by an packed array of (pool, tokenAIn)
tuples. So each step in the path is 160 + 8 = 168 bits of data. e.g. path = abi.encodePacked(pool1, true, pool2, false);
amount
uint256
The raw input amount. (e.g. 1.0 in an 18-decimal token will be 1e18)
exactOutput
bool
A boolean indicating whether amount
is the desired input amount (false
) or the desired output amount (true
).
With the paths, a user can use RPC calls to the contract and calculateMultiHopSwap
function to get the prices.
Accepts an input token, output token, and the amount to swap. Queries available liquidity pools, calculates potential 1-hop, 2-hop, and 3-hop paths, checks for sufficient liquidity for the given amount, scores the paths based on liquidity, volume, and fees, and returns the top 5 ranked paths.
The amount of the input token to swap, represented as a string to preserve precision.
10.34
The contract address of the token being swapped FROM.
0xEa237441c92CAe6FC17Caaf9a7acB3f953be4bd1
Pattern: ^0x[a-fA-F0-9]{40}$
The contract address of the token being swapped TO.
0xdddD73F5Df1F0DC31373357beAC77545dC5A6f3F
Pattern: ^0x[a-fA-F0-9]{40}$