Options
All
  • Public
  • Public/Protected
  • All
Menu

Pool represents a liquidity pool in the PACT AMM.

Typically, users don't have to instantiate this class manually. Use PactClient.fetchPoolById or PactClient.fetchPoolsByAssets instead.

The primary methods of the pool are to create the transaction groups to enable you to

  • Add Liquidity,
  • Removing Liquidity,
  • Create a Swap on the Pool.

Hierarchy

  • Pool

Index

Constructors

  • Constructs a new pool.

    Parameters

    • algod: default

      the algorand client that this pool is created on.

    • appId: number

      the application id for the pool.

    • primaryAsset: Asset

      The primary asset for the pool.

    • secondaryAsset: Asset

      The secondary asset for the pool.

    • liquidityAsset: Asset

      The asset that is given to liquidity providers.

    • internalState: AppInternalState

      The current internal state for the pool.

    Returns Pool

Properties

algod: default

The Algorand client to use.

appId: number

The application id for the pool.

calculator: PoolCalculator

Contains the code to do the math behind the pool.

feeBps: number

The fee in basis points for swaps trading on the pool.

internalState: AppInternalState

The global state on the blockchain for this pool.

liquidityAsset: Asset

The asset for the liquidity pool token (LP token) that is given when liquidity is added, and burned when liquidity is withdrawn.

poolType: PoolType

Different pool types use different formulas for making swaps.

primaryAsset: Asset

The asset of the liquidity pool with the lower index.

secondaryAsset: Asset

The asset of the liquidity pool with the higher index.

state: PoolState

Contains the current state of the pool.

version: number

The version of the contract. May be 0 for some old pools which don't expose the version in the global state.

Methods

  • Builds the transactions to add liquidity for the primary asset and secondary asset of the pool as per the options passed in.

    In typical circumstances 3 transactions are generated:

    • deposit of asset A
    • deposit of asset B
    • "ADDLIQ" application call to add liquidity with the above deposits

    The initial liquidity must satisfy the expression sqrt(a * b) - 1000 > 0.

    throws

    PactSdkError if initial liquidity is too low.

    Parameters

    Returns Transaction[]

    Array of transactions to add the liquidity.

  • This creates two transactions in a group for the remove operation.

    • deposit of the liquidity asset
    • "REMLIQ" application call to remove the LP token from the account and receive the deposited assets in return

    Parameters

    Returns Transaction[]

    Array of transactions to remove the liquidity.

  • Builds two transactions:

    • deposit of the asset to swap
    • "SWAP' application call that performs the swap to receive the other asset

    Parameters

    Returns Transaction[]

    Array of transactions to perform the swap.

  • Builds the transactions to perform a Zap on the pool as per the options passed in. Zap allows to add liquidity to the pool by providing only one asset.

    This function will generate swap Txs to get a proper amount of the second asset and then generate add liquidity Txs with both of those assets. See Pool.buildSwapTxs and Pool.buildAddLiquidityTxs for more details.

    This feature is supposed to work with constant product pools only. Stableswaps can accept one asset to add liquidity by default.

    Parameters

    Returns Transaction[]

    Array of transactions to swap & add liquidity.

  • getEscrowAddress(): string
  • Get the escrow address of the pool.

    Returns string

    The address corresponding to that pools's escrow account.

  • Returns the "other" asset, i.e. primary if secondary is passed in and vice versa.

    throws

    PactSdkError if the asset passed in is not the primary or secondary asset.

    Parameters

    • asset: Asset

      The primary or secondary asset of the pool.

    Returns Asset

    The other asset, if the primary asset was passed in it will be the secondary asset and vice versa.

  • isAssetInThePool(asset: Asset): boolean
  • Check if the asset is the primary or secondary asset of this pool.

    Parameters

    • asset: Asset

      The asset to check is in the pool.

    Returns boolean

    True if the asset is in the pool or false otherwise.

  • Prepares the transaction group for removing liquidity from the pool.

    Parameters

    Returns Promise<TransactionGroup>

    Transaction group that when executed will remove liquidity from the pool.

  • Creates a new swap instance for receiving the amount of asset within the slippage percent from the pool.

    throws

    PactSdkError if the asset is not in the pool.

    throws

    SwapValidationError if slippage is outside of bounds [0, 100].

    throws

    SwapValidationError if pool is empty.

    throws

    LiquiditySurpassedError if swapForExact flag is enabled and tried to swap for more then current liquidity allows.

    Parameters

    Returns Swap

    A new swap object.

  • Prepares a transaction group that when executed will perform a swap on the pool.

    Parameters

    Returns Promise<TransactionGroup>

    Transaction group that when executed will perform a swap on the pool.

  • Creates a new zap instance for getting all required data for performing a zap.

    throws

    PactSdkError if the asset is not in the pool or if the pool is a Stableswap type.

    Parameters

    Returns Zap

    A new zap object.

  • Updates the internal and pool state properties by re-reading the global state in the blockchain.

    Updating the pool state is recommended if there is a pause between the construction of the pool and the creation of the transactions on the pool. Calling this method ensures that the the pool state is not stale.

    Returns Promise<PoolState>

    The new pool state.

Generated using TypeDoc