getRouteDetails
The getRouteDetails
method extracts and calculates detailed information about a swap route. It processes both single and multi-path routes and provides comprehensive details about the swap.
Signature
getRouteDetails(): RouteDetails
Returns
Returns an object containing:
totalOut
- Total output amount in raw units (bigint)totalOutFormatted
- Total output amount formatted with token decimals (string)pathPercentages
- Percentage split between paths, e.g., [60, 40] for 60-40 split (number[])pathCount
- Number of paths in the route (number)amountIn
- Total input amount in raw units (bigint)amountInFormatted
- Total input amount formatted with token decimals (string)swapTypes
- Array of swap types for each step (number[])tokenIn
- Input token address (string)tokenOut
- Output token address (string)tokenInData
- Input token metadata from Symphony (object)tokenOutData
- Output token metadata from Symphony (object)route
- Original route array (array)
Example Usage
const symphony = new Symphony();
// Get a route
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// Get detailed information about the route
const details = route.getRouteDetails();
// Access route information
console.log(details.totalOutFormatted); // Expected output amount
console.log(details.pathPercentages); // Split between paths, e.g., [100] or [60, 40]
console.log(details.pathCount); // Number of paths
console.log(details.tokenInData.attributes.symbol); // Input token symbol
Notes
- Provides comprehensive information about the route, including amounts, paths, and token details
- Handles both single-path and multi-path routes
- All amounts are provided in both raw and formatted units
- Token metadata includes decimals, symbols, and other attributes
- Path percentages show how the input amount is split across different paths
Error Handling
The method will throw an error if:
- The route is invalid or empty
- Token data is missing from Symphony
- Path structure is invalid