Query editor
-- Q24 · Small-Cap Lending Protocol Flow Cluster (v2)-- v2 fix (2026-04-22): lending.supply/borrow amount_usd is SIGNED (negative for-- withdraw / repay / liquidation rows) and transaction_type label varies across-- projects ('deposit' vs 'supply'; 'deposit_liquidation' exists). Previous v1-- filter (amount_usd BETWEEN 1 AND 100e6) silently dropped all withdraws.-- Covers lending protocols outside the Aave/Morpho primary coverage (Q3/Q4).WITH supply_clean AS (SELECTDATE_TRUNC('day', block_time) AS day,project,blockchain,transaction_type,amount_usdFROM lending.supplyWHERE project IN ('euler','fluid','gearbox','spark','compound','radiant','benqi','moonwell','seamlessprotocol','sonne_finance','aave_lido','aave_horizon','aave_etherfi')AND blockchain IN ('ethereum','base','arbitrum','optimism','polygon','avalanche_c','bnb')AND block_time >= NOW() - INTERVAL '14' DAYAND amount_usd IS NOT NULLAND ABS(amount_usd) BETWEEN 1 AND 100e6),borrow_clean AS (SELECTDATE_TRUNC('day', block_time) AS day,project,blockchain,transaction_type,amount_usdFROM lending.borrowWHERE project IN ('euler','fluid','gearbox','spark','compound','radiant','benqi','moonwell','seamlessprotocol','sonne_finance','aave_lido','aave_horizon','aave_etherfi')AND blockchain IN ('ethereum','base','arbitrum','optimism','polygon','avalanche_c','bnb')AND block_time >= NOW() - INTERVAL '14' DAYAND amount_usd IS NOT NULLAND ABS(amount_usd) BETWEEN 1 AND 100e6),daily AS (SELECTday, project, blockchain,SUM(CASE WHEN transaction_type IN ('deposit','supply') THEN ABS(amount_usd) ELSE 0 END) AS deposits_usd,SUM(CASE WHEN transaction_type = 'withdraw' THEN ABS(amount_usd) ELSE 0 END) AS withdrawals_usd,SUM(CASE WHEN transaction_type = 'deposit_liquidation' THEN ABS(amount_usd) ELSE 0 END) AS supply_liquidations_usd,0.0 AS borrows_usd,0.0 AS repays_usd,0.0 AS borrow_liquidations_usdFROM supply_cleanGROUP BY 1, 2, 3UNION ALLSELECTday, project, blockchain,0.0 AS deposits_usd,0.0 AS withdrawals_usd,0.0 AS supply_liquidations_usd,SUM(CASE WHEN transaction_type = 'borrow' THEN ABS(amount_usd) ELSE 0 END) AS borrows_usd,SUM(CASE WHEN transaction_type IN ('repay','repay_with_atokens') THEN ABS(amount_usd) ELSE 0 END) AS repays_usd,SUM(CASE WHEN transaction_type = 'borrow_liquidation' THEN ABS(amount_usd) ELSE 0 END) AS borrow_liquidations_usdFROM borrow_cleanGROUP BY 1, 2, 3