arrow-progressRoutes API

Calculate Optimal Swap Paths

post

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.

Body
amountstring · decimalRequired

The amount of the input token to swap, represented as a string to preserve precision.

Example: 10.34
inputTokenAddressstring · addressRequired

The contract address of the token being swapped FROM.

Example: 0xEa237441c92CAe6FC17Caaf9a7acB3f953be4bd1Pattern: ^0x[a-fA-F0-9]{40}$
outputTokenAddressstring · addressRequired

The contract address of the token being swapped TO.

Example: 0xdddD73F5Df1F0DC31373357beAC77545dC5A6f3FPattern: ^0x[a-fA-F0-9]{40}$
Responses
chevron-right
200

Successfully calculated and returned the top swap paths.

application/json
post
/api/swap

RPC Calls to Quoter

With the paths, a user can use RPC calls to the MaverickV2Quoterarrow-up-right contract and calculateMultiHopSwap function to get the prices.

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).

Last updated