Query editor
WITH vault_state AS(SELECT SUM(supply_amount_usd) as total_supply_usd,SUM(collat_amount_usd) as total_collat_usd,SUM(borrow_amount_usd) as total_borrow_usd,id, market_name, blockchainFROM query_3957464GROUP BY id, market_name, blockchain),interest_state AS(SELECT SUM(borrow_amount_usd) as total_interest_usd,id, blockchainFROM query_3957464WHERE action = 'borrow interest'GROUP BY id, blockchain),borrow_rates AS(SELECT id, blockchain,prevBorrowRate/ pow(10, 18) * 365*24*60*60 as borrow_rateFROM(SELECT id, prevBorrowRate, 'ethereum' as blockchain,RANK() OVER (PARTITION BY id ORDER BY evt_block_time DESC) rFROM morpho_blue_ethereum.MorphoBlue_evt_AccrueInterestUNION ALLSELECT id, prevBorrowRate, 'base' as blockchain,RANK() OVER (PARTITION BY id ORDER BY evt_block_time DESC) rFROM morpho_blue_base.MorphoBlue_evt_AccrueInterest)WHERE r=1)SELECT '<a href=https://app.morpho.org/market?id=' || cast(id as varchar) || '&network=' ||CASEWHEN blockchain = 'base' THEN 'base'ELSE 'mainnet'END || '>' || market_name || '</a>' as market,blockchain,total_supply_usd, total_borrow_usd,total_supply_usd-total_borrow_usd as liquidity_usd,total_collat_usd,total_interest_usd,GREATEST(0., LEAST(1., total_borrow_usd / total_supply_usd)) as util,borrow_rate,borrow_rate * total_borrow_usd / total_supply_usd as supply_rate,concat(substr(cast(id as varchar), 1, 4), '...', substr(cast(id as varchar), 64, 3)) as id_small,idFROM vault_stateJOIN interest_stateUSING (id, blockchain)JOIN borrow_ratesUSING (id, blockchain)ORDER BY total_collat_usd DESC