cloud_functions: notional-tvl response includes token decimals (#1274)

This commit is contained in:
kev1n-peters 2022-06-15 15:12:35 -05:00 committed by GitHub
parent 1414005ed5
commit 6c8ae81fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 29 deletions

View File

@ -41,6 +41,7 @@ type TransferData struct {
DestinationChain string
Notional float64
TokenPrice float64
TokenDecimals int
}
// finds all the TokenTransfer rows within the specified period
@ -77,6 +78,8 @@ func fetchTransferRowsInInterval(tbl *bigtable.Table, ctx context.Context, prefi
t.TokenAddress = string(item.Value)
case "TokenTransferDetails:CoinGeckoCoinId":
t.CoinGeckoCoinId = string(item.Value)
case "TokenTransferDetails:Decimals":
t.TokenDecimals, _ = strconv.Atoi(string(item.Value))
}
}
@ -109,7 +112,7 @@ func fetchTransferRowsInInterval(tbl *bigtable.Table, ctx context.Context, prefi
),
bigtable.ChainFilters(
bigtable.FamilyFilter(fmt.Sprintf("%v|%v", columnFamilies[2], columnFamilies[5])),
bigtable.ColumnFilter("Amount|NotionalUSD|OriginSymbol|OriginName|OriginChain|TargetChain|CoinGeckoCoinId|OriginTokenAddress|TokenPriceUSD"),
bigtable.ColumnFilter("Amount|NotionalUSD|OriginSymbol|OriginName|OriginChain|TargetChain|CoinGeckoCoinId|OriginTokenAddress|TokenPriceUSD|Decimals"),
bigtable.LatestNFilter(1),
),
bigtable.BlockAllFilter(),

View File

@ -33,6 +33,7 @@ type LockedAsset struct {
Amount float64
Notional float64
TokenPrice float64
TokenDecimals int
}
// finds the daily amount of each symbol transferred to each chain, from the specified start to the present.
@ -125,6 +126,7 @@ func tvlInInterval(tbl *bigtable.Table, ctx context.Context, start time.Time) ma
Address: row.TokenAddress,
CoinGeckoId: row.CoinGeckoCoinId,
TokenPrice: row.TokenPrice,
TokenDecimals: row.TokenDecimals,
Amount: 0,
Notional: 0,
}
@ -221,6 +223,7 @@ func tvlSinceDate(tbl *bigtable.Table, ctx context.Context, dailyTotals map[stri
CoinGeckoId: lockedAsset.CoinGeckoId,
Amount: lockedAsset.Amount,
TokenPrice: lockedAsset.TokenPrice,
TokenDecimals: lockedAsset.TokenDecimals,
}
}
}
@ -359,6 +362,7 @@ func ComputeTVL(w http.ResponseWriter, r *http.Request) {
Amount: lockedAsset.Amount,
Notional: roundToTwoDecimalPlaces(notionalVal),
TokenPrice: currentPrice,
TokenDecimals: lockedAsset.TokenDecimals,
}
if asset, ok := notionalLocked[chain]["*"]; ok {

View File

@ -66,8 +66,9 @@ var tokensToSkip = map[string]bool{
"0xE389Ac691BD2b0228DAFFfF548fbcE38470373E8": true, // fake WMATIC on poly
"0x7e347498dfef39a88099e3e343140ae17cde260e": true, // fake wAVAX on bsc
"0x685629e5e99e3959254c4d23cd9097fbaef01fb2": true, // amWeth
"terra1vpehfldr2u2m2gw38zaryp4tfw7fe2kw2lryjf": true, //fake btc on terra
"terra1vpehfldr2u2m2gw38zaryp4tfw7fe2kw2lryjf": true, // fake btc on terra
"0xe9986beb0bcfff418dc4a252904cec370dfb14b8": true, // fake Dai Stablecoin on bsc
"0xdaff96cc3d5e2fa982812ec12ce74833deb51327": true, // fake btc on bsc
}
// init runs during cloud function initialization. So, this will only run during an