diff --git a/dbt_subprojects/tokens/macros/transfers/transfers_enrich.sql b/dbt_subprojects/tokens/macros/transfers/transfers_enrich.sql index 95d71fd05d0..2d29100af28 100644 --- a/dbt_subprojects/tokens/macros/transfers/transfers_enrich.sql +++ b/dbt_subprojects/tokens/macros/transfers/transfers_enrich.sql @@ -13,6 +13,7 @@ END , prices_model = null , evms_info_model = null , transfers_start_date = '2000-01-01' + , transfers_end_date = '9999-12-31' , blockchain = null , usd_amount_threshold = 25000000000 ) @@ -23,10 +24,11 @@ WITH base_transfers as ( * FROM {{ base_transfers }} - {% if is_incremental() %} WHERE - {{ incremental_predicate('block_date') }} - {% endif %} + block_date BETWEEN DATE '{{ transfers_start_date }}' AND DATE '{{ transfers_end_date }}' + {% if is_incremental() %} + AND {{ incremental_predicate('block_date') }} + {% endif %} ) , prices AS ( SELECT @@ -38,13 +40,11 @@ WITH base_transfers as ( , price FROM {{ prices_model }} - {% if is_incremental() %} WHERE - {{ incremental_predicate('minute') }} - {% else %} - WHERE - minute >= TIMESTAMP '{{ transfers_start_date }}' - {% endif %} + minute BETWEEN TIMESTAMP '{{ transfers_start_date }}' AND TIMESTAMP '{{ transfers_end_date }}' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% endif %} ) , transfers as ( SELECT diff --git a/dbt_subprojects/tokens/macros/transfers/transfers_enrich_beta.sql b/dbt_subprojects/tokens/macros/transfers/transfers_enrich_beta.sql new file mode 100644 index 00000000000..a1f26340f0f --- /dev/null +++ b/dbt_subprojects/tokens/macros/transfers/transfers_enrich_beta.sql @@ -0,0 +1,117 @@ +{% macro transfers_enrich_beta( + base_transfers = null + , tokens_erc20_model = null + , prices_model = null + , evms_info_model = null + , transfers_start_date = '2000-01-01' + , transfers_end_date = '9999-12-31' + , blockchain = null + , usd_amount_threshold = 25000000000 + ) +%} + +WITH base_transfers as ( + SELECT + * + FROM + {{ base_transfers }} + WHERE + block_date BETWEEN DATE '{{ transfers_start_date }}' AND DATE '{{ transfers_end_date }}' + {% if is_incremental() %} + AND {{ incremental_predicate('block_date') }} + {% endif %} +) +, prices AS ( + SELECT + timestamp + , blockchain + , contract_address + , decimals + , symbol + , price + FROM + {{ prices_model }} + WHERE + timestamp BETWEEN TIMESTAMP '{{ transfers_start_date }}' AND TIMESTAMP '{{ transfers_end_date }}' + {% if is_incremental() %} + AND {{ incremental_predicate('timestamp') }} + {% endif %} +) +, transfers as ( + SELECT + t.unique_key + , t.blockchain + , t.block_month + , t.block_date + , t.block_time + , date_trunc('hour', t.block_time) AS block_hour + , t.block_number + , t.tx_hash + , t.evt_index + , t.trace_address + , t.token_standard + , t.tx_from + , t.tx_to + , t.tx_index + , t."from" + , t.to + , t.contract_address + , {{case_when_token_standard('evms_info.native_token_symbol', 'tokens_erc20.symbol', 'NULL')}} AS symbol + , t.amount_raw + , {{case_when_token_standard('t.amount_raw / power(10, 18)', 't.amount_raw / power(10, tokens_erc20.decimals)', 'cast(t.amount_raw as double)')}} AS amount + , prices.price AS price_usd + , {{case_when_token_standard('(t.amount_raw / power(10, 18)) * prices.price', + '(t.amount_raw / power(10, tokens_erc20.decimals)) * prices.price', + 'NULL')}} AS amount_usd + FROM + base_transfers as t + INNER JOIN + {{ evms_info_model }} as evms_info + ON evms_info.blockchain = t.blockchain + LEFT JOIN + {{ tokens_erc20_model }} as tokens_erc20 + ON tokens_erc20.blockchain = t.blockchain + AND tokens_erc20.contract_address = t.contract_address + LEFT JOIN + prices + ON date_trunc('hour', t.block_time) = prices.timestamp + AND CASE + WHEN t.token_standard = 'native' + THEN + prices.blockchain IS NULL + AND prices.contract_address IS NULL + AND evms_info.native_token_symbol = prices.symbol + ELSE + prices.blockchain = '{{ blockchain }}' + AND t.contract_address = prices.contract_address + END +) +SELECT + unique_key + , blockchain + , block_month + , block_date + , block_time + , block_number + , tx_hash + , evt_index + , trace_address + , token_standard + , tx_from + , tx_to + , tx_index + , "from" + , to + , contract_address + , symbol + , amount_raw + , amount + , price_usd + , CASE + WHEN amount_usd >= {{ usd_amount_threshold }} + THEN CAST(NULL as double) + ELSE amount_usd -- Select only transfers where USD amount is less than the threshold + END AS amount_usd +FROM + transfers +{%- endmacro %} diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/blast/_schema.yml b/dbt_subprojects/tokens/models/transfers_and_balances/blast/_schema.yml index 3d31ba98c6c..84a8c947519 100644 --- a/dbt_subprojects/tokens/models/transfers_and_balances/blast/_schema.yml +++ b/dbt_subprojects/tokens/models/transfers_and_balances/blast/_schema.yml @@ -63,6 +63,62 @@ models: combination_of_columns: - block_date - unique_key + columns: + - name: unique_key + description: "Surrogate key to identify unique row" + - name: blockchain + description: "The blockchain of the transfers" + - name: block_date + description: "The date of the block" + - name: block_time + description: "The time of the block" + - name: block_number + description: "The block number" + - name: tx_hash + description: "The transaction hash" + - name: evt_index + description: "The log event index of the transfer if any" + - name: trace_address + description: "The trace address of the transfer if any" + - name: token_standard + description: "The token standard of the transfer" + - name: tx_from + description: "The transaction sender" + - name: tx_to + description: "The transaction receiver" + - name: tx_index + description: "The transaction index" + - name: from + description: "The sender of the transfer" + - name: to + description: "The receiver of the transfer" + - name: contract_address + description: "The contract address of the transfer" + - name: symbol + description: "The token symbol transferred" + - name: amount_raw + description: "The raw amount of the transfer" + - name: amount + description: "The formatted amount of the transfer" + - name: price_usd + description: "The USD price used to calculate the amount_usd" + - name: amount_usd + description: "The USD amount of the transfer" + + - name: tokens_blast_transfers_beta + meta: + blockchain: blast + sector: tokens + contributors: aalan3, jeff-dude, hildobby + config: + tags: [ 'tokens','transfers', 'blast' ] + description: > + Token transfers + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - unique_key columns: - name: unique_key description: "Surrogate key to identify unique row" diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers.sql index 6ec565ff64d..82deda70b5d 100644 --- a/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers.sql +++ b/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers.sql @@ -20,7 +20,8 @@ , tokens_erc20_model = source('tokens', 'erc20') , prices_model = source('prices', 'usd') , evms_info_model = source('evms','info') - , transfers_start_date = '2020-04-22' + , transfers_start_date = '2024-08-01' + , transfers_end_date = '2024-08-10' , blockchain = 'blast' ) }} diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers_beta.sql b/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers_beta.sql new file mode 100644 index 00000000000..c6f742fe8ec --- /dev/null +++ b/dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers_beta.sql @@ -0,0 +1,27 @@ +{{config( + schema = 'tokens_blast', + alias = 'transfers_beta', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_date','unique_key'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')], + post_hook='{{ expose_spells(\'["blast"]\', + "sector", + "tokens", + \'["aalan3", "jeff-dude", "hildobby"]\') }}' +) +}} + +{{ + transfers_enrich_beta( + base_transfers = ref('tokens_blast_base_transfers') + , tokens_erc20_model = source('tokens', 'erc20') + , prices_model = ref('prices_hour') + , evms_info_model = source('evms','info') + , transfers_start_date = '2024-08-01' + , transfers_end_date = '2024-08-10' + , blockchain = 'blast' + ) +}} diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/_schema.yml b/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/_schema.yml index a59e171c2ce..e1e767e1a53 100644 --- a/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/_schema.yml +++ b/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/_schema.yml @@ -190,3 +190,59 @@ models: - name: symbol - name: decimals - name: collection_name + + - name: tokens_ethereum_transfers_beta + meta: + blockchain: ethereum + sector: tokens + contributors: aalan3, jeff-dude + config: + tags: [ 'tokens','transfers', 'ethereum' ] + description: > + Token transfers + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - unique_key + columns: + - name: unique_key + description: "Surrogate key to identify unique row" + - name: blockchain + description: "The blockchain of the transfers" + - name: block_date + description: "The date of the block" + - name: block_time + description: "The time of the block" + - name: block_number + description: "The block number" + - name: tx_hash + description: "The transaction hash" + - name: evt_index + description: "The log event index of the transfer if any" + - name: trace_address + description: "The trace address of the transfer if any" + - name: token_standard + description: "The token standard of the transfer" + - name: tx_from + description: "The transaction sender" + - name: tx_to + description: "The transaction receiver" + - name: tx_index + description: "The transaction index" + - name: from + description: "The sender of the transfer" + - name: to + description: "The receiver of the transfer" + - name: contract_address + description: "The contract address of the transfer" + - name: symbol + description: "The token symbol transferred" + - name: amount_raw + description: "The raw amount of the transfer" + - name: amount + description: "The formatted amount of the transfer" + - name: price_usd + description: "The USD price used to calculate the amount_usd" + - name: amount_usd + description: "The USD amount of the transfer" \ No newline at end of file diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers.sql index 62d36fb8682..bb5a971ef9f 100644 --- a/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers.sql +++ b/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers.sql @@ -20,7 +20,8 @@ , tokens_erc20_model = source('tokens', 'erc20') , prices_model = source('prices', 'usd') , evms_info_model = source('evms','info') - , transfers_start_date = '2015-08-07' + , transfers_start_date = '2024-08-01' + , transfers_end_date = '2024-08-02' , blockchain = 'ethereum' ) }} diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers_beta.sql b/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers_beta.sql new file mode 100644 index 00000000000..e447bc1c635 --- /dev/null +++ b/dbt_subprojects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers_beta.sql @@ -0,0 +1,27 @@ +{{config( + schema = 'tokens_ethereum', + alias = 'transfers_beta', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_date','unique_key'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')], + post_hook='{{ expose_spells(\'["ethereum"]\', + "sector", + "tokens", + \'["aalan3", "jeff-dude"]\') }}' +) +}} + +{{ + transfers_enrich_beta( + base_transfers = ref('tokens_ethereum_base_transfers') + , tokens_erc20_model = source('tokens', 'erc20') + , prices_model = ref('prices_hour') + , evms_info_model = source('evms','info') + , transfers_start_date = '2024-08-01' + , transfers_end_date = '2024-08-02' + , blockchain = 'ethereum' + ) +}}