Route Class
The Route class represents a found route for token swapping. It contains methods for executing swaps and managing approvals.
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 address
Methods
getConfig
getConfig(): SymphonyConfig
Returns the current configuration of the Symphony instance.
setConfig
setConfig(options: Partial<SymphonyConfig>): void
Updates the configuration of the Symphony instance.
swap
async swap(options?: {
skipApproval?: boolean,
skipCheckApproval?: boolean
}): Promise<{
swapReceipt: TransactionReceipt,
approveReceipt?: TransactionReceipt
}>
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(): Promise<TransactionReceipt>
Approves the Symphony contract to spend tokens on behalf of the user.
Returns
- Transaction receipt of the approval transaction
checkApproval
async checkApproval(): Promise<boolean>
Checks if the Symphony contract has approval to spend tokens.
Returns
true
if approval is sufficient,false
otherwise
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 prices
getRouteDetails
getRouteDetails(): RouteDetails
Returns detailed information about the route.
getTokenIn
getTokenIn(): string
Returns the input token address.
getTokenOut
getTokenOut(): string
Returns 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
getTotalAmountIn(): {
amountIn: bigint,
amountInFormatted: string,
tokenIn: string,
tokenOut: string
}
Returns the total input amount required for the swap.
getTotalAmountOut
getTotalAmountOut(): {
amountOut: bigint,
amountOutFormatted: string,
tokenIn: string,
tokenOut: string
}
Returns the expected output amount from the swap.