Query editor
with midnight_take as (select 'base' as chain, topic1 as id_,bytearray_to_uint256(bytearray_substring(data, 65, 32)) <> uint256 '0' as offer_is_buy,bytearray_to_uint256(bytearray_substring(data, 225, 32)) as buyer_assets,block_time as evt_block_timefrom base.logswhere contract_address = 0xadedd8ab6de832766fedf0fac4992e5c4d3ea18aand topic0 = 0xbd88656d0ee14d32d4f74f814f6ccb5c750a4c542d6fdf83ee00ddca4edebff0and block_time >= timestamp '2026-07-05'union allselect 'ethereum' as chain, topic1 as id_,bytearray_to_uint256(bytearray_substring(data, 65, 32)) <> uint256 '0' as offer_is_buy,bytearray_to_uint256(bytearray_substring(data, 225, 32)) as buyer_assets,block_time as evt_block_timefrom ethereum.logswhere contract_address = 0x471686c42792f93528b000bef54bc10e3aa2045fand topic0 = 0xbd88656d0ee14d32d4f74f814f6ccb5c750a4c542d6fdf83ee00ddca4edebff0and block_time >= timestamp '2026-07-05'),tok as (select blockchain as chain, contract_address, max(decimals) as decimalsfrom tokens.erc20 where blockchain in ('base', 'ethereum') group by 1, 2),mkt as (select chain, id_, from_hex(json_extract_scalar(market, '$.loanToken')) as loan_tokenfrom morpho_midnight_multichain.midnight_evt_marketcreated),mkt_named as (select m.chain, m.id_, m.loan_token, lt.decimals as loan_decfrom mkt mleft join tok lt on lt.chain = m.chain and lt.contract_address = m.loan_token),px_universe as (select distinct chain, loan_token as token from mkt where loan_token is not null),px_spot as (select blockchain as chain, contract_address, price as pxfrom prices.latestwhere blockchain in ('base', 'ethereum') and contract_address in (select token from px_universe)),prices_min as (select 'base' as chain, contract_address, minute, price from prices.usdwhere blockchain = 'base' and minute >= timestamp '2026-07-05' and contract_address in (select token from px_universe)union allselect 'ethereum' as chain, contract_address, minute, price from prices.usdwhere blockchain = 'ethereum' and minute >= timestamp '2026-07-05' and contract_address in (select token from px_universe)),enriched as (-- chain used only to price each fill; flow is COMBINED across chainsselect t.evt_block_time, t.offer_is_buy,t.buyer_assets / power(10, m.loan_dec) * coalesce(pm.price, f.px) as usdfrom midnight_take tjoin mkt_named m on m.chain = t.chain and m.id_ = t.id_left join px_spot f on f.chain = t.chain and f.contract_address = m.loan_tokenleft join prices_min pm on pm.chain = t.chain and pm.contract_address = m.loan_tokenand pm.minute = date_trunc('minute', t.evt_block_time)),flows as (select cast(date_trunc('day', evt_block_time) as date) as d,case when offer_is_buy then 'Taker: borrow' else 'Taker: lend' end as series, -usd as vfrom enrichedunion all