Skip to content

Commit

Permalink
Merge pull request #82 from Artemis-xyz/sm-rolling-active-addresses
Browse files Browse the repository at this point in the history
Adding MAU and WAU
  • Loading branch information
SebMelendez01 authored May 14, 2024
2 parents 64b81f3 + be293c1 commit f33ab31
Show file tree
Hide file tree
Showing 39 changed files with 757 additions and 46 deletions.
38 changes: 38 additions & 0 deletions macros/bridge/cctp_transfers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% macro cctp_transfers(chain, contract_address, source_domain_id) %}
{% if chain == 'solana' %}
select
block_timestamp,
block_id as block_number,
tx_id as tx_hash,
program_id as contract_address,
PC_DBT_DB.PROD.BASE58_TO_HEX(f.value:data) as hex_data,
PC_DBT_DB.PROD.hex_to_base58(SUBSTRING(hex_data,129,64)) as sender, -- Need to figure out which one is the sender
PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,33,16)) as nonce,
'0x' || SUBSTRING(hex_data,193,64) as reciepient,
PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,113,16)) as amount,
PC_DBT_DB.PROD.hex_to_base58(SUBSTRING(hex_data,49,64)) as burn_token,
5 as source_domain_id,
PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,257,8)) as destination_domain_id
succeeded as status
FROM solana_flipside.core.fact_events,
lateral flatten(input => get_path(inner_instruction, 'instructions')) AS f
where program_id = 'CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3'
and SUBSTRING(hex_data,17,16) = '90fc9192064aa7eb'
{% else %}
select
block_timestamp,
block_number,
tx_hash,
contract_address,
decoded_log:depositor::string as sender,
decoded_log:amount::number as nonce,
decoded_log:mintRecipient::string as reciepient,
decoded_log:amount::number as amount,
decoded_log:burnToken::string as burn_token,
{{ source_domain_id }} as source_domain_id,
decoded_log:destinationDomain::number as destination_domain_id ,
tx_status as status
from {{ chain }}_flipside.core.ez_decoded_event_logs
where lower(contract_address) = lower('{{ contract_address }}') and event_name in ('DepositForBurn')
{% endif %}
{% endmacro %}
24 changes: 0 additions & 24 deletions macros/metrics/get_mau_metrics.sql

This file was deleted.

7 changes: 7 additions & 0 deletions macros/metrics/get_rolling_active_address_metrics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro get_rolling_active_address_metrics(chain) %}
select
date,
mau,
wau
from {{ref("fact_" ~ chain ~ "_rolling_active_addresses")}}
{% endmacro %}
63 changes: 63 additions & 0 deletions macros/rolling_active_addresses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% macro rolling_active_addresses(chain) %}
with
{% if chain == 'solana' %}
distinct_dates as (
select distinct
raw_date
from {{ chain }}.prod_raw.ez_transactions
where succeeded = 'TRUE'
{% if is_incremental() %}
and raw_date > (select dateadd('day', -1, max(date)) from {{ this }})
{% endif %}
),
distinct_dates_for_rolling_active_address as (
select distinct
raw_date,
value as from_address
from {{ chain }}.prod_raw.ez_transactions, lateral flatten(input => signers)
where succeeded = 'TRUE'
),
{% else %}
distinct_dates as (
select distinct
raw_date
from {{ chain }}.prod_raw.ez_transactions
{% if is_incremental() %}
where raw_date > (select dateadd('day', -1, max(date)) from {{ this }})
{% endif %}
),
distinct_dates_for_rolling_active_address as (
select distinct
raw_date,
from_address
from {{ chain }}.prod_raw.ez_transactions
),
{% endif %}


