Other

  • Calculate the SwapInput parameters amount & otherAmountThreshold based on the amountIn & amountOut estimates from a quote.

    Parameters

    • amount: BN

      The amount of tokens the user wanted to swap from.

    • estAmountIn: BN

      The estimated amount of input tokens expected in a SwapQuote

    • estAmountOut: BN

      The estimated amount of output tokens expected from a SwapQuote

    • slippageTolerance: Percentage

      The amount of slippage to adjust for.

    • amountSpecifiedIsInput: boolean

      Specifies the token the parameter amountrepresents in the swap quote. If true, the amount represents the input token of the swap.

    Returns Pick<SwapInput, "amount" | "otherAmountThreshold">

    A Partial SwapInput object containing the slippage adjusted 'amount' & 'otherAmountThreshold' parameters.

  • Get the default values for the otherAmountThreshold parameter in a swap.

    Parameters

    • amountSpecifiedIsInput: boolean

      The direction of a swap

    Returns BN

    The default values for the otherAmountThreshold parameter in a swap.

  • Get the default values for the sqrtPriceLimit parameter in a swap.

    Parameters

    • aToB: boolean

      The direction of a swap

    Returns BN

    The default values for the sqrtPriceLimit parameter in a swap.

  • Given the intended token mint to swap, return the swap direction of a swap for a Whirlpool

    Parameters

    • pool: WhirlpoolData

      The Whirlpool to evaluate the mint against

    • swapTokenMint: PublicKey

      The token mint PublicKey the user bases their swap against

    • swapTokenIsInput: boolean

      Whether the swap token is the input token. (similar to amountSpecifiedIsInput from swap Ix)

    Returns undefined | SwapDirection

    The direction of the swap given the swapTokenMint. undefined if the token mint is not part of the trade pair of the pool.

  • Parameters

    • quote: SwapInput
    • ctx: WhirlpoolContext
    • whirlpool: PublicKey
    • tokenVaultA: PublicKey
    • tokenVaultB: PublicKey
    • inputTokenAssociatedAddress: Address
    • outputTokenAssociatedAddress: Address
    • wallet: PublicKey

    Returns SwapParams

  • Given a set of tickArrays, interpolate the tickArrays with zeroed tick data if they are not initialized.

    Parameters

    • whirlpoolAddress: PublicKey

      PublicKey of the whirlpool to swap on.

    • tickArrays: TickArray[]

      Fetched tickArrays to interpolate.

    Returns TickArray[]

    An array of TickArray objects with zeroed tick data if they are not initialized.

Whirlpool Utils

  • Given the tickArrays, return the fallback tickArray account that this swap may traverse across.

    Parameters

    • tickArrays: TickArray[]

      An array of tickArrays to be used in the swap.

    • tickSpacing: number

      The tickSpacing for the Whirlpool.

    • aToB: boolean

      The direction of the trade.

    • programId: PublicKey

      The Whirlpool programId which the Whirlpool lives on.

    • whirlpoolAddress: PublicKey

      PublicKey of the whirlpool to swap on.

    Returns undefined | PublicKey

    A PublicKey for the fallback tickArray account that this swap may traverse across. If the fallback tickArray does not exist, return undefined.

  • Given the current tick-index, returns the dervied PDA and fetched data for the tick-arrays that this swap may traverse across.

    Parameters

    • tickCurrentIndex: number

      The current tickIndex for the Whirlpool to swap on.

    • tickSpacing: number

      The tickSpacing for the Whirlpool.

    • aToB: boolean

      The direction of the trade.

    • programId: PublicKey

      The Whirlpool programId which the Whirlpool lives on.

    • whirlpoolAddress: PublicKey

      PublicKey of the whirlpool to swap on.

    Returns PublicKey[]

    An array of PublicKey[] for the tickArray accounts that this swap may traverse across.

  • Given the current tick-index, returns TickArray objects that this swap may traverse across.

    Parameters

    • tickCurrentIndex: number

      The current tickIndex for the Whirlpool to swap on.

    • tickSpacing: number

      The tickSpacing for the Whirlpool.

    • aToB: boolean

      The direction of the trade.

    • programId: PublicKey

      The Whirlpool programId which the Whirlpool lives on.

    • whirlpoolAddress: PublicKey

      PublicKey of the whirlpool to swap on.

    • fetcher: WhirlpoolAccountFetcherInterface
    • Optionalopts: SimpleAccountFetchOptions

      an WhirlpoolAccountFetchOptions object to define fetch and cache options when accessing on-chain accounts

    Returns Promise<TickArray[]>

    An array of PublicKey[] for the tickArray accounts that this swap may traverse across.