Query editor
with q as (select * from dune.wintermute_research.result_morpho_bundles_callswhere product_id is not null),by_prod as (selectchain, protocol, product_type, product_id,max(product_link) as product,max(product_url) as product_url,count(*) as calls,count(distinct caller) as users,count_if(has_fee) as fee_calls,array_join(array_sort(array_agg(distinct fee_recipient_name) filter (where has_fee)), ', ') as fee_recipients,sum(fee_amount_usd) as fees_usd,sum(fee_base_usd) as fee_base_usdfrom qgroup by 1, 2, 3, 4),tot as (select sum(calls) as grand_calls from by_prod)selectrow_number() over (order by b.fees_usd desc nulls last, b.calls desc) as rank,b.chain,b.protocol,b.product_type,b.product,b.product_id,b.product_url,b.calls,b.calls * 1.0 / nullif(t.grand_calls, 0) as share_of_calls,b.users,b.fee_calls,b.fee_calls * 1.0 / b.calls as fee_call_share,b.fee_recipients,b.fees_usd,b.fee_base_usdfrom by_prod bcross join tot twhere b.fee_calls > 0order by rank