Documentation
    Preparing search index...

    Helper class to interact with a Whirlpool account and build complex transactions.

    interface Whirlpool {
        closePosition: (
            positionAddress: Address,
            slippageTolerance: Percentage,
            destinationWallet?: Address,
            positionWallet?: Address,
            payer?: Address,
            usePriceSlippage?: boolean,
        ) => Promise<TransactionBuilder[]>;
        getAddress: () => PublicKey;
        getData: () => WhirlpoolData;
        getRewardInfos: () => WhirlpoolRewardInfo[];
        getTokenAInfo: () => TokenInfo;
        getTokenBInfo: () => TokenInfo;
        getTokenVaultAInfo: () => AccountWithTokenProgram;
        getTokenVaultBInfo: () => AccountWithTokenProgram;
        initTickArrayForTicks: (
            ticks: number[],
            funder?: Address,
            opts?: SimpleAccountFetchOptions,
        ) => Promise<null | TransactionBuilder>;
        openPosition: (
            tickLower: number,
            tickUpper: number,
            liquidityInput: IncreaseLiquidityInput,
            wallet?: Address,
            funder?: Address,
            positionMint?: PublicKey,
            tokenProgramId?: PublicKey,
        ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>;
        openPositionWithMetadata: (
            tickLower: number,
            tickUpper: number,
            liquidityInput: IncreaseLiquidityInput,
            wallet?: Address,
            funder?: Address,
            positionMint?: PublicKey,
            tokenProgramId?: PublicKey,
        ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>;
        refreshData: () => Promise<WhirlpoolData>;
        swap: (input: SwapInput, wallet?: PublicKey) => Promise<TransactionBuilder>;
        swapWithDevFees: (
            input: DevFeeSwapInput,
            devFeeWallet: PublicKey,
            wallet?: PublicKey,
            payer?: PublicKey,
        ) => Promise<TransactionBuilder>;
    }
    Index

    Properties

    closePosition: (
        positionAddress: Address,
        slippageTolerance: Percentage,
        destinationWallet?: Address,
        positionWallet?: Address,
        payer?: Address,
        usePriceSlippage?: boolean,
    ) => Promise<TransactionBuilder[]>

    Withdraw all tokens from a position, close the account and burn the position token.

    Users have to collect all fees and rewards from this position prior to closing the account.

    If positionWallet, payer is provided, the wallet owner has to sign this transaction.

    Type declaration

      • (
            positionAddress: Address,
            slippageTolerance: Percentage,
            destinationWallet?: Address,
            positionWallet?: Address,
            payer?: Address,
            usePriceSlippage?: boolean,
        ): Promise<TransactionBuilder[]>
      • Parameters

        • positionAddress: Address

          The address of the position account.

        • slippageTolerance: Percentage

          The amount of slippage the caller is willing to accept when withdrawing liquidity.

        • OptionaldestinationWallet: Address

          The wallet that the tokens withdrawn and rent lamports will be sent to. If null, the WhirlpoolContext wallet is used.

        • OptionalpositionWallet: Address

          The wallet that houses the position token that corresponds to this position address. If null, the WhirlpoolContext wallet is used.

        • Optionalpayer: Address

          the wallet that will fund the cost needed to initialize the token ATA accounts. If null, the WhirlpoolContext wallet is used.

        • OptionalusePriceSlippage: boolean

          if true, use the price slippage to calculate the minimum tokens to receive. If false, use the token slippage.

        Returns Promise<TransactionBuilder[]>

        transactions that will close the position. The transactions must be executed serially.

    getAddress: () => PublicKey

    Return the address for this Whirlpool instance.

    Type declaration

      • (): PublicKey
      • Returns PublicKey

        the PublicKey for this Whirlpool instance.

    getData: () => WhirlpoolData

    Return the most recently fetched Whirlpool account data.

    Type declaration

    getRewardInfos: () => WhirlpoolRewardInfo[]

    Get the WhirlpoolRewardInfos for this pool.

    Type declaration

      • (): WhirlpoolRewardInfo[]
      • Returns WhirlpoolRewardInfo[]

        Array of 3 WhirlpoolRewardInfos. However, not all of them may be initialized. Use the initialized field on WhirlpoolRewardInfo to check if the reward is active.

    getTokenAInfo: () => TokenInfo

    Get the TokenInfo for token A of this pool.

    Type declaration

    getTokenBInfo: () => TokenInfo

    Get the TokenInfo for token B of this pool.

    Type declaration

    getTokenVaultAInfo: () => AccountWithTokenProgram

    Get the TokenAccountInfo for token vault A of this pool.

    Type declaration

    getTokenVaultBInfo: () => AccountWithTokenProgram

    Get the TokenAccountInfo for token vault B of this pool.

    Type declaration

    initTickArrayForTicks: (
        ticks: number[],
        funder?: Address,
        opts?: SimpleAccountFetchOptions,
    ) => Promise<null | TransactionBuilder>

    Initialize a set of tick-arrays that encompasses the provided ticks.

    If funder is provided, the funder wallet has to sign this transaction.

    Type declaration

      • (
            ticks: number[],
            funder?: Address,
            opts?: SimpleAccountFetchOptions,
        ): Promise<null | TransactionBuilder>
      • Parameters

        • ticks: number[]

          A group of ticks that define the desired tick-arrays to initialize. If the tick's array has been initialized, it will be ignored.

        • Optionalfunder: Address

          the wallet that will fund the cost needed to initialize the position. If null, the WhirlpoolContext wallet is used.

        • Optionalopts: SimpleAccountFetchOptions

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

        Returns Promise<null | TransactionBuilder>

        a transaction that will initialize the defined tick-arrays if executed. Return null if all of the tick's arrays are initialized.

    openPosition: (
        tickLower: number,
        tickUpper: number,
        liquidityInput: IncreaseLiquidityInput,
        wallet?: Address,
        funder?: Address,
        positionMint?: PublicKey,
        tokenProgramId?: PublicKey,
    ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>

    Open and fund a position on this Whirlpool.

    User has to ensure the TickArray for tickLower and tickUpper has been initialized prior to calling this function.

    If wallet or funder is provided, those wallets have to sign this transaction.

    Type declaration

      • (
            tickLower: number,
            tickUpper: number,
            liquidityInput: IncreaseLiquidityInput,
            wallet?: Address,
            funder?: Address,
            positionMint?: PublicKey,
            tokenProgramId?: PublicKey,
        ): Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>
      • Parameters

        • tickLower: number

          the tick index for the lower bound of this position

        • tickUpper: number

          the tick index for the upper bound of this position

        • liquidityInput: IncreaseLiquidityInput

          an InputLiquidityInput type to define the desired liquidity amount to deposit

        • Optionalwallet: Address

          the wallet to withdraw tokens to deposit into the position and house the position token. If null, the WhirlpoolContext wallet is used.

        • Optionalfunder: Address

          the wallet that will fund the cost needed to initialize the position. If null, the WhirlpoolContext wallet is used.

        • OptionalpositionMint: PublicKey

          the mint address of the position token to be created. If null, a new mint address will be created.

        • OptionaltokenProgramId: PublicKey

          the token program id to use for the position token. The default is TOKEN_PROGRAM_ID.

        Returns Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>

        positionMint - the position to be created. tx - The transaction containing the instructions to perform the operation on chain.

    openPositionWithMetadata: (
        tickLower: number,
        tickUpper: number,
        liquidityInput: IncreaseLiquidityInput,
        wallet?: Address,
        funder?: Address,
        positionMint?: PublicKey,
        tokenProgramId?: PublicKey,
    ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>

    Open and fund a position with meta-data on this Whirlpool.

    User has to ensure the TickArray for tickLower and tickUpper has been initialized prior to calling this function.

    If wallet or funder is provided, the wallet owners have to sign this transaction.

    Type declaration

      • (
            tickLower: number,
            tickUpper: number,
            liquidityInput: IncreaseLiquidityInput,
            wallet?: Address,
            funder?: Address,
            positionMint?: PublicKey,
            tokenProgramId?: PublicKey,
        ): Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>
      • Parameters

        • tickLower: number

          the tick index for the lower bound of this position

        • tickUpper: number

          the tick index for the upper bound of this position

        • liquidityInput: IncreaseLiquidityInput

          input that defines the desired liquidity amount and maximum tokens willing to be to deposited.

        • Optionalwallet: Address

          the wallet to withdraw tokens to deposit into the position and house the position token. If null, the WhirlpoolContext wallet is used.

        • Optionalfunder: Address

          the wallet that will fund the cost needed to initialize the position. If null, the WhirlpoolContext wallet is used.

        • OptionalpositionMint: PublicKey

          the mint address of the position token to be created. If null, a new mint address will be created.

        • OptionaltokenProgramId: PublicKey

          the token program id to use for the position token. The default is TOKEN_PROGRAM_ID.

        Returns Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>

        positionMint - the position to be created. tx - The transaction containing the instructions to perform the operation on chain.

    refreshData: () => Promise<WhirlpoolData>

    Fetch and return the most recently fetched Whirlpool account data.

    Type declaration

    swap: (input: SwapInput, wallet?: PublicKey) => Promise<TransactionBuilder>

    Perform a swap between tokenA and tokenB on this pool.

    Type declaration

      • (input: SwapInput, wallet?: PublicKey): Promise<TransactionBuilder>
      • Parameters

        • input: SwapInput

          A quote on the desired tokenIn and tokenOut for this swap. Use swapQuoteWithParams or other swap quote functions to generate this object.

        • Optionalwallet: PublicKey

          The wallet that tokens will be withdrawn and deposit into. If null, the WhirlpoolContext wallet is used.

        Returns Promise<TransactionBuilder>

        a transaction that will perform the swap once executed.

    swapWithDevFees: (
        input: DevFeeSwapInput,
        devFeeWallet: PublicKey,
        wallet?: PublicKey,
        payer?: PublicKey,
    ) => Promise<TransactionBuilder>

    Collect a developer fee and perform a swap between tokenA and tokenB on this pool.

    Type declaration

      • (
            input: DevFeeSwapInput,
            devFeeWallet: PublicKey,
            wallet?: PublicKey,
            payer?: PublicKey,
        ): Promise<TransactionBuilder>
      • Parameters

        • input: DevFeeSwapInput

          A quote on the desired tokenIn and tokenOut for this swap. Use swapQuoteByInputTokenWithDevFees to generate this object.

        • devFeeWallet: PublicKey

          The wallet that developer fees will be deposited into.

        • Optionalwallet: PublicKey

          The wallet that swap tokens will be withdrawn and deposit into. If null, the WhirlpoolContext wallet is used.

        • Optionalpayer: PublicKey

          The wallet that will fund the cost needed to initialize the dev wallet token ATA accounts. If null, the WhirlpoolContext wallet is used.

        Returns Promise<TransactionBuilder>

        a transaction that will perform the swap once executed.