Query editor
-- Counter for dashboard: how many markets are currently flashing HIGH ALERT (pressure >200%)WITH borrows AS (SELECT blockchain, project, symbol, SUM(amount_usd) AS borrow_usdFROM lending.borrowWHERE blockchain IN ('ethereum','arbitrum','base')AND block_time >= NOW() - INTERVAL '14' DAYAND transaction_type = 'borrow'AND symbol IN ('USDC','USDT','WETH','USDe','wstETH','weETH','DAI','USDS','sDAI')GROUP BY 1,2,3),supplies AS (SELECT blockchain, project, symbol, SUM(amount_usd) AS supply_usdFROM lending.supplyWHERE blockchain IN ('ethereum','arbitrum','base')AND block_time >= NOW() - INTERVAL '14' DAYAND transaction_type = 'deposit'AND symbol IN ('USDC','USDT','WETH','USDe','wstETH','weETH','DAI','USDS','sDAI')GROUP BY 1,2,3)SELECTCOUNT(*) AS high_alert_markets,COUNT(CASE WHEN 100.0 * b.borrow_usd / NULLIF(s.supply_usd,0) > 200 THEN 1 END) AS markets_over_200pct,COUNT(CASE WHEN 100.0 * b.borrow_usd / NULLIF(s.supply_usd,0) > 100 THEN 1 END) AS markets_over_100pctFROM borrows bJOIN supplies s USING (blockchain, project, symbol)WHERE s.supply_usd > 1000000