Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine Historical Yield Models #665

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
1 change: 1 addition & 0 deletions models/staging/defillama/_defillama_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sources:
tables:
- name: raw_defillama_chain_data
- name: raw_defillama_yield_data
- name: raw_defillama_yield_historical_data
- name: raw_defillama_protocol_data
- name: raw_defillama_protocol_tvls
- name: raw_defillama_chain_tvls
Expand Down
23 changes: 23 additions & 0 deletions models/staging/defillama/fact_defillama_yield_historical.sql
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)
2 changes: 2 additions & 0 deletions models/staging/defillama/fact_defillama_yields.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{ config(materialized="table") }}

WITH max_extraction AS (
SELECT max(extraction_date) AS max_date
FROM {{ source("PROD_LANDING", "raw_defillama_yield_data") }}
Expand Down
Loading