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

@ -26,13 +26,14 @@ var warmTvlFilePath = "tvl-cache.json"
var notionalTvlResultPath = "notional-tvl.json"
type LockedAsset struct {
Symbol string
Name string
Address string
CoinGeckoId string
Amount float64
Notional float64
TokenPrice float64
Symbol string
Name string
Address string
CoinGeckoId string
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.
@ -120,13 +121,14 @@ func tvlInInterval(tbl *bigtable.Table, ctx context.Context, start time.Time) ma
if _, ok := results[dateStr][row.OriginChain][row.TokenAddress]; !ok {
results[dateStr][row.OriginChain][row.TokenAddress] = LockedAsset{
Symbol: row.TokenSymbol,
Name: row.TokenName,
Address: row.TokenAddress,
CoinGeckoId: row.CoinGeckoCoinId,
TokenPrice: row.TokenPrice,
Amount: 0,
Notional: 0,
Symbol: row.TokenSymbol,
Name: row.TokenName,
Address: row.TokenAddress,
CoinGeckoId: row.CoinGeckoCoinId,
TokenPrice: row.TokenPrice,
TokenDecimals: row.TokenDecimals,
Amount: 0,
Notional: 0,
}
}
@ -215,12 +217,13 @@ func tvlSinceDate(tbl *bigtable.Table, ctx context.Context, dailyTotals map[stri
} else {
// have not seen this asset in previous days
result[chain][address] = LockedAsset{
Symbol: lockedAsset.Symbol,
Name: lockedAsset.Name,
Address: lockedAsset.Address,
CoinGeckoId: lockedAsset.CoinGeckoId,
Amount: lockedAsset.Amount,
TokenPrice: lockedAsset.TokenPrice,
Symbol: lockedAsset.Symbol,
Name: lockedAsset.Name,
Address: lockedAsset.Address,
CoinGeckoId: lockedAsset.CoinGeckoId,
Amount: lockedAsset.Amount,
TokenPrice: lockedAsset.TokenPrice,
TokenDecimals: lockedAsset.TokenDecimals,
}
}
}
@ -352,13 +355,14 @@ func ComputeTVL(w http.ResponseWriter, r *http.Request) {
}
notionalLocked[chain][address] = LockedAsset{
Symbol: lockedAsset.Symbol,
Name: lockedAsset.Name,
Address: lockedAsset.Address,
CoinGeckoId: lockedAsset.CoinGeckoId,
Amount: lockedAsset.Amount,
Notional: roundToTwoDecimalPlaces(notionalVal),
TokenPrice: currentPrice,
Symbol: lockedAsset.Symbol,
Name: lockedAsset.Name,
Address: lockedAsset.Address,
CoinGeckoId: lockedAsset.CoinGeckoId,
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