Query editor
-- This query computes how much surplus has been provided to CoW AMMs, when trading with other user orders-- as part of a CoW. For that, a CoW detector query is used (4025739(). Finally, the query computes the-- distribution of an amount {{cow_budget}} of COW tokens to solvers, proportionally to the surplus generated-- via CoWs and pushed to CoW AMMs.-- Parameters:-- {{start_time}} - the start date timestamp for the accounting period (inclusively)-- {{end_time}} - the end date timestamp for the accounting period (exclusively)-- {{cow_budget}} -- the amount of COW that needs to be distributedwith cow_surplus_per_batch_ethereum as (select --noqa: ST06'ethereum' as blockchain,cow_per_batch.block_time,cow_per_batch.tx_hash,concat(solvers.environment,'-',casewhen solvers.environment = 'new' then cast(solvers.address as varchar)else solvers.nameend) AS solver_name,naive_cow, -- fraction of batch volume traded within a CoWtrades.surplus_usd as surplus_in_usd, -- surplus of the executed CoW AMM order, expressed in USDnaive_cow * trades.surplus_usd as realized_cow_surplus_in_usd -- surplus of the CoW AMM that is assumed to be generated via a CoW.from "query_4025739(blockchain='ethereum',start_time='{{start_time}}',end_time='{{end_time}}')" as cow_per_batchinner join cow_protocol_ethereum.trades as trades on cow_per_batch.tx_hash = trades.tx_hashinner join cow_protocol_ethereum.batches as batches on cow_per_batch.tx_hash = batches.tx_hashinner join cow_protocol_ethereum.solvers as solvers on batches.solver_address = solvers.address and solvers.activewhere trades.trader in (select address from query_3959044 where blockchain = 'ethereum')),cow_surplus_per_batch_gnosis as (select --noqa: ST06'gnosis' as blockchain,cow_per_batch.block_time,cow_per_batch.tx_hash,concat(solvers.environment,'-',casewhen solvers.environment = 'new' then cast(solvers.address as varchar)else solvers.nameend) as solver_name,naive_cow, -- fraction of batch volume traded within a CoWtrades.surplus_usd as surplus_in_usd, -- surplus of the executed CoW AMM order, expressed in USDnaive_cow * trades.surplus_usd as realized_cow_surplus_in_usd -- surplus of the CoW AMM that is assumed to be generated via a CoW.from "query_4025739(blockchain='gnosis',start_time='{{start_time}}',end_time='{{end_time}}')" as cow_per_batchinner join cow_protocol_gnosis.trades as trades on cow_per_batch.tx_hash = trades.tx_hashinner join cow_protocol_gnosis.batches as batches on cow_per_batch.tx_hash = batches.tx_hashinner join cow_protocol_gnosis.solvers as solvers on batches.solver_address = solvers.address and solvers.activewhere trades.trader in (select address from query_3959044 where blockchain = 'gnosis')),cow_surplus_per_batch_arbitrum as (select --noqa: ST06'arbitrum' as blockchain,cow_per_batch.block_time,cow_per_batch.tx_hash,