From 85e3e07a8bc248299918df9b049c796bd86603d8 Mon Sep 17 00:00:00 2001 From: Son Do Date: Thu, 22 Aug 2024 17:33:53 -0400 Subject: [PATCH] Added Trending --- .../all_chains_gas_dau_txns_by_category.sql | 1 + .../all_chains_gas_dau_txns_by_chain.sql | 1 + .../all_chains_gas_dau_txns_by_contract.sql | 18 +++ .../all_chains_gas_dau_txns_by_namespace.sql | 1 + models/staging/sei/fact_sei_transactions.sql | 151 +++++++++++------- .../sei/fact_sei_wasm_transactions.sql | 2 +- models/trending/bam_trending_data.sql | 6 + 7 files changed, 117 insertions(+), 63 deletions(-) diff --git a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_category.sql b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_category.sql index 0caba3c4..85a859dc 100644 --- a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_category.sql +++ b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_category.sql @@ -13,6 +13,7 @@ with ref("ez_near_metrics_by_category"), ref("ez_optimism_metrics_by_category"), ref("ez_polygon_metrics_by_category"), + ref("ez_sei_metrics_by_category"), ref("ez_solana_metrics_by_category"), ref("ez_sui_metrics_by_category"), ref("ez_tron_metrics_by_category"), diff --git a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_chain.sql b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_chain.sql index 61553dec..84dc7ca6 100644 --- a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_chain.sql +++ b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_chain.sql @@ -14,6 +14,7 @@ with ref("ez_near_metrics"), ref("ez_optimism_metrics"), ref("ez_polygon_metrics"), + ref("ez_sei_metrics"), ref("ez_solana_metrics"), ref("ez_sui_metrics"), ref("ez_tron_metrics"), diff --git a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_contract.sql b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_contract.sql index 6cc39f17..58957533 100644 --- a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_contract.sql +++ b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_contract.sql @@ -144,6 +144,24 @@ select 'polygon' as chain from {{ ref("ez_polygon_metrics_by_contract") }} union +select + contract_address, + date, + name, + null as symbol, + app as namespace, + friendly_name, + category, + gas as total_gas, + gas_usd as total_gas_usd, + txns as transactions, + dau, + null as token_transfer_usd, + null as token_transfer, + null as avg_token_price, + 'sei' as chain +from {{ ref("ez_sei_metrics_by_contract") }} +union select contract_address, date, diff --git a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_namespace.sql b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_namespace.sql index 913bb5cc..661c1a8b 100644 --- a/models/bam_models/all_chains/all_chains_gas_dau_txns_by_namespace.sql +++ b/models/bam_models/all_chains/all_chains_gas_dau_txns_by_namespace.sql @@ -14,6 +14,7 @@ with ref("ez_near_metrics_by_application"), ref("ez_optimism_metrics_by_application"), ref("ez_polygon_metrics_by_application"), + ref("ez_sei_metrics_by_application"), ref("ez_solana_metrics_by_application"), ref("ez_sui_metrics_by_application"), ref("ez_tron_metrics_by_application"), diff --git a/models/staging/sei/fact_sei_transactions.sql b/models/staging/sei/fact_sei_transactions.sql index 90942e7a..a1ec547b 100644 --- a/models/staging/sei/fact_sei_transactions.sql +++ b/models/staging/sei/fact_sei_transactions.sql @@ -5,68 +5,95 @@ snowflake_warehouse="SEI_LG", ) }} +WITH transaction_data as ( + SELECT + tx_hash, + status = 'SUCCESS' as success, + block_timestamp, + raw_date, + from_address, + tx_fee, + gas_usd, + contract_address, + name, + app, + friendly_name, + sub_category, + inserted_timestamp, + category, + user_type, + address_life_span, + cur_total_txns, + cur_distinct_to_address_count, + probability, + engagement_type, + balance_usd, + native_token_balance, + stablecoin_balance + FROM {{ ref("fact_sei_evm_transactions") }} + {% if is_incremental() %} + where + -- this filter will only be applied on an incremental run + inserted_timestamp + >= (select dateadd('day', -5, max(inserted_timestamp)) from {{ this }}) + {% endif %} + UNION ALL + SELECT + tx_hash, + success, + block_timestamp, + raw_date, + signer as from_address, + tx_fee, + gas_usd, + contract_address, + name, + app, + friendly_name, + sub_category, + inserted_timestamp, + category, + user_type, + address_life_span, + cur_total_txns, + cur_distinct_to_address_count, + probability, + engagement_type, + balance_usd, + native_token_balance, + stablecoin_balance + FROM {{ ref("fact_sei_wasm_transactions") }} + {% if is_incremental() %} + where + -- this filter will only be applied on an incremental run + inserted_timestamp + >= (select dateadd('day', -5, max(inserted_timestamp)) from {{ this }}) + {% endif %} +) SELECT tx_hash, - status = 'SUCCESS' as success, - block_timestamp, - raw_date, - from_address, - tx_fee, - gas_usd, + max(success) as success, + max(block_timestamp) as block_timestamp, + max(raw_date) as raw_date, + max(from_address) as from_address, + max(tx_fee) as tx_fee, + max(gas_usd) as gas_usd, 'sei' as chain, - contract_address, - name, - app, - friendly_name, - sub_category, - inserted_timestamp, - category, - user_type, - address_life_span, - cur_total_txns, - cur_distinct_to_address_count, - probability, - engagement_type, - balance_usd, - native_token_balance, - stablecoin_balance -FROM {{ ref("fact_sei_evm_transactions") }} -{% if is_incremental() %} -where - -- this filter will only be applied on an incremental run - inserted_timestamp - >= (select dateadd('day', -5, max(inserted_timestamp)) from {{ this }}) -{% endif %} -UNION ALL -SELECT - tx_hash, - success, - block_timestamp, - raw_date, - signer as from_address, - tx_fee, - gas_usd, - 'sei' as chain, - contract_address, - name, - app, - friendly_name, - sub_category, - inserted_timestamp, - category, - user_type, - address_life_span, - cur_total_txns, - cur_distinct_to_address_count, - probability, - engagement_type, - balance_usd, - native_token_balance, - stablecoin_balance -FROM {{ ref("fact_sei_wasm_transactions") }} -{% if is_incremental() %} -where - -- this filter will only be applied on an incremental run - inserted_timestamp - >= (select dateadd('day', -5, max(inserted_timestamp)) from {{ this }}) -{% endif %} \ No newline at end of file + max(contract_address) as contract_address, + max(name) as name, + max(app) as app, + max(friendly_name) as friendly_name, + max(sub_category) as sub_category, + max(inserted_timestamp) as inserted_timestamp, + max(category) as category, + max(user_type) as user_type, + max(address_life_span) as address_life_span, + max(cur_total_txns) as cur_total_txns, + max(cur_distinct_to_address_count) as cur_distinct_to_address_count, + max(probability) as probability, + max(engagement_type) as engagement_type, + max(balance_usd) as balance_usd, + max(native_token_balance) as native_token_balance, + max(stablecoin_balance) as stablecoin_balance +FROM transaction_data +GROUP BY tx_hash diff --git a/models/staging/sei/fact_sei_wasm_transactions.sql b/models/staging/sei/fact_sei_wasm_transactions.sql index 8c1277ba..733c2656 100644 --- a/models/staging/sei/fact_sei_wasm_transactions.sql +++ b/models/staging/sei/fact_sei_wasm_transactions.sql @@ -111,5 +111,5 @@ with t1.block_timestamp < date(sysdate()) {% if is_incremental() %} AND - inserted_timestamp >= (select dateadd('day', -5, max(inserted_timestamp)) from {{ this }}) + t2.inserted_timestamp >= (select dateadd('day', -5, max(inserted_timestamp)) from {{ this }}) {% endif %} diff --git a/models/trending/bam_trending_data.sql b/models/trending/bam_trending_data.sql index 81cb7a13..f8cf5b12 100644 --- a/models/trending/bam_trending_data.sql +++ b/models/trending/bam_trending_data.sql @@ -48,6 +48,12 @@ union all select *, 'polygon' as chain from {{ ref("polygon_trending_weekly_monthly") }} union all +select *, 'sei' as chain +from {{ ref("sei_trending_daily") }} +union all +select *, 'sei' as chain +from {{ ref("sei_trending_weekly_monthly") }} +union all select *, 'solana' as chain from {{ ref("solana_trending_daily") }} union all