Query editor
with-- Fetch transaction dataresults_per_tx as (selectblock_time,tx_hash,solver_addressfrom "query_4070065(blockchain='{{blockchain}}',start_time='{{start_time}}',end_time='{{end_time}}',slippage_table_name='slippage_per_transaction')"),-- Join with dex.trades to get protocol information and USD volumetx_counterparties_with_volume as (selectrpt.tx_hash,dt.project as counterparty_protocol, -- Use the project/protocol column from dex.tradessum(dt.amount_usd) as total_volume_usd, -- Sum of USD volume for each protocol per txcount(*) as counterparty_count -- Count occurrences of each protocol per txfrom results_per_tx as rptinner join dex.trades as dt -- Join with dex.trades tableon rpt.tx_hash = dt.tx_hashwhere dt.blockchain = 'ethereum' -- Filter for Ethereumgroup by rpt.tx_hash, dt.project),-- Rank counterparties for each transactionranked_counterparties as (selecttx_hash,counterparty_protocol,total_volume_usd,counterparty_count,row_number() over (partition by tx_hash order by total_volume_usd desc) as counterparty_rankfrom tx_counterparties_with_volume),-- Join with batches and solvers to get block_time, batch_value, and solver_namefinal_data as (selectb.block_number,rpt.block_time,concat(s.environment, '-', s.name) as solver_name,b.batch_value,rpt.tx_hashfrom results_per_tx as rptinner join cow_protocol_ethereum.batches as b on rpt.tx_hash = b.tx_hashinner join cow_protocol_ethereum.solvers as s on s.address = rpt.solver_addresswhere concat(s.environment, '-', s.name) = '{{solver}}' -- Filter for solver_name = 'prod-Barter')-- Select top 4 counterparties for each transaction with their USD volume, block_time, batch_value, and solver_nameselectfd.block_time,fd.batch_value,fd.solver_name, -- Include solver_name in the final outputfd.tx_hash,array_agg(rc.counterparty_protocol) as top_4_counterparties, -- Highlight top 4 counterpartiesarray_agg(round(rc.total_volume_usd, 0)) as top_4_counterparties_volume_usd -- Round USD volumes to 2 decimal placesfrom final_data as fdleft join ranked_counterparties as rc on fd.tx_hash = rc.tx_hash