Skip to content

CTFExchange

The CTFExchange contract is the settlement layer for the prediction market. It validates signed orders, verifies signatures, and executes matched fills on-chain.

Order Structure

Orders are EIP-712 typed data signed by traders:

solidity
struct Order {
    uint256 salt;
    address maker;
    address signer;
    address taker;
    uint256 tokenId;
    uint256 makerAmount;
    uint256 takerAmount;
    uint256 expiration;
    uint256 nonce;
    uint256 feeRateBps;
    uint8 side;         // 0 = BUY, 1 = SELL
    uint8 signatureType;
}

Signature Types

The exchange supports multiple signature verification methods:

TypeValueDescription
EOA0Standard ECDSA signature from an externally-owned account
POLY_PROXY1Signature verified through a deterministic proxy wallet
POLY_GNOSIS_SAFE2Signature verified through a deterministic safe wallet
POLY_12713EIP-1271 smart contract signature verification

Settlement

The matcher calls matchOrders to settle fills:

solidity
function matchOrders(
    Order memory takerOrder,
    Order[] memory makerOrders,
    uint256 takerFillAmount,
    uint256[] memory makerFillAmounts,
    bytes memory takerSignature,
    bytes[] memory makerSignatures
) external

Settlement atomically:

  1. Verifies all signatures
  2. Checks order validity (expiration, nonce, cancellation)
  3. Transfers collateral from buyer to seller
  4. Splits collateral into conditional tokens (or transfers existing positions)
  5. Emits fill events for reconciliation

Access Control

RolePermissions
AdminAdd/remove operators, pause/unpause exchange
OperatorSubmit matchOrders transactions, register token pairs

Collateral

The exchange uses an ERC-20 token as collateral. In the test environment, MockCollateral is a freely-mintable token. In production, this would be USDC or another stablecoin.

solidity
// MockCollateral — test only
function mint(address to, uint256 amount) external

Traders must approve the exchange to spend their collateral and conditional tokens before trading.