Helper class to help interact with Whirlpool Accounts with a simpler interface.

interface WhirlpoolClient {
    collectFeesAndRewardsForPositions: ((positionAddresses: Address[], opts?: SimpleAccountFetchOptions) => Promise<TransactionBuilder[]>);
    collectProtocolFeesForPools: ((poolAddresses: Address[]) => Promise<TransactionBuilder>);
    createPool: ((whirlpoolsConfig: Address, tokenMintA: Address, tokenMintB: Address, tickSpacing: number, initialTick: number, funder: Address) => Promise<{
        poolKey: PublicKey;
        tx: TransactionBuilder;
    }>);
    createSplashPool: ((whirlpoolsConfig: Address, tokenMintA: Address, tokenMintB: Address, initialPrice: Decimal, funder: Address) => Promise<{
        poolKey: PublicKey;
        tx: TransactionBuilder;
    }>);
    getContext: (() => WhirlpoolContext);
    getFetcher: (() => WhirlpoolAccountFetcherInterface);
    getPool: ((poolAddress: Address, opts?: SimpleAccountFetchOptions) => Promise<Whirlpool>);
    getPools: ((poolAddresses: Address[], opts?: SimpleAccountFetchOptions) => Promise<Whirlpool[]>);
    getPosition: ((positionAddress: Address, opts?: SimpleAccountFetchOptions) => Promise<Position>);
    getPositions: ((positionAddresses: Address[], opts?: SimpleAccountFetchOptions) => Promise<Record<string, null | Position>>);
    getRouter: ((poolAddresses: Address[]) => Promise<WhirlpoolRouter>);
}

Properties

collectFeesAndRewardsForPositions: ((positionAddresses: Address[], opts?: SimpleAccountFetchOptions) => Promise<TransactionBuilder[]>)

Collect all fees and rewards from a list of positions.

the addresses of the Position accounts to collect fee & rewards from.

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

A set of transaction-builders to resolve ATA for affliated tokens, collect fee & rewards for all positions.

collectProtocolFeesForPools: ((poolAddresses: Address[]) => Promise<TransactionBuilder>)

Collect protocol fees from a list of pools

Type declaration

    • (poolAddresses): Promise<TransactionBuilder>
    • Parameters

      • poolAddresses: Address[]

        the addresses of the Whirlpool accounts to collect protocol fees from

      Returns Promise<TransactionBuilder>

      A transaction builder to resolve ATA for tokenA and tokenB if needed, and collect protocol fees for all pools

createPool: ((whirlpoolsConfig: Address, tokenMintA: Address, tokenMintB: Address, tickSpacing: number, initialTick: number, funder: Address) => Promise<{
    poolKey: PublicKey;
    tx: TransactionBuilder;
}>)

Create a Whirlpool account for a group of token A, token B and tick spacing

Type declaration

    • (whirlpoolsConfig, tokenMintA, tokenMintB, tickSpacing, initialTick, funder): Promise<{
          poolKey: PublicKey;
          tx: TransactionBuilder;
      }>
    • Parameters

      • whirlpoolsConfig: Address
      • tokenMintA: Address

        the address of the token A

      • tokenMintB: Address

        the address of the token B

      • tickSpacing: number

        the space between two ticks in the tick array

      • initialTick: number

        the initial tick that the pool is set to (derived from initial price)

      • funder: Address

        the account to debit SOL from to fund the creation of the account(s)

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

      poolKey: The public key of the newly created whirlpool account. tx: The transaction containing instructions for the on-chain operations.

error when the tokens are not in the canonical byte-based ordering. To resolve this, invert the token order and the initialTick (see TickUtil.invertTick(), PriceMath.invertSqrtPriceX64(), or PriceMath.invertPrice()).

createSplashPool: ((whirlpoolsConfig: Address, tokenMintA: Address, tokenMintB: Address, initialPrice: Decimal, funder: Address) => Promise<{
    poolKey: PublicKey;
    tx: TransactionBuilder;
}>)

Create a Whirlpool account for a group of token A, token B and tick spacing

Type declaration

    • (whirlpoolsConfig, tokenMintA, tokenMintB, initialPrice, funder): Promise<{
          poolKey: PublicKey;
          tx: TransactionBuilder;
      }>
    • Parameters

      • whirlpoolsConfig: Address
      • tokenMintA: Address

        the address of the token A

      • tokenMintB: Address

        the address of the token B

      • initialPrice: Decimal

        the initial price of the pool (as x token B per 1 token A)

      • funder: Address

        the account to debit SOL from to fund the creation of the account(s)

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

      poolKey: The public key of the newly created whirlpool account. tx: The transaction containing instructions for the on-chain operations.

error when the tokens are not in the canonical byte-based ordering. To resolve this, invert the token order and the initialTick (see TickUtil.invertTick(), PriceMath.invertSqrtPriceX64(), or PriceMath.invertPrice()).

getContext: (() => WhirlpoolContext)

Get this client's WhirlpoolContext object

Type declaration

Get an WhirlpoolAccountCacheInterface to fetch and cache Whirlpool accounts

Type declaration

getPool: ((poolAddress: Address, opts?: SimpleAccountFetchOptions) => Promise<Whirlpool>)

Get a Whirlpool object to interact with the Whirlpool account at the given address.

Type declaration

    • (poolAddress, opts?): Promise<Whirlpool>
    • Parameters

      • poolAddress: Address

        the address of the Whirlpool account

      • Optionalopts: SimpleAccountFetchOptions

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

      Returns Promise<Whirlpool>

      a Whirlpool object to interact with

getPools: ((poolAddresses: Address[], opts?: SimpleAccountFetchOptions) => Promise<Whirlpool[]>)

Get a list of Whirlpool objects matching the provided list of addresses.

Type declaration

    • (poolAddresses, opts?): Promise<Whirlpool[]>
    • Parameters

      • poolAddresses: Address[]

        the addresses of the Whirlpool accounts

      • Optionalopts: SimpleAccountFetchOptions

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

      Returns Promise<Whirlpool[]>

      a list of Whirlpool objects to interact with

getPosition: ((positionAddress: Address, opts?: SimpleAccountFetchOptions) => Promise<Position>)

Get a Position object to interact with the Position account at the given address.

Type declaration

    • (positionAddress, opts?): Promise<Position>
    • Parameters

      • positionAddress: Address

        the address of the Position account

      • Optionalopts: SimpleAccountFetchOptions

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

      Returns Promise<Position>

      a Position object to interact with.

error when address does not return a Position account.

getPositions: ((positionAddresses: Address[], opts?: SimpleAccountFetchOptions) => Promise<Record<string, null | Position>>)

Get a list of Position objects to interact with the Position account at the given addresses.

Type declaration

    • (positionAddresses, opts?): Promise<Record<string, null | Position>>
    • Parameters

      • positionAddresses: Address[]
      • Optionalopts: SimpleAccountFetchOptions

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

      Returns Promise<Record<string, null | Position>>

      a Record object between account address and Position. If an address is not a Position account, it will be null.

getRouter: ((poolAddresses: Address[]) => Promise<WhirlpoolRouter>)

Get a WhirlpoolRouter to help generate the best prices when transacting across a set of pools.

Type declaration

WhirlpoolRouter will be removed in the future release. Please use endpoint which provides qoutes.