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:
| Type | Value | Description |
|---|---|---|
EOA | 0 | Standard ECDSA signature from an externally-owned account |
POLY_PROXY | 1 | Signature verified through a deterministic proxy wallet |
POLY_GNOSIS_SAFE | 2 | Signature verified through a deterministic safe wallet |
POLY_1271 | 3 | EIP-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
) externalSettlement atomically:
- Verifies all signatures
- Checks order validity (expiration, nonce, cancellation)
- Transfers collateral from buyer to seller
- Splits collateral into conditional tokens (or transfers existing positions)
- Emits fill events for reconciliation
Access Control
| Role | Permissions |
|---|---|
| Admin | Add/remove operators, pause/unpause exchange |
| Operator | Submit 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) externalTraders must approve the exchange to spend their collateral and conditional tokens before trading.