Find Best Paths

Function input params

  • fromToken: the token address about from.

  • toToken: the token address about to.

  • byAmountIn: If set true, it means fixed amount of input token, otherwise fixed amount of output token.

  • amount: when byAmountIn set true, it means amount of input token, otherwise means amount of output token.

  • maxHops(Option): the max hops number, default set 2.

Result Params

  • combinedPaths: the detail about router path.

    • basicPaths: the detail about one hop(in one pool)

      • poolAddress: the address of clmm pool

      • decimal0: the decimal of token0 of pool.

      • decimal1: the decimal of token1 of pool.

      • a2b: the swap direction.

      • byAmountIn: the fixed direction in this pool, the same as input params.

      • isExceed: is exceed in this pool.

      • feeAmount: the amount of fee.

      • feeRate: the fee rate of pool.

      • currentSqrtPrice: the sqrt price of pool before swap.

      • afterSqrtPrice: the sqrt price of pool after swap.

      • amountIn(Option): the amount of input in this pool.

      • amountOut(Option): the amount of output in this pool.

    • amountIn: the amount of input in this combined path.

    • amountOut: the amount of output in this combined path.

    • isExceed: is this combined path exceed.

    • feeAmount: the total amount of fee in this combined path.

    • percent: the percent of input/output amount(base of byAmountIn).

  • amountIn: the amount of input.

  • amountOut: the amount of output.

  • isExceed: the router result is exceed.

  • feeAmount: the amount of fee.

  • byAmountIn: the same as input params.

  • priceImpact: the impact between swaped price and init price.

  • amountTooSmall: if input amount is too small when fixed input amount(byAmountIn = true).

    combinedPaths: RouterCombinedPath[]
    amountIn: number
    amountOut: number
    isExceed: boolean
    feeAmount: number
    byAmountIn: boolean
    priceImpact: number
    amountTooSmall: boolean

Example

const token0 = 0x4b7cf6f28fdff5237c85b77f2ba4adabdca4f5c69877d314ba28e776d4d2730f
const token1 = 0x9976e868ba06d58fb8566b294efcf5ac6929aa7a0f306afc90313abc0d6a3ec4
const res = await tucanaRouterClient.findBestPaths(token0, token1, true, 100000000)

Last updated