Skip to content

Commit

Permalink
Count delegate txn in NEAR DAU (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyyim authored Jun 26, 2024
1 parent 0165d65 commit e524b9a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
56 changes: 53 additions & 3 deletions macros/metrics/get_fundamental_data_for_chain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@
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 '60 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
),
{% endif %}
{% if chain not in ("starknet") %}
bot as (
select
Expand Down Expand Up @@ -45,9 +84,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")) %}
,
Expand All @@ -65,6 +112,9 @@
chain,
txns,
dau,
{% if chain in ("near") %}
adjusted_dau,
{% endif %}
fees_native,
fees,
avg_txn_fee,
Expand Down
1 change: 1 addition & 0 deletions models/projects/near/core/ez_near_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ select
fundamental_data.chain,
txns,
dau,
fundamental_data.adjusted_dau,
wau,
mau,
fees_native,
Expand Down

0 comments on commit e524b9a

Please sign in to comment.