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

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

Properties

closePosition: ((positionAddress, slippageTolerance, destinationWallet?, positionWallet?, payer?, usePriceSlippage?) => 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, slippageTolerance, destinationWallet?, positionWallet?, payer?, usePriceSlippage?): 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.

      Parameters

      • positionAddress: Address

        The address of the position account.

      • slippageTolerance: Percentage

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

      • Optional destinationWallet: Address

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

      • Optional positionWallet: Address

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

      • Optional payer: Address

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

      • Optional usePriceSlippage: 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.

Param: positionAddress

The address of the position account.

Param: slippageTolerance

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

Param: destinationWallet

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

Param: positionWallet

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

Param: payer

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

Param: usePriceSlippage

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

Returns

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

getAddress: (() => PublicKey)

Return the address for this Whirlpool instance.

Type declaration

    • (): PublicKey
    • Return the address for this Whirlpool instance.

      Returns PublicKey

      the PublicKey for this Whirlpool instance.

Returns

the PublicKey for this Whirlpool instance.

getData: (() => WhirlpoolData)

Return the most recently fetched Whirlpool account data.

Type declaration

    • (): WhirlpoolData
    • Return the most recently fetched Whirlpool account data.

      Returns WhirlpoolData

      most recently fetched WhirlpoolData for this address.

Returns

most recently fetched WhirlpoolData for this address.

getRewardInfos: (() => WhirlpoolRewardInfo[])

Get the WhirlpoolRewardInfos for this pool.

Type declaration

    • (): WhirlpoolRewardInfo[]
    • Get the WhirlpoolRewardInfos for this pool.

      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.

Returns

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

    • (): TokenInfo
    • Get the TokenInfo for token A of this pool.

      Returns TokenInfo

      TokenInfo for token A

Returns

TokenInfo for token A

getTokenBInfo: (() => TokenInfo)

Get the TokenInfo for token B of this pool.

Type declaration

    • (): TokenInfo
    • Get the TokenInfo for token B of this pool.

      Returns TokenInfo

      TokenInfo for token B

Returns

TokenInfo for token B

getTokenVaultAInfo: (() => AccountWithTokenProgram)

Get the TokenAccountInfo for token vault A of this pool.

Type declaration

    • (): AccountWithTokenProgram
    • Get the TokenAccountInfo for token vault A of this pool.

      Returns AccountWithTokenProgram

      TokenAccountInfo for token vault A

Returns

TokenAccountInfo for token vault A

getTokenVaultBInfo: (() => AccountWithTokenProgram)

Get the TokenAccountInfo for token vault B of this pool.

Type declaration

    • (): AccountWithTokenProgram
    • Get the TokenAccountInfo for token vault B of this pool.

      Returns AccountWithTokenProgram

      TokenAccountInfo for token vault B

Returns

TokenAccountInfo for token vault B

initTickArrayForTicks: ((ticks, funder?, opts?) => 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, funder?, opts?): 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.

      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.

      • Optional funder: Address

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

      • Optional opts: 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.

Param: ticks

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

Param: funder

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

Param: opts

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

Returns

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

openPosition: ((tickLower, tickUpper, liquidityInput, wallet?, funder?, positionMint?) => 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, tickUpper, liquidityInput, wallet?, funder?, positionMint?): 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.

      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

      • Optional wallet: Address

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

      • Optional funder: Address

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

      • Optional positionMint: PublicKey

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

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

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

Param: tickLower

the tick index for the lower bound of this position

Param: tickUpper

the tick index for the upper bound of this position

Param: liquidityInput

an InputLiquidityInput type to define the desired liquidity amount to deposit

Param: wallet

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

Param: funder

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

Param: positionMint

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

Returns

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

openPositionWithMetadata: ((tickLower, tickUpper, liquidityInput, wallet?, funder?, positionMint?) => 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, tickUpper, liquidityInput, wallet?, funder?, positionMint?): 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.

      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.

      • Optional wallet: Address

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

      • Optional funder: Address

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

      • Optional positionMint: PublicKey

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

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

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

Param: tickLower

the tick index for the lower bound of this position

Param: tickUpper

the tick index for the upper bound of this position

Param: liquidityInput

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

Param: wallet

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

Param: funder

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

Param: positionMint

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

Returns

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

    • (): Promise<WhirlpoolData>
    • Fetch and return the most recently fetched Whirlpool account data.

      Returns Promise<WhirlpoolData>

      the most up to date WhirlpoolData for this address.

Returns

the most up to date WhirlpoolData for this address.

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

Perform a swap between tokenA and tokenB on this pool.

Type declaration

    • (input, wallet?): Promise<TransactionBuilder>
    • Perform a swap between tokenA and tokenB on this pool.

      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.

      • Optional wallet: 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.

Param: input

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

Param: wallet

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

Returns

a transaction that will perform the swap once executed.

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

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

Type declaration

    • (input, devFeeWallet, wallet?, payer?): Promise<TransactionBuilder>
    • Collect a developer fee and perform a swap between tokenA and tokenB on this pool.

      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.

      • Optional wallet: PublicKey

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

      • Optional payer: 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.

Param: input

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

Param: devFeeWallet

The wallet that developer fees will be deposited into.

Param: wallet

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

Param: payer

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

Returns

a transaction that will perform the swap once executed.

Generated using TypeDoc