Skip to content
🚧 Under Development! May be incomplete.Some pages/links may be incomplete or subject to change.

Valuing BeraSwap LP Tokens

Overview

It's common to want to know the value of a BeraSwap LP token. This generally comes down to its Net Asset Value (NAV), i.e., the value of the underlying tokens.

Equation

The Net Asset Value (NAV) of an LP token is calculated as:

PriceLP token=i(Balancei×Pricei)SupplyLP Tokens

Where:

  • Balance₍ᵢ₎ is the balance of token i in the pool
  • Price₍ᵢ₎ is the market price of token i (e.g., from an oracle or price feed)
  • Supply₍ₗₚ₎ is the total supply of LP tokens

Pseudocode

solidity
(tokens, balances, lastChangeBlock) = vault.getPoolTokens(poolId);
prices = fetchPricesFromPriceProvider(tokens); // e.g., from an oracle
poolValueUsd = sum(balances[i] * price[i]);
lpTokenPriceUsd = poolValueUsd / lpToken.totalSupply();

Special Considerations

Stable Pools

For stable pools, they have pre-minted LP tokens. In such cases:

  • Use getActualSupply() instead of totalSupply() to get the correct pool supply

Calculating Value for a Specific Address

To calculate the value of LP tokens held by a specific address:

solidity
myLpTokenValueUsd = lpToken.balanceOf(myAddress) * lpTokenPriceUsd;

If LP tokens are staked, include staked balance:

solidity
myLpTokens = lpToken.balanceOf(myAddress) + lpStakingContract.balanceOf(myAddress);
myLpTokenValueUsd = myLpTokens * lpTokenPriceUsd;

Example: Valuing $BERA/$HONEY LP Tokens

Let's value LP tokens for a $BERA/$HONEY pool:

StepActionResult
1Query BeraSwaptokens = [$BERA, $HONEY], balances = [1000 BERA, 10000 HONEY]
2Fetch pricesprices = [$10 (BERA), $1 (HONEY)]
3Calculate pool valuepoolValueUsd = (1000 _ $10) + (10000 _ $1) = $20,000
4Get total LP supplytotalLpSupply = 1000
5Calculate LP token pricelpTokenPriceUsd = $20,000 / 1000 = $20

In this example, each LP token is worth $20.