Skip to content

Commit baa92be

Browse files
authored
Small fix for Uniswap Liquidity events -- ready for review (duneanalytics#8532)
* small update * reload * small fix to price table * refresh tvl & events aggregated tables
1 parent d68ff34 commit baa92be

19 files changed

Lines changed: 79 additions & 14 deletions

File tree

dbt_subprojects/dex/macros/models/_project/uniswap_compatible_liquidity.sql

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
{% if is_incremental() %}
3939

40+
-- force price reload
41+
4042
with
4143

4244
base_events as (
@@ -85,11 +87,21 @@ get_latest_active_pools as (
8587
, max_by(th.evt_index, th.block_index_sum) as evt_index
8688
, max(block_index_sum) as block_index_sum
8789
, max_by(sqrtpricex96, th.block_index_sum) as sqrtpricex96
88-
from
89-
{{this}} th
90-
inner join
91-
get_active_pools ga
92-
on th.id = ga.id
90+
from (
91+
select
92+
th.*,
93+
be.block_index_sum as base_block_index_sum
94+
from
95+
{{this}} th
96+
inner join
97+
get_active_pools ga
98+
on th.id = ga.id
99+
left join
100+
base_events be
101+
on th.id = be.id
102+
and th.block_index_sum = be.block_index_sum
103+
) th
104+
where base_block_index_sum is null
93105
group by 1
94106

95107
union all
@@ -256,7 +268,8 @@ modify_liquidity_events as (
256268

257269
get_events as (
258270
select
259-
evt_block_time
271+
evt_tx_from as tx_from
272+
, evt_block_time
260273
, evt_block_number
261274
, evt_block_number + evt_index/1e6 as block_index_sum
262275
, id
@@ -328,7 +341,8 @@ fee_collection as (
328341

329342
get_fees as (
330343
select
331-
call_tx_hash as tx_hash
344+
call_tx_from as tx_from
345+
, call_tx_hash as tx_hash
332346
, call_block_time as block_time
333347
, call_block_number as block_number
334348
, 1 as evt_index -- we don't actually use index here for anything and some indexes are missing in the call table so hardcoding here as evt_index
@@ -345,14 +359,15 @@ fee_collection as (
345359
agg_fees as (
346360
select
347361
tx_hash
362+
, tx_from
348363
, block_time
349364
, block_number
350365
, min(evt_index) as evt_index
351366
, sum(amount) as fee_amount
352367
, currency as fee_currency
353368
from
354369
get_fees
355-
group by 1, 2, 3, 6
370+
group by 1, 2, 3, 4, 7
356371
),
357372

358373
modify_events as (
@@ -396,7 +411,8 @@ fee_collection as (
396411

397412
join_with_pools as (
398413
select
399-
gf.tx_hash
414+
gf.tx_from
415+
, gf.tx_hash
400416
, gf.block_time
401417
, gf.block_number
402418
, gf.evt_index
@@ -417,11 +433,12 @@ fee_collection as (
417433
inner join
418434
get_pools gp
419435
on ae.id = gp.id
420-
group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
436+
group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
421437
)
422438

423439
select
424440
id
441+
, tx_from
425442
, block_time
426443
, block_number
427444
, tx_hash
@@ -441,7 +458,8 @@ fee_collection as (
441458

442459
swap_events as (
443460
select
444-
evt_block_time
461+
evt_tx_from as tx_from
462+
, evt_block_time
445463
, evt_block_number
446464
, evt_tx_hash
447465
, evt_index
@@ -458,6 +476,7 @@ swap_events as (
458476
liquidity_change_base as (
459477
select
460478
ml.id
479+
, ml.tx_from
461480
, ml.evt_block_time as block_time
462481
, ml.evt_block_number as block_number
463482
, ml.evt_tx_hash as tx_hash
@@ -477,6 +496,7 @@ liquidity_change_base as (
477496

478497
select
479498
se.id
499+
, se.tx_from
480500
, se.evt_block_time as block_time
481501
, se.evt_block_number as block_number
482502
, se.evt_tx_hash as tx_hash
@@ -496,6 +516,7 @@ liquidity_change_base as (
496516

497517
select
498518
id
519+
, tx_from
499520
, block_time
500521
, block_number
501522
, tx_hash
@@ -509,7 +530,6 @@ liquidity_change_base as (
509530
fee_collection
510531
where tx_hash not in (select evt_tx_hash from swap_events)
511532
)
512-
513533
select
514534
'{{blockchain}}' as blockchain
515535
, '{{project}}' as project
@@ -520,6 +540,7 @@ liquidity_change_base as (
520540
, block_number
521541
, id
522542
, tx_hash
543+
, tx_from
523544
, evt_index
524545
, event_type
525546
, token0

dbt_subprojects/dex/macros/models/enrich_dex_liq_with_prices.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ WITH base_liquidity as (
4949
, base.block_number
5050
, base.id
5151
, base.tx_hash
52+
, base.tx_from
5253
, base.evt_index
5354
, base.event_type
5455
, base.token0
@@ -80,6 +81,7 @@ WITH base_liquidity as (
8081
, en.block_number
8182
, en.id
8283
, en.tx_hash
84+
, en.tx_from
8385
, en.evt_index
8486
, en.event_type
8587
, en.token0
@@ -114,6 +116,7 @@ SELECT
114116
, block_number
115117
, id
116118
, tx_hash
119+
, tx_from
117120
, evt_index
118121
, event_type
119122
, token0

dbt_subprojects/dex/models/_projects/uniswap/_schema.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ models:
317317
- &tx_hash
318318
name: tx_hash
319319
description: "The hash of the transaction"
320+
- &tx_from
321+
name: tx_from
322+
description: "Address that initiated the txn"
320323
- &evt_index
321324
name: evt_index
322325
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"
@@ -376,6 +379,7 @@ models:
376379
- *block_number
377380
- *id
378381
- *tx_hash
382+
- *tx_from
379383
- *evt_index
380384
- *event_type
381385
- *token0

dbt_subprojects/dex/models/_projects/uniswap/arbitrum/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

dbt_subprojects/dex/models/_projects/uniswap/avalanche_c/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

dbt_subprojects/dex/models/_projects/uniswap/base/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

dbt_subprojects/dex/models/_projects/uniswap/blast/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

dbt_subprojects/dex/models/_projects/uniswap/bnb/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

dbt_subprojects/dex/models/_projects/uniswap/ethereum/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

dbt_subprojects/dex/models/_projects/uniswap/ink/_schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ models:
120120
- &tx_hash
121121
name: tx_hash
122122
description: "The hash of the transaction"
123+
- &tx_from
124+
name: tx_from
125+
description: "Address that initiated the txn"
123126
- &evt_index
124127
name: evt_index
125128
description: "Index of the event in the transaction. Can be used to uniquely identify the order of events within a transaction"

0 commit comments

Comments
 (0)