From 3c098630976bd1c5e04fd30b491c591a7903223d Mon Sep 17 00:00:00 2001 From: Anthony Yim Date: Tue, 25 Jun 2024 20:10:23 -0400 Subject: [PATCH 1/4] Count delegate txn in NEAR DAU --- .../get_fundamental_data_for_chain.sql | 65 ++++++++++++++++++- models/projects/near/core/ez_near_metrics.sql | 1 + 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/macros/metrics/get_fundamental_data_for_chain.sql b/macros/metrics/get_fundamental_data_for_chain.sql index ad3301a4..c7603cac 100644 --- a/macros/metrics/get_fundamental_data_for_chain.sql +++ b/macros/metrics/get_fundamental_data_for_chain.sql @@ -12,6 +12,54 @@ from min_date group by start_date ), + {% if chain in ("near") %} + truncated_near_fact_txns as ( + select * + from near_flipside.core.fact_transactions + where block_timestamp > current_date() - interval '15 days' + ), + fact_transactions_delegate_extracted as ( + select + tx_hash, + tx_signer, + tx_receiver, + tx, + tx_succeeded, + block_timestamp::date as date, + case + when action.value:Delegate is not null then true + else false + end as is_delegate + from + truncated_near_fact_txns, + lateral flatten(input => tx:actions) as action + where + tx_succeeded = TRUE + ), + fact_transactions_adjusted as ( + select + tx_hash, + tx_signer, + tx_receiver, + tx, + tx_succeeded, + date, + is_delegate, + case when is_delegate = TRUE then tx_receiver else tx_signer end as adjusted_signer, + case when is_delegate = TRUE then tx_signer else tx_receiver end as adjusted_receiver, + from + fact_transactions_delegate_extracted + order by date DESC + ), + near_dau as ( + select + date, + count(distinct adjusted_signer) as adjusted_dau + from fact_transactions_adjusted + group by date + order by date DESC + ), + {% endif %} {% if chain not in ("starknet") %} bot as ( select @@ -45,9 +93,17 @@ sum(gas_usd) fees, count(*) txns, sum(gas_usd) / count(*) as avg_txn_fee, - count(distinct from_address) dau - from {{ chain }}.prod_raw.ez_transactions - group by date + {% if chain in ("near") %} + count(distinct from_address) dau, + count(distinct adjusted_signer) as adjusted_dau + {% else %} + count(distinct from_address) dau + {% endif %} + from {{ chain }}.prod_raw.ez_transactions as t + {% if chain in ("near") %} + left join fact_transactions_adjusted as n on t.tx_hash = n.tx_hash + {% endif %} + group by t.raw_date ) {% if (chain not in ("near", "starknet")) %} , @@ -65,6 +121,9 @@ chain, txns, dau, + {% if chain in ("near") %} + adjusted_dau, + {% endif %} fees_native, fees, avg_txn_fee, diff --git a/models/projects/near/core/ez_near_metrics.sql b/models/projects/near/core/ez_near_metrics.sql index 1f09aba3..4c39aa50 100644 --- a/models/projects/near/core/ez_near_metrics.sql +++ b/models/projects/near/core/ez_near_metrics.sql @@ -31,6 +31,7 @@ select fundamental_data.chain, txns, dau, + fundamental_data.adjusted_dau, wau, mau, fees_native, From fbaf6bad7349b5035285901b62c62d34c2ec817f Mon Sep 17 00:00:00 2001 From: Anthony Yim Date: Wed, 26 Jun 2024 18:47:47 -0400 Subject: [PATCH 2/4] Remove unnecessary CTE --- macros/metrics/get_fundamental_data_for_chain.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/macros/metrics/get_fundamental_data_for_chain.sql b/macros/metrics/get_fundamental_data_for_chain.sql index c7603cac..23be825c 100644 --- a/macros/metrics/get_fundamental_data_for_chain.sql +++ b/macros/metrics/get_fundamental_data_for_chain.sql @@ -51,14 +51,6 @@ fact_transactions_delegate_extracted order by date DESC ), - near_dau as ( - select - date, - count(distinct adjusted_signer) as adjusted_dau - from fact_transactions_adjusted - group by date - order by date DESC - ), {% endif %} {% if chain not in ("starknet") %} bot as ( From 8412371c226d1ef237ed2031de337c29e89cd10b Mon Sep 17 00:00:00 2001 From: Anthony Yim Date: Wed, 26 Jun 2024 18:52:35 -0400 Subject: [PATCH 3/4] Remove date order --- macros/metrics/get_fundamental_data_for_chain.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/macros/metrics/get_fundamental_data_for_chain.sql b/macros/metrics/get_fundamental_data_for_chain.sql index 23be825c..9f053e79 100644 --- a/macros/metrics/get_fundamental_data_for_chain.sql +++ b/macros/metrics/get_fundamental_data_for_chain.sql @@ -49,7 +49,6 @@ case when is_delegate = TRUE then tx_signer else tx_receiver end as adjusted_receiver, from fact_transactions_delegate_extracted - order by date DESC ), {% endif %} {% if chain not in ("starknet") %} From bad67d59bd8c3e4bdebc37af8b70c2b0c1ada439 Mon Sep 17 00:00:00 2001 From: Anthony Yim Date: Wed, 26 Jun 2024 19:03:12 -0400 Subject: [PATCH 4/4] Update to pull last 60d --- macros/metrics/get_fundamental_data_for_chain.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/metrics/get_fundamental_data_for_chain.sql b/macros/metrics/get_fundamental_data_for_chain.sql index 9f053e79..8b38315d 100644 --- a/macros/metrics/get_fundamental_data_for_chain.sql +++ b/macros/metrics/get_fundamental_data_for_chain.sql @@ -16,7 +16,7 @@ truncated_near_fact_txns as ( select * from near_flipside.core.fact_transactions - where block_timestamp > current_date() - interval '15 days' + where block_timestamp > current_date() - interval '60 days' ), fact_transactions_delegate_extracted as ( select