Query editor
-- aave_v4 Ethena Ecosystem and Ethena Correlated spokes : per-wallet USDe liquidation price-- Positions rebuilt as in queries 8648074 and 8648070 (Spoke share events, latest observed share price).-- Shock: USDe price p falls, sUSDe = susde_rate USDe (fixed), every other price constant. USDe debt moves with p.-- Aave v4 has one collateral factor per reserve, so max_ltv = lltv = collateral factor. Premium debt excluded.withreserves_raw as (select 'ethena_ecosystem' as spoke, reserveId, assetId, hub from aave_v4_ethereum.ethenaecosystemspoke_evt_AddReservewhere contract_address = 0xba1b3d55d249692b669a164024a838309b7508afunion allselect 'ethena_correlated', reserveId, assetId, hub from aave_v4_ethereum.ethenacorrelatedspoke_evt_AddReservewhere contract_address = 0x58131e79531cab1d52301228d1f7b842f26b9649),reserves as (select r.spoke, r.reserveId, a.underlying, cast(a.decimals as integer) as decimalsfrom reserves_raw rjoin (select assetId, underlying, decimals, contract_address from aave_v4_ethereum.corehub_evt_AddAssetunion all select assetId, underlying, decimals, contract_address from aave_v4_ethereum.plushub_evt_AddAssetunion all select assetId, underlying, decimals, contract_address from aave_v4_ethereum.primehub_evt_AddAssetunion all select assetId, underlying, decimals, contract_address from aave_v4_ethereum.globaldollarhub_evt_AddAsset) a on a.assetId = r.assetId and a.contract_address = r.hub),cf as (select spoke, reserveId, collateral_factorfrom (select *, row_number() over (partition by spoke, reserveId order by evt_block_number desc, evt_index desc) rnfrom (select 'ethena_ecosystem' as spoke, reserveId, cast(json_extract_scalar(config, '$.collateralFactor') as double) / 1e4 as collateral_factor, evt_block_number, evt_indexfrom aave_v4_ethereum.ethenaecosystemspoke_evt_AddDynamicReserveConfigunion allselect 'ethena_ecosystem', reserveId, cast(json_extract_scalar(config, '$.collateralFactor') as double) / 1e4, evt_block_number, evt_indexfrom aave_v4_ethereum.ethenaecosystemspoke_evt_UpdateDynamicReserveConfigunion allselect 'ethena_correlated', reserveId, cast(json_extract_scalar(config, '$.collateralFactor') as double) / 1e4, evt_block_number, evt_indexfrom aave_v4_ethereum.ethenacorrelatedspoke_evt_AddDynamicReserveConfigunion allselect 'ethena_correlated', reserveId, cast(json_extract_scalar(config, '$.collateralFactor') as double) / 1e4, evt_block_number, evt_indexfrom aave_v4_ethereum.ethenacorrelatedspoke_evt_UpdateDynamicReserveConfig)) where rn = 1),ev as (select 'ethena_ecosystem' as spoke, reserveId, user, cast(suppliedShares as double) as supply_sh, cast(0 as double) as debt_shfrom aave_v4_ethereum.ethenaecosystemspoke_evt_Supplyunion all select 'ethena_ecosystem', reserveId, user, -cast(withdrawnShares as double), 0 from aave_v4_ethereum.ethenaecosystemspoke_evt_Withdrawunion all select 'ethena_ecosystem', reserveId, user, 0, cast(drawnShares as double) from aave_v4_ethereum.ethenaecosystemspoke_evt_Borrowunion all select 'ethena_ecosystem', reserveId, user, 0, -cast(drawnShares as double) from aave_v4_ethereum.ethenaecosystemspoke_evt_Repayunion all select 'ethena_correlated', reserveId, user, cast(suppliedShares as double), 0 from aave_v4_ethereum.ethenacorrelatedspoke_evt_Supplyunion all select 'ethena_correlated', reserveId, user, -cast(withdrawnShares as double), 0 from aave_v4_ethereum.ethenacorrelatedspoke_evt_Withdrawunion all select 'ethena_correlated', reserveId, user, 0, cast(drawnShares as double) from aave_v4_ethereum.ethenacorrelatedspoke_evt_Borrowunion all select 'ethena_correlated', reserveId, user, 0, -cast(drawnShares as double) from aave_v4_ethereum.ethenacorrelatedspoke_evt_Repay),shares as (select spoke, reserveId, user, sum(supply_sh) as supply_sh, sum(debt_sh) as debt_shfrom ev group by 1, 2, 3),