Query editor
with block_range as (selectmin("number") as start_block,max("number") as end_blockfrom {{blockchain}}.blockswhere time >= cast('{{start_time}}' as timestamp) and time < cast('{{end_time}}' as timestamp)),all_trades as (selectt.block_time,date_trunc('hour', t.block_time) as hour, --noqa: RF04rd.auction_id,rd.environment,t.order_uid,t.order_type,t.tx_hash,t.sell_token_address,t.buy_token_address,t.usd_value,t.atoms_sold,t.atoms_bought,rd.protocol_fee,rd.protocol_fee_native_price,rd.protocol_fee * rd.protocol_fee_native_price / pow(10,18) as protocol_fee_collected_native_unitsfrom cow_protocol_{{blockchain}}.trades as t inner join "query_4364122(blockchain='{{blockchain}}')" as rdon t.order_uid = rd.order_uid and t.tx_hash = rd.tx_hashand t.block_number >= (select start_block from block_range) and t.block_number <= (select end_block from block_range)),prices as (select *from "query_4064601(blockchain='{{blockchain}}', start_time='{{start_time}}',end_time='{{end_time}}')"),trades_with_dune_prices as (selectt.*,sp.price_atom as sell_token_atom_usd_price,sp.price_unit as sell_token_unit_usd_price,bp.price_atom as buy_token_atom_usd_price,bp.price_unit as buy_token_unit_usd_price,np.price_atom as native_token_atom_usd_price,np.price_unit as native_token_unit_usd_pricefrom all_trades as tleft join prices as sp on t.hour = sp.hour and t.sell_token_address = sp.token_addressleft join prices as bp on t.hour = bp.hour and t.buy_token_address = bp.token_addressleft join prices as np on t.hour = np.hour and np.token_address = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)selectsum(protocol_fee_collected_native_units) as total_protocol_fee_in_eth_with_native_prices,sum(casewhen order_type = 'SELL' then protocol_fee * buy_token_atom_usd_price / native_token_unit_usd_priceelse protocol_fee * sell_token_atom_usd_price / native_token_unit_usd_price