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')"),-- Calculate total volume of all trades within each transactiontransaction_volume AS (SELECTrpt.tx_hash,SUM(dt.amount_usd) AS total_trade_volume_usd -- Sum of USD volume for all trades in the transactionFROM 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),-- 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')-- Calculate ratio of total trade volume to batch_valueSELECTfd.block_time,fd.batch_value,fd.solver_name,fd.tx_hash,tv.total_trade_volume_usd, -- Total volume of all trades in the transactiontv.total_trade_volume_usd / fd.batch_value AS ratio -- Ratio of total trade volume to batch_valueFROM final_data AS fdINNER JOIN transaction_volume AS tv ON fd.tx_hash = tv.tx_hash -- Join to get total trade volumeORDER BY fd.block_time DESC;