Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Polymarket/ctf-exchange/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Fills an order with the caller (msg.sender) as the taker. This function allows an operator to execute a single order for a specified fill amount.
function fillOrder(Order memory order, uint256 fillAmount) external nonReentrant onlyOperator notPaused

Parameters

order
Order
required
The order to be filled. See Order Structure for details.The order must:
  • Have a valid signature from the maker
  • Not be expired (if expiration is set)
  • Not be cancelled or fully filled
  • Have a valid nonce
  • Have a fee rate below the maximum allowed
  • Reference a registered token ID
fillAmount
uint256
required
The amount to be filled, always denominated in terms of the maker amount.Must be:
  • Less than or equal to the remaining unfilled amount
  • Greater than 0 for a meaningful fill

Requirements

  • Caller must be an authorized operator (onlyOperator)
  • Trading must not be paused (notPaused)
  • Function must not be re-entered (nonReentrant)
  • Order must pass all validation checks (signature, expiration, nonce, etc.)
  • Caller must have sufficient balance of the taker asset
  • Order maker must have sufficient balance of the maker asset

Behavior

Asset Transfer Flow

  1. Validation: The order is validated including signature verification, expiration check, and nonce validation
  2. Fee Calculation: Fees are calculated based on the order’s feeRateBps and the fill amounts
  3. Asset Transfers:
    • Taker asset (minus fees) is transferred from the operator to the order maker
    • Maker asset is transferred from the order maker to the operator
    • Fees are implicitly collected by the operator (deducted from assets paid by operator)
  4. State Update: Order status is updated with the new remaining amount

Partial Fills

Orders can be partially filled. The order’s remaining amount is tracked on-chain and updated with each fill. When fully filled, the order is marked as isFilledOrCancelled = true.

Events

OrderFilled
event
Emitted when an order is successfully filled.
event OrderFilled(
    bytes32 indexed orderHash,
    address indexed maker,
    address indexed taker,
    uint256 makerAssetId,
    uint256 takerAssetId,
    uint256 makerAmountFilled,
    uint256 takerAmountFilled,
    uint256 fee
)
  • orderHash: Hash of the filled order
  • maker: Address of the order maker
  • taker: Address of the taker (operator calling fillOrder)
  • makerAssetId: Token ID of the asset sold by maker (0 for collateral)
  • takerAssetId: Token ID of the asset bought by maker (0 for collateral)
  • makerAmountFilled: Amount of maker asset transferred
  • takerAmountFilled: Amount of taker asset transferred
  • fee: Fee charged to the maker on their proceeds
FeeCharged
event
Emitted when a fee is charged (if fee > 0).
event FeeCharged(
    address indexed receiver,
    uint256 indexed tokenId,
    uint256 amount
)

Errors

NotOperator
error
Caller is not an authorized operator
Paused
error
Trading is currently paused
OrderExpired
error
Order has passed its expiration timestamp
OrderFilledOrCancelled
error
Order has already been fully filled or cancelled
InvalidSignature
error
Order signature is invalid
InvalidNonce
error
Order nonce is invalid (maker has incremented their nonce)
FeeTooHigh
error
Order fee rate exceeds the maximum allowed
MakingGtRemaining
error
Fill amount exceeds the remaining unfilled amount
NotTaker
error
Order specifies a specific taker and caller is not that address

Example Usage

// Create a BUY order for YES tokens
Order memory order = Order({
    salt: 1,
    maker: 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb,
    signer: 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb,
    taker: address(0), // Public order
    tokenId: yesTokenId,
    makerAmount: 50_000_000, // 50 USDC (6 decimals)
    takerAmount: 100_000_000, // 100 YES tokens
    expiration: 0, // No expiration
    nonce: 0,
    feeRateBps: 100, // 1% fee
    side: Side.BUY,
    signatureType: SignatureType.EOA,
    signature: orderSignature
});

// Fill 50% of the order (25 USDC worth)
uint256 fillAmount = 25_000_000;

// As an operator, fill the order
exchange.fillOrder(order, fillAmount);

// Result:
// - Operator receives 25 USDC from maker
// - Maker receives ~50 YES tokens (minus 1% fee)
// - Order can be filled again for remaining 25 USDC

See Also

Build docs developers (and LLMs) love