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

Underlying Tokens in BeraSwap

Overview

It's common to want to know what underlying tokens a BeraSwap LP token represents. This documentation explains how to query this information directly from the BeraSwap contract and LP tokens.

Querying the BeraSwap Contract and LP Tokens

The BeraSwap contract can provide the exact number of tokens in a pool. By querying this information and calculating your share of the pool, you can determine your underlying token balances.

Step-by-Step Process

  1. Query the BeraSwap contract for pool tokens and balances
  2. Calculate your pool share
  3. Calculate your underlying token balances

Pseudocode

solidity
(tokens, balances, lastChangeBlock) = vault.getPoolTokens(poolId);
yourPoolShare = lpToken.balanceOf(yourAddress) / lpToken.totalSupply();
uint256[] yourUnderlyingBalances = new uint256[](balances.length);
for (i = 0; i < balances.length; i++) {
    yourUnderlyingBalances[i] = balances[i] * yourPoolShare;
}
return (tokens, yourUnderlyingBalances);

Special Considerations

Stable Pools

For stable pools in BeraSwap:

  1. Use getActualSupply() instead of totalSupply() to get the correct pool supply
  2. If you've staked your LP tokens, calculate your total LP token balance as:
    solidity
    myLpTokens = lpToken.balanceOf(yourAddress) + lpStakingContract.balanceOf(yourAddress);

Example: Querying BERA/HONEY Pool

Let's say you want to know your underlying BERA and HONEY balances for a BERA/HONEY pool:

StepActionResult
1Query BeraSwaptokens = [BERA, HONEY], balances = [1000 BERA, 10000 HONEY]
2Get LP token balanceyourLpTokens = 100
3Get total LP supplyactualSupply = getActualSupply() = 1000
4Calculate pool shareyourPoolShare = 100 / 1000 = 0.1 (10%)
5Calculate underlyingyourBera = 1000 * 0.1 = 100 BERA
6Calculate underlyingyourHoney = 10000 * 0.1 = 1000 HONEY

In this example, your 100 LP tokens represent 100 BERA and 1000 HONEY.