Skip to main content
CTFExchange is an order-matching contract that settles trades against ConditionalTokens. PredictStreet deploys it with the quadratic taker-fee formula fee = k × P × (1−P) × outcomeTokens. See Fees for the mathematical background.

Key entry points

Fee formula

The contract executes the PS_QUADRATIC_V1 parabolic curve (peak at P=0.5, smoothly decaying to zero at P=0 and P=1):
  • Peak fee (at P = 0.5): feeRateBps / 4 / BPS_DIVISOR.
  • Cap: feeRateBps <= MAX_FEE_RATE_BIPS (1000) (peak 2.5%).
  • Inspect getFeeFormulaId() on-chain to verify: returns bytes32("PS_QUADRATIC_V1").

Events

Every trade execution event includes a monotonically increasing seq counter:
Note: maker (and takerOrderMaker / takerMaker) is always the order’s vault address, not the signing EOA.

Security invariants

  • Signature replay impossible — every filled or cancelled order hash is recorded in orderStatus[hash].isFilledOrCancelled.
  • Maker authority cryptographic — the exchange accepts only signatureType = 1 (VAULT). The signature must recover to signer, and maker must equal vaultFactory.vaultOf(signer). Orders with deprecated signatureType = 0 revert with InvalidSignature().
  • Admin cannot seize funds — no admin function transfers user tokens or collateral.
  • Operator rotation — compromised operator keys can be immediately disabled via removeOperator(address).

MatchFailed reason codes

When batchMatchOrders catches a per-leg revert, the reason bytes contain the 4-byte selector of the custom error:
To avoid OrderExpired() settlement failures, sign orders with expiration = 0 (no on-chain expiry — skips the block.timestamp >= expiration check).

Neg-risk variant (NegRiskCtfExchange)

For multi-outcome markets, NegRiskCtfExchange inherits CTFExchange identically, but points its internal CT router to NegRiskAdapter. All order matching, fee calculation, and event semantics remain identical to CTFExchange.

Source

0x90EA87493E208A14011EC700Ac9cbAf4d064acc0 on Blockscout.