Skip to content

Commit

Permalink
chiliz fundamental models
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwes committed Sep 5, 2024
1 parent d803096 commit aa2f58c
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 0 deletions.
22 changes: 22 additions & 0 deletions macros/routescan_helpers/convert_routescan_api_daus_for_chain.sql
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") }}
),
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 %}
23 changes: 23 additions & 0 deletions macros/routescan_helpers/convert_routescan_api_txns_for_chain.sql
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 %}
37 changes: 37 additions & 0 deletions models/projects/chiliz/core/ez_chiliz_metrics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{
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")}}
)

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
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")
}}

0 comments on commit aa2f58c

Please sign in to comment.