-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
models/metrics/stablecoins/yield/fact_stablecoin_yield_historical.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,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) |