Skip to content

Compute lp_token_value in USD #3

Open

Description

@AngelaKTE

lp_token_value in USD
refers to the value of a liquiditiy provider's pool share at any point in time.

How to calculate:
a) ((total_token_value in USD = TVL)/total_pool_balance)*lp_pool_balance
b) (((total_pool_balance/lp_pool_balance)*token_a_balance)*USD)+((total_pool_balance /lp_pool_balance)*token_b_balance)*USD)+...
....
check logic and options for implementation

Activity

  1. added
    model logic (concept)all issues related to model logic, how we'll translate a mechanism to our model
    on Jan 14, 2021
  2. changed the title [-]lp_token_value in USD - calculation[/-] [+]Compute lp_token_value in USD[/+] on Jan 14, 2021
  3. VasilySumanov commented on Jan 16, 2021

    @VasilySumanov
    Contributor

    Algorithm of lp_token_value function:

    1. Retrieve total_token_balance - current token balances in the pool
    2. Calculate total_pool_value - the TVL of the pool by multiplying token balances on their USD prices
    3. Calculate lp_pool_value - the value of some number of BPT tokens based on share in underlying basket

    Step 1: Function for calculation total_token_balance

    The function should return the array containing token balances

    The sample of solidity code is below. Input argument: address of balancer pool.
    It calls the getCurrentTokens function of the pool and after that getBalance in the cycle, retrieving actual balances of tokens inside the pool. Finally, the array containing token balances is returned.

    function getBalancerTokensAndBalances(address _balancerPool)
        public
        view
        returns (address[] memory tokens, uint256[] memory balances)
      {
        tokens = BPoolInterface(_balancerPool).getCurrentTokens();
        uint256 len = tokens.length;
    
        balances = new uint256[](len);
        for (uint256 i = 0; i < len; i++) {
          balances[i] = BPoolInterface(_balancerPool).getBalance(tokens[i]);
        }
      }
    

    Step 2: Function for calculation total_pool_value
    Function uses total_token_balances to calculate the pool_value (TVL in the pool).

    Solidity code sample:

     function balancerPoolUsdTokensSum(address _balancerPool) public view returns (uint256) {
        (address[] memory tokens, uint256[] memory balances) = getBalancerTokensAndBalances(_balancerPool);
        return usdcTokensSum(tokens, balances);
      }
    

    We need to create our own usdcTokensSum that uses input data (price feeds). It can be artificial data set or the Uniswap token prices data set.

    Step 3: Function for calculation lp_pool_value
    The sample of solidity code is below. The total supply of LP shares can be calculated by calling total_pool_balance function as this token is basically ERC20 token

    function totalSupply() public view returns (uint) {
         return _totalSupply;
     }
    

    After the total supply of LP share is received, we find a ratio: [number of given LP shares]/[totalSupply] and multiply it on TVL

    References for code samples:
    Step 1,2: https://github.com/powerpool-finance/power-oracle-contracts/blob/master/contracts/InstantUniswapPrice.sol
    Step 3: https://github.com/balancer-labs/balancer-core/blob/master/contracts/BToken.sol

  4. AngelaKTE commented on Jan 18, 2021

    @AngelaKTE
    ContributorAuthor

    @raul pls check for
    C1 - analyse LP pool share value over time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

model logic (concept)all issues related to model logic, how we'll translate a mechanism to our model

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions