Skip to content

Commit

Permalink
fix: calc swap volume using TokenOut to capture only executed volume:
Browse files Browse the repository at this point in the history
    - and note that TokenOut volume excludes the value of fees paid.
      this is because the swap volume is a balance of the equation:
      `value in (reserves in) = value out (reserves out + fee out)`
  • Loading branch information
dib542 committed Mar 28, 2024
1 parent e65cc18 commit 5d9107c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/routes/timeseries/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const routes = [
[
'time_unix',
[
`amount ${request.params['tokenA']}`,
`amount ${request.params['tokenB']}`,
`amount (excluding fee) ${request.params['tokenA']}`,
`amount (excluding fee) ${request.params['tokenB']}`,
`fee ${request.params['tokenA']}`,
`fee ${request.params['tokenB']}`,
],
Expand Down
8 changes: 4 additions & 4 deletions src/storage/sqlite3/db/event.TickUpdate/getSwapVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const swapVolumeCache: PolicyOptions<DataSet> = {
(
CASE
WHEN (
'event.TickUpdate'.'TokenIn' = 'event.TickUpdate'.'TokenZero' AND
'event.TickUpdate'.'TokenOut' = 'event.TickUpdate'.'TokenZero' AND
'event.TickUpdate'.'derived.ReservesDiff' > 0
)
THEN CAST('event.TickUpdate'.'derived.ReservesDiff' as FLOAT)
Expand All @@ -94,7 +94,7 @@ export const swapVolumeCache: PolicyOptions<DataSet> = {
(
CASE
WHEN (
'event.TickUpdate'.'TokenIn' = 'event.TickUpdate'.'TokenZero' AND
'event.TickUpdate'.'TokenOut' = 'event.TickUpdate'.'TokenZero' AND
'event.TickUpdate'.'derived.ReservesDiff' > 0
)
THEN (
Expand All @@ -108,7 +108,7 @@ export const swapVolumeCache: PolicyOptions<DataSet> = {
(
CASE
WHEN (
'event.TickUpdate'.'TokenIn' = 'event.TickUpdate'.'TokenOne' AND
'event.TickUpdate'.'TokenOut' = 'event.TickUpdate'.'TokenOne' AND
'event.TickUpdate'.'derived.ReservesDiff' > 0
)
THEN CAST('event.TickUpdate'.'derived.ReservesDiff' as FLOAT)
Expand All @@ -119,7 +119,7 @@ export const swapVolumeCache: PolicyOptions<DataSet> = {
(
CASE
WHEN (
'event.TickUpdate'.'TokenIn' = 'event.TickUpdate'.'TokenOne' AND
'event.TickUpdate'.'TokenOut' = 'event.TickUpdate'.'TokenOne' AND
'event.TickUpdate'.'derived.ReservesDiff' > 0
)
THEN (
Expand Down

0 comments on commit 5d9107c

Please sign in to comment.