GPv2Settlement Contract
TheGPv2Settlement contract serves as CoW Protocol’s core infrastructure, inheriting from GPv2Signing, ReentrancyGuard, and StorageAccessible to enable batch settlements and order validation.
Source: src/contracts/GPv2Settlement.sol
License: LGPL-3.0-or-later
Solidity: >=0.7.6 <0.9.0
State Variables
Immutable
Storage
Primary Functions
settle()
Executes batch orders at uniform clearing prices with pre/intra/post-settlement interactions.swap()
Matches orders directly against Balancer V2 pools for optimized single-pool trades.invalidateOrder()
Allows order owners to revoke on-chain orders by invalidating the order UID.Storage Cleanup
Gas refund functions for expired orders:Settlement Execution Flow
Security Protections
- All orders include a
validTotimestamp checked on execution - Filled amount tracking prevents over-filling
- Limit price validation ensures trades respect order parameters
- Solver authorization restricts settlement access via
onlySolvermodifier nonReentrantmodifier prevents reentrancy attacks