Convienience class to find routes through a set of Whirlpools and execute a swap across them. The router only supports up to 2-hop trades between pools and does not support arbitrage trades between the same token.

WhirlpoolRouter will be removed in the future release. Please use endpoint which provides qoutes.

interface WhirlpoolRouter {
    findAllRoutes(trade: Trade, opts?: Partial<RoutingOptions>, fetchOpts?: SimpleAccountFetchOptions): Promise<TradeRoute[]>;
    findBestRoute(trade: Trade, opts?: Partial<RoutingOptions>, selectionOpts?: Partial<RouteSelectOptions>, fetchOpts?: SimpleAccountFetchOptions): Promise<null | ExecutableRoute>;
    swap(trade: TradeRoute, slippage: Percentage, resolvedAtas: null | AtaAccountInfo[]): Promise<TransactionBuilder>;
}

Methods

  • Finds all possible routes for a trade and select the best route that is executable under the current execution environment.

    Parameters

    Returns Promise<null | ExecutableRoute>

    The best ExecutableRoute that can be used to execute a swap. If no executable route is found, null is returned.

    WhirlpoolRouter will be removed in the future release. Please use endpoint which provides qoutes.

  • Construct a TransactionBuilder to help execute a trade route.

    Parameters

    • trade: TradeRoute

      The trade route to execute.

    • slippage: Percentage

      The slippage tolerance for the trade.

    • resolvedAtas: null | AtaAccountInfo[]

      The ATA accounts that the executing wallet owns / needed by the execution. If not provided, the router will attempt to resolve them.

    Returns Promise<TransactionBuilder>

    A TransactionBuilderthat can be used to execute the trade. If provvided from ExecutableRoute, plug the AddressLookupTableAccounts into builder to lower the transaction size.

    WhirlpoolRouter will be removed in the future release. Please use endpoint which provides qoutes.