From fd298e2a4d272387831395002fe629620c29a896 Mon Sep 17 00:00:00 2001 From: alexwes Date: Wed, 4 Sep 2024 21:06:19 -0400 Subject: [PATCH] Blur: inital fundamentals commit (#453) --- databases.csv | 1 + dbt_project.yml | 2 ++ models/projects/blur/core/ez_blur_metrics.sql | 34 +++++++++++++++++++ models/staging/blur/__blur__sources.yml | 8 +++++ models/staging/blur/fact_blur_daily_txns.sql | 26 ++++++++++++++ models/staging/blur/fact_blur_daus.sql | 26 ++++++++++++++ models/staging/blur/fact_blur_fees.sql | 26 ++++++++++++++ 7 files changed, 123 insertions(+) create mode 100644 models/projects/blur/core/ez_blur_metrics.sql create mode 100644 models/staging/blur/__blur__sources.yml create mode 100644 models/staging/blur/fact_blur_daily_txns.sql create mode 100644 models/staging/blur/fact_blur_daus.sql create mode 100644 models/staging/blur/fact_blur_fees.sql diff --git a/databases.csv b/databases.csv index 7d7f4361..c1f825d1 100644 --- a/databases.csv +++ b/databases.csv @@ -18,6 +18,7 @@ BITCOIN BITCOIN_FLIPSIDE BLAST BLAST_FLIPSIDE +BLUR BSC BSC_FLIPSIDE BUSD diff --git a/dbt_project.yml b/dbt_project.yml index e70ba3a5..ea9b2f6b 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -63,6 +63,8 @@ models: +snowflake_warehouse: "BITCOIN" blast: +snowflake_warehouse: "BLAST" + blur: + +snowflake_warehouse: "BLUR" cardano: +snowflake_warehouse: "CARDANO" cctp: diff --git a/models/projects/blur/core/ez_blur_metrics.sql b/models/projects/blur/core/ez_blur_metrics.sql new file mode 100644 index 00000000..0cb9da72 --- /dev/null +++ b/models/projects/blur/core/ez_blur_metrics.sql @@ -0,0 +1,34 @@ +{{ + config( + materialized = 'table', + snowflake_warehouse = 'BLUR', + database = 'blur', + schema = 'core', + alias = 'ez_metrics' + ) +}} + +with + blur_fees as ( + select * + from {{ ref("fact_blur_fees") }} + ) + , blur_daus as ( + select * + from {{ ref("fact_blur_daus") }} + ) + , blur_daily_txns as ( + select * + from {{ ref("fact_blur_daily_txns") }} + ) + +select + blur_daus.date, + blur_daus.dau, + blur_daily_txns.daily_txns as txns, + blur_fees.fees +from blur_daus +left join blur_daily_txns + on blur_daus.date = blur_daily_txns.date +left join blur_fees + on blur_daus.date = blur_fees.date \ No newline at end of file diff --git a/models/staging/blur/__blur__sources.yml b/models/staging/blur/__blur__sources.yml new file mode 100644 index 00000000..1d3a64f9 --- /dev/null +++ b/models/staging/blur/__blur__sources.yml @@ -0,0 +1,8 @@ +sources: + - name: PROD_LANDING + schema: PROD_LANDING + database: LANDING_DATABASE + tables: + - name: raw_blur_dau + - name: raw_blur_fees + - name: raw_blur_daily_txns diff --git a/models/staging/blur/fact_blur_daily_txns.sql b/models/staging/blur/fact_blur_daily_txns.sql new file mode 100644 index 00000000..0f91a249 --- /dev/null +++ b/models/staging/blur/fact_blur_daily_txns.sql @@ -0,0 +1,26 @@ +{{ + config( + materialized = 'table' + ) +}} + +with + max_extraction as ( + select max(extraction_date) as max_date + from {{ source("PROD_LANDING", "raw_blur_daily_txns") }} + ), + latest_data as ( + select parse_json(source_json) as data + from {{ source("PROD_LANDING", "raw_blur_daily_txns") }} + where extraction_date = (select max_date from max_extraction) + ), + flattened_data as ( + select + date(to_timestamp(SUBSTR(f.value:time, 0, 10)::date)) as date, + f.value:trades::number as daily_txns + from latest_data, lateral flatten(input => data) as f + ) +select date, daily_txns, 'ethereum' as chain, 'blur' as app +from flattened_data +where date < to_date(sysdate()) +order by date desc \ No newline at end of file diff --git a/models/staging/blur/fact_blur_daus.sql b/models/staging/blur/fact_blur_daus.sql new file mode 100644 index 00000000..71574e88 --- /dev/null +++ b/models/staging/blur/fact_blur_daus.sql @@ -0,0 +1,26 @@ +{{ + config( + materialized = 'table' + ) +}} + +with + max_extraction as ( + select max(extraction_date) as max_date + from {{ source("PROD_LANDING", "raw_blur_dau") }} + ), + latest_data as ( + select parse_json(source_json) as data + from {{ source("PROD_LANDING", "raw_blur_dau") }} + where extraction_date = (select max_date from max_extraction) + ), + flattened_data as ( + select + date(to_timestamp(SUBSTR(f.value:time, 0, 10)::date)) as date, + f.value:traders::number as dau + from latest_data, lateral flatten(input => data) as f + ) +select date, dau, 'ethereum' as chain, 'blur' as app +from flattened_data +where date < to_date(sysdate()) +order by date desc \ No newline at end of file diff --git a/models/staging/blur/fact_blur_fees.sql b/models/staging/blur/fact_blur_fees.sql new file mode 100644 index 00000000..d22b054a --- /dev/null +++ b/models/staging/blur/fact_blur_fees.sql @@ -0,0 +1,26 @@ +{{ + config( + materialized = 'table' + ) +}} + +with + max_extraction as ( + select max(extraction_date) as max_date + from {{ source("PROD_LANDING", "raw_blur_fees") }} + ), + latest_data as ( + select parse_json(source_json) as data + from {{ source("PROD_LANDING", "raw_blur_fees") }} + where extraction_date = (select max_date from max_extraction) + ), + flattened_data as ( + select + date(to_timestamp(SUBSTR(f.value:time, 0, 10)::date)) as date, + f.value:fees_paid::number as fees + from latest_data, lateral flatten(input => data) as f + ) +select date, fees, 'ethereum' as chain, 'blur' as app +from flattened_data +where date < to_date(sysdate()) +order by date desc \ No newline at end of file