Skip to main content

Overview

BEX LP tokens represent a share of a liquidity pool. Accurately valuing these tokens is essential for displaying balances, calculating rewards, and for on-chain operations like collateralization and liquidation. There are several methods to value LP tokens, each suited to different use cases.

Methods of valuation

Informational (sum of balances)

This calculation is for informational purposes only and should NOT be used on-chain as it can be easily manipulated.
This method is suitable for off-chain, informational, or UI purposes. It is not manipulation-resistant and should not be used for on-chain or critical financial operations. Formula: PriceLP token=i(Balancei×Pricei)SupplyLP TokensPrice_{LP\ token} = \frac{\sum_i (Balance_i \times Price_i)}{Supply_{LP\ Tokens}} Where:
  • Balancei: balance of token ii in the pool
  • Pricei: market price of token ii
  • SupplyLP\ Tokens: total supply of LP tokens
Example: Suppose a $BERA/$HONEY pool contains the following:
TokenBalancePrice (USD)Value (USD)
$BERA1,000$10$10,000
$HONEY10,000$1$10,000
Total Pool Value$20,000
LP Token Supply1,000
  • Pool Value: 1000 $BERA ×\times 10 USD + 10000 $HONEY ×\times 1 USD = 20000 USD
  • LP Token Price: 20000 USD // 1000 $LPTOKEN = 20 USD

Weighted pools

Weighted pools use a constant product invariant with custom weights. This method is manipulation-resistant and is recommended for on-chain or robust off-chain use.
Calculation StepsFormula
Step 1: Pool Invariant where iwi=1\sum_i w_i = 1x1w1x2w2xnwn=kx_1^{w_1} x_2^{w_2} \cdots x_n^{w_n} = k
Step 2: Token Weighted Valuesp1x1w1==pnxnwn=k^\frac{p_1 x_1}{w_1} = \cdots = \frac{p_n x_n}{w_n} = \hat{k}
Step 3: Calculate k^\hat{k}k^=ki(piwi)wi\hat{k} = k \cdot \prod_i \left( \frac{p_i}{w_i} \right)^{w_i}
Step 4: Final LP Token Price where ss is the LP token supplypLP=k^s=ksi(piwi)wip_{LP} = \frac{\hat{k}}{s} = \frac{k}{s} \cdot \prod_i \left( \frac{p_i}{w_i} \right)^{w_i}
Example Imagine an 80 $BAL/20 $WETH Pool with the following:
Calculation StepsValues
Step 1: Token Weightsw1=0.8w_1 = 0.8 ($BAL)
w2=0.2w_2 = 0.2 ($WETH)
Step 2: Oracle Pricesp1p_1 \approx $4.53 ($BAL)
p2p_2 \approx $1090.82 ($WETH)
Step 3: Pool Parametersk2,852,257.5k \approx 2,852,257.5 (from pool.getInvariant())
s5,628,392.26s \approx 5,628,392.26 (from pool.totalSupply())
Step 4: Final LP Token PricepLP=ksi(piwi)wip_{LP} = \frac{k}{s} \cdot \prod_i \left( \frac{p_i}{w_i} \right)^{w_i} \approx $11.34

Stable pools

Stable pools are optimized for assets that trade at or near parity (e.g., stablecoins). They use the StableSwap invariant and often expose a getRate() function. StableSwap Invariant: Annixi+D=ADnn+Dn+1nnixiA \cdot n^n \cdot \sum_i x_i + D = A \cdot D \cdot n^n + \frac{D^{n+1}}{n^n \cdot \prod_i x_i} Where:
  • AA is the amplification parameter
  • nn is the number of tokens
  • xix_i are token balances
  • DD is the invariant
LP Token Price (using getRate): Most stable pools expose a getRate() function, which returns the value of 1 LP token in terms of the pool’s base asset (e.g., USD or a stablecoin): pLP=getRate()×(price of base asset)p_{LP} = \text{getRate()} \times \text{(price of base asset)} Manual Calculation (if needed): pLP=ixipiSp_{LP} = \frac{\sum_i x_i \cdot p_i}{S} Where SS is the actual supply (use getActualSupply() for pre-minted pools). Example: Suppose a USDC/DAI/USDT pool with getRate()=1.01getRate() = 1.01 and USD as the base asset:
  • LP token price: pLP=1.01×1=1.01p_{LP} = 1.01 \times 1 = 1.01 USD per LP token

Linear pools

Linear pools are designed for pairs where one token is a yield-bearing or wrapped version of the other. They use a simple linear invariant and expose a getRate() function. Linear Pool Invariant: xmain+rxwrapped=kx_{main} + r \cdot x_{wrapped} = k Where rr is the rate between the wrapped and main token. LP Token Price (using getRate): pLP=getRate()×(price of main token)p_{LP} = \text{getRate()} \times \text{(price of main token)} Manual Calculation (if needed): pLP=xmainpmain+xwrappedpwrappedSp_{LP} = \frac{x_{main} \cdot p_{main} + x_{wrapped} \cdot p_{wrapped}}{S} Where SS is the virtual supply (use getVirtualSupply()). Example: Suppose a wstETH/ETH pool with getRate()=1.05getRate() = 1.05 and ETH at 20002000:
  • LP token price: pLP=1.05×2000=2100p_{LP} = 1.05 \times 2000 = 2100 USD per LP token

Special considerations

  • Pre-minted Supply: Some pools (especially stable pools) pre-mint the maximum possible LP tokens. Always use getActualSupply() or getVirtualSupply() as appropriate.
  • Protocol Fees: Some pools accrue protocol fees, which may affect the actual value of LP tokens. Weighted and stable pools account for these in their supply functions.
  • Manipulation Resistance: For on-chain or critical use, always use invariant-based or rate-based pricing, not simple sum-of-balances.
  • Re-entrancy Protection: When evaluating on-chain, always check for Vault re-entrancy using ensureNotInVaultContext(vault).
  • Staked LP Tokens: If LP tokens are staked, include both wallet and staked balances in your calculations.

References