CowSettlementHelpers
Inherits: Assertion
Title: CowSettlementHelpers
Author: Phylax Systems
Fork-aware, log-aware helpers for the CoW Protocol (GPv2) settlement assertions.
The assertion adopter is the GPv2Settlement contract. These helpers wire up the bundle’s
immutable configuration and provide the two observations the invariants need:
- the solver that authored a settlement call (the call’s caller), and
- the value the settlement contract moves out to a given recipient (via Transfer logs and ERC20 balance deltas). All reads go through snapshot forks / call-scoped logs; the bundle keeps no assertion-owned state of its own.
Constants
GPV2_TRADE_TOPIC
keccak256(“Trade(address,address,address,uint256,uint256,uint256,bytes)”) from GPv2Settlement.
bytes32 internal constant GPV2_TRADE_TOPIC =
keccak256("Trade(address,address,address,uint256,uint256,uint256,bytes)")
SETTLEMENT
The GPv2 settlement contract this bundle protects (the assertion adopter).
address internal immutable SETTLEMENT
SWEEP_RECIPIENT
The single authorized destination for buffer outflows (the CoW DAO reward/sweep Safe). Net reductions of the settlement’s buffer are only allowed when they land here.
address internal immutable SWEEP_RECIPIENT
State Variables
bufferTokens
The buffer tokens whose settlement-held balances are protected (e.g. fee tokens that accumulate between DAO sweeps, such as the DAI buffer drained in the 2023 incident).
address[] internal bufferTokens
Functions
constructor
Configuration is passed in explicitly; the constructor never reads adopter state, since the assertion-deploy runtime is isolated from the calling state.
constructor(
address settlement_,
address sweepRecipient_,
address[] memory bufferTokens_,
uint256 bufferToleranceBps_
) ;
_requireSettlementIsAdopter
Reverts unless the configured settlement is the adopter for the current transaction.
function _requireSettlementIsAdopter() internal view;
_reportedTradeVolume
Returns token volume that GPv2 itself reported as executed for the watched token.
Sums both sell and buy legs from GPv2 Trade events. The event does not identify the
receiver, so this is a per-token volume allowance rather than recipient authorization.
function _reportedTradeVolume(address token) internal view returns (uint256 volume);
_transferredValueFrom
Returns total standard ERC20 outflow from from for one token over the transaction.
function _transferredValueFrom(address token, address from) internal view returns (uint256 value);