Routes API
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}$
POST /api/swap HTTP/1.1
Host: api.rooster-protocol.xyz
Content-Type: application/json
Accept: */*
Content-Length: 149
{
"amount": "10.34",
"inputTokenAddress": "0xEa237441c92CAe6FC17Caaf9a7acB3f953be4bd1",
"outputTokenAddress": "0xdddD73F5Df1F0DC31373357beAC77545dC5A6f3F"
}
{
"paths": [
[
"0x4a14398c5c5b4b7913954cb82521fb7afa676314",
false
],
[
"0x10b02da17f82f263252c6ac9e2f785cb9fe4d544",
false,
"0x8872127381209fd106e48666b2ecad4a151c9ea9",
true
],
[
"0x098dbf700286109e3bcd1465f00a6554488ec148",
false,
"0xb1ac405847eaa909a67a7e5d67d61115303f6fa0",
false
]
]
}
RPC Calls to Quoter
With the paths, a user can use RPC calls to the MaverickV2Quoter 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
function calculateMultiHopSwap(bytes memory path, uint256 amount, bool exactOutput)
external
returns (uint256 returnAmount, uint256 gasEstimate);
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