Overview
Solvers are the backbone of CoW Protocol, responsible for finding optimal solutions to batch auction problems. They compete to provide the best execution for user orders while earning fees for their service.What is a Solver?
A solver is an off-chain agent that:- Monitors the order pool for new and existing orders
- Computes optimal settlements by finding clearing prices and trade routes
- Sources liquidity from on-chain AMMs, aggregators, and private inventory
- Submits settlement transactions to the blockchain
- Earns rewards for successful settlements
Solvers run complex optimization algorithms to maximize trader surplus while ensuring all orders respect their limit prices.
Solver Authorization
Only authorized solvers can call thesettle() function:
src/contracts/GPv2Settlement.sol
Authentication Contract
TheGPv2AllowListAuthentication contract manages solver permissions:
src/contracts/GPv2AllowListAuthentication.sol
Solver Competition
CoW Protocol uses a competitive mechanism to ensure optimal execution:Solution Quality Metrics
Solutions are ranked based on:- Surplus Generated: How much better than limit price traders receive
- Number of Orders Filled: More filled orders = better batch
- Gas Efficiency: Lower gas costs for users
- Risk Score: Probability of on-chain execution success
The winning solver is selected off-chain, but anyone can verify that the on-chain settlement respects all order constraints.
Settlement Responsibilities
When a solver submits a winning solution, they must provide:1. Token List
2. Clearing Prices
tokens array.
3. Trades
src/contracts/libraries/GPv2Trade.sol
4. Interactions
Three arrays of contract interactions to execute at different phases:Pre-Interactions (Phase 0)
Pre-Interactions (Phase 0)
Executed before pulling user tokens. Used for:
- Setting up flash loans
- Unwrapping/wrapping tokens
- Pre-funding the settlement contract
Intra-Interactions (Phase 1)
Intra-Interactions (Phase 1)
Executed after pulling user tokens but before distributing. Used for:
- Trading on external DEXs (Uniswap, Curve, 1inch, etc.)
- Rebalancing the batch through arbitrage
- Sourcing missing liquidity
Post-Interactions (Phase 2)
Post-Interactions (Phase 2)
Executed after all user transfers complete. Used for:
- Repaying flash loans
- Returning dust to solver
- Cleanup operations
Solver Economics
Gas Costs
Solvers pay the gas costs for settlement transactions, which include:- Base transaction cost (~21k gas)
- Order signature verification
- Token transfers (per order)
- External interaction calls
- Storage updates
Batch settlements amortize fixed costs across multiple orders, making them more gas-efficient than individual trades.
Revenue Sources
- Protocol Fees: Solvers retain a portion of fees collected from filled orders
- Surplus Capture: Small percentage of surplus above limit prices (if any)
- CoW Finding: Trading orders directly against each other earns the full surplus
- Arbitrage: Profiting from price discrepancies between liquidity sources
Risk Management
Solvers face several risks:- Execution Failure: Transactions that revert waste gas costs
- Front-running: MEV bots may extract value from visible settlement transactions
- Slippage: Prices may move between solution computation and on-chain execution
- Competition: Other solvers may submit better solutions
Interaction with External Liquidity
Solvers access liquidity from multiple sources:src/contracts/libraries/GPv2Interaction.sol
Example: Uniswap V3 Swap
Example: Curve Exchange
Solver Slashing
While not implemented at the smart contract level, the protocol includes off-chain slashing mechanisms:- Invalid Solutions: Submitting solutions that violate invariants
- Failed Transactions: Excessive revert rate reduces solver score
- Malicious Behavior: Attempting to extract value from users
Slashing is enforced through the solver registry by reducing rewards and potentially removing solver authorization.
Manager Role
The manager controls the solver allowlist:src/contracts/GPv2AllowListAuthentication.sol
Manager Responsibilities
- Add new solvers to the allowlist
- Remove misbehaving solvers
- Monitor solver performance
- Respond to security incidents
Events
Solver-related events for monitoring:src/contracts/GPv2AllowListAuthentication.sol
src/contracts/GPv2Settlement.sol
Direct Balancer Swaps
For orders that can be fully filled against Balancer liquidity, solvers can use the optimizedswap() function:
src/contracts/GPv2Settlement.sol
- Avoiding batch settlement overhead
- Using Balancer’s optimized swap routing
- Skipping interaction execution
The
swap() function is limited to fill-or-kill orders that can be completely satisfied by Balancer pools.Becoming a Solver
To become an authorized solver:- Develop Optimization Algorithm: Build a system that can find optimal settlements
- Implement Settlement Logic: Create infrastructure to submit transactions
- Stake (if required): Some deployments may require economic stake
- Request Authorization: Apply to the protocol DAO/manager
- Monitor & Maintain: Continuously optimize and monitor performance
Solver authorization is permissioned to ensure protocol security and user protection during the initial phases.
