How is the TVL Calculated?

How is the TVL on the homepage of Position Exchange calculated?

Here is the code:

stakedAmountInNaivePoolPOSI, err := s.evmAdapter.GetPOSIBalance(constants.POSIStakingManagerAddress)
if err != nil {
	return err
}
stakedAmountInNaivePoolPOSIV2, err := s.evmAdapter.GetPOSIBalance(constants.POSIStakingManagerV2Address)
if err != nil {
	return err
}
stakedAmountInNFTPoolsPOSI, err := s.getStakedAmountInNFTPoolsPOSI()
if err != nil {
	return err
}
stakedAmountInLPPairFarmsPOSI, err := s.getStakedAmountInLPPairFarmsPOSI()
if err != nil {
	return err
}
USDPriceOfPOSI, err := s.redisAdapter.GetUSDPrice(ctx, constants.PositionExchangeContractAddress)
if err != nil {
	return err
}

// stakedAmountInLPPairFarmsPOSI multiply 2 because LP value in USD is the same for the other token
// based on x.y = k formula
totalUSDValueLocked := stakedAmountInLPPairFarmsPOSI.Mul(decimal.NewFromInt(2)).Add(*stakedAmountInNaivePoolPOSI).Add(*stakedAmountInNaivePoolPOSIV2).Add(*stakedAmountInNFTPoolsPOSI).Mul(*USDPriceOfPOSI)
return s.redisAdapter.SetStatistics(ctx,
	constants.PositionExchangeContractAddress,
	constants.StatisticsTotalValueLockedFieldName,
	&totalUSDValueLocked)

Explain:

(posi.balanceOf(POSIStakingManagerAddress) + posi.balanceOf(POSIStakingManagerV2Address)

+posi.balanceOf(POSINFTMintProxyV1) + posi.balanceOf(POSINFTMintProxyV2) +

(posi.balanceOf(BUSDLP) + posi.balanceOf(BNBLP))*2)

*posiUSD

Where:

Let's verify by yourself!

Last updated