Skip to content

Commit

Permalink
fix tvl calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bonedaddy committed Jan 25, 2021
1 parent 9a697f5 commit 6ceb195
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ Note: Updating the uniswap bindings is a bit tedious because of the usage of waf

## Adding New TVL Tracking

There are two ways to calculate the USD value of assets in indices. One if by looking up their DAI uniswap pairs, the other is by looking up their ETH uniswap pairs and converting that to DAI. DAI uniswap pairs are preferrable as it reduces the amoutn of RPCs and time to calculate TVL however not all pairs have sufficient liquidity, and some pairs may not even have liquidity so you must lookup the pair on uniswap first to make sure that the liquidity is present. Otherwise you update `bclient/pool.go` to specify the alternate path (X -> ETH -> DAI) as the default behavior is X -> DAI.

The default behavior for TVL calculation is to derive the price of assets by looking up their ETH uniswap pairs, and converting that to DAI. So for AAVE the USD price determination process is `AAVE -> ETH -> DAI`
## Contract Bindings

# bindings/uniswapv2_oracle
Expand Down
16 changes: 1 addition & 15 deletions bclient/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Client) GetTotalValueLocked(ip IndexPool) (float64, error) {
for symbol, addr := range tokens {
// hard coded list for alternate price lookups of X->ETH->DAI
switch strings.ToLower(symbol) {
case "crv", "uma", "omg", "yfi", "aave":
default:
erc, err := erc20.NewErc20(addr, c.ec)
if err != nil {
return 0, errors.Wrap(err, "failed to get erc20 contract")
Expand Down Expand Up @@ -103,20 +103,6 @@ func (c *Client) GetTotalValueLocked(ip IndexPool) (float64, error) {
tokenAddress: addr,
}
log.Printf("%s USD value: %0.2f", symbol, values[symbol].tokenUsdValue)
default:
// calculate the reserves
reserves, err := uc.GetReserves(addr, DAITokenAddress)
if err != nil {
return 0, errors.Wrap(err, "failed to get reserves for "+symbol)
}
price := new(big.Int).Div(reserves.Reserve1, reserves.Reserve0)

priceF, _ := new(big.Float).SetInt(price).Float64()
values[symbol] = &tokenValue{
tokenUsdValue: priceF,
tokenAddress: addr,
}
log.Printf("%s USD value: %0.2f", symbol, values[symbol].tokenUsdValue)
}
}
var totalValueUSD float64
Expand Down

0 comments on commit 6ceb195

Please sign in to comment.