MEV Losses in Swapping: How CoW Protocol Integration Works
A user signs a swap, and before inclusion in a block the transaction sits in the public mempool in plain view — with the exact amount, pair, and allowed slippage. A sandwich bot reads it before others: buys the same asset ahead of it, moves the price, sells immediately after.
The difference between the price before and after is paid by the sender — and this is not a one-off incident but a cost on every swap.
Standard measures do not remove the problem. Slippage limit only limits damage and increases share of reverted trades, splitting order into parts adds fees, and increasing priority fee turns into arms race with bots that respond in kind.
While the order is visible in the shared pool, swap losses remain built into the route — routing is based on a price from which someone else's surplus has already been subtracted.
CoW Protocol changes the way an order is submitted: the order is signed off-chain and does not become an executable transaction in the public mempool; instead it enters a batch auction, where orders are matched with each other and against external liquidity.
Below we break down how MEV protection works in such a scheme, where sandwich attacks in swapping lose their foothold, and what this changes for the sender — from execution price to behavior on volatile pairs.
Batch Order Settlement: What Changes in Trades
A batch auction of orders matches opposing orders in one interval with a single settlement. After integration with CoW Protocol, the report shows how three values change: order execution price, share of failed trades, and resistance to interception.
Execution Price: One Settlement for the Entire Batch
Opposing orders within the batch close each other out, so the price is determined by the overall balance of supply and demand, not by who got into the queue first. The difference between the best orders does not go to a third party — it is distributed among participants. On liquid pairs, the spread between buy and sell price becomes noticeably narrower.
Share of Failed Trades Drops by a Factor
Settlement is shared, so a participant does not pay for attempts without execution: an order either passes at the final batch price or is not sent to the network. Priority inclusion costs cease to be a mandatory line item, and the share of rejected orders shrinks by a factor.
Interception: Protection in the Execution Order Itself
An order does not enter the publicly accessible queue before batch settlement, so an observer cannot see the intention and cannot wedge in ahead of it. Protection does not depend on a private channel: even an openly announced order cannot be front-run.
A whole class of attacks disappears, where the outcome is influenced by whoever learned about the trade earlier.
What We Record in Metrics
Before the transition, we calculate baseline values: the discrepancy between expected and actual price, the share of rejected orders, the share of trades worse than the quoted price.
Then we compare across the same cuts, separately by liquidity and order size: the larger the order, the more noticeable the effect of batch settlement.
CoW Protocol: Connection Modes and Limitations
Connection to CoW Protocol is possible in three modes, and they are not interchangeable — each has its own level of control over order flow.
Direct connection to the auction gives a full set of order types and front-running protection, but you keep order signing, cancellation, and solver reputation on your side.
Smart orders move logic into a contract: an order executes on a condition and can be embedded in a strategy or tied to a position. An intermediate router connects fastest when flow is already coming from a wallet or aggregator, but part of the volume goes to external routes.
| Option | When it fits | Limitations |
|---|---|---|
| Direct connection to the auction | Your own order flow; a full set of order types is needed | You need your own solver; price and liquidity are visible to participants |
| Smart orders | Conditional execution, connection to other position contracts | The order cannot be changed after placement; some routes are unavailable |
| Intermediate router | Orders come from a wallet or aggregator | Control over the final price is lost; protection does not cover the entire volume |
We check compatibility with aggregators before launch: whether the router splits the order, what share reaches the auction, how rollback works.
Routing limitations do not cancel the scheme, but the entire flow cannot be considered protected — we record this in the plan in advance.
Integration Stages: From Flow Audit to Launch
Connecting to CoW Protocol is not installing a module but rebuilding the path an order takes. We start with an audit: how an order enters the network, who sees it before execution, and at what point the possibility of a front-running trade arises. Then comes the scheme, solver configuration, a test environment, and migration of real traffic.
- Order flow audit. We examine the order route: source, signature, publication points, wallet and contract behavior. The output is a map of the areas where flow is exposed before execution and becomes vulnerable.
- Integration scheme. We determine what goes to CoW Protocol and what stays in the current infrastructure: routing, fallback execution path, separation of rights and keys. We fix the scheme before work begins.
- Solver configuration. We define the logic for matching opposing orders and batch formation parameters: price tolerances, priorities, liquidity limits. We separately examine behavior with a thin order book.
- Test environment validation. We run regular, opposing, partially executable, and canceled orders. We compare the result with the expected one and record metrics: match rate, deviation from quote, time to settlement.
- Gradual traffic migration. We enable part of the volume with an order-size limit and compare actual performance with test results. If there is a deviation, we return to the fallback route without stopping the service.
- Handover to operations. We provide configurations, the scheme, access policies, and monitoring procedures, and train the on-call team. After that comes support and adjustment of parameters based on actual data.
Each stage closes with a verifiable result: without it, the next step makes no sense.
What We Hand Over: Configurations, Diagrams, Procedures
After release, the client retains a set of artifacts that make it possible to develop and maintain the integration without us. Below is what exactly we hand over and why each document is needed in daily work.
-
Configuration files — router configurations: network node addresses, allowable slippage limits, retry timeouts, and the threshold at which an order goes directly to the liquidity pool rather than through matches. Each parameter with a comment, allowed value range, and a safe default value.
-
Routing diagram — the path of an order from wallet to execution: which trade types pass through CoW Protocol, which bypass it, where protective checks trigger, and at what point the decision can still be canceled before signing.
-
Access policies — a matrix of roles and rights: who changes limits, who signs transactions, how keys are stored and rotated. A separate section covers the procedure for granting and revoking access for contractors.
-
Integration documentation — description of methods, request and response formats, error codes and ways to handle them, with examples of correct and erroneous responses.
-
Monitoring procedure — metrics and trigger thresholds: share of orders closed by matches, deviation of execution price from quote, signature failures, response delay. For each metric — alarm level and responsible person.
-
Incident response procedure — step-by-step actions for execution failure: how to isolate order flow, how to roll configuration back to the previous one, whom to notify and within what timeframe.
-
Test suite and acceptance checklist — scenarios on historical data, including periods of sharp market movements, by which the client independently checks the integration after release.
Case: Share of Sandwich Attacks in Flow Before and After
Before: Interception in the Public Mempool
The client is a team trading through its own router on decentralized exchanges.
Before integration, large orders went into the public mempool, where searcher-sandwichers found them: the trade was framed with opposing orders, and the entry price worsened by 0.4–0.9% on each large order.
This was compensated by a high allowable slippage threshold — otherwise the transaction reverted on the check — and interception was shifted into permanent costs: about 12% of flow executed worse than the quote, and this could not be predicted in advance.
After: Batch Execution Instead of an Open Order
We integrated CoW Protocol: orders are no longer placed in the public mempool but collected into a shared batch, where several orders execute at a single settlement price.
A classic sandwich is impossible in such a scheme — the interceptor has nothing to frame, and matching interests of participants are closed directly.
What changed in numbers: the share of trades executed worse than the quote fell from ~12% to 0.3%, average slippage — from 0.6–1.2% to 0.05–0.15%, and the share of reverts on the slippage check — from 7% to 1%. We keep the allowable deviation threshold strict rather than leaving a buffer for interception.
A whole class of costs disappeared from permanent losses — the lost price at entry. Execution became predictable: trade size is planned by quote, not by worst-case scenario, and the share of deviations stays within tenths of a percent.
Batch Auction vs AMM Swap: What's the Difference
In a swap along a liquidity curve, the counterparty is always the same — the pool. The price is recalculated by an invariant formula and depends on volume: the larger the order, the more it shifts reserves and the worse the rate.
The trade is visible in the queue before execution, and it can be front-run by an opposing transaction that takes the difference for itself.
A batch auction calculates differently. Orders accumulate into a batch, and the solver looks for matches inside it: if one participant sells what another buys, the exchange happens directly, without the pool.
Order matching gives all trades in the batch a single price, and the missing liquidity is sourced externally on behalf of the entire batch.
| Feature | Swap along a liquidity curve | Batch auction |
|---|---|---|
| Counterparty | Liquidity pool | Other orders in the batch |
| Trade price calculation | By the curve and order volume | Single equilibrium for the entire batch |
| Slippage | Grows with trade size | Decreases due to matches |
| What the observer sees | The rate of each trade separately | Only the batch result |
CoW Protocol is built on this distinction: an order does not carry a separate execution price, so there is nothing to front-run. The curve wins on small trades where immediacy matters, while the batch auction wins on large volumes and pairs with thin liquidity.
Reviewing Common Technical Concerns
Engineering-level concerns around integration come down to four topics: visibility of orders before inclusion in a block, responsibility for an external solver, the scope of contract verification, and partial migration of flow.
An order does not enter the public mempool — how is it executed then?
The user signs an intention with price boundaries and sends it directly to the solver network. Before inclusion in a block, such an order is not seen by front-runners, so price substitution and sandwiching become technically impossible, not merely difficult.
The order is closed by the solver with the best result, and the price is fixed in the settlement itself — CoW Protocol provides this as a protocol property, not as a setting.
Who is responsible if an external solver does not execute the order?
An intention is a signed trade condition, not an obligation to execute. If no solver offered an option no worse than the specified minimum, the order expires, assets remain with the owner, and losses are limited to the gas cost. We take on cancellation of unexecuted orders and settlement control.
What exactly is checked before connection?
The audit covers the adapter between your contract and the protocol: scope of rights, limits by amounts and tokens, refunds, behavior when an order is rejected. We separately check signatures and approval schemes — so that a granted permission cannot be reused or expanded.
Can only part of the flow be migrated?
You do not need to abandon the current route: part of the volume goes through intentions, the remainder goes through the previous channel, and the share is regulated by routing configuration.
The effect is tested on a limited segment, and rollback amounts to changing the distribution rule, not reworking the exchange logic.
Let's Discuss the Task: Order of Starting Work
To come back with an estimate and work plan rather than general wording, we need input data on the flow: which pairs are in circulation, where orders come from, who signs transactions, how balance accounting is structured, and whether there is your own network node.
This is enough to understand whether we are connecting CoW Protocol as an additional execution route or migrating the main share of volume to it.
The first conversation is technical, without presentations: our engineer and your developer or infrastructure lead walk through the current order path from signature to settlement. Then we move through the stages.
- We compare the input data on the flow with how it actually goes in code and logs — discrepancies usually surface here.
- We calculate where value is currently lost on execution: price difference, unfavorable ordering of other orders, downtime during sharp market movements.
- We determine the insertion point: a separate route for part of the volume or the main channel with fallback to the previous path.
- We fix which keys, accesses, and test environment are needed to start the integration, and who provides them.
- We agree on the order of work: first a test environment with limited volume, then expansion of the share and rollout to the main flow.
- We agree on acceptance criteria: by which indicator we consider protection working, and by which we return to the previous scheme.
Based on the results, you receive an estimate and work plan with stage boundaries, an order flow diagram before and after, a list of accesses, and a rollback procedure. Describe the task — we will come back with an estimate and plan.







