Skip to content

Commit

Permalink
adding mantle to bam datahub models
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 committed Nov 26, 2024
1 parent 8bd24c0 commit 246084d
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ with
ref("ez_solana_metrics_by_category"),
ref("ez_sui_metrics_by_category"),
ref("ez_tron_metrics_by_category"),
ref("ez_mantle_metrics_by_category"),
]
)
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ with
ref("ez_solana_metrics"),
ref("ez_sui_metrics"),
ref("ez_tron_metrics"),
ref("ez_mantle_metrics"),
]
)
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,21 @@ select
null as avg_token_price,
'injective' as chain
from {{ ref("ez_injective_metrics_by_contract") }}
union
select
contract_address,
date,
name,
null as symbol,
app as namespace,
friendly_name,
category,
gas as total_gas,
gas_usd as total_gas_usd,
txns as transactions,
dau,
null as token_transfer_usd,
null as token_transfer,
null as avg_token_price,
'mantle' as chain
from {{ ref("ez_mantle_metrics_by_contract") }}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ with
ref("ez_solana_metrics_by_application"),
ref("ez_sui_metrics_by_application"),
ref("ez_tron_metrics_by_application"),
ref("ez_mantle_metrics_by_application"),
]
)
}}
Expand Down
65 changes: 65 additions & 0 deletions models/staging/mantle/mantle_trending_daily.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{ config(materialized="table", snowflake_warehouse="BAM_TRENDING_WAREHOUSE") }}

with
last_2_day as (
select
t.contract_address to_address,
from_address,
date_trunc('day', block_timestamp) date,
tx_fee,
gas_usd,
name,
app as namespace,
friendly_name,
category
from {{ref('fact_mantle_transactions')}} as t
where
t.contract_address is not null
and t.block_timestamp >= dateadd(day, -2, current_date)
),
last_day as (
select
t.to_address to_address,
count(*) txns,
count(distinct(from_address)) dau,
sum(tx_fee) as gas,
sum(gas_usd) as gas_usd,
max(name) name,
max(namespace) namespace,
max(friendly_name) friendly_name,
max(category) category
from last_2_day as t
where t.to_address is not null and t.date >= dateadd(day, -1, current_date)
group by to_address
),
two_days as (
select
t.to_address to_address,
count(*) txns,
count(distinct(from_address)) dau,
sum(tx_fee) as gas,
sum(gas_usd) as gas_usd
from last_2_day as t
where
t.to_address is not null
and t.date < dateadd(day, -1, current_date)
and t.date >= dateadd(day, -2, current_date)
group by to_address
)
select
last_day.to_address,
last_day.txns,
last_day.gas,
last_day.gas_usd,
last_day.dau,
two_days.txns prev_txns,
two_days.gas prev_gas,
two_days.gas_usd prev_gas_usd,
two_days.dau prev_dau,
last_day.name,
last_day.namespace,
last_day.friendly_name,
last_day.category,
'daily' as granularity
from last_day
left join two_days on lower(last_day.to_address) = lower(two_days.to_address)
121 changes: 121 additions & 0 deletions models/staging/mantle/mantle_trending_weekly_monthly.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{{ config(materialized="table", snowflake_warehouse="BAM_TRENDING_WAREHOUSE") }}

with
last_2_month as (
select
t.contract_address to_address,
from_address,
date_trunc('day', block_timestamp) date,
tx_fee,
gas_usd,
name,
app as namespace,
friendly_name,
category
from {{ref("fact_mantle_transactions")}} as t
where
t.contract_address is not null
and t.block_timestamp >= dateadd(day, -60, current_date)
),
last_week as (
select
to_address to_address,
count(*) as txns,
count(distinct(from_address)) dau,
sum(tx_fee) as gas,
sum(gas_usd) as gas_usd,
max(name) name,
max(namespace) namespace,
max(friendly_name) friendly_name,
max(category) category
from last_2_month
where to_address is not null and date >= dateadd(day, -7, current_date)
group by to_address
),
two_week as (
select
to_address to_address,
count(*) txns,
count(distinct(from_address)) dau,
sum(tx_fee) as gas,
sum(gas_usd) as gas_usd
from last_2_month
where
to_address is not null
and date < dateadd(day, -7, current_date)
and date >= dateadd(day, -14, current_date)
group by to_address
),
trending_week as (
select
last_week.to_address,
last_week.txns,
last_week.gas,
last_week.gas_usd,
last_week.dau,
two_week.txns prev_txns,
two_week.gas prev_gas,
two_week.gas_usd prev_gas_usd,
two_week.dau prev_dau,
last_week.name,
last_week.namespace,
last_week.friendly_name,
last_week.category,
'weekly' as granularity
from last_week
left join two_week on lower(last_week.to_address) = lower(two_week.to_address)
),
last_month as (
select
to_address to_address,
count(*) as txns,
count(distinct(from_address)) dau,
sum(tx_fee) as gas,
sum(gas_usd) as gas_usd,
max(name) name,
max(namespace) namespace,
max(friendly_name) friendly_name,
max(category) category
from last_2_month
where to_address is not null and date >= dateadd(day, -30, current_date)
group by to_address
),
two_month as (
select
to_address to_address,
count(*) txns,
count(distinct(from_address)) dau,
sum(tx_fee) as gas,
sum(gas_usd) as gas_usd
from last_2_month
where
to_address is not null
and date < dateadd(day, -30, current_date)
and date >= dateadd(day, -60, current_date)
group by to_address
),
trending_month as (
select
last_month.to_address,
last_month.txns,
last_month.gas,
last_month.gas_usd,
last_month.dau,
two_month.txns prev_txns,
two_month.gas prev_gas,
two_month.gas_usd prev_gas_usd,
two_month.dau prev_dau,
last_month.name,
last_month.namespace,
last_month.friendly_name,
last_month.category,
'monthly' as granularity
from last_month
left join
two_month on lower(last_month.to_address) = lower(two_month.to_address)
)
select *
from trending_week
union
select *
from trending_month
6 changes: 6 additions & 0 deletions models/trending/bam_trending_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ select *, 'injective' as chain
from {{ ref("injective_trending_daily") }}
union all
select *, 'injective' as chain
from {{ ref("injective_trending_weekly_monthly") }}
union all
select *, 'injective' as chain
from {{ ref("mantle_trending_daily") }}
union all
select *, 'injective' as chain
from {{ ref("injective_trending_weekly_monthly") }}

0 comments on commit 246084d

Please sign in to comment.