Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • SwapUtils

Index

Other

  • calculateSwapAmountsFromQuote(amount: BN, estAmountIn: BN, estAmountOut: BN, slippageTolerance: Percentage, amountSpecifiedIsInput: boolean): Pick<SwapInput, "amount" | "otherAmountThreshold">
  • 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.

  • getDefaultOtherAmountThreshold(amountSpecifiedIsInput: boolean): BN
  • 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.

  • getDefaultSqrtPriceLimit(aToB: boolean): BN
  • 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.

  • getSwapParamsFromQuoteKeys(quote: SwapInput, ctx: WhirlpoolContext, whirlpool: PublicKey, tokenVaultA: PublicKey, tokenVaultB: PublicKey, inputTokenAssociatedAddress: Address, outputTokenAssociatedAddress: Address, wallet: PublicKey): SwapParams

Whirlpool Utils

  • getTickArrayPublicKeys(tickCurrentIndex: number, tickSpacing: number, aToB: boolean, programId: PublicKey, whirlpoolAddress: PublicKey): PublicKey[]
  • 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.

  • getTickArrays(tickCurrentIndex: number, tickSpacing: number, aToB: boolean, programId: PublicKey, whirlpoolAddress: PublicKey, fetcher: WhirlpoolAccountFetcherInterface, opts?: SimpleAccountFetchOptions): Promise<TickArray[]>
  • 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
    • Optional opts: 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.

Generated using TypeDoc