Skip to content

Commit

Permalink
Use inner joins instead of left joins on transactions (#1465)
Browse files Browse the repository at this point in the history
* 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 <66172107+soispoke@users.noreply.github.com>
  • Loading branch information
aalan3 and soispoke authored Aug 31, 2022
1 parent be0c47c commit efedfb1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
8 changes: 6 additions & 2 deletions models/opensea/ethereum/opensea_v1_ethereum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ WHERE
(addrs[3] = '0x5b3256965e7c3cf26e11fcaf296dfc8807c01073'
OR addrs[10] = '0x5b3256965e7c3cf26e11fcaf296dfc8807c01073')
AND call_success = true
{% if is_incremental() %}
AND call_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
),

wyvern_all as
Expand Down Expand Up @@ -88,7 +91,8 @@ SELECT
AND fees.trace_address = wc.call_trace_address
{% if is_incremental() %}
AND fees.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
WHERE wc.call_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
),

erc_transfers as
Expand Down Expand Up @@ -177,7 +181,7 @@ SELECT DISTINCT
wa.fee_currency_symbol as royalty_fee_currency_symbol,
'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
FROM wyvern_all wa
LEFT JOIN {{ source('ethereum','transactions') }} tx ON wa.call_tx_hash = tx.hash
INNER JOIN {{ source('ethereum','transactions') }} tx ON wa.call_tx_hash = tx.hash
{% if is_incremental() %}
and tx.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
Expand Down
8 changes: 4 additions & 4 deletions models/seaport/ethereum/seaport_ethereum_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ with p1_call as (
string) as unique_trade_id,
a.zone
from p1_txn_level a
left join {{ source('ethereum','transactions') }} tx
inner join {{ source('ethereum','transactions') }} tx
on tx.hash = a.tx_hash
{% if not is_incremental() %}
and tx.block_number > 14801608
Expand Down Expand Up @@ -415,7 +415,7 @@ with p1_call as (
string) as unique_trade_id,
a.zone
from p2_transfer_level a
left join {{ source('ethereum','transactions') }} tx
inner join {{ source('ethereum','transactions') }} tx
on tx.hash = a.tx_hash
{% if not is_incremental() %}
and tx.block_number > 14801608
Expand Down Expand Up @@ -645,7 +645,7 @@ with p1_call as (
string) as unique_trade_id,
a.zone
from p3_txn_level a
left join {{ source('ethereum','transactions') }} tx
inner join {{ source('ethereum','transactions') }} tx
on tx.hash = a.tx_hash
{% if not is_incremental() %}
and tx.block_number > 14801608
Expand Down Expand Up @@ -850,7 +850,7 @@ with p1_call as (
string) as unique_trade_id,
a.zone
from p4_transfer_level a
left join {{ source('ethereum','transactions') }} tx
inner join {{ source('ethereum','transactions') }} tx
on tx.hash = a.tx_hash
{% if not is_incremental() %}
and tx.block_number > 14801608
Expand Down
18 changes: 9 additions & 9 deletions models/sudoswap/ethereum/sudoswap_ethereum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ WITH
, sb.ownerfee
, sb.protocolfee
FROM swaps_w_fees sb
LEFT JOIN {{ source('ethereum', 'traces') }} tr
INNER JOIN {{ source('ethereum', 'traces') }} tr
ON tr.type = 'call'
AND tr.call_type = 'call'
AND tr.tx_hash = sb.call_tx_hash
Expand Down Expand Up @@ -237,6 +237,14 @@ WITH
, tx.from as tx_from
, tx.to as tx_to
FROM swaps_cleaned sc
INNER JOIN {{ source('ethereum', 'transactions') }} tx
ON tx.hash=sc.tx_hash
{% if is_incremental() %}
AND tx.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
{% if not is_incremental() %}
AND tx.block_time >= '2022-4-1'
{% endif %}
LEFT JOIN {{ source('prices', 'usd') }} pu ON pu.blockchain='ethereum'
AND date_trunc('minute', pu.minute)=date_trunc('minute', sc.block_time)
AND symbol = 'WETH'
Expand All @@ -247,14 +255,6 @@ WITH
AND pu.minute >= '2022-4-1'
{% endif %}
--add in `pu.contract_address = sc.currency_address` in the future when ERC20 pairs are added in.
LEFT JOIN {{ source('ethereum', 'transactions') }} tx
ON tx.hash=sc.tx_hash
{% if is_incremental() %}
AND tx.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
{% if not is_incremental() %}
AND tx.block_time >= '2022-4-1'
{% endif %}
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.
LEFT JOIN tokens_ethereum_nft tokens ON nft_contract_address = tokens.contract_address
),
Expand Down
8 changes: 4 additions & 4 deletions models/x2y2/ethereum/x2y2_ethereum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ SELECT 'ethereum' AS blockchain
END AS royalty_fee_currency_symbol
, 'x2y2-' || txs.tx_hash || '-' || txs.nft_contract_address || txs.token_id || '-' || txs.seller || '-' || txs.evt_index || 'Trade' AS unique_trade_id
FROM all_x2y2_txs txs
INNER JOIN {{ source('ethereum','transactions') }} et ON et.hash=txs.tx_hash
{% if is_incremental() %}
AND et.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
LEFT JOIN {{ source('prices','usd') }} pu ON pu.blockchain='ethereum'
AND date_trunc('minute', pu.minute)=date_trunc('minute', txs.block_time)
AND (pu.contract_address=txs.currency_contract
OR (pu.contract_address='0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AND txs.currency_contract='0x0000000000000000000000000000000000000000'))
{% if is_incremental() %}
AND pu.minute >= date_trunc("day", now() - interval '1 week')
{% endif %}
LEFT JOIN {{ source('ethereum','transactions') }} et ON et.hash=txs.tx_hash
{% if is_incremental() %}
AND et.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
LEFT JOIN {{ source('erc721_ethereum','evt_transfer') }} erct ON txs.project_contract_address=erct.contract_address
AND erct.evt_tx_hash=txs.tx_hash
AND erct.tokenId=txs.token_id
Expand Down

0 comments on commit efedfb1

Please sign in to comment.