-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
macros/routescan_helpers/convert_routescan_api_daus_for_chain.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
43 changes: 43 additions & 0 deletions
43
macros/routescan_helpers/convert_routescan_api_fees_native_for_chain.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
macros/routescan_helpers/convert_routescan_api_txns_for_chain.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ | ||
convert_routescan_api_daus_for_chain(chain="chiliz") | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ | ||
convert_routescan_api_fees_native_for_chain(chain="chiliz") | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ | ||
convert_routescan_api_txns_for_chain(chain="chiliz") | ||
}} |