From 7dab4dc997d2cb74fbec510982b1a79de67a3faa Mon Sep 17 00:00:00 2001 From: Alex Kan <29241719+akan72@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:58:17 -0500 Subject: [PATCH] Add DFL yields data --- .../staging/defillama/_defillama_sources.yml | 1 + .../defillama/fact_defillama_yields.sql | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 models/staging/defillama/fact_defillama_yields.sql diff --git a/models/staging/defillama/_defillama_sources.yml b/models/staging/defillama/_defillama_sources.yml index 4b479e3b..502812ac 100644 --- a/models/staging/defillama/_defillama_sources.yml +++ b/models/staging/defillama/_defillama_sources.yml @@ -4,6 +4,7 @@ sources: database: LANDING_DATABASE tables: - name: raw_defillama_chain_data + - name: raw_defillama_yield_data - name: raw_defillama_protocol_data - name: raw_defillama_protocol_tvls - name: raw_defillama_chain_tvls diff --git a/models/staging/defillama/fact_defillama_yields.sql b/models/staging/defillama/fact_defillama_yields.sql new file mode 100644 index 00000000..495aa4f2 --- /dev/null +++ b/models/staging/defillama/fact_defillama_yields.sql @@ -0,0 +1,29 @@ +WITH max_extraction AS ( + SELECT max(extraction_date) AS max_date + FROM {{ source("PROD_LANDING", "raw_defillama_yield_data") }} + ), + protocol_data AS ( + SELECT + extraction_date::date as date, + parse_json(source_json):"data" AS data + FROM {{ source("PROD_LANDING", "raw_defillama_yield_data") }} + WHERE extraction_date = (SELECT max_date FROM max_extraction) + + ) +SELECT + date, + value:"chain"::string AS chain, + value:"project"::string AS project, + value:"symbol"::string AS symbol, + value:"tvlUsd"::float AS tvl_usd, + value:"apyBase" AS apy_base, + value:"apyReward" AS apy_reward, + value:"apy"::float AS apy, + value:"pool"::string AS pool, + value:"apyPct1D"::string AS apy_pct_1d, + value:"apyPct7D"::string AS apy_pct_7d, + value:"apyPct30D"::string AS apy_pct_30d, + value:"stablecoin"::boolean AS is_stablecoin, + value:"apyBase7d"::string AS apy_base_7d, + value:"apyMean30d"::string AS apy_mean_30d +FROM protocol_data, lateral flatten(input => data)