From bd5bfd58062838dce15d1dd9021507e000844f77 Mon Sep 17 00:00:00 2001 From: Alex Kan <29241719+akan72@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:43:52 -0500 Subject: [PATCH] Combine DFL and Artemis data --- .../fact_stablecoin_yield_historical.sql | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 models/metrics/stablecoins/yield/fact_stablecoin_yield_historical.sql diff --git a/models/metrics/stablecoins/yield/fact_stablecoin_yield_historical.sql b/models/metrics/stablecoins/yield/fact_stablecoin_yield_historical.sql new file mode 100644 index 00000000..878b2f13 --- /dev/null +++ b/models/metrics/stablecoins/yield/fact_stablecoin_yield_historical.sql @@ -0,0 +1,44 @@ +{{ config( materialized="table") }} + +WITH defillama_data AS ( + SELECT + a.date, + UPPER(b.chain) AS chain, + UPPER(b.symbol) AS stablecoin, + a.apy, + UPPER(b.project) AS project, + 'defillama' AS source, + MAX(a.date) OVER() AS max_date + FROM {{ ref("fact_defillama_yield_historical") }} a + INNER JOIN {{ ref("fact_defillama_yields") }} b + ON a.pool = b.pool + ORDER BY tvl_usd DESC +), artemis_data AS ( + SELECT + date, + 'SOLANA' AS chain, + UPPER(market) AS stablecoin, + daily_avg_deposit_rate AS apy, + 'DRIFT' AS project, + 'artemis' AS source, + MAX(date) OVER() AS max_date + FROM {{ ref("fact_drift_daily_spot_data") }} +), agg AS ( +SELECT + * +FROM defillama_data +UNION ALL +SELECT + * +FROM artemis_data +WHERE + stablecoin IN ( + SELECT + DISTINCT stablecoin + FROM defillama_data + ) +) +SELECT + * +FROM agg +WHERE date <= (SELECT MIN(max_date) FROM agg)