sum chains and tokens for /notionaltvl
commit-id:cfa4c5dd
This commit is contained in:
parent
ccfc7fd13e
commit
69390882af
|
@ -358,6 +358,14 @@ func TVL(w http.ResponseWriter, r *http.Request) {
|
||||||
tokenPrices := fetchTokenPrices(ctx, coinIdSet)
|
tokenPrices := fetchTokenPrices(ctx, coinIdSet)
|
||||||
|
|
||||||
notionalLocked := map[string]map[string]LockedAsset{}
|
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 {
|
for chain, tokens := range tokensLocked {
|
||||||
notionalLocked[chain] = map[string]LockedAsset{}
|
notionalLocked[chain] = map[string]LockedAsset{}
|
||||||
notionalLocked[chain]["*"] = 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/*
|
// round the the amount for chain/*
|
||||||
if asset, ok := notionalLocked[chain]["*"]; ok {
|
if asset, ok := notionalLocked[chain]["*"]; ok {
|
||||||
asset.Notional = roundToTwoDecimalPlaces(asset.Notional)
|
asset.Notional = roundToTwoDecimalPlaces(asset.Notional)
|
||||||
|
|
Loading…
Reference in New Issue