Skip to content

Commit

Permalink
Fix uniqueness issue looksrare/opensea trades (#1294)
Browse files Browse the repository at this point in the history
Brief comments on the purpose of your changes:


*For Dune Engine V2*
I've checked that:

* [ ] I tested the query on dune.com after compiling the model with dbt compile (compiled queries are written to the target directory)
* [ ] I used "refs" to reference other models in this repo and "sources" to reference raw or decoded tables 
* [ ] if adding a new model, I added a test
* [ ] the filename is unique and ends with .sql
* [ ] each sql file is a select statement and has only one view, table or function defined  
* [ ] column names are `lowercase_snake_cased`

When you are ready for a review, tag duneanalytics/data-experience. We will re-open your forked pull request as an internal pull request. Then your spells will run in dbt and the logs will be avaiable in Github Actions DBT Slim CI. This job will only run the models and tests changed by your PR compared to the production project.
  • Loading branch information
soispoke authored Jul 18, 2022
1 parent c8ba103 commit ee157e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}}

WITH looks_rare AS (
SELECT
SELECT
ask.evt_block_time AS block_time,
ask.tokenId::string AS token_id,
ask.amount AS number_of_items,
Expand Down Expand Up @@ -118,7 +118,7 @@ SELECT DISTINCT
WHEN agg.name is NULL AND erc.value_unique is NULL AND erc.count_erc > 1 THEN erc.count_erc
WHEN tokens.standard = 'erc1155' THEN erc.value_unique
WHEN tokens.standard = 'erc721' THEN erc.count_erc
ELSE (SELECT
ELSE COALESCE((SELECT
count(1)::bigint cnt
FROM {{ source('erc721_ethereum','evt_transfer') }} erc721
WHERE erc721.evt_tx_hash = tx_hash
Expand All @@ -127,9 +127,9 @@ SELECT DISTINCT
count(1)::bigint cnt
FROM {{ source('erc1155_ethereum','evt_transfersingle') }} erc1155
WHERE erc1155.evt_tx_hash = tx_hash
) END AS number_of_items,
), 0) END AS number_of_items,
looks_rare.category as trade_category,
evt_type,
CASE WHEN evt_type is NULL THEN 'Other' ELSE evt_type END as evt_type,
seller,
buyer,
looks_rare.price / power(10,erc20.decimals) AS amount_original,
Expand All @@ -153,7 +153,7 @@ SELECT DISTINCT
royalty_fee / looks_rare.price * 100 as royalty_fee_percentage,
royalty_fee_receive_address,
royalty_fee_currency_symbol,
tx_hash || '-' || token_id || '-' || seller || '-' || looks_rare.evt_index::string || '-' || evt_type as unique_trade_id
'looksrare' || '-' || tx_hash || '-' || token_id::string || '-' || seller::string || '-' || COALESCE(erc.contract_address, nft_contract_address) || '-' || looks_rare.evt_index::string || '-' || COALESCE(evt_type::string, 'Other') || '-' || COALESCE(case when erc.value_unique::string is null then '0' ELSE '1' end, '1') as unique_trade_id
FROM looks_rare
INNER JOIN {{ source('ethereum','transactions') }} tx ON tx_hash = tx.hash
AND tx.block_time > '2022-01-01'
Expand All @@ -164,7 +164,8 @@ LEFT JOIN {{ source('prices', 'usd') }} p ON p.minute = date_trunc('minute', loo
AND p.contract_address = currency_contract
AND p.blockchain ='ethereum'
LEFT JOIN {{ ref('tokens_ethereum_erc20') }} erc20 ON erc20.contract_address = currency_contract
WHERE number_of_items >= 1
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
WHERE looks_rare.block_time >= (select max(block_time) from {{ this }})
AND looks_rare.block_time >= (select max(block_time) from {{ this }})
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ SELECT DISTINCT
(wa.fees / wa.amount_original * 100)::string AS royalty_fee_percentage,
wa.fee_receive_address as royalty_fee_receive_address,
wa.fee_currency_symbol as royalty_fee_currency_symbol,
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
'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
LEFT JOIN erc_transfers ON erc_transfers.evt_tx_hash = wa.call_tx_hash AND (wa.token_id = erc_transfers.token_id_erc
Expand Down

0 comments on commit ee157e4

Please sign in to comment.