Skip to content

Commit fe075d4

Browse files
cronokirbyerwanor
andauthored
pindexer(dex_ex): fix volume calculation in Candle::flip (#4981)
## Describe your changes This fixes two bugs in pindexer: 1. Volumes in aggregate and per pair summary were far too high. 2. The different windows of the aggregate summary all reported the same value. Bug 1. stemmed from multiplying by a price rather than dividing by it when mixing two directions of a candle. Bug 2. was just a missing filter in an SQL query. To test, run pindexer again, and do some sanity checks on the aggregate summary, and pair summaries for pairs like USDC / UM. ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > indexing only --------- Co-authored-by: Erwan Or <erwanor@penumbralabs.xyz>
1 parent a8a23f2 commit fe075d4

File tree

1 file changed

+6
-2
lines changed
  • crates/bin/pindexer/src/dex_ex

1 file changed

+6
-2
lines changed

crates/bin/pindexer/src/dex_ex/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ mod candle {
5050

5151
impl Candle {
5252
pub fn from_candlestick_data(data: &CandlestickData) -> Self {
53+
// The volume is tracked in terms of input asset.
54+
// We can use the closing price (aka. the common clearing price) to convert
55+
// the volume to the other direction i.e, the batch swap output.
5356
Self {
5457
open: data.open,
5558
close: data.close,
@@ -88,8 +91,8 @@ mod candle {
8891
close: 1.0 / self.close,
8992
low: 1.0 / self.low,
9093
high: 1.0 / self.high,
91-
direct_volume: self.direct_volume / self.close,
92-
swap_volume: self.swap_volume / self.close,
94+
direct_volume: self.direct_volume * self.close,
95+
swap_volume: self.swap_volume * self.close,
9396
}
9497
}
9598
}
@@ -545,6 +548,7 @@ mod summary {
545548
ON ed_end.asset = asset_end
546549
JOIN eligible_denoms AS ed_start
547550
ON ed_start.asset = asset_start
551+
WHERE the_window = $3
548552
),
549553
sums AS (
550554
SELECT

0 commit comments

Comments
 (0)