Skip to content

Commit

Permalink
mplx daw add incremental, fix ez metric reference
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwes committed Nov 19, 2024
1 parent 646dfff commit 06575b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 12 additions & 6 deletions models/projects/metaplex/core/ez_metaplex_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
alias="ez_metrics",
)
}}

with revenue as (
-- 2020-10-25
with date_spine as (
select date
from {{ ref("dim_date_spine") }}
where date between date('2021-03-29') and to_date(sysdate())
)
, revenue as (
select
date
, sum(revenue_usd) as revenue_usd
Expand Down Expand Up @@ -47,7 +52,7 @@ with revenue as (
, transactions as (
select
date
, sum(txns) as txns
, sum(daily_signed_transactions) as txns
from {{ ref("fact_metaplex_transaction_counts") }}
group by 1
)
Expand All @@ -63,7 +68,7 @@ with revenue as (
)

SELECT
coalesce(price.date, revenue.date, buybacks.date, transactions.date) as date
ds.date
, coalesce(revenue.revenue_usd * 2, 0) as fees
, coalesce(revenue.revenue_usd, 0) as revenue -- Fees are paid continuously, but revenue is only recognized at the time of the buyback
, coalesce(buybacks.buyback, 0) as buyback -- 50% of fees (ie all of revenue) go to buybacks but buybacks are done in batches, at the time of the buyback
Expand All @@ -79,12 +84,13 @@ SELECT
, price.token_turnover_circulating
, price.token_turnover_fdv
, price.token_volume
FROM price
FROM date_spine ds
LEFT JOIN price USING (date)
LEFT JOIN revenue USING (date)
LEFT JOIN buybacks USING (date)
LEFT JOIN mints USING (date)
LEFT JOIN active_wallets USING (date)
LEFT JOIN transactions USING (date)
LEFT JOIN unique_signers USING (date)
LEFT JOIN new_holders USING (date)
where coalesce(price.date, revenue.date, buybacks.date, transactions.date) < to_date(sysdate())
where ds.date < to_date(sysdate())
10 changes: 9 additions & 1 deletion models/staging/metaplex/fact_metaplex_active_wallets.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
materialized="incremental",
snowflake_warehouse="METAPLEX"
snowflake_warehouse="METAPLEX",
unique_key=["date"]
) }}

WITH all_activity AS (
Expand All @@ -22,6 +23,9 @@ WITH all_activity AS (
seller AS wallet
FROM
{{ ref('fact_metaplex_sales') }} AS s
{% if is_incremental() %}
WHERE block_timestamp >= (SELECT MAX(date) FROM {{ this }})
{% endif %}

UNION ALL

Expand All @@ -31,6 +35,9 @@ WITH all_activity AS (
purchaser AS wallet
FROM
{{ ref('fact_metaplex_sales') }} AS s
{% if is_incremental() %}
WHERE block_timestamp >= (SELECT MAX(date) FROM {{ this }})
{% endif %}

UNION ALL

Expand Down Expand Up @@ -96,6 +103,7 @@ SELECT
COUNT(DISTINCT wallet) AS daily_active_users
FROM
all_activity
WHERE date < to_date(sysdate())
GROUP BY
date
ORDER BY
Expand Down

0 comments on commit 06575b3

Please sign in to comment.