Skip to content

Valuing BEX LP Tokens

Overview

BEX LP tokens represent a share of a liquidity pool. Accurately valuing these tokens is essential for displaying user 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)

WARNING

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 Tokens

Where:

  • Balancei: balance of token i in the pool
  • Pricei: market price of token i
  • 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 × 10 USD + 10000 $HONEY × 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=1x1w1x2w2xnwn=k
Step 2: Token Weighted Valuesp1x1w1==pnxnwn=k^
Step 3: Calculate k^k^=ki(piwi)wi
Step 4: Final LP Token Price where s is the LP token supplypLP=k^s=ksi(piwi)wi

Example

Imagine an 80 $BAL/20 $WETH Pool with the following:

Calculation StepsValues
Step 1: Token Weightsw1=0.8 ($BAL)
w2=0.2 ($WETH)
Step 2: Oracle Pricesp1$4.53 ($BAL)
p2$1090.82 ($WETH)
Step 3: Pool Parametersk2,852,257.5 (from pool.getInvariant())
s5,628,392.26 (from pool.totalSupply())
Step 4: Final LP Token PricepLP=ksi(piwi)wi$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+1nnixi

Where:

  • A is the amplification parameter
  • n is the number of tokens
  • xi are token balances
  • D 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)

Manual Calculation (if needed):

pLP=ixipiS

Where S is the actual supply (use getActualSupply() for pre-minted pools).

Example:

Suppose a USDC/DAI/USDT pool with getRate()=1.01 and USD as the base asset:

  • LP token price: pLP=1.01×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=k

Where r is the rate between the wrapped and main token.

LP Token Price (using getRate):

pLP=getRate()×(price of main token)

Manual Calculation (if needed):

pLP=xmainpmain+xwrappedpwrappedS

Where S is the virtual supply (use getVirtualSupply()).

Example:

Suppose a wstETH/ETH pool with getRate()=1.05 and ETH at 2000:

  • LP token price: pLP=1.05×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