Query editor
with q as (select * from dune.wintermute_research.result_morpho_bundles_callswhere has_fee),by_rec as (selectchain, fee_recipient,max(fee_recipient_link) as link,min(block_time) as first_fee,max(block_time) as last_fee,count(*) as fee_calls,count(distinct caller) as users,array_join(array_sort(array_agg(distinct format('%.4f%%', fee_pct * 100))), ', ') as fee_rates,array_join(array_sort(array_agg(distinct fn)), ', ') as entry_points,array_join(array_sort(array_agg(distinct fee_symbol)), ', ') as fee_tokens,sum(fee_amount_usd) as fees_usd,sum(fee_base_usd) as fee_base_usdfrom qgroup by 1, 2),rec_prod as (select chain, fee_recipient, product, sum(fee_amount_usd) as v,row_number() over (partition by chain, fee_recipient order by sum(fee_amount_usd) desc nulls last, count(*) desc) as rnfrom qwhere product is not nullgroup by 1, 2, 3),top_prod as (select chain, fee_recipient, array_join(array_agg(product order by rn), ', ') as top_productsfrom rec_prod where rn <= 3 group by 1, 2),tot as (select sum(fees_usd) as grand from by_rec)selectrow_number() over (order by b.fees_usd desc nulls last, b.fee_calls desc) as rank,b.chain,b.link as recipient,'0x' || lower(to_hex(b.fee_recipient)) as address,b.fees_usd,b.fees_usd / nullif(t.grand, 0) as share,b.fee_base_usd,b.fees_usd / nullif(b.fee_base_usd, 0) as effective_fee_rate,b.fee_rates,b.fee_calls,b.users,tp.top_products,b.entry_points,b.fee_tokens,b.first_fee,b.last_feefrom by_rec bcross join tot tleft join top_prod tp on tp.chain = b.chain and tp.fee_recipient = b.fee_recipientorder by rank