mirror of
https://github.com/luxfi/graph.git
synced 2026-09-24 00:26:07 +00:00
an unobserved day reports no value locked, not zero
What a pool holds is not in its trades — the balances say, and only about now. Days that passed before the series existed carry the volume and the candles they can be shown; reporting "0.00" locked would claim the pool was empty and a chart would draw the claim as a cliff to zero. Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
+18
-4
@@ -211,8 +211,8 @@ func (idx *Indexer) writeSeries(s snapshot) {
|
||||
Token: tokenRef(c.subject, s.tokens),
|
||||
Volume: fmtAmount(c.volume),
|
||||
VolumeUSD: fmtUSD(c.volumeUSD),
|
||||
TotalValueLocked: fmtAmount(c.locked),
|
||||
TotalValueLockedUSD: fmtUSD(c.lockedUSD),
|
||||
TotalValueLocked: fmtHeld(c.locked, c.held),
|
||||
TotalValueLockedUSD: fmtHeld(c.lockedUSD, c.held),
|
||||
PriceUSD: fmtPrice(c.close),
|
||||
Open: fmtPrice(c.open),
|
||||
High: fmtPrice(c.high),
|
||||
@@ -230,7 +230,7 @@ func (idx *Indexer) writeSeries(s snapshot) {
|
||||
Date: c.date,
|
||||
Pool: poolRef(c.subject, s.pools, s.tokens),
|
||||
VolumeUSD: fmtUSD(c.volumeUSD),
|
||||
TotalValueLockedUSD: fmtUSD(c.lockedUSD),
|
||||
TotalValueLockedUSD: fmtHeld(c.lockedUSD, c.held),
|
||||
TxCount: c.txCount,
|
||||
Open: fmtPrice(c.open),
|
||||
High: fmtPrice(c.high),
|
||||
@@ -247,7 +247,7 @@ func (idx *Indexer) writeSeries(s snapshot) {
|
||||
ID: dayID(c.subject, c.date),
|
||||
Date: c.date,
|
||||
VolumeUSD: fmtUSD(c.volumeUSD),
|
||||
TotalValueLockedUSD: fmtUSD(c.lockedUSD),
|
||||
TotalValueLockedUSD: fmtHeld(c.lockedUSD, c.held),
|
||||
TxCount: c.txCount,
|
||||
})
|
||||
}
|
||||
@@ -355,6 +355,20 @@ func poolRef(id string, pools map[string]*storage.SeedPoolData, tokens map[strin
|
||||
}
|
||||
}
|
||||
|
||||
// fmtHeld renders what was held on a day that recorded it, and nothing at all
|
||||
// on a day that did not.
|
||||
//
|
||||
// What a pool holds is not in its trades — only the balances say, and they only
|
||||
// say what is true now. So a day that passed before this ran has volume and
|
||||
// candles it can be shown and no locked value it cannot. "0.00" there would
|
||||
// claim the pool was empty, and a chart would draw that claim as a cliff.
|
||||
func fmtHeld(v float64, held bool) string {
|
||||
if !held {
|
||||
return ""
|
||||
}
|
||||
return fmtUSD(v)
|
||||
}
|
||||
|
||||
// fmtAmount renders a token-denominated quantity at full significance. fmtUSD's
|
||||
// two decimals are a currency format: a token amount is legitimately a
|
||||
// millionth of a unit, and unlike a price, zero of it is a real answer.
|
||||
|
||||
@@ -413,6 +413,12 @@ func TestPoolSeriesAndProtocolTotal(t *testing.T) {
|
||||
t.Errorf("pool row does not carry its pool: %v", day["pool"])
|
||||
}
|
||||
|
||||
// What the pool held on a day that passed before this ran is not in the
|
||||
// trades. Reporting it as $0 would draw a cliff to zero liquidity.
|
||||
if got := fmt.Sprint(day["tvlUSD"]); got != "" {
|
||||
t.Errorf("a past day claims tvlUSD %q; it was never observed", got)
|
||||
}
|
||||
|
||||
// The protocol total behind the explore page's tiles.
|
||||
protocol := rows(t, idx.store.GetFactoryDayDatas, 1000, nil)
|
||||
if len(protocol) < 3 {
|
||||
|
||||
Reference in New Issue
Block a user