Skip to content

Commit

Permalink
pindexer(dex_ex): fix volume calculation in Candle::flip (#4981)
Browse files Browse the repository at this point in the history
## 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>
  • Loading branch information
cronokirby and erwanor authored Jan 11, 2025
1 parent a8a23f2 commit fe075d4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/bin/pindexer/src/dex_ex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ mod candle {

impl Candle {
pub fn from_candlestick_data(data: &CandlestickData) -> Self {
// The volume is tracked in terms of input asset.
// We can use the closing price (aka. the common clearing price) to convert
// the volume to the other direction i.e, the batch swap output.
Self {
open: data.open,
close: data.close,
Expand Down Expand Up @@ -88,8 +91,8 @@ mod candle {
close: 1.0 / self.close,
low: 1.0 / self.low,
high: 1.0 / self.high,
direct_volume: self.direct_volume / self.close,
swap_volume: self.swap_volume / self.close,
direct_volume: self.direct_volume * self.close,
swap_volume: self.swap_volume * self.close,
}
}
}
Expand Down Expand Up @@ -545,6 +548,7 @@ mod summary {
ON ed_end.asset = asset_end
JOIN eligible_denoms AS ed_start
ON ed_start.asset = asset_start
WHERE the_window = $3
),
sums AS (
SELECT
Expand Down

0 comments on commit fe075d4

Please sign in to comment.