Query editor
-- Aave V3 Ethereum "Interest Income / Expense / NIM" over time-- Interest Income = weighted borrow APY (what borrowers pay)-- Interest Expense = weighted supply APY (what suppliers earn)-- NIM = spread that goes to reserve factor + covers protocol overheadWITH rate_updates AS (SELECTreserve AS asset_address,date_trunc('month', evt_block_time) AS month,evt_block_time,CAST(liquidityRate AS DOUBLE) / 1e27 AS supply_apr,CAST(variableBorrowRate AS DOUBLE) / 1e27 AS borrow_apr,ROW_NUMBER() OVER (PARTITION BY reserve, date_trunc('month', evt_block_time)ORDER BY evt_block_time DESC) AS rnFROM aave_v3_ethereum.pool_evt_reservedataupdatedWHERE evt_block_time >= TIMESTAMP '2025-06-30'AND evt_block_time < TIMESTAMP '2026-06-30'),monthly_rates AS (SELECT month, asset_address, supply_apr, borrow_aprFROM rate_updatesWHERE rn = 1AND supply_apr > 0AND supply_apr < 1 -- filter unreasonable outliers (>100% APR)AND borrow_apr < 2),-- Weight by asset size — get each asset's cumulative net supply as the weightmonthly_supply AS (SELECTdate_trunc('month', block_time) AS month,token_address,SUM(SUM(amount_usd)) OVER (PARTITION BY token_addressORDER BY date_trunc('month', block_time)) AS cumulative_supply_usdFROM lending.supplyWHERE project = 'aave'AND blockchain = 'ethereum'AND version = '3'AND block_month >= TIMESTAMP '2025-06-01'AND block_time >= TIMESTAMP '2025-06-30'AND block_time < TIMESTAMP '2026-06-30'AND amount_usd IS NOT NULLAND ABS(amount_usd) < 1e9GROUP BY 1, 2),joined AS (SELECTr.month,r.asset_address,r.supply_apr,r.borrow_apr,GREATEST(COALESCE(s.cumulative_supply_usd, 0), 0) AS weight_usdFROM monthly_rates rLEFT JOIN monthly_supply s