Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/WITH solver_info as (SELECTname,max(block_time) last_solution,count(*) as batches_solved,sum(dex_swaps) as dex_swaps,sum(num_trades) as num_trades,sum(gas_used) as gas_used,sum(batch_value) as total_batch_value,avg(batch_value) as average_batch_volume,avg(num_trades) as average_batch_sizeFROM cow_protocol_{{Blockchain}}.batches bJOIN cow_protocol_{{Blockchain}}.solversON solver_address = addressWHERE environment not in ('test', 'service')and block_date > now() - interval '{{LastNDays}}' dayand active = TrueGROUP BY name),info_results as (SELECTname as solver_name,-- concat(environment, '-', name) as solver_name,last_solution,batches_solved,num_trades,dex_swaps,total_batch_value,1.0 * gas_used / num_trades as average_gas_per_trade,1.0 * dex_swaps / num_trades as average_dex_swaps_per_trade,average_batch_size,average_batch_volumeFROM solver_info-- JOIN cow_protocol_ethereum.solvers-- ON solver_address = address-- WHERE active = True-- AND environment not in ('test', 'service')ORDER BY num_trades DESC)-- --- Next for Surplus Computation-- batches_with_nested_uids_and_trades AS (-- SELECT call_tx_hash,-- array_agg(-- "orderUid"-- ORDER BY evt_index ASC-- ) as uids,-- (-- select jsonb_agg(t->'sellAmount')-- from jsonb_array_elements(trades) as x(t)-- ) as sell_amount_limits,-- (-- select jsonb_agg(t->'buyAmount')-- from jsonb_array_elements(trades) as x(t)-- ) as buy_amount_limits,-- (-- select jsonb_agg(t->'sellTokenIndex')-- from jsonb_array_elements(trades) as x(t)