Query editor
-- Morpho Blue - Aggregated User Positions by Market (log-replay)-- Notes:-- - Balances are accurate as-of each market's latest on-chain interaction (interest only accrues when triggered).-- - Requires the Morpho Blue core contract address on the target chain.-- - Default chain/table here is Base: replace `base.logs` / `params.blockchain` as needed.WITHparams AS (SELECT0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb AS morpho_address, -- Morpho Blue core (Base)'base' AS blockchain),-- Markets to monitor (bytes32 market ids / topic1 of Morpho events).market_watchlist AS (SELECT 0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836 AS market_id UNION ALLSELECT 0x1c21c59df9db44bf6f645d854ee710a8ca17b479451447e9f56758aee10a2fad AS market_id UNION ALLSELECT 0xdba352d93a64b17c71104cbddc6aef85cd432322a1446b5b65163cbbc615cd0c AS market_id UNION ALLSELECT 0x8793cf302b8ffd655ab97bd1c695dbd967807e8367a65cb2f4edaf1380ba1bda AS market_id),-- Event signature topics (keccak256 of event signatures).topics AS (SELECT0xac4b2400f169220b0c0afdde7a0b32e775ba727ea1cb30b35f935cdaab8683ac AS topic_create_market,0xedf8870433c83823eb071d3df1caa8d008f12f6440918c20d75a3602cda30fe0 AS topic_supply,0xa56fc0ad5702ec05ce63666221f796fb62437c32db1aa1aa075fc6484cf58fbf AS topic_withdraw,0x570954540bed6b1304a87dfe815a5eda4a648f7097a16240dcd85c9b5fd42a43 AS topic_borrow,0x52acb05cebbd3cd39715469f22afbf5a17496295ef3bc9bb5944056c63ccaa09 AS topic_repay,0xa3b9472a1399e17e123f3c2e6586c23e504184d504de59cdaa2b375e880c6184 AS topic_supply_collateral,0xe80ebd7cc9223d7382aab2e0d1d6155c65651f83d53c8b9b06901d167e321142 AS topic_withdraw_collateral,0xa4946ede45d0c6f06a0f5ce92c9ad3b4751452d2fe0e25010783bcab57a67e41 AS topic_liquidate,0x9d9bd501d0657d7dfe415f779a620a62b78bc508ddc0891fbbd8b7ac0f8fce87 AS topic_accrue_interest,0x2e979f80fe4d43055c584cf4a8467c55875ea36728fc37176c05acd784eb7a73 AS topic_set_fee_recipient),-- Single log scan: keep only Morpho logs we need.raw_logs AS (SELECTl.block_time,l.block_number,l.index,l.topic0,l.topic1,l.topic2,l.topic3,l.dataFROM base.logs lCROSS JOIN params pCROSS JOIN topics tWHERE l.contract_address = p.morpho_addressAND ((l.topic0 IN (t.topic_create_market,t.topic_supply,t.topic_withdraw,t.topic_borrow,t.topic_repay,t.topic_supply_collateral,