From 77a7774eac789628acaa1d38a123c057eaae205e Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Tue, 21 May 2024 15:26:42 -0400 Subject: [PATCH] updating ton dex data --- models/projects/ton/core/ez_ton_metrics.sql | 9 ++- models/staging/ton/__ton__sources.yml | 1 + ...xns_gas_gas_usd_revenue_revenue_native.yml | 80 +++++++++++++++++++ models/staging/ton/fact_ton_dex_volumes.sql | 22 +++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 models/staging/ton/_test_fact_ton_daa_txns_gas_gas_usd_revenue_revenue_native.yml create mode 100644 models/staging/ton/fact_ton_dex_volumes.sql diff --git a/models/projects/ton/core/ez_ton_metrics.sql b/models/projects/ton/core/ez_ton_metrics.sql index 90a2fc1a..94fec789 100644 --- a/models/projects/ton/core/ez_ton_metrics.sql +++ b/models/projects/ton/core/ez_ton_metrics.sql @@ -24,6 +24,12 @@ with ), price_data as ({{ get_coingecko_metrics("the-open-network") }}), defillama_data as ({{ get_defillama_metrics("ton") }}), + dex_data as ( + select + date, + dex_volumes + from {{ ref("fact_ton_dex_volumes") }} + ), github_data as ({{ get_github_metrics("ton") }}) select fundamental_data.date, @@ -39,7 +45,7 @@ select market_cap, fdmc, tvl, - dex_volumes, + dex_data.dex_volumes, weekly_commits_core_ecosystem, weekly_commits_sub_ecosystem, weekly_developers_core_ecosystem, @@ -48,4 +54,5 @@ from fundamental_data left join price_data on fundamental_data.date = price_data.date left join defillama_data on fundamental_data.date = defillama_data.date left join github_data on fundamental_data.date = github_data.date +left join dex_data on fundamental_data.date = dex_data.date where fundamental_data.date < to_date(sysdate()) diff --git a/models/staging/ton/__ton__sources.yml b/models/staging/ton/__ton__sources.yml index 6cb75145..3201e375 100644 --- a/models/staging/ton/__ton__sources.yml +++ b/models/staging/ton/__ton__sources.yml @@ -7,3 +7,4 @@ sources: - name: raw_ton_gas - name: raw_ton_revenue - name: raw_ton_txns + - name: raw_ton_dex_volumes diff --git a/models/staging/ton/_test_fact_ton_daa_txns_gas_gas_usd_revenue_revenue_native.yml b/models/staging/ton/_test_fact_ton_daa_txns_gas_gas_usd_revenue_revenue_native.yml new file mode 100644 index 00000000..41f67ace --- /dev/null +++ b/models/staging/ton/_test_fact_ton_daa_txns_gas_gas_usd_revenue_revenue_native.yml @@ -0,0 +1,80 @@ +models: + - name: fact_ton_daa_txns_gas_gas_usd_revenue_revenue_native + tests: + - "dbt_expectations.expect_table_row_count_to_be_between:": + min_value: 1 + max_value: 1000000 + columns: + - name: CHAIN + tests: + - not_null + - dbt_expectations.expect_column_to_exist + - name: txns + tests: + - not_null + - dbt_expectations.expect_column_to_exist + - dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs: + date_column_name: DATE + period: day + lookback_periods: 1 + trend_periods: 14 + test_periods: 28 + sigma_threshold: 3 + take_logs: true + severity: warn + - name: dau + tests: + - dbt_expectations.expect_column_to_exist + - dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs: + date_column_name: DATE + period: day + lookback_periods: 1 + trend_periods: 14 + test_periods: 28 + sigma_threshold: 3 + take_logs: true + severity: warn + - name: date + tests: + - not_null + - dbt_expectations.expect_column_to_exist + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 3 + severity: warn + - name: revenue + tests: + - dbt_expectations.expect_column_to_exist + - dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs: + date_column_name: DATE + period: day + lookback_periods: 1 + trend_periods: 14 + test_periods: 28 + sigma_threshold: 3 + take_logs: true + severity: warn + - name: fees + tests: + - dbt_expectations.expect_column_to_exist + - dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs: + date_column_name: DATE + period: day + lookback_periods: 1 + trend_periods: 14 + test_periods: 28 + sigma_threshold: 3 + take_logs: true + severity: warn + - name: fees_native + tests: + - dbt_expectations.expect_column_to_exist + - dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs: + date_column_name: DATE + period: day + lookback_periods: 1 + trend_periods: 14 + test_periods: 28 + sigma_threshold: 3 + take_logs: true + severity: warn diff --git a/models/staging/ton/fact_ton_dex_volumes.sql b/models/staging/ton/fact_ton_dex_volumes.sql new file mode 100644 index 00000000..67ac8d4f --- /dev/null +++ b/models/staging/ton/fact_ton_dex_volumes.sql @@ -0,0 +1,22 @@ +with + max_extraction as ( + select + max(extraction_date) as max_extraction, + value:date::date as date + from landing_database.prod_landing.raw_ton_dex_volumes, + lateral flatten(input => source_json) + group by date + ), + flattened_data as ( + select value:"date"::date as date, value:"dex_volumes"::float as dex_volumes, extraction_date + from landing_database.prod_landing.raw_ton_dex_volumes, + lateral flatten(input => source_json) + ), + prices as ({{ get_coingecko_price_with_latest("the-open-network") }}) +select + t1.date, + 'ton' as chain, + dex_volumes * price as dex_volumes +from flattened_data t1 +inner join max_extraction t2 on t1.date = t2.date and t1.extraction_date = t2.max_extraction +left join prices on t1.date = prices.date