Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count delegate txn in NEAR DAU #248

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading