Skip to main content

Overview

The OrderStructs library defines the core data structures and enums used throughout the Polymarket CTF Exchange for order management and matching.

ORDER_TYPEHASH

EIP-712 type hash used for order signature verification.
bytes32 constant ORDER_TYPEHASH = keccak256(
    "Order(uint256 salt,address maker,address signer,address taker,uint256 tokenId,uint256 makerAmount,uint256 takerAmount,uint256 expiration,uint256 nonce,uint256 feeRateBps,uint8 side,uint8 signatureType)"
);

Order

The main order struct representing a buy or sell order on the exchange.
struct Order {
    uint256 salt;
    address maker;
    address signer;
    address taker;
    uint256 tokenId;
    uint256 makerAmount;
    uint256 takerAmount;
    uint256 expiration;
    uint256 nonce;
    uint256 feeRateBps;
    Side side;
    SignatureType signatureType;
    bytes signature;
}

Fields

salt
uint256
Unique salt to ensure entropy and uniqueness of order hashes
maker
address
Maker of the order, i.e. the source of funds for the order
signer
address
Signer of the order. For EOA signature types, must match the maker address
taker
address
Address of the order taker. The zero address (address(0)) is used to indicate a public order that anyone can fill
tokenId
uint256
Token ID of the CTF ERC1155 asset to be bought or sold
  • If BUY: This is the tokenId of the asset to be bought (makerAssetId)
  • If SELL: This is the tokenId of the asset to be sold (takerAssetId)
makerAmount
uint256
Maker amount, i.e. the maximum amount of tokens to be sold by the maker
takerAmount
uint256
Taker amount, i.e. the minimum amount of tokens to be received by the maker
expiration
uint256
Timestamp after which the order is expired and can no longer be filled
nonce
uint256
Nonce used for onchain cancellations. Must match the maker’s current nonce
feeRateBps
uint256
Fee rate in basis points (bps) charged to the order maker on proceeds. 100 bps = 1%
side
Side
The side of the order: BUY or SELL
signatureType
SignatureType
Signature type used by the order: EOA, POLY_PROXY, POLY_GNOSIS_SAFE, or POLY_1271
signature
bytes
The order signature bytes

OrderStatus

Tracks the fill status of an order.
struct OrderStatus {
    bool isFilledOrCancelled;
    uint256 remaining;
}

Fields

isFilledOrCancelled
bool
Whether the order has been completely filled or cancelled
remaining
uint256
Remaining maker amount that can still be filled. When this reaches 0, isFilledOrCancelled is set to true

Side

Enum representing the side of an order.
enum Side {
    BUY,   // 0: buy order
    SELL   // 1: sell order
}

Values

BUY
uint8
Buy order - maker is buying outcome tokens with collateral
SELL
uint8
Sell order - maker is selling outcome tokens for collateral

SignatureType

Enum representing the signature type used for order validation.
enum SignatureType {
    EOA,              // 0
    POLY_PROXY,       // 1
    POLY_GNOSIS_SAFE, // 2
    POLY_1271         // 3
}

Values

EOA
uint8
ECDSA EIP-712 signatures signed by Externally Owned Accounts (EOAs)
POLY_PROXY
uint8
EIP-712 signatures signed by EOAs that own Polymarket Proxy wallets
POLY_GNOSIS_SAFE
uint8
EIP-712 signatures signed by EOAs that own Polymarket Gnosis Safes
POLY_1271
uint8
EIP-1271 signatures signed by smart contracts. Used by smart contract wallets or vaults

MatchType

Enum representing the type of match between two orders.
enum MatchType {
    COMPLEMENTARY, // 0
    MINT,          // 1
    MERGE          // 2
}

Values

COMPLEMENTARY
uint8
Buy vs sell - a buy order matched with a sell order
MINT
uint8
Both buys - two buy orders matched together, requiring minting of new position tokens
MERGE
uint8
Both sells - two sell orders matched together, resulting in merging of position tokens

Usage Example

import { Order, Side, SignatureType } from "exchange/libraries/OrderStructs.sol";

// Create a buy order
Order memory order = Order({
    salt: 1,
    maker: makerAddress,
    signer: makerAddress,
    taker: address(0), // Public order
    tokenId: yesTokenId,
    makerAmount: 50_000_000,  // Spending 50 USDC
    takerAmount: 100_000_000, // Receiving 100 outcome tokens
    expiration: block.timestamp + 1 days,
    nonce: 0,
    feeRateBps: 100, // 1% fee
    side: Side.BUY,
    signatureType: SignatureType.EOA,
    signature: orderSignature
});