Query editor
-- Aave V3 Ethereum: LTV histogram (10% buckets) + % of users-- Filters:-- • total_borrow_usd > 0 (removes supply-only users)-- • 1% <= LTV <= 100%WITHparams AS (SELECT coalesce(try_cast('{{Trading Num Days}}' AS integer), 30) AS n_days),time_window AS (SELECT date_add('day', -n_days, now()) AS start_timeFROM params),price_hourly AS (SELECTdate_trunc('hour', minute) AS hour,contract_address,avg(price) AS avg_priceFROM prices.usdCROSS JOIN time_windowWHERE blockchain = 'ethereum'AND minute >= start_timeGROUP BY 1, 2),borrow_amount_hourly AS (SELECTdate_trunc('hour', b.evt_block_time) AS hour,b.reserve AS contract_address,b."user" AS user_address,sum(cast(b.amount AS double) / pow(10, coalesce(t.decimals, 18))) AS amount_tokenFROM aave_v3_ethereum.Pool_evt_Borrow bLEFT JOIN tokens.erc20 tON t.blockchain = 'ethereum'AND t.contract_address = b.reserveCROSS JOIN time_windowWHERE b.evt_block_time >= start_timeGROUP BY 1, 2, 3),borrow_usd AS (SELECTuser_address AS user,coalesce(sum(amount_token * ph.avg_price), 0) AS borrow_usdFROM borrow_amount_hourly bahLEFT JOIN price_hourly phON ph.hour = bah.hourAND ph.contract_address = bah.contract_addressGROUP BY 1),supply_amount_hourly AS (SELECTdate_trunc('hour', s.evt_block_time) AS hour,s.reserve AS contract_address,s."user" AS user_address,sum(cast(s.amount AS double) / pow(10, coalesce(t.decimals, 18))) AS amount_tokenFROM aave_v3_ethereum.Pool_evt_Supply sLEFT JOIN tokens.erc20 tON t.blockchain = 'ethereum'