From 69390882af58f2a75a41cec1d32c0dc9dadde649 Mon Sep 17 00:00:00 2001 From: justinschuldt Date: Wed, 23 Feb 2022 17:00:21 -0600 Subject: [PATCH] sum chains and tokens for /notionaltvl commit-id:cfa4c5dd --- event_database/cloud_functions/notional-tvl.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/event_database/cloud_functions/notional-tvl.go b/event_database/cloud_functions/notional-tvl.go index b5e0c1c52..60e7ed138 100644 --- a/event_database/cloud_functions/notional-tvl.go +++ b/event_database/cloud_functions/notional-tvl.go @@ -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)