Route Class
The Route class represents a found route for token swapping. It contains methods for executing swaps and managing approvals.
TypeScript Types
// Import for viem
import { Route } from 'symphony-sdk/viem';
import type { RoutePayload, SwapResult } from 'symphony-sdk/types/viem';
import type { TransactionReceipt } from 'viem';
// Import for ethersV5
import { Route } from 'symphony-sdk/ethersV5';
import type { RoutePayload, SwapResult } from 'symphony-sdk/types/ethersV5';
import type { TransactionReceipt } from 'ethers';
// Import for ethers v6
import { Route } from 'symphony-sdk/ethers';
import type { RoutePayload, SwapResult } from 'symphony-sdk/types/ethers';
import type { TransactionReceipt } from 'ethers';Properties
route: Raw route data from the APIamountIn: Input amount in raw unitsamountInFormatted: Input amount formattedamountOut: Output amount in raw unitsamountOutFormatted: Output amount formattedpathPercentages: Split between pathspathCount: Number of pathsincludesNative: Whether route includes native tokentokenIn: Input token addresstokenOut: Output token addressswapFee: Fee that Symphony gets on execution of Route.tokenInUsd: USD value of a tokenIn.tokenOutUsd: USD value of a tokenOut.priceImpactPercentage: Price impact percentage that Route has. Could be positive due to efficient routing provided by Symphony.
Methods
getConfig
getConfig(): SymphonyConfigReturns the current configuration of the Symphony instance.
setConfig
setConfig(options: Partial<SymphonyConfig>): voidUpdates the configuration of the Symphony instance.
swap
async swap(params?: {
signer?: Signer; // ethers/ethersV5
walletClient?: WalletClient; // viem
options?: {
skipApproval?: boolean;
skipCheckApproval?: boolean;
wait?: number;
isRaw?: boolean;
outTokenDecimals?: number;
};
slippage?: {
slippageAmount?: string | number;
isBps?: boolean;
}
}): Promise<SwapResult>Executes the token swap using the found route. Requires a connected wallet.
Returns
swapReceipt: Transaction receipt of the swapapproveReceipt: Transaction receipt of the approval (if applicable)
Example
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
const { swapReceipt, approveReceipt } = await route.swap();
console.log(`Swap executed: ${swapReceipt.transactionHash}`);
if (approveReceipt) {
console.log(`Approval executed: ${approveReceipt.transactionHash}`);
}giveApproval
async giveApproval(params?: {
signer?: Signer; // ethers/ethersV5
walletClient?: WalletClient; // viem
amount?: string | bigint;
options?: {
isRaw?: boolean;
wait?: number;
}
}): Promise<TransactionReceipt>Approves the Symphony contract to spend tokens on behalf of the user. Supports custom approval amounts.
Returns
- Transaction receipt of the approval transaction (already waited for confirmations)
checkApproval
async checkApproval(params?: {
signer?: Signer; // ethers/ethersV5
walletClient?: WalletClient; // viem
amount?: string | bigint;
includesNative?: boolean;
options?: {
isRaw?: boolean;
}
}): Promise<boolean>Checks if the Symphony contract has approval to spend tokens.
Returns
trueif approval is sufficient,falseotherwise
refresh
async refresh(): Promise<Route>Refreshes the route with current market prices.
Returns
- A new Route instance with updated prices
Example
let route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// Wait some time...
route = await route.refresh(); // Get updated pricesgetRouteDetails
async getRouteDetails(): Promise<RouteDetails>Returns detailed information about the route. This method is async as of v3.0.0.
getTokenIn
getTokenIn(): stringReturns the input token address.
getTokenOut
getTokenOut(): stringReturns the output token address.
getSwapTypes
getSwapTypes(): number[][]Returns the types of swaps used in the route.
getTokenList
getTokenList(): Token[]Returns a list of all tokens involved in the route.
getTotalAmountIn
async getTotalAmountIn(): Promise<{
amountIn: bigint | BigNumber; // bigint for viem/ethers v6, BigNumber for ethersV5
amountInFormatted: string;
tokenIn: string;
tokenOut: string;
}>Returns the total input amount required for the swap. This method is async as of v3.0.0.
getTotalAmountOut
async getTotalAmountOut(): Promise<{
amountOut: bigint | BigNumber; // bigint for viem/ethers v6, BigNumber for ethersV5
amountOutFormatted: string;
tokenIn: string;
tokenOut: string;
}>Returns the expected output amount from the swap. This method is async as of v3.0.0.

