From 4e7af7ab8df885875c74f2a58f06a5f735a4c269 Mon Sep 17 00:00:00 2001 From: tomfutago <35136350+tomfutago@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:57:32 +0100 Subject: [PATCH] Nexus Mutual - capital pool tweaks (#6099) * tweaks * add avg_usdc_usd_price * fix usdc addition --------- Co-authored-by: Huang Geyang --- .../ethereum/capital_pool/_schema.yml | 8 ++++++ ...xusmutual_ethereum_capital_pool_latest.sql | 4 +++ ...xusmutual_ethereum_capital_pool_totals.sql | 25 ++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/models/nexusmutual/ethereum/capital_pool/_schema.yml b/models/nexusmutual/ethereum/capital_pool/_schema.yml index 9953ced90ee..84b850bfe58 100644 --- a/models/nexusmutual/ethereum/capital_pool/_schema.yml +++ b/models/nexusmutual/ethereum/capital_pool/_schema.yml @@ -75,6 +75,12 @@ models: - &avg_eth_usd_price name: avg_eth_usd_price description: "Daily average ETH/USD price" + - &avg_dai_usd_price + name: avg_dai_usd_price + description: "Daily average DAI/USD price" + - &avg_usdc_usd_price + name: avg_usdc_usd_price + description: "Daily average USDC/USD price" - &avg_capital_pool_eth_total name: avg_capital_pool_eth_total description: "Daily average Capital Pool total expressed in ETH" @@ -169,6 +175,8 @@ models: columns: - *block_date - *avg_eth_usd_price + - *avg_dai_usd_price + - *avg_usdc_usd_price - *avg_capital_pool_eth_total - *avg_capital_pool_usd_total - *eth_total diff --git a/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_latest.sql b/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_latest.sql index d91e40fb40a..fb952a11d3c 100644 --- a/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_latest.sql +++ b/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_latest.sql @@ -16,6 +16,8 @@ daily_running_totals as ( select block_date, avg_eth_usd_price, + avg_dai_usd_price, + avg_usdc_usd_price, -- Capital Pool avg_capital_pool_eth_total, avg_capital_pool_usd_total, @@ -58,6 +60,8 @@ daily_running_totals as ( select block_date, avg_eth_usd_price, + avg_dai_usd_price, + avg_usdc_usd_price, -- Capital Pool avg_capital_pool_eth_total, avg_capital_pool_usd_total, diff --git a/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_totals.sql b/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_totals.sql index a5557c2d1b4..6a08e2826b3 100644 --- a/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_totals.sql +++ b/models/nexusmutual/ethereum/capital_pool/nexusmutual_ethereum_capital_pool_totals.sql @@ -397,9 +397,24 @@ daily_running_totals as ( sum(coalesce(tt.dai_total, 0)) over (order by ds.block_date) as dai_total, sum(coalesce(tt.reth_total, 0)) over (order by ds.block_date) as reth_total, sum(coalesce(tt.usdc_total, 0)) over (order by ds.block_date) as usdc_total, - coalesce(steth_rt.steth_total, lag(steth_rt.steth_total) over (order by ds.block_date), 0) as steth_total, - coalesce(nxmty_rt.nxmty_total, lag(nxmty_rt.nxmty_total) over (order by ds.block_date), 0) as nxmty_total, - coalesce(nxmty_rt.nxmty_in_eth_total, lag(nxmty_rt.nxmty_in_eth_total) over (order by ds.block_date), 0) as nxmty_eth_total, + coalesce( + steth_rt.steth_total, + lag(steth_rt.steth_total, 1) over (order by ds.block_date), + lag(steth_rt.steth_total, 2) over (order by ds.block_date), + 0 + ) as steth_total, + coalesce( + nxmty_rt.nxmty_total, + lag(nxmty_rt.nxmty_total, 1) over (order by ds.block_date), + lag(nxmty_rt.nxmty_total, 2) over (order by ds.block_date), + 0 + ) as nxmty_total, + coalesce( + nxmty_rt.nxmty_in_eth_total, + lag(nxmty_rt.nxmty_in_eth_total, 1) over (order by ds.block_date), + lag(nxmty_rt.nxmty_in_eth_total, 2) over (order by ds.block_date), + 0 + ) as nxmty_eth_total, coalesce(cre.amount, 0) as cover_re_usdc_total, coalesce(aave_s.supplied_amount, 0) as aave_collateral_weth_total, -1 * coalesce(aave_b.borrowed_amount, 0) as aave_debt_usdc_total @@ -416,6 +431,8 @@ daily_running_totals_enriched as ( select drt.block_date, coalesce(p_avg_eth.price_usd, 0) as avg_eth_usd_price, + coalesce(p_avg_dai.price_usd, 0) as avg_dai_usd_price, + coalesce(p_avg_usdc.price_usd, 0) as avg_usdc_usd_price, -- ETH coalesce(drt.eth_total, 0) as eth_total, coalesce(drt.eth_total * p_avg_eth.price_usd, 0) as avg_eth_usd_total, @@ -458,6 +475,8 @@ daily_running_totals_enriched as ( select block_date, avg_eth_usd_price, + avg_dai_usd_price, + avg_usdc_usd_price, -- Capital Pool totals eth_total + nxmty_eth_total + steth_total + avg_dai_eth_total + avg_reth_eth_total + avg_usdc_eth_total + avg_cover_re_usdc_eth_total + aave_collateral_weth_total + avg_aave_debt_usdc_eth_total as avg_capital_pool_eth_total,