Documentation Index
Fetch the complete documentation index at: https://cowswap-mintlify-seo-audit-1777280932.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Core Libraries
CoW Protocol employs specialized libraries designed for gas efficiency and security, using low-level optimizations where appropriate.GPv2Order
Defines the complete order structure and provides utilities for order management.Data Structure
Key Functions
hash(Data memory order)- Computes EIP-712 digest for signingactualReceiver(Data memory order)- Resolves recipient address (handles zero-address as owner)packOrderUidParams()- Encodes 56-byte UID (32-byte digest + 20-byte owner + 4-byte timestamp)extractOrderUidParams()- Decodes UID components
Pre-computed Constants
GPv2Trade
Handles compact settlement representation through a flags field that encodes order parameters into a singleuint256 value.
Flag Encoding
| Bits | Field | Values |
|---|---|---|
| 0 | Order kind | 0 = sell, 1 = buy |
| 1 | Fill type | 0 = fill-or-kill, 1 = partially fillable |
| 2-3 | Sell token balance | 00 = ERC20, 01 = external, 10 = internal |
| 4 | Buy token balance | 0 = ERC20, 1 = internal |
| 5-6 | Signing scheme | 00 = EIP-712, 01 = eth_sign, 10 = EIP-1271, 11 = PreSign |
0x00 represents the most common case: a fill-or-kill sell order by an externally owned account using EIP-712 signatures.
Key Functions
extractOrder()- Converts trade data into a full order structextractFlags()- Unpacks flags into separate order parameters
GPv2Interaction
Enables arbitrary contract calls during settlement using inline assembly for gas optimization.Data Structure
Key Functions
execute(Data calldata interaction)- Performs the contract interactionselector(Data calldata interaction)- Extracts 4-byte function selector
Settlement Phases
Interactions run at three distinct phases:- Pre-settlement - Setup operations like approvals
- Intra-settlement - Liquidity transformations after input transfers
- Post-settlement - Cleanup tasks like token unwrapping
GPv2Signing
Supports four signature schemes:| Scheme | Description |
|---|---|
| EIP-712 | Standard typed data signing |
| eth_sign | Legacy signing with message prefix |
| EIP-1271 | Smart contract signature verification |
| PreSign | On-chain pre-authorization |
Key Features
- Careful memory management to avoid unnecessary copies
- Extensive use of
calldatainstead ofmemoryfor read-only data - Domain separator includes contract address for replay protection
- Pre-computed hash constants for common types