Query editor
with bundles as (select * from (values('ethereum', 0x02912516d49dE997db75B9D7858faAE59209650B, 'VaultBundlesV1'),('ethereum', 0x38B0C12AB81976e9417D4ebfe2A34DB6DF22e6AD, 'BlueBundlesV1'),('ethereum', 0xaf85af286637a033be7d59ed8cc566afa3309b02, 'VaultExitBundlesV1'),('ethereum', 0x7c00dbb2b6b6b9b28745332e550dc8782fcf77ec, 'MidnightBundlesV1'),('base', 0x2B08A911f48dE25A7e305D910Afb5597aBE8ea7B, 'VaultBundlesV1'),('base', 0x4D28D900e381eCE4B351302f1Abe588496793A2b, 'BlueBundlesV1'),('base', 0xE52E169C342C096C4949ABb944DC9f30E3F5Ea84, 'VaultExitBundlesV1'),('base', 0x091183d729BE9f808c212b475E387A12E67850A7, 'MidnightBundlesV1')) as t(chain, bundle, bundle_name)),by_bundle as (selectchain,bundle_name,max(protocol) as protocol,count(*) as calls,count(distinct caller) as users,count_if(has_fee) as fee_calls,count(distinct fee_recipient) as fee_recipients,sum(fee_amount_usd) as fees_usd,sum(fee_base_usd) as fee_base_usd,min(block_time) as first_call,max(block_time) as last_callfrom dune.wintermute_research.result_morpho_bundles_callsgroup by 1, 2),tot as (select sum(fees_usd) as grand_fees, sum(calls) as grand_calls from by_bundle)selectrow_number() over (order by x.fees_usd desc nulls last, x.calls desc) as rank,x.chain,x.protocol,'<a href="https://' || (case when x.chain = 'ethereum' then 'etherscan.io' else 'basescan.org' end)|| '/address/0x' || lower(to_hex(b.bundle)) || '">' || x.bundle_name || '</a>' as bundle,'0x' || lower(to_hex(b.bundle)) as bundle_addr,x.calls,x.calls * 1.0 / nullif(t.grand_calls, 0) as share_of_calls,x.users,x.fee_calls,x.fee_calls * 1.0 / x.calls as fee_call_share,x.fee_recipients,x.fees_usd,x.fees_usd / nullif(t.grand_fees, 0) as share_of_fees,x.fee_base_usd,x.first_call,x.last_callfrom by_bundle xcross join tot tleft join bundles b on b.chain = x.chain and b.bundle_name = x.bundle_namewhere x.fee_calls > 0order by rank