Skip to content

Commit b6adb5e

Browse files
soispokehildobby
andauthored
Tornado Cash: Fix sources, lowercase and improve materialization strategy (#1460)
* Fix sources, lowercase and improve materialization strat * ALTER TABLE, not VIEW * Revert "ALTER TABLE, not VIEW" This reverts commit f707c2e. * changed avalanche to avalanche_c in blockchain name for consistency across dune * Lowercase for blockchains and versiosn on schema.yml * avalanche to avalanche_c in schema and macro files * transactions_006 to transactions * Update alter_table_properties.sql * fix transactions_006 * Replace LEFT BY INNER JOINS on base transactions tables Co-authored-by: Hildebert Moulié <[email protected]>
1 parent 5c1734d commit b6adb5e

9 files changed

+77
-117
lines changed

macros/alter_table_properties.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,16 @@ ALTER TABLE airdrop_optimism.addresses SET TBLPROPERTIES ('dune.public'='true',
579579

580580
{% set tornado_cash_deposits %}
581581
ALTER TABLE tornado_cash.deposits SET TBLPROPERTIES ('dune.public'='true',
582-
'dune.data_explorer.blockchains'='["ethereum", "bnb", "avalanche", "gnosis", "optimism", "arbitrum"]',
582+
'dune.data_explorer.blockchains'='["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum"]',
583583
'dune.data_explorer.category'='abstraction',
584584
'dune.data_explorer.abstraction.type'='project',
585585
'dune.data_explorer.abstraction.name'='tornado_cash',
586586
'dune.data_explorer.contributors'='["hildobby", "dot2dotseurat"]');
587587
{% endset %}
588588

589589
{% set tornado_cash_withdrawals %}
590-
ALTER TABLE tornado_cash.withdrawals SET TBLPROPERTIES ('dune.public'='true',
591-
'dune.data_explorer.blockchains'='["ethereum", "bnb", "avalanche", "gnosis", "optimism", "arbitrum"]',
590+
ALTER VIEW tornado_cash.withdrawals SET TBLPROPERTIES ('dune.public'='true',
591+
'dune.data_explorer.blockchains'='["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum"]',
592592
'dune.data_explorer.category'='abstraction',
593593
'dune.data_explorer.abstraction.type'='project',
594594
'dune.data_explorer.abstraction.name'='tornado_cash',

models/ens/ens_ethereum_sources.yml

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ sources:
2424
error_after: { count: 24, period: hour }
2525
loaded_at_field: evt_block_time
2626
- name: ENSRegistry_evt_NewOwner
27-
freshness:
28-
warn_after: { count: 12, period: hour }
29-
error_after: { count: 24, period: hour }
3027
loaded_at_field: evt_block_time
3128
- name: ENSRegistryWithFallback_evt_NewOwner
3229
freshness:

models/sudoswap/ethereum/sudoswap_ethereum_sources.yml

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ sources:
1515
error_after: { count: 24, period: hour }
1616
loaded_at_field: call_block_time
1717
- name: LSSVMPair_general_call_swapTokenForAnyNFTs
18-
freshness:
19-
warn_after: { count: 12, period: hour }
20-
error_after: { count: 24, period: hour }
2118
loaded_at_field: call_block_time
2219
- name: LSSVMPair_general_call_swapTokenForSpecificNFTs
2320
freshness:

models/tornado_cash/tornado_cash_deposits.sql

+35-35
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ FROM
1515
SELECT tc.evt_block_time AS block_time
1616
, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AS currency_contract
1717
, 'ETH' AS currency_symbol
18-
, 'Ethereum' AS blockchain
19-
, 'Classic' AS tornado_version
18+
, 'ethereum' AS blockchain
19+
, 'classic' AS tornado_version
2020
, et.from AS depositor
2121
, tc.contract_address AS contract_address
2222
, CASE WHEN tc.contract_address='0x12d66f87a04a9e220743712ce6d9bb1b5616b8fc' THEN 0.1
@@ -29,19 +29,19 @@ FROM
2929
, tc.evt_index
3030
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
3131
FROM {{ source('tornado_cash_ethereum','eth_evt_Deposit') }} tc
32-
LEFT JOIN {{ source('ethereum','transactions_0006') }} et
32+
INNER JOIN {{ source('ethereum','transactions') }} et
3333
ON et.hash=tc.evt_tx_hash
3434
{% if not is_incremental() %}
3535
AND et.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_ethereum','eth_evt_Deposit') }})
3636
{% endif %}
3737
{% if is_incremental() %}
38-
AND et.block_time >= (select max(block_time) from {{ this }})
38+
AND et.block_time >= date_trunc("day", now() - interval '1 week')
3939
{% endif %}
4040
{% if not is_incremental() %}
4141
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_ethereum','eth_evt_Deposit') }})
4242
{% endif %}
4343
{% if is_incremental() %}
44-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
44+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
4545
{% endif %}
4646

4747
UNION
@@ -94,8 +94,8 @@ FROM
9494
WHEN tc.contract_address='0x610b717796ad172b316836ac95a2ffad065ceab4' THEN 'WBTC'
9595
WHEN tc.contract_address='0xbb93e510bbcd0b7beb5a853875f9ec60275cf498' THEN 'WBTC'
9696
END AS currency_symbol
97-
, 'Ethereum' AS blockchain
98-
, 'Classic' AS tornado_version
97+
, 'ethereum' AS blockchain
98+
, 'classic' AS tornado_version
9999
, et.from AS depositor
100100
, tc.contract_address AS contract_address
101101
, CASE WHEN tc.contract_address='0xd4b88df4d29f5cedd6857912842cff3b20c8cfa3' THEN 100
@@ -126,19 +126,19 @@ FROM
126126
, tc.evt_index
127127
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
128128
FROM {{ source('tornado_cash_ethereum','erc20_evt_Deposit') }} tc
129-
LEFT JOIN {{ source('ethereum','transactions_0006') }} et
129+
INNER JOIN {{ source('ethereum','transactions') }} et
130130
ON et.hash=tc.evt_tx_hash
131131
{% if not is_incremental() %}
132132
AND et.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_ethereum','erc20_evt_Deposit') }})
133133
{% endif %}
134134
{% if is_incremental() %}
135-
AND et.block_time >= (select max(block_time) from {{ this }})
135+
AND et.block_time >= date_trunc("day", now() - interval '1 week')
136136
{% endif %}
137137
{% if not is_incremental() %}
138138
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_ethereum','erc20_evt_Deposit') }})
139139
{% endif %}
140140
{% if is_incremental() %}
141-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
141+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
142142
{% endif %}
143143

144144
UNION
@@ -147,8 +147,8 @@ FROM
147147
SELECT tc.evt_block_time AS block_time
148148
, '0xb8c77482e45f1f44de1745f52c74426c631bdd52' AS currency_contract
149149
, 'BNB' AS currency_symbol
150-
, 'BNB' AS blockchain
151-
, 'Classic' AS tornado_version
150+
, 'bnb' AS blockchain
151+
, 'classic' AS tornado_version
152152
, bt.from AS depositor
153153
, tc.contract_address AS contract_address
154154
, CASE WHEN tc.contract_address='0x84443cfd09a48af6ef360c6976c5392ac5023a1f' THEN 0.1
@@ -161,19 +161,19 @@ FROM
161161
, tc.evt_index
162162
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
163163
FROM {{ source('tornado_cash_bnb','TornadoCashBNB_evt_Deposit') }} tc
164-
LEFT JOIN {{ source('bnb','transactions') }} bt
164+
INNER JOIN {{ source('bnb','transactions') }} bt
165165
ON bt.hash=tc.evt_tx_hash
166166
{% if not is_incremental() %}
167167
AND bt.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_bnb','TornadoCashBNB_evt_Deposit') }})
168168
{% endif %}
169169
{% if is_incremental() %}
170-
AND bt.block_time >= (select max(block_time) from {{ this }})
170+
AND bt.block_time >= date_trunc("day", now() - interval '1 week')
171171
{% endif %}
172172
{% if not is_incremental() %}
173173
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_bnb','TornadoCashBNB_evt_Deposit') }})
174174
{% endif %}
175175
{% if is_incremental() %}
176-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
176+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
177177
{% endif %}
178178

179179
UNION
@@ -182,8 +182,8 @@ FROM
182182
SELECT tc.evt_block_time AS block_time
183183
, '0x6b175474e89094c44da98b954eedeac495271d0f' AS currency_contract
184184
, 'xDAI' AS currency_symbol
185-
, 'Gnosis' AS blockchain
186-
, 'Classic' AS tornado_version
185+
, 'gnosis' AS blockchain
186+
, 'classic' AS tornado_version
187187
, gt.from AS depositor
188188
, tc.contract_address AS contract_address
189189
, CASE WHEN tc.contract_address='0x1e34a77868e19a6647b1f2f47b51ed72dede95dd' THEN 100
@@ -196,19 +196,19 @@ FROM
196196
, tc.evt_index
197197
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
198198
FROM {{ source('tornado_cash_gnosis','eth_evt_Deposit') }} tc
199-
LEFT JOIN {{ source('gnosis','transactions') }} gt
199+
INNER JOIN {{ source('gnosis','transactions') }} gt
200200
ON gt.hash=tc.evt_tx_hash
201201
{% if not is_incremental() %}
202202
AND gt.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_gnosis','eth_evt_Deposit') }})
203203
{% endif %}
204204
{% if is_incremental() %}
205-
AND gt.block_time >= (select max(block_time) from {{ this }})
205+
AND gt.block_time >= date_trunc("day", now() - interval '1 week')
206206
{% endif %}
207207
{% if not is_incremental() %}
208208
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_gnosis','eth_evt_Deposit') }})
209209
{% endif %}
210210
{% if is_incremental() %}
211-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
211+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
212212
{% endif %}
213213

214214
UNION
@@ -217,8 +217,8 @@ FROM
217217
SELECT tc.evt_block_time AS block_time
218218
, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AS currency_contract
219219
, 'ETH' AS currency_symbol
220-
, 'Optimism' AS blockchain
221-
, 'Classic' AS tornado_version
220+
, 'optimism' AS blockchain
221+
, 'classic' AS tornado_version
222222
, ot.from AS depositor
223223
, tc.contract_address AS contract_address
224224
, CASE WHEN tc.contract_address='0x84443cfd09a48af6ef360c6976c5392ac5023a1f' THEN 0.1
@@ -231,19 +231,19 @@ FROM
231231
, tc.evt_index
232232
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
233233
FROM {{ source('tornado_cash_optimism','ETHTornado_evt_Deposit') }} tc
234-
LEFT JOIN {{ source('optimism','transactions') }} ot
234+
INNER JOIN {{ source('optimism','transactions') }} ot
235235
ON ot.hash=tc.evt_tx_hash
236236
{% if not is_incremental() %}
237237
AND ot.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_optimism','ETHTornado_evt_Deposit') }})
238238
{% endif %}
239239
{% if is_incremental() %}
240-
AND ot.block_time >= (select max(block_time) from {{ this }})
240+
AND ot.block_time >= date_trunc("day", now() - interval '1 week')
241241
{% endif %}
242242
{% if not is_incremental() %}
243243
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_optimism','ETHTornado_evt_Deposit') }})
244244
{% endif %}
245245
{% if is_incremental() %}
246-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
246+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
247247
{% endif %}
248248

249249
UNION
@@ -252,8 +252,8 @@ FROM
252252
SELECT tc.evt_block_time AS block_time
253253
, '0x85f138bfEE4ef8e540890CFb48F620571d67Eda3' AS currency_contract
254254
, 'AVAX' AS currency_symbol
255-
, 'Avalanche' AS blockchain
256-
, 'Classic' AS tornado_version
255+
, 'avalanche_c' AS blockchain
256+
, 'classic' AS tornado_version
257257
, at.from AS depositor
258258
, tc.contract_address AS contract_address
259259
, CASE WHEN tc.contract_address='0x330bdfade01ee9bf63c209ee33102dd334618e0a' THEN 10
@@ -265,19 +265,19 @@ FROM
265265
, tc.evt_index
266266
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
267267
FROM {{ source('tornado_cash_avalanche_c','ETHTornado_evt_Deposit') }} tc
268-
LEFT JOIN {{ source('avalanche_c','transactions') }} at
268+
INNER JOIN {{ source('avalanche_c','transactions') }} at
269269
ON at.hash=tc.evt_tx_hash
270270
{% if not is_incremental() %}
271271
AND at.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_avalanche_c','ETHTornado_evt_Deposit') }})
272272
{% endif %}
273273
{% if is_incremental() %}
274-
AND at.block_time >= (select max(block_time) from {{ this }})
274+
AND at.block_time >= date_trunc("day", now() - interval '1 week')
275275
{% endif %}
276276
{% if not is_incremental() %}
277277
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_avalanche_c','ETHTornado_evt_Deposit') }})
278278
{% endif %}
279279
{% if is_incremental() %}
280-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
280+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
281281
{% endif %}
282282

283283
UNION
@@ -286,8 +286,8 @@ FROM
286286
SELECT tc.evt_block_time AS block_time
287287
, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AS currency_contract
288288
, 'ETH' AS currency_symbol
289-
, 'Arbitrum' AS blockchain
290-
, 'Classic' AS tornado_version
289+
, 'arbitrum' AS blockchain
290+
, 'classic' AS tornado_version
291291
, at.from AS depositor
292292
, tc.contract_address AS contract_address
293293
, CASE WHEN tc.contract_address='0x84443cfd09a48af6ef360c6976c5392ac5023a1f' THEN 0.1
@@ -300,18 +300,18 @@ FROM
300300
, tc.evt_index
301301
, TRY_CAST(date_trunc('DAY', tc.evt_block_time) AS date) AS block_date
302302
FROM {{ source('tornado_cash_arbitrum','ETHTornado_evt_Deposit') }} tc
303-
LEFT JOIN {{ source('arbitrum','transactions') }} at
303+
INNER JOIN {{ source('arbitrum','transactions') }} at
304304
ON at.hash=tc.evt_tx_hash
305305
{% if not is_incremental() %}
306306
AND at.block_time >= (select min(evt_block_time) from {{ source('tornado_cash_arbitrum','ETHTornado_evt_Deposit') }})
307307
{% endif %}
308308
{% if is_incremental() %}
309-
AND at.block_time >= (select max(block_time) from {{ this }})
309+
AND at.block_time >= date_trunc("day", now() - interval '1 week')
310310
{% endif %}
311311
{% if not is_incremental() %}
312312
WHERE tc.evt_block_time >= (select min(evt_block_time) from {{ source('tornado_cash_arbitrum','ETHTornado_evt_Deposit') }})
313313
{% endif %}
314314
{% if is_incremental() %}
315-
WHERE tc.evt_block_time >= (select max(block_time) from {{ this }})
315+
WHERE tc.evt_block_time >= date_trunc("day", now() - interval '1 week')
316316
{% endif %}
317317
)

models/tornado_cash/tornado_cash_schema.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ version: 2
55
models:
66
- name: tornado_cash_deposits
77
meta:
8-
blockchain: ethereum, bnb, avalanche, gnosis, optimism, arbitrum #, polygon
8+
blockchain: ethereum, bnb, avalanche_c, gnosis, optimism, arbitrum #, polygon
99
project: tornado_cash
1010
contibutors: [hildobby, dot2dotseurat]
1111
config:
12-
tags: ['tornado_cash', 'deposits', 'ethereum', 'bnb', 'avalanche', 'gnosis', 'optimism', 'arbitrum']
12+
tags: ['tornado_cash', 'deposits', 'ethereum', 'bnb', 'avalanche_c', 'gnosis', 'optimism', 'arbitrum']
1313
description: "Tornado Cash Deposits"
1414
columns:
1515
- &block_time
@@ -25,13 +25,13 @@ models:
2525
name: blockchain
2626
tests:
2727
- accepted_values:
28-
values: ['Ethereum', 'BNB', 'Avalanche', 'Gnosis', 'Optimism', 'Arbitrum', 'Polygon']
28+
values: ['ethereum', 'bnb', 'avalanche_c', 'gnosis', 'optimism', 'arbitrum', 'polygon']
2929
description: "Blockchain"
3030
- &tornado_version
3131
name: tornado_version
3232
tests:
3333
- accepted_values:
34-
values: ['Classic', 'Nova']
34+
values: ['classic', 'nova']
3535
description: "Version of Tornado Cash used for this transaction"
3636
- &depositor
3737
name: depositor

models/tornado_cash/tornado_cash_sources.yml

-30
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ sources:
44
- name: tornado_cash_bnb
55
freshness:
66
warn_after: { count: 12, period: hour }
7-
error_after: { count: 24, period: hour }
87
tables:
98
- name: TornadoCashBNB_evt_Deposit
109
loaded_at_field: evt_block_time
@@ -16,18 +15,6 @@ sources:
1615
- name: commitment
1716
- name: leafIndex
1817
- name: timestamp
19-
- name: ETHTornado_evt_Withdrawal
20-
loaded_at_field: evt_block_time
21-
columns:
22-
- name: contract_address
23-
- name: evt_tx_hash
24-
- name: evt_index
25-
- name: evt_block_time
26-
- name: evt_block_number
27-
- name: fee
28-
- name: nullifierHash
29-
- name: relayer
30-
- name: to
3118
- name: TornadoCashBNB_evt_Withdrawal
3219
loaded_at_field: evt_block_time
3320
columns:
@@ -44,7 +31,6 @@ sources:
4431
- name: tornado_cash_arbitrum
4532
freshness:
4633
warn_after: { count: 12, period: hour }
47-
error_after: { count: 24, period: hour }
4834
tables:
4935
- name: ETHTornado_evt_Deposit
5036
loaded_at_field: evt_block_time
@@ -73,7 +59,6 @@ sources:
7359
- name: tornado_cash_optimism
7460
freshness:
7561
warn_after: { count: 12, period: hour }
76-
error_after: { count: 24, period: hour }
7762
tables:
7863
- name: ETHTornado_evt_Deposit
7964
loaded_at_field: evt_block_time
@@ -86,18 +71,6 @@ sources:
8671
- name: commitment
8772
- name: leafIndex
8873
- name: timestamp
89-
- name: erc20_evt_Withdrawal
90-
loaded_at_field: evt_block_time
91-
columns:
92-
- name: contract_address
93-
- name: evt_tx_hash
94-
- name: evt_index
95-
- name: evt_block_time
96-
- name: evt_block_number
97-
- name: fee
98-
- name: nullifierHash
99-
- name: relayer
100-
- name: to
10174
- name: ETHTornado_evt_Withdrawal
10275
loaded_at_field: evt_block_time
10376
columns:
@@ -114,7 +87,6 @@ sources:
11487
- name: tornado_cash_avalanche_c
11588
freshness:
11689
warn_after: { count: 12, period: hour }
117-
error_after: { count: 24, period: hour }
11890
tables:
11991
- name: ETHTornado_evt_Deposit
12092
loaded_at_field: evt_block_time
@@ -143,7 +115,6 @@ sources:
143115
- name: tornado_cash_ethereum
144116
freshness:
145117
warn_after: { count: 12, period: hour }
146-
error_after: { count: 24, period: hour }
147118
tables:
148119
- name: erc20_evt_Deposit
149120
loaded_at_field: evt_block_time
@@ -191,7 +162,6 @@ sources:
191162
- name: tornado_cash_gnosis
192163
freshness:
193164
warn_after: { count: 12, period: hour }
194-
error_after: { count: 24, period: hour }
195165
tables:
196166
- name: eth_evt_Deposit
197167
loaded_at_field: evt_block_time

0 commit comments

Comments
 (0)