Skip to main content

GPv2Order API

The GPv2Order library provides core order data structures and utilities for Gnosis Protocol v2, handling order hashing, UID packing, and parameter extraction.

Data Structure

struct Data {
    IERC20 sellToken;
    IERC20 buyToken;
    address receiver;
    uint256 sellAmount;
    uint256 buyAmount;
    uint32 validTo;
    bytes32 appData;
    uint256 feeAmount;
    bytes32 kind;
    bool partiallyFillable;
    bytes32 sellTokenBalance;
    bytes32 buyTokenBalance;
}
FieldTypeDescription
sellTokenIERC20Token to sell
buyTokenIERC20Token to buy
receiveraddressRecipient of buy tokens (address(0) defaults to owner)
sellAmountuint256Amount of sell token
buyAmountuint256Amount of buy token
validTouint32Order expiration as Unix timestamp
appDatabytes32Application-specific metadata
feeAmountuint256Fee amount in sell token
kindbytes32Order kind (KIND_SELL or KIND_BUY)
partiallyFillableboolWhether partial fills are allowed
sellTokenBalancebytes32Source of sell tokens
buyTokenBalancebytes32Destination of buy tokens

Constants

bytes32 constant KIND_SELL = keccak256("sell");
bytes32 constant KIND_BUY = keccak256("buy");
bytes32 constant BALANCE_ERC20 = keccak256("erc20");
bytes32 constant BALANCE_EXTERNAL = keccak256("external");
bytes32 constant BALANCE_INTERNAL = keccak256("internal");
uint256 constant UID_LENGTH = 56;

Functions

hash

Generates the EIP-712 signing digest for an order.
function hash(
    Data memory order,
    bytes32 domainSeparator
) internal pure returns (bytes32);

actualReceiver

Resolves the receiver address, returning the owner if receiver is address(0).
function actualReceiver(
    Data memory order,
    address owner
) internal pure returns (address);

packOrderUidParams

Encodes the 56-byte order UID from its components.
function packOrderUidParams(
    bytes memory orderUid,
    bytes32 orderDigest,
    address owner,
    uint32 validTo
) internal pure;

extractOrderUidParams

Decodes UID components from a packed order UID.
function extractOrderUidParams(
    bytes calldata orderUid
) internal pure returns (
    bytes32 orderDigest,
    address owner,
    uint32 validTo
);

Order UID Format

The 56-byte UID is packed as:
BytesField
0-31Order digest (EIP-712 hash)
32-51Owner address
52-55validTo timestamp
All functions use assembly optimization for gas efficiency.
Last modified on March 4, 2026