Options
All
  • Public
  • Public/Protected
  • All
Menu

Contains functions for calculation statistics and other numerical data about the pool.

The pool calculator uses internal data from the pool to calculate values like the Prices, Net Amounts and values for the swap. Uses different formulas based on pool type.

Hierarchy

  • PoolCalculator

Index

Constructors

Properties

swapCalculator: SwapCalculator

Accessors

  • get isEmpty(): boolean
  • Checks if the pool is currently empty.

    A pool is empty if either the primary or secondary asset is zero.

    Returns boolean

    true if the pool is empty, false otherwise.

  • get primaryAssetAmount(): bigint
  • get primaryAssetAmountDecimal(): number
  • get primaryAssetPrice(): number
  • get secondaryAssetAmount(): bigint
  • get secondaryAssetAmountDecimal(): number
  • get secondaryAssetPrice(): number

Methods

  • amountDepositedToGrossAmountReceived(asset: Asset, amountDeposited: bigint): bigint
  • amountDepositedToNetAmountReceived(asset: Asset, amountDeposited: bigint): bigint
  • Converts amount deposited in the contract to amount received from the contract. Includes fee calculations.

    Parameters

    • asset: Asset

      Asset to deposit in the contract.

    • amountDeposited: bigint

      Amount to deposit in the contract.

    Returns bigint

    The amount to receive from the contract.

  • getAssetPriceAfterLiqChange(asset: Asset, primaryLiqChange: number, secondaryLiqChange: number): number
  • Simulates new asset price after changing the pool's liquidity.

    Parameters

    • asset: Asset

      The asset for which to calculate the price for.

    • primaryLiqChange: number

      The change of primary liquidity on the pool.

    • secondaryLiqChange: number

      The change of secondary liquidity on the pool.

    Returns number

    New asset price.

  • getFee(asset: Asset, amountDeposited: bigint): bigint
  • Calculates the exchange fee based on deposited amount.

    Parameters

    • asset: Asset

      The asset to deposit in the contract.

    • amountDeposited: bigint

      The amount to deposit in the contract.

    Returns bigint

    The calculated fee.

  • getFeeFromGrossAmount(grossAmount: bigint): bigint
  • Calculates the fee from the gross amount based on pool's feeBps.

    Parameters

    • grossAmount: bigint

      The amount to receive from the contract not yet lessened by the fee.

    Returns bigint

    The calculated fee.

  • getFeeFromNetAmount(netAmount: bigint): bigint
  • Calculates the fee from the net amount based on pool's feeBps. This is used in the swap exact for calculations.

    Parameters

    • netAmount: bigint

      The amount to receive from the contract already lessened by the fee.

    Returns bigint

    The calculated fee.

  • getLiquidities(asset: Asset): [bigint, bigint]
  • Returns the array of liquidities from the pool, sorting them by setting provided asset as primary.

    Parameters

    • asset: Asset

      The asset that is supposed to be the primary one.

    Returns [bigint, bigint]

    Total liquidities of assets.

  • getMinimumAmountReceived(asset: Asset, amountDeposited: bigint, slippageBps: bigint): bigint
  • Based on the deposited amount and a slippage, calculate the minimum amount the user will receive from the contract.

    Parameters

    • asset: Asset

      The asset to deposit in the contract.

    • amountDeposited: bigint

      The amount to deposit in the contract.

    • slippageBps: bigint

      Slippage in base points.

    Returns bigint

    The minimum amount to receive from the contract.

  • getPriceImpactPct(asset: Asset, primaryLiqChange: number, secondaryLiqChange: number): number
  • Calculates the price impact of changing the liquidity in a certain way.

    Parameters

    • asset: Asset

      The asset for which to calculate the price impact for.

    • primaryLiqChange: number

      The change of primary liquidity on the pool.

    • secondaryLiqChange: number

      The change of secondary liquidity on the pool.

    Returns number

    The asset price impact.

  • getSwapPrice(assetDeposited: Asset, amountDeposited: bigint): number
  • Calculates the price for which the asset in going to be swapped.

    Parameters

    • assetDeposited: Asset

      The asset deposited in the contract.

    • amountDeposited: bigint

      The amount deposited in the contract.

    Returns number

    The price of deposited asset in relation to received asset.

  • grossAmountReceivedToAmountDeposited(asset: Asset, intGrossAmountReceived: bigint): bigint
  • netAmountReceivedToAmountDeposited(asset: Asset, netAmountReceived: bigint): bigint
  • Converts amount received from the contract to amount deposited in the contract.

    Parameters

    • asset: Asset

      Asset to deposit in the contract.

    • netAmountReceived: bigint

      Amount to receive from the contract.

    Returns bigint

    The amount to deposit in the contract.

Generated using TypeDoc