Pathfinder API - the Route Request Response
Sample Response
The Route Response object contains the following fields:
A route request JSON object contains the following fields:
token_out: Hex-string formatted swap output token address
token_in: Hex-string formatted swap input token address
amount_in: Hex-string formatted swap amount in
amount_out: Hex-string formatted swap amount out (quote)
swap_paths: Bytecode package for on-chain token swap call
swap_viz_data: Data for graphical representation of the swap paths
price impact: Estimated price impact for the swap.*
Confirming the quote on-chain
The quoted price can be confirmed via an on-chain call to the BrainDex Router contract by passing the route route request response swap_paths
to getMultiSwapAmountOut() on the BrainDex Router contract.
Quote Confirmation function definition
Sample quote confirmation call using wagmi.sh
Route Response Parameters In-Depth
Contract call parameters
The following parameters are necessary inputs for the onchain call to perform the swap.
token_in
Hex-string formatted ethereum-style address. Should echo the token_in from the route request object.
token_out
Hex-string formatted ethereum-style address. Should echo the token_out from the route request object.
amount_in
Hex-string formatted integer value. Should echo the amount_in from the route request object.
amount_out
Hex-string formatted integer value, the swap output quote.
swap_paths
Hex-string formatted bytes package representing the routing data for the above parameters. Can be passed to the view function getMultiSwapAmountOut on the BrainDex Router to confirm quote result on chain.
Route visualization parameters
The following parameter is for route visualization via frontend interface.
price_impact
A decimal-formatted percentage value indicating the estimated price impact of the swap. Price impact is calculated as the weighted average of the sum of the price impacts for each hop in a route.
swap_viz_data
Array of path objects. Each element of the array represents one, the net of which represents the total route.
route_tokens
Array of token addresses, each representing one hop in the swap path. The first element should always be token_in, and the last element should always be token_out of above route response object. Intermediary addresses represent tokens used as intermediaries in a cross-trade route.
route_protocols
Array of protocol IDs, each representing the protocol through which the above swap was processed. This array should always be one element shorter than route_tokens, as the protocols represent the pool through which the tokens were swapped.
route_percent
Number value representing what percentage of the total swap volume was used for the given route. A value of 95 signifies that 95% of the total swap amount_in was routed through this route, whereas a value of 5 signifies that 5% of the total swap volume was routed through this route. For a given route response, all route_percents should sum to 100.
Price Impact Note
Due to the nature of cross-route swaps, sometimes price impact may be higher than 100%. This may change in the future.
Last updated