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.
GPv2Trade API
TheGPv2Trade library is a Solidity utility for encoding and decoding trade data in settlement batches, enabling gas-efficient batch settlements.
Data Structure
Functions
extractOrder
Converts trade data into a full order struct while extracting the signing scheme from packed flags.extractFlags
Unpacks a singleuint256 value into separate order parameters.
Flag Encoding
The library uses a bitfield approach where individual bits represent different order properties:| Bit(s) | 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.
Supported Signing Schemes
| Scheme | Value | Description |
|---|---|---|
| EIP-712 | 0b00 | Standard typed data signing |
| eth_sign | 0b01 | Legacy message signing |
| EIP-1271 | 0b10 | Smart contract wallet validation |
| PreSign | 0b11 | On-chain pre-approval |
Gas Efficiency
The encoding reduces calldata costs by:- Using token indices instead of full addresses
- Packing multiple values into single storage slots
- Optimizing for zero bytes in calldata (cheaper on Ethereum)