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

Chiliz: Fundamental metrics #466

Merged
merged 2 commits into from
Sep 6, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% macro convert_routescan_api_daus_for_chain(chain) %}
with
max_extraction as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_dau") }}
),
akan72 marked this conversation as resolved.
Show resolved Hide resolved
latest_data as (
select parse_json(source_json) as data
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_dau") }}
where extraction_date = (select max_date from max_extraction)
),
data as (
select
f.value:date::date as date,
f.value:addresses::int as dau
from latest_data, lateral flatten(input => data) f
)
select date, dau
from data
where date < to_date(sysdate())
order by date desc
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% macro convert_routescan_api_fees_native_for_chain(chain) %}
with
max_extraction_gas_used as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_gas_used") }}

),
latest_data_gas_used as (
select parse_json(source_json) as data
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_gas_used") }}
where extraction_date = (select max_date from max_extraction_gas_used)
),
gas_used as (
select
f.value:date::date as date,
f.value:"gas-used"::int as gas_used
from latest_data_gas_used, lateral flatten(input => data) f
),
max_extraction_avg_gas_price as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_avg_gas_price") }}

),
latest_data_avg_gas_price as (
select parse_json(source_json) as data
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_avg_gas_price") }}
where extraction_date = (select max_date from max_extraction_avg_gas_price)
),
avg_gas_price as (
select
f.value:date::date as date,
f.value:"avg-gas-price"::int as avg_gas_price
from latest_data_avg_gas_price, lateral flatten(input => data) f
)
select
gas_used.date,
gas_used.gas_used,
avg_gas_price.avg_gas_price,
gas_used.gas_used * avg_gas_price.avg_gas_price / pow(10, 18) as fees_native
from gas_used
left join avg_gas_price on gas_used.date = avg_gas_price.date

{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% macro convert_routescan_api_txns_for_chain(chain) %}
with
max_extraction as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_txns") }}

),
latest_data as (
select parse_json(source_json) as data
from {{ source("PROD_LANDING", "raw_" ~ chain ~ "_txns") }}
where extraction_date = (select max_date from max_extraction)
),
data as (
select
f.value:date::date as date,
f.value:txs::int as txns
from latest_data, lateral flatten(input => data) f
)
select date, txns
from data
where date < to_date(sysdate())
order by date desc
{% endmacro %}
38 changes: 38 additions & 0 deletions models/projects/chiliz/core/ez_chiliz_metrics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{
config(
materialized = "table",
snowflake_warehouse = "CHILIZ",
database = "CHILIZ",
schema = "CORE",
alias = "ez_metrics"
)
}}

with fees as (
select
date,
fees_usd
from {{ref("fact_chiliz_fees")}}
),
txns as (
select
date,
txns
from {{ref("fact_chiliz_txns")}}
)
, daus as (
select
date,
dau
from {{ref("fact_chiliz_dau")}}
where dau < 170000 -- There is a DQ issue with the Chiliz dau data: 2 days with > 170k DAU while the rest of the data around those days is < 1k
akan72 marked this conversation as resolved.
Show resolved Hide resolved
)

select
coalesce(fees.date, txns.date, daus.date) as date,
dau,
txns,
fees_usd as fees
from fees
left join txns on fees.date = txns.date
left join daus on fees.date = daus.date
4 changes: 4 additions & 0 deletions models/staging/chiliz/__chiliz__sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ sources:
database: LANDING_DATABASE
tables:
- name: raw_chiliz_trading_volume
- name: raw_chiliz_txns
- name: raw_chiliz_gas_used
- name: raw_chiliz_avg_gas_price
- name: raw_chiliz_dau
3 changes: 3 additions & 0 deletions models/staging/chiliz/fact_chiliz_dau.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{
convert_routescan_api_daus_for_chain(chain="chiliz")
}}
15 changes: 15 additions & 0 deletions models/staging/chiliz/fact_chiliz_fees.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

with prices as (
select
date(hour) as date,
avg(price) as price
from ethereum_flipside.price.ez_prices_hourly
akan72 marked this conversation as resolved.
Show resolved Hide resolved
where lower(token_address) = lower('0x3506424f91fd33084466f402d5d97f05f8e3b4af')
group by 1
)
select
f.date,
f.fees_native * p.price as fees_usd
from {{ref("fact_chiliz_fees_native")}} f
left join prices p on p.date = f.date
where f.date < to_date(sysdate())
3 changes: 3 additions & 0 deletions models/staging/chiliz/fact_chiliz_fees_native.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{
convert_routescan_api_fees_native_for_chain(chain="chiliz")
}}
3 changes: 3 additions & 0 deletions models/staging/chiliz/fact_chiliz_txns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{
convert_routescan_api_txns_for_chain(chain="chiliz")
}}
Loading