Query editor
WITHparams AS (SELECTCAST('{{snapshot_date}}' AS TIMESTAMP) AS snapshot_ts),/* 1. Aave V3 Ethereum reserve -> aToken / debtToken 映射 */reserve_tokens AS (SELECTlower(cast(asset AS varchar)) AS reserve,lower(cast(aToken AS varchar)) AS atoken,lower(cast(stableDebtToken AS varchar)) AS stable_debt_token,lower(cast(variableDebtToken AS varchar)) AS variable_debt_tokenFROM aave_v3_ethereum.PoolConfigurator_evt_ReserveInitializedWHERE evt_block_time <= (SELECT snapshot_ts FROM params)), /* 2. token metadata */ token_meta as (selectlower(cast(contract_address as varchar)) as reserve, symbol, decimalsfrom tokens.erc20where blockchain = 'ethereum'), /* 3. 历史 USD price(取snapshot_ts时刻之前最近的价格) */ latest_prices as (selectlower(cast(contract_address as varchar)) as reserve, pricefrom (selectcontract_address, price, ROW_NUMBER() over (partition bycontract_addressorder byminute desc) as rnfrom prices.usdwhere blockchain = 'ethereum'and minute <= (selectsnapshot_tsfrom params))where rn = 1), /* 4. 历史 liquidation threshold */ latest_liquidation_threshold as (selectreserve, liquidation_threshold / 10000.0 as liquidation_thresholdfrom (selectlower(cast(asset as varchar)) as reserve, liquidationThreshold as liquidation_threshold, ROW_NUMBER() over (partition byasset