Skip to content

Commit efedfb1

Browse files
aalan3soispoke
andauthored
Use inner joins instead of left joins on transactions (#1465)
* Use inner joins instead of left joins on transactions * Handle the fees for opensea differently * Change sudoswap join on traces to inner * add incremental filter on wyvern_call_data Co-authored-by: soispoke <[email protected]>
1 parent be0c47c commit efedfb1

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

models/opensea/ethereum/opensea_v1_ethereum_events.sql

+6-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ WHERE
5959
(addrs[3] = '0x5b3256965e7c3cf26e11fcaf296dfc8807c01073'
6060
OR addrs[10] = '0x5b3256965e7c3cf26e11fcaf296dfc8807c01073')
6161
AND call_success = true
62+
{% if is_incremental() %}
63+
AND call_block_time >= date_trunc("day", now() - interval '1 week')
64+
{% endif %}
6265
),
6366

6467
wyvern_all as
@@ -88,7 +91,8 @@ SELECT
8891
AND fees.trace_address = wc.call_trace_address
8992
{% if is_incremental() %}
9093
AND fees.block_time >= date_trunc("day", now() - interval '1 week')
91-
{% endif %}
94+
WHERE wc.call_block_time >= date_trunc("day", now() - interval '1 week')
95+
{% endif %}
9296
),
9397

9498
erc_transfers as
@@ -177,7 +181,7 @@ SELECT DISTINCT
177181
wa.fee_currency_symbol as royalty_fee_currency_symbol,
178182
'opensea' || '-' || wa.call_tx_hash || '-' || coalesce(wa.token_id, token_id_erc, '') || '-' || wa.seller || '-' || coalesce(evt_index::string, '') || '-' || coalesce(wa.call_trace_address::string,'') as unique_trade_id
179183
FROM wyvern_all wa
180-
LEFT JOIN {{ source('ethereum','transactions') }} tx ON wa.call_tx_hash = tx.hash
184+
INNER JOIN {{ source('ethereum','transactions') }} tx ON wa.call_tx_hash = tx.hash
181185
{% if is_incremental() %}
182186
and tx.block_time >= date_trunc("day", now() - interval '1 week')
183187
{% endif %}

models/seaport/ethereum/seaport_ethereum_transfers.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ with p1_call as (
210210
string) as unique_trade_id,
211211
a.zone
212212
from p1_txn_level a
213-
left join {{ source('ethereum','transactions') }} tx
213+
inner join {{ source('ethereum','transactions') }} tx
214214
on tx.hash = a.tx_hash
215215
{% if not is_incremental() %}
216216
and tx.block_number > 14801608
@@ -415,7 +415,7 @@ with p1_call as (
415415
string) as unique_trade_id,
416416
a.zone
417417
from p2_transfer_level a
418-
left join {{ source('ethereum','transactions') }} tx
418+
inner join {{ source('ethereum','transactions') }} tx
419419
on tx.hash = a.tx_hash
420420
{% if not is_incremental() %}
421421
and tx.block_number > 14801608
@@ -645,7 +645,7 @@ with p1_call as (
645645
string) as unique_trade_id,
646646
a.zone
647647
from p3_txn_level a
648-
left join {{ source('ethereum','transactions') }} tx
648+
inner join {{ source('ethereum','transactions') }} tx
649649
on tx.hash = a.tx_hash
650650
{% if not is_incremental() %}
651651
and tx.block_number > 14801608
@@ -850,7 +850,7 @@ with p1_call as (
850850
string) as unique_trade_id,
851851
a.zone
852852
from p4_transfer_level a
853-
left join {{ source('ethereum','transactions') }} tx
853+
inner join {{ source('ethereum','transactions') }} tx
854854
on tx.hash = a.tx_hash
855855
{% if not is_incremental() %}
856856
and tx.block_number > 14801608

models/sudoswap/ethereum/sudoswap_ethereum_events.sql

+9-9
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ WITH
155155
, sb.ownerfee
156156
, sb.protocolfee
157157
FROM swaps_w_fees sb
158-
LEFT JOIN {{ source('ethereum', 'traces') }} tr
158+
INNER JOIN {{ source('ethereum', 'traces') }} tr
159159
ON tr.type = 'call'
160160
AND tr.call_type = 'call'
161161
AND tr.tx_hash = sb.call_tx_hash
@@ -237,6 +237,14 @@ WITH
237237
, tx.from as tx_from
238238
, tx.to as tx_to
239239
FROM swaps_cleaned sc
240+
INNER JOIN {{ source('ethereum', 'transactions') }} tx
241+
ON tx.hash=sc.tx_hash
242+
{% if is_incremental() %}
243+
AND tx.block_time >= date_trunc("day", now() - interval '1 week')
244+
{% endif %}
245+
{% if not is_incremental() %}
246+
AND tx.block_time >= '2022-4-1'
247+
{% endif %}
240248
LEFT JOIN {{ source('prices', 'usd') }} pu ON pu.blockchain='ethereum'
241249
AND date_trunc('minute', pu.minute)=date_trunc('minute', sc.block_time)
242250
AND symbol = 'WETH'
@@ -247,14 +255,6 @@ WITH
247255
AND pu.minute >= '2022-4-1'
248256
{% endif %}
249257
--add in `pu.contract_address = sc.currency_address` in the future when ERC20 pairs are added in.
250-
LEFT JOIN {{ source('ethereum', 'transactions') }} tx
251-
ON tx.hash=sc.tx_hash
252-
{% if is_incremental() %}
253-
AND tx.block_time >= date_trunc("day", now() - interval '1 week')
254-
{% endif %}
255-
{% if not is_incremental() %}
256-
AND tx.block_time >= '2022-4-1'
257-
{% endif %}
258258
LEFT JOIN nft_ethereum_aggregators agg ON agg.contract_address = tx.to --assumes aggregator is the top level call. Will need to change this to check for agg calls in internal traces later on.
259259
LEFT JOIN tokens_ethereum_nft tokens ON nft_contract_address = tokens.contract_address
260260
),

models/x2y2/ethereum/x2y2_ethereum_events.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,17 @@ SELECT 'ethereum' AS blockchain
189189
END AS royalty_fee_currency_symbol
190190
, 'x2y2-' || txs.tx_hash || '-' || txs.nft_contract_address || txs.token_id || '-' || txs.seller || '-' || txs.evt_index || 'Trade' AS unique_trade_id
191191
FROM all_x2y2_txs txs
192+
INNER JOIN {{ source('ethereum','transactions') }} et ON et.hash=txs.tx_hash
193+
{% if is_incremental() %}
194+
AND et.block_time >= date_trunc("day", now() - interval '1 week')
195+
{% endif %}
192196
LEFT JOIN {{ source('prices','usd') }} pu ON pu.blockchain='ethereum'
193197
AND date_trunc('minute', pu.minute)=date_trunc('minute', txs.block_time)
194198
AND (pu.contract_address=txs.currency_contract
195199
OR (pu.contract_address='0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AND txs.currency_contract='0x0000000000000000000000000000000000000000'))
196200
{% if is_incremental() %}
197201
AND pu.minute >= date_trunc("day", now() - interval '1 week')
198202
{% endif %}
199-
LEFT JOIN {{ source('ethereum','transactions') }} et ON et.hash=txs.tx_hash
200-
{% if is_incremental() %}
201-
AND et.block_time >= date_trunc("day", now() - interval '1 week')
202-
{% endif %}
203203
LEFT JOIN {{ source('erc721_ethereum','evt_transfer') }} erct ON txs.project_contract_address=erct.contract_address
204204
AND erct.evt_tx_hash=txs.tx_hash
205205
AND erct.tokenId=txs.token_id

0 commit comments

Comments
 (0)