Skip to main content

GPv2Trade API

The GPv2Trade library is a Solidity utility for encoding and decoding trade data in settlement batches, enabling gas-efficient batch settlements.

Data Structure

Rather than storing full token addresses, the struct uses an index into the tokens array for sell and buy tokens to reduce gas costs.

Functions

extractOrder

Converts trade data into a full order struct while extracting the signing scheme from packed flags.

extractFlags

Unpacks a single uint256 value into separate order parameters.

Flag Encoding

The library uses a bitfield approach where individual bits represent different order properties: The default 0x00 represents the most common case: a fill-or-kill sell order by an externally owned account using EIP-712 signatures.

Supported Signing Schemes

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)
Last modified on March 4, 2026