You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Retrieve total_token_balance - current token balances in the pool
Calculate total_pool_value - the TVL of the pool by multiplying token balances on their USD prices
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
Activity
[-]lp_token_value in USD - calculation[/-][+]Compute lp_token_value in USD[/+]VasilySumanov commentedon Jan 16, 2021
Algorithm of
lp_token_valuefunction:total_token_balance- current token balances in the pooltotal_pool_value- the TVL of the pool by multiplying token balances on their USD priceslp_pool_value- the value of some number of BPT tokens based on share in underlying basketStep 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
getCurrentTokensfunction of the pool and after thatgetBalancein the cycle, retrieving actual balances of tokens inside the pool. Finally, the array containing token balances is returned.Step 2: Function for calculation total_pool_value
Function uses
total_token_balancesto calculate thepool_value(TVL in the pool).Solidity code sample:
We need to create our own
usdcTokensSumthat 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_valueThe sample of solidity code is below. The total supply of LP shares can be calculated by calling
total_pool_balancefunction as this token is basically ERC20 tokenAfter 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
AngelaKTE commentedon Jan 18, 2021
@raul pls check for
C1 - analyse LP pool share value over time