sum chains and tokens for /notionaltvl

commit-id:cfa4c5dd
This commit is contained in:
justinschuldt 2022-02-23 17:00:21 -06:00 committed by Justin Schuldt
parent ccfc7fd13e
commit 69390882af
1 changed files with 14 additions and 0 deletions

View File

@ -358,6 +358,14 @@ func TVL(w http.ResponseWriter, r *http.Request) {
tokenPrices := fetchTokenPrices(ctx, coinIdSet)
notionalLocked := map[string]map[string]LockedAsset{}
// initialize the struct that will hold the total for all chains, all assets
notionalLocked["*"] = map[string]LockedAsset{}
notionalLocked["*"]["*"] = LockedAsset{
Symbol: "*",
Name: "all",
Notional: 0,
}
for chain, tokens := range tokensLocked {
notionalLocked[chain] = map[string]LockedAsset{}
notionalLocked[chain]["*"] = LockedAsset{
@ -394,6 +402,12 @@ func TVL(w http.ResponseWriter, r *http.Request) {
}
}
// add the chain total to the overall total
if all, ok := notionalLocked["*"]["*"]; ok {
all.Notional += notionalLocked[chain]["*"].Notional
notionalLocked["*"]["*"] = all
}
// round the the amount for chain/*
if asset, ok := notionalLocked[chain]["*"]; ok {
asset.Notional = roundToTwoDecimalPlaces(asset.Notional)