From 6c07fafc1d5c6d4925ca28688f0c3f3f473f1682 Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Mon, 5 Sep 2022 11:18:38 +0200 Subject: [PATCH] Add Archipelago market to nft.trades (#1473) * add archipelago trades to nft.trades * whitespace and newlines * requested changes Co-authored-by: soispoke <66172107+soispoke@users.noreply.github.com> --- dbt_project.yml | 8 + macros/alter_table_properties.sql | 30 +++ macros/optimize_tables.sql | 7 +- .../ethereum/archipelago_ethereum_events.sql | 227 ++++++++++++++++++ .../ethereum/archipelago_ethereum_fees.sql | 39 +++ .../ethereum/archipelago_ethereum_schema.yml | 208 ++++++++++++++++ .../ethereum/archipelago_ethereum_sources.yml | 15 ++ .../ethereum/archipelago_ethereum_trades.sql | 34 +++ models/nft/nft_events.sql | 44 +++- models/nft/nft_fees.sql | 39 ++- models/nft/nft_trades.sql | 34 ++- .../archipelago_ethereum_assert_trades.sql | 31 +++ 12 files changed, 709 insertions(+), 7 deletions(-) create mode 100644 models/archipelago/ethereum/archipelago_ethereum_events.sql create mode 100644 models/archipelago/ethereum/archipelago_ethereum_fees.sql create mode 100644 models/archipelago/ethereum/archipelago_ethereum_schema.yml create mode 100644 models/archipelago/ethereum/archipelago_ethereum_sources.yml create mode 100644 models/archipelago/ethereum/archipelago_ethereum_trades.sql create mode 100644 tests/archipelago/ethereum/archipelago_ethereum_assert_trades.sql diff --git a/dbt_project.yml b/dbt_project.yml index 3be4ff9c3d4..8b957dd78b6 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -148,6 +148,13 @@ models: +schema: tornado_cash +materialized: view + archipelago: + +schema: archipelago + +materialized: view + ethereum: + +schema: archipelago_ethereum + +materialized: view + integration_test: +schema: integration_test +materialized: view @@ -216,6 +223,7 @@ seeds: token_bought_amount: float token_sold_address: string token_sold_amount: float + sudoswap: +enabled: true +schema: test_data diff --git a/macros/alter_table_properties.sql b/macros/alter_table_properties.sql index 03bd2a2aec4..dfb257cab31 100644 --- a/macros/alter_table_properties.sql +++ b/macros/alter_table_properties.sql @@ -641,6 +641,33 @@ ALTER VIEW tokens_optimism.erc20 SET TBLPROPERTIES('dune.public'='true', 'dune.data_explorer.contributors'='["msilb7", "chuxinh"]'); {% endset %} +{% set archipelago_ethereum_events %} +ALTER TABLE archipelago_ethereum.events SET TBLPROPERTIES ('dune.public'='true', + 'dune.data_explorer.blockchains'='["ethereum"]', + 'dune.data_explorer.category'='abstraction', + 'dune.data_explorer.abstraction.type'='project', + 'dune.data_explorer.abstraction.name'='archipelago', + 'dune.data_explorer.contributors'='["0xRob"]'); +{% endset %} + +{% set archipelago_ethereum_trades %} +ALTER VIEW archipelago_ethereum.trades SET TBLPROPERTIES ('dune.public'='true', + 'dune.data_explorer.blockchains'='["ethereum"]', + 'dune.data_explorer.category'='abstraction', + 'dune.data_explorer.abstraction.type'='project', + 'dune.data_explorer.abstraction.name'='archipelago', + 'dune.data_explorer.contributors'='["0xRob"]'); +{% endset %} + +{% set archipelago_ethereum_fees %} +ALTER VIEW archipelago_ethereum.fees SET TBLPROPERTIES ('dune.public'='true', + 'dune.data_explorer.blockchains'='["ethereum"]', + 'dune.data_explorer.category'='abstraction', + 'dune.data_explorer.abstraction.type'='project', + 'dune.data_explorer.abstraction.name'='archipelago', + 'dune.data_explorer.contributors'='["0xRob"]'); +{% endset %} + {% do run_query(balances_ethereum_erc20_day) %} {% do run_query(balances_ethereum_erc20_hour) %} @@ -712,6 +739,9 @@ ALTER VIEW tokens_optimism.erc20 SET TBLPROPERTIES('dune.public'='true', {% do run_query(uniswap_v3_optimism_pools) %} {% do run_query(tokens_optimism_nft) %} {% do run_query(tokens_optimism_erc20) %} +{% do run_query(archipelago_ethereum_events) %} +{% do run_query(archipelago_ethereum_trades) %} +{% do run_query(archipelago_ethereum_fees) %} {% do log("Tables generated", info=True) %} {%- else -%} diff --git a/macros/optimize_tables.sql b/macros/optimize_tables.sql index 55d0df69ffe..b59760d3d19 100644 --- a/macros/optimize_tables.sql +++ b/macros/optimize_tables.sql @@ -83,6 +83,10 @@ OPTIMIZE uniswap_v2_ethereum.trades; OPTIMIZE x2y2_ethereum.events; {% endset %} +{% set archipelago_ethereum_events %} +OPTIMIZE archipelago_ethereum.events; +{% endset %} + {% do run_query(looksrare_ethereum_events) %} {% do run_query(magiceden_solana_events) %} @@ -103,5 +107,6 @@ OPTIMIZE x2y2_ethereum.events; {% do run_query(uniswap_v1_ethereum_trades) %} {% do run_query(uniswap_v2_ethereum_trades) %} {% do run_query(x2y2_ethereum_events) %} +{% do run_query(archipelago_ethereum_events) %} {% do log("Tables Optimized", info=True) %} -{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/models/archipelago/ethereum/archipelago_ethereum_events.sql b/models/archipelago/ethereum/archipelago_ethereum_events.sql new file mode 100644 index 00000000000..c10b4c94e03 --- /dev/null +++ b/models/archipelago/ethereum/archipelago_ethereum_events.sql @@ -0,0 +1,227 @@ +{{ config( + alias = 'events', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_date', 'unique_trade_id'] + ) +}} + +WITH + trade_events as ( + SELECT + contract_address as project_contract_address + , evt_block_number as block_number + , evt_block_time as block_time + , evt_tx_hash as tx_hash + , buyer + , seller + , cost as amount_raw + , currency as currency_contract + , tradeId as unique_trade_id + FROM {{ source('archipelago_ethereum','ArchipelagoMarket_evt_Trade') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc("day", now() - interval '1 week') + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= '2022-6-20' + {% endif %} + + ), + + token_events as ( + SELECT + evt_block_number as block_number + , evt_block_time as block_time + , evt_tx_hash as tx_hash + , tokenAddress as nft_contract_address + , tokenId as token_id + , tradeId as unique_trade_id + FROM {{ source('archipelago_ethereum','ArchipelagoMarket_evt_TokenTrade') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc("day", now() - interval '1 week') + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= '2022-6-20' + {% endif %} + + ), + + fee_events as ( + SELECT + evt_block_number as block_number + , evt_block_time as block_time + , evt_tx_hash as tx_hash + , amount as fee_amount_raw + , currency as fee_currency_contract + , recipient as fee_receive_address + , micros / pow(10,4) as fee_percentage + , tradeId as unique_trade_id + , case when ( + upper(recipient) = upper('0xA76456bb6aBC50FB38e17c042026bc27a95C3314') + or upper(recipient) = upper('0x1fC12C9f68A6B0633Ba5897A40A8e61ed9274dC9') + ) then true else false end + as is_protocol_fee + FROM {{ source('archipelago_ethereum','ArchipelagoMarket_evt_RoyaltyPayment') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc("day", now() - interval '1 week') + {% endif %} + {% if not is_incremental() %} + WHERE evt_block_time >= '2022-6-20' + {% endif %} + + ), + + tokens_ethereum_nft as ( + SELECT + * + FROM {{ ref('tokens_ethereum_nft') }} + ), + + nft_ethereum_aggregators as ( + SELECT + * + FROM {{ ref('nft_ethereum_aggregators') }} + ), + + -- enrichments + + trades_with_nft_and_tx as ( + select + e.* + , t.nft_contract_address + , t.token_id + , tx.from as tx_from + , tx.to as tx_to + from trade_events e + inner join token_events t + ON e.block_number = t.block_number and e.unique_trade_id = t.unique_trade_id + inner join {{ source('ethereum', 'transactions') }} tx + ON e.block_number = tx.block_number and e.tx_hash = 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-6-20' + {% endif %} + ), + + platform_fees as ( + select + block_number + ,sum(fee_amount_raw) as platform_fee_amount_raw + ,sum(fee_percentage) as platform_fee_percentage + ,unique_trade_id + from fee_events + where is_protocol_fee + group by block_number,unique_trade_id + ), + + royalty_fees as ( + select + block_number + ,sum(fee_amount_raw) as royalty_fee_amount_raw + ,sum(fee_percentage) as royalty_fee_percentage + ,null::string as royalty_fee_receive_address -- we have multiple address so have to null this field + ,unique_trade_id + from fee_events + where not is_protocol_fee + group by block_number,unique_trade_id + ), + + + trades_with_fees as ( + select + t.* + , pf.platform_fee_amount_raw + , pf.platform_fee_percentage + , rf.royalty_fee_amount_raw + , rf.royalty_fee_percentage + , rf.royalty_fee_receive_address + from trades_with_nft_and_tx t + left join platform_fees pf + ON t.block_number = pf.block_number and t.unique_trade_id = pf.unique_trade_id + left join royalty_fees rf + ON t.block_number = rf.block_number and t.unique_trade_id = rf.unique_trade_id + + ), + + trades_with_price as ( + select + t.* + , p.symbol as currency_symbol + , amount_raw/pow(10, p.decimals) as amount_original + , amount_raw/pow(10, p.decimals)*p.price as amount_usd + , platform_fee_amount_raw/pow(10, p.decimals) as platform_fee_amount + , platform_fee_amount_raw/pow(10, p.decimals)*p.price as platform_fee_amount_usd + , royalty_fee_amount_raw/pow(10, p.decimals) as royalty_fee_amount + , royalty_fee_amount_raw/pow(10, p.decimals)*p.price as royalty_fee_amount_usd + , p.symbol as royalty_fee_currency_symbol + from trades_with_fees t + left join {{ source('prices', 'usd') }} p ON p.blockchain='ethereum' + AND p.symbol = 'WETH' -- currently we only have ETH trades + AND date_trunc('minute', p.minute)=date_trunc('minute', t.block_time) + {% if is_incremental() %} + AND p.minute >= date_trunc("day", now() - interval '1 week') + {% endif %} + {% if not is_incremental() %} + AND p.minute >= '2022-4-1' + {% endif %} + ), + + trades_enhanced as ( + select + t.* + , nft.standard as token_standard + , nft.name as collection + , agg.contract_address as aggregator_address + , agg.name as aggregator_name + from trades_with_price t + left join tokens_ethereum_nft nft + ON nft_contract_address = nft.contract_address + left join nft_ethereum_aggregators agg + ON tx_to = agg.contract_address + ) + + +SELECT + 'ethereum' as blockchain + , 'archipelago' as project + , 'v1' as version + , TRY_CAST(date_trunc('DAY', block_time) AS date) AS block_date + , block_time + , block_number + , token_id + , token_standard + , 1 as number_of_items + , 'Single Item Trade' as trade_type + , case when tx_from = seller then 'Sell' else 'Buy' end as trade_category + , 'Trade' as evt_type + , seller + , buyer + , amount_raw + , amount_original + , amount_usd + , currency_symbol + , currency_contract + , project_contract_address + , nft_contract_address + , collection + , tx_hash + , tx_from + , tx_to + , aggregator_address + , aggregator_name + , platform_fee_amount + , platform_fee_amount_raw + , platform_fee_amount_usd + , platform_fee_percentage + , royalty_fee_amount + , royalty_fee_amount_usd + , royalty_fee_amount_raw + , royalty_fee_currency_symbol + , royalty_fee_receive_address -- null here + , royalty_fee_percentage + , unique_trade_id +from trades_enhanced diff --git a/models/archipelago/ethereum/archipelago_ethereum_fees.sql b/models/archipelago/ethereum/archipelago_ethereum_fees.sql new file mode 100644 index 00000000000..f1fa1a167a3 --- /dev/null +++ b/models/archipelago/ethereum/archipelago_ethereum_fees.sql @@ -0,0 +1,39 @@ + {{ + config( + alias='fees') +}} + +SELECT + blockchain, + project, + version, + block_time, + token_id, + collection, + platform_fee_amount_raw, + platform_fee_amount, + platform_fee_amount_usd, + platform_fee_percentage, + royalty_fee_amount_raw, + royalty_fee_amount, + royalty_fee_amount_usd, + royalty_fee_percentage, + royalty_fee_receive_address, + royalty_fee_currency_symbol, + token_standard, + trade_type, + number_of_items, + trade_category, + evt_type, + seller, + buyer, + nft_contract_address, + project_contract_address, + aggregator_name, + aggregator_address, + tx_hash, + block_number, + tx_from, + tx_to, + unique_trade_id +FROM ({{ ref('archipelago_ethereum_events') }}) diff --git a/models/archipelago/ethereum/archipelago_ethereum_schema.yml b/models/archipelago/ethereum/archipelago_ethereum_schema.yml new file mode 100644 index 00000000000..5df32bc4097 --- /dev/null +++ b/models/archipelago/ethereum/archipelago_ethereum_schema.yml @@ -0,0 +1,208 @@ +version: 2 + +models: + - name: archipelago_ethereum_events + meta: + blockchain: ethereum + project: archipelago + contributors: 0xRob + config: + tags: ['ethereum','archipelago','v1','events'] + description: > + Archipelago v1 events on ethereum + columns: + - &blockchain + name: blockchain + - &project + name: project + - &version + name: version + description: "Project version" + - name: block_date + description: "UTC event block date" + - &block_time + name: block_time + description: "UTC event block time" + - &block_number + name: block_number + description: "Block number tx included in" + - &token_id + name: token_id + description: "NFT Token ID" + - &token_standard + name: token_standard + - &number_of_items + name: number_of_items + description: "Number of items traded" + tests: + - not_null + - &trade_type + name: trade_type + description: "Identify whether it was a single NFT trade or multiple NFTs traded" + - &trade_category + name: trade_category + description: "How was this NFT traded ? (Direct buy, auction, etc...)" + - &evt_type + name: evt_type + description: "Event type (Trade, Mint, Burn)" + - &seller + name: seller + description: "Seller wallet address" + - &buyer + name: buyer + description: "Buyer wallet address" + - &amount_raw + name: amount_raw + description: "Traded amount in original currency before decimals correction" + - &amount_original + name: amount_original + description: "Traded amount in original currency" + tests: + - not_null + - ¤cy_symbol + name: currency_symbol + description: "Symbol of original currency used for payment" + - ¤cy_contract + name: currency_contract + description: "Contract address of original token used for payment, with ETH contract address swapped for WETH" + - &nft_contract_address + name: nft_contract_address + description: "NFT contract address, only if 1 nft was transacted" + - &project_contract_address + name: project_contract_address + description: "Contract address used by the project, in this case wyvern contract" + - &tx_hash + name: tx_hash + - name: evt_index + - &platform_fee_amount_raw + name: platform_fee_amount_raw + description: "Raw numerical amount for platform fees" + - &platform_fee_amount + name: platform_fee_amount + description: "Platform fee amount in original token currency (properly formatted in decimals)" + - &platform_fee_percentage + name: platform_fee_amount_usd + description: "Platform fee in % of the amount paid for a given trade" + - &royalty_fee_amount_raw + name: royalty_fee_amount_raw + description: "Raw numerical amount for royalty fees" + - &royalty_fee_amount + name: royalty_fee_amount + description: "Royalty fee amount in original token currency (properly formatted in decimals)" + - &royalty_fee_percentage + name: royalty_fee_percentage + description: "Royalty fee in % of the amount paid for a given trade" + - &royalty_fee_receive_address + name: royalty_fee_receive_address + description: "Wallet addresses receiving fees from the transaction" + - &royalty_fee_currency_symbol + name: royalty_fee_currency_symbol + description: "Symbol of the token in which fees are paid out" + - &collection + name: collection + description: "NFT collection name" + - &aggregator_name + name: aggregator_name + description: "If the trade was performed via an aggregator, displays aggregator name" + - &aggregator_address + name: aggregator_address + description: "If the trade was performed via an aggregator, displays aggregator address" + - &amount_usd + name: amount_usd + description: "USD value of the trade at time of execution" + - &royalty_fee_amount_usd + name: royalty_fee_amount_usd + description: "Royalty fee amount in USD" + - &platform_fee_amount_usd + name: platform_fee_amount_usd + description: "Platform fee amount in USD" + - &tx_from + name: tx_from + description: "Address that initiated the transaction" + - &tx_to + name: tx_to + description: "Address that received the transaction" + - &unique_trade_id + name: unique_trade_id + description: "Unique trade ID" + + - name: archipelago_ethereum_trades + meta: + blockchain: ethereum + project: archipelago + contributors: 0xRob + config: + tags: ['ethereum','archipelago','trades'] + description: > + Archipelago trades on Ethereum + columns: + - *blockchain + - *project + - *version + - *block_time + - *token_id + - *collection + - *amount_usd + - *token_standard + - *trade_type + - *number_of_items + - *trade_category + - *evt_type + - *seller + - *buyer + - *amount_original + - *amount_raw + - *currency_symbol + - *currency_contract + - *nft_contract_address + - *project_contract_address + - *aggregator_name + - *aggregator_address + - *tx_hash + - *block_number + - *tx_from + - *tx_to + - *unique_trade_id + + - name: archipelago_ethereum_fees + meta: + blockchain: ethereum + project: archipelago + contributors: 0xRob + config: + tags: ['ethereum','archipelago','fees'] + description: > + archipelago fees on Ethereum + columns: + - *blockchain + - *project + - *version + - *block_time + - *token_id + - *collection + - *platform_fee_amount_raw + - *platform_fee_amount + - *platform_fee_amount_usd + - *platform_fee_percentage + - *royalty_fee_amount_raw + - *royalty_fee_amount + - *royalty_fee_amount_usd + - *royalty_fee_percentage + - *royalty_fee_receive_address + - *royalty_fee_currency_symbol + - *token_standard + - *trade_type + - *number_of_items + - *trade_category + - *evt_type + - *seller + - *buyer + - *nft_contract_address + - *project_contract_address + - *aggregator_name + - *aggregator_address + - *tx_hash + - *block_number + - *tx_from + - *tx_to + - *unique_trade_id diff --git a/models/archipelago/ethereum/archipelago_ethereum_sources.yml b/models/archipelago/ethereum/archipelago_ethereum_sources.yml new file mode 100644 index 00000000000..94f1db00a80 --- /dev/null +++ b/models/archipelago/ethereum/archipelago_ethereum_sources.yml @@ -0,0 +1,15 @@ +version: 2 + +sources: + - name: archipelago_ethereum + freshness: + warn_after: { count: 12, period: hour } +# Safer just to be warned for now in case the underlying table isn't refreshed - @soispoke +# error_after: { count: 24, period: hour } + tables: + - name: ArchipelagoMarket_evt_Trade + loaded_at_field: evt_block_time + - name: ArchipelagoMarket_evt_TokenTrade + loaded_at_field: evt_block_time + - name: ArchipelagoMarket_evt_RoyaltyPayment + loaded_at_field: evt_block_time diff --git a/models/archipelago/ethereum/archipelago_ethereum_trades.sql b/models/archipelago/ethereum/archipelago_ethereum_trades.sql new file mode 100644 index 00000000000..d351baef3ca --- /dev/null +++ b/models/archipelago/ethereum/archipelago_ethereum_trades.sql @@ -0,0 +1,34 @@ + {{ + config( + alias='trades') +}} + +SELECT + blockchain, + project, + version, + block_time, + token_id, + collection, + amount_usd, + token_standard, + trade_type, + number_of_items, + trade_category, + evt_type, + seller, + buyer, + amount_original, + amount_raw, + currency_symbol, + currency_contract, + nft_contract_address, + project_contract_address, + aggregator_name, + aggregator_address, + tx_hash, + block_number, + tx_from, + tx_to, + unique_trade_id +FROM ({{ ref('archipelago_ethereum_events') }}) diff --git a/models/nft/nft_events.sql b/models/nft/nft_events.sql index 34b1824129e..9d801121713 100644 --- a/models/nft/nft_events.sql +++ b/models/nft/nft_events.sql @@ -44,7 +44,7 @@ FROM royalty_fee_amount_usd, royalty_fee_percentage, unique_trade_id - FROM {{ ref('opensea_events') }} + FROM {{ ref('opensea_events') }} UNION SELECT blockchain, @@ -205,4 +205,44 @@ FROM royalty_fee_percentage, unique_trade_id FROM {{ ref('sudoswap_ethereum_events') }} -) \ No newline at end of file + UNION + SELECT + blockchain, + project, + version, + block_time, + token_id, + collection, + amount_usd, + token_standard, + trade_type, + number_of_items, + trade_category, + evt_type, + seller, + buyer, + amount_original, + amount_raw, + currency_symbol, + currency_contract, + nft_contract_address, + project_contract_address, + aggregator_name, + aggregator_address, + tx_hash, + block_number, + tx_from, + tx_to, + platform_fee_amount_raw, + platform_fee_amount, + platform_fee_amount_usd, + platform_fee_percentage, + royalty_fee_receive_address, + royalty_fee_currency_symbol, + royalty_fee_amount_raw, + royalty_fee_amount, + royalty_fee_amount_usd, + royalty_fee_percentage, + unique_trade_id + FROM {{ ref('archipelago_ethereum_events') }} +) diff --git a/models/nft/nft_fees.sql b/models/nft/nft_fees.sql index b037ef8ca65..cfc543ee9a3 100644 --- a/models/nft/nft_fees.sql +++ b/models/nft/nft_fees.sql @@ -39,7 +39,7 @@ FROM tx_from, tx_to, unique_trade_id - FROM {{ ref('opensea_fees') }} + FROM {{ ref('opensea_fees') }} UNION SELECT blockchain, @@ -145,4 +145,39 @@ FROM tx_to, unique_trade_id FROM {{ ref('sudoswap_ethereum_fees') }} -) \ No newline at end of file + UNION + SELECT + blockchain, + project, + version, + block_time, + token_id, + collection, + platform_fee_amount_raw, + platform_fee_amount, + platform_fee_amount_usd, + platform_fee_percentage, + royalty_fee_amount_raw, + royalty_fee_amount, + royalty_fee_amount_usd, + royalty_fee_percentage, + royalty_fee_receive_address, + royalty_fee_currency_symbol, + token_standard, + trade_type, + number_of_items, + trade_category, + evt_type, + seller, + buyer, + nft_contract_address, + project_contract_address, + aggregator_name, + aggregator_address, + tx_hash, + block_number, + tx_from, + tx_to, + unique_trade_id + FROM {{ ref('archipelago_ethereum_fees') }} +) diff --git a/models/nft/nft_trades.sql b/models/nft/nft_trades.sql index 385e1ec218a..d3af6a288c3 100644 --- a/models/nft/nft_trades.sql +++ b/models/nft/nft_trades.sql @@ -34,7 +34,7 @@ FROM tx_from, tx_to, unique_trade_id - FROM {{ ref('opensea_trades') }} + FROM {{ ref('opensea_trades') }} UNION SELECT blockchain, @@ -155,4 +155,34 @@ FROM tx_to, unique_trade_id FROM {{ ref('sudoswap_ethereum_trades') }} -) \ No newline at end of file + UNION + SELECT + blockchain, + project, + version, + block_time, + token_id, + collection, + amount_usd, + token_standard, + trade_type, + number_of_items, + trade_category, + evt_type, + seller, + buyer, + amount_original, + amount_raw, + currency_symbol, + currency_contract, + nft_contract_address, + project_contract_address, + aggregator_name, + aggregator_address, + tx_hash, + block_number, + tx_from, + tx_to, + unique_trade_id + FROM {{ ref('archipelago_ethereum_trades') }} +) diff --git a/tests/archipelago/ethereum/archipelago_ethereum_assert_trades.sql b/tests/archipelago/ethereum/archipelago_ethereum_assert_trades.sql new file mode 100644 index 00000000000..47e7cb1b35e --- /dev/null +++ b/tests/archipelago/ethereum/archipelago_ethereum_assert_trades.sql @@ -0,0 +1,31 @@ +-- Check if all archipelago trade events make it into the nft.trades +WITH raw_events AS ( + SELECT + evt_block_time as raw_block_time + , evt_tx_hash as raw_tx_hash + , tradeId as raw_unique_trade_id + FROM {{ source('archipelago_ethereum','ArchipelagoMarket_evt_Trade') }} + WHERE evt_block_time >= '2022-6-20' + AND evt_block_time < now() - interval '1 day' -- allow some head desync +) + +, processed_events AS ( + SELECT + block_time as processed_block_time + , tx_hash as processed_tx_hash + , unique_trade_id as processed_trade_id + FROM {{ ref('nft_trades') }} + WHERE + blockchain = 'ethereum' + AND project = 'archipelago' + and version = 'v1' + AND block_time >= '2022-6-20' + AND block_time < now() - interval '1 day' -- allow some head desync +) + +SELECT + * + from raw_events + outer join processed_events n + ON raw_block_time = processed_block_time AND raw_unique_trade_id = processed_trade_id + where not raw_unique_trade_id = processed_trade_id