-
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.
Combine Historical Yield Models (#665)
- Loading branch information
Showing
4 changed files
with
70 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) |
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
23 changes: 23 additions & 0 deletions
23
models/staging/defillama/fact_defillama_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,23 @@ | ||
{{ config(materialized="table") }} | ||
|
||
WITH max_extraction AS ( | ||
SELECT max(extraction_date) AS max_date | ||
FROM {{ source("PROD_LANDING", "raw_defillama_yield_historical_data") }} | ||
), | ||
protocol_data AS ( | ||
SELECT | ||
extraction_date::date as date, | ||
parse_json(source_json):"pool" AS pool, | ||
parse_json(source_json):"data" AS data | ||
FROM {{ source("PROD_LANDING", "raw_defillama_yield_historical_data") }} | ||
WHERE extraction_date = (SELECT max_date FROM max_extraction) | ||
|
||
) | ||
SELECT | ||
value:"timestamp"::date AS date, | ||
pool::varchar AS pool, | ||
value:"apy"::float AS apy, | ||
value:"apyBase"::float AS apy_base, | ||
value:"apyBase7d"::float AS apy_base_7d, | ||
value:"apyReward"::float AS apy_reward, | ||
FROM protocol_data, lateral flatten(input => data) |
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