rolling_mau as (
select
t1.raw_date,
count(distinct t2.from_address) as mau
from distinct_dates t1
join distinct_dates_for_rolling_active_address t2 on t2.raw_date between dateadd(DAY, -29, t1.raw_date) and t1.raw_date
group by t1.raw_date
),
rolling_wau as (
select
t1.raw_date,
count(distinct t2.from_address) as wau
from distinct_dates t1
join distinct_dates_for_rolling_active_address t2 on t2.raw_date between dateadd(DAY, -6, t1.raw_date) and t1.raw_date
group by t1.raw_date
)
select
rolling_mau.raw_date as date,
'{{ chain }}' as chain,
mau,
wau
from rolling_mau
left join rolling_wau using(raw_date)
where rolling_mau.raw_date < to_date(sysdate())
order by date
{% endmacro %}
5 changes: 3 additions & 2 deletions models/projects/arbitrum/core/ez_arbitrum_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ with
contract_data as ({{ get_contract_metrics("arbitrum") }}),
nft_metrics as ({{ get_nft_metrics("arbitrum") }}),
p2p_metrics as ({{ get_p2p_metrics("arbitrum") }}),
mau_metrics as ({{ get_mau_metrics("arbitrum") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("arbitrum") }})
select
fundamental_data.date,
fundamental_data.chain,
txns,
dau,
wau,
mau,
fees_native, -- total gas fees paid on l2 by users(L2 Fees)
fees,
Expand Down Expand Up @@ -73,5 +74,5 @@ left join github_data on fundamental_data.date = github_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join nft_metrics on fundamental_data.date = nft_metrics.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/avalanche/core/ez_avalanche_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ with
),
nft_metrics as ({{ get_nft_metrics("avalanche") }}),
p2p_metrics as ({{ get_p2p_metrics("avalanche") }}),
mau_metrics as ({{ get_mau_metrics("avalanche") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("avalanche") }})

select
coalesce(fundamental_data.date, staking_data.date) as date,
coalesce(fundamental_data.chain, 'avalanche') as chain,
txns,
dau,
wau,
mau,
fees_native,
case when fees is null then fees_native * price else fees end as fees,
Expand Down Expand Up @@ -78,5 +79,5 @@ left join contract_data on staking_data.date = contract_data.date
left join issuance_data on staking_data.date = issuance_data.date
left join nft_metrics on staking_data.date = nft_metrics.date
left join p2p_metrics on staking_data.date = p2p_metrics.date
left join mau_metrics on staking_data.date = mau_metrics.date
left join rolling_metrics on staking_data.date = rolling_metrics.date
where coalesce(fundamental_data.date, staking_data.date) < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/base/core/ez_base_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ with
), -- supply side revenue and fees
nft_metrics as ({{ get_nft_metrics("base") }}),
p2p_metrics as ({{ get_p2p_metrics("base") }}),
mau_metrics as ({{ get_mau_metrics("base") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("base") }})

select
fundamental_data.date,
fundamental_data.chain,
txns,
dau,
wau,
mau,
fees_native, -- total gas fees paid on l2 by users(L2 Fees)
fees,
Expand Down Expand Up @@ -62,5 +63,5 @@ left join expenses_data on fundamental_data.date = expenses_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join nft_metrics on fundamental_data.date = nft_metrics.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/blast/core/ez_blast_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with
select date, chain, l1_data_cost_native, l1_data_cost, revenue_native, revenue
from {{ ref("agg_daily_blast_revenue") }}
),
mau_metrics as ({{ get_mau_metrics("blast") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("blast") }})
select
coalesce(
fundamental_data.date,
Expand All @@ -33,6 +33,7 @@ select
'blast' as chain,
txns,
dau,
wau,
mau,
fees_native,
fees,
Expand All @@ -59,5 +60,5 @@ left join defillama_data on fundamental_data.date = defillama_data.date
left join stablecoin_data on fundamental_data.date = stablecoin_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join expenses_data on fundamental_data.date = expenses_data.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/bsc/core/ez_bsc_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ with
github_data as ({{ get_github_metrics("Binance Smart Chain") }}),
contract_data as ({{ get_contract_metrics("bsc") }}),
nft_metrics as ({{ get_nft_metrics("bsc") }}),
mau_metrics as ({{ get_mau_metrics("bsc") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("bsc") }})
select
fundamental_data.date,
fundamental_data.chain,
txns,
dau,
wau,
mau,
fees_native,
fees,
Expand Down Expand Up @@ -58,5 +59,5 @@ left join stablecoin_data on fundamental_data.date = stablecoin_data.date
left join github_data on fundamental_data.date = github_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join nft_metrics on fundamental_data.date = nft_metrics.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
4 changes: 1 addition & 3 deletions models/projects/celo/core/ez_celo_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ with
price_data as ({{ get_coingecko_metrics("celo") }}),
defillama_data as ({{ get_defillama_metrics("celo") }}),
github_data as ({{ get_github_metrics("celo") }}),
stablecoin_data as ({{ get_stablecoin_metrics("celo") }}),
mau_metrics as ({{ get_mau_metrics("celo") }})
stablecoin_data as ({{ get_stablecoin_metrics("celo") }})
select
fundamental_data.date,
fundamental_data.chain,
Expand Down Expand Up @@ -47,5 +46,4 @@ left join price_data on fundamental_data.date = price_data.date
left join defillama_data on fundamental_data.date = defillama_data.date
left join github_data on fundamental_data.date = github_data.date
left join stablecoin_data on fundamental_data.date = stablecoin_data.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
where fundamental_data.date < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/ethereum/core/ez_ethereum_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ with
),
nft_metrics as ({{ get_nft_metrics("ethereum") }}),
p2p_metrics as ({{ get_p2p_metrics("ethereum") }}),
mau_metrics as ({{ get_mau_metrics("ethereum") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("ethereum") }})

select
fundamental_data.date,
fundamental_data.chain,
txns,
dau,
wau,
mau,
fees_native,
case when fees is null then fees_native * price else fees end as fees,
Expand Down Expand Up @@ -99,5 +100,5 @@ left join github_data on fundamental_data.date = github_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join nft_metrics on fundamental_data.date = nft_metrics.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
7 changes: 6 additions & 1 deletion models/projects/near/core/ez_near_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ with
),
github_data as ({{ get_github_metrics("near") }}),
contract_data as ({{ get_contract_metrics("near") }}),
p2p_metrics as ({{ get_p2p_metrics("near") }})
p2p_metrics as ({{ get_p2p_metrics("near") }}),
rolling_metrics as ({{ get_rolling_active_address_metrics("near") }})


select
fundamental_data.date,
fundamental_data.chain,
txns,
dau,
wau,
mau,
fees_native,
case when fees is null then fees_native * price else fees end as fees,
avg_txn_fee,
Expand Down Expand Up @@ -56,4 +60,5 @@ left join revenue_data on fundamental_data.date = revenue_data.date
left join github_data on fundamental_data.date = github_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/optimism/core/ez_optimism_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ with
), -- supply side revenue and fees
nft_metrics as ({{ get_nft_metrics("optimism") }}),
p2p_metrics as ({{ get_p2p_metrics("optimism") }}),
mau_metrics as ({{ get_mau_metrics("optimism") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("optimism") }})

select
coalesce(
Expand All @@ -37,6 +37,7 @@ select
'optimism' as chain,
txns,
dau,
wau,
mau,
fees_native, -- total gas fees paid on l2 by users(L2 Fees)
fees,
Expand Down Expand Up @@ -82,5 +83,5 @@ left join github_data on fundamental_data.date = github_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join nft_metrics on fundamental_data.date = nft_metrics.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
5 changes: 3 additions & 2 deletions models/projects/polygon/core/ez_polygon_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ with
),
nft_metrics as ({{ get_nft_metrics("polygon") }}),
p2p_metrics as ({{ get_p2p_metrics("polygon") }}),
mau_metrics as ({{ get_mau_metrics("polygon") }})
rolling_metrics as ({{ get_rolling_active_address_metrics("polygon") }})

select
fundamental_data.date,
fundamental_data.chain,
txns,
dau,
wau,
mau,
fees_native,
fees,
Expand Down Expand Up @@ -72,5 +73,5 @@ left join contract_data on fundamental_data.date = contract_data.date
left join revenue_data on fundamental_data.date = revenue_data.date
left join nft_metrics on fundamental_data.date = nft_metrics.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
left join mau_metrics on fundamental_data.date = mau_metrics.date
left join rolling_metrics on fundamental_data.date = rolling_metrics.date
where fundamental_data.date < to_date(sysdate())
4 changes: 4 additions & 0 deletions models/projects/solana/core/ez_solana_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ with
),
nft_metrics as ({{ get_nft_metrics("solana") }}),
p2p_metrics as ({{ get_p2p_metrics("solana") }}),
rolling_metrics as ({{ get_rolling_active_address_metrics("solana") }}),
{% if not is_incremental() %}
unrefreshed_data as (
select
Expand Down Expand Up @@ -152,6 +153,8 @@ select
-- fact_votes_agg_block
txns,
dau,
wau,
mau,
returning_users,
new_users,
weekly_commits_core_ecosystem,
Expand Down Expand Up @@ -185,4 +188,5 @@ left join staking_data on fundamental_usage.date = staking_data.date
left join issuance_data on fundamental_usage.date = issuance_data.date
left join nft_metrics on fundamental_usage.date = nft_metrics.date
left join p2p_metrics on fundamental_usage.date = p2p_metrics.date
left join rolling_metrics on fundamental_usage.date = rolling_metrics.date
where fundamental_usage.date < to_date(sysdate())
Loading

0 comments on commit f33ab31

Please sign in to comment.