documentation

Contract

One immutable, non-upgradeable Exchange contract holds all USDC collateral, ERC-1155 outcome shares, fills, and Chainlink settlement.

The active chain ID, exchange address, and USDC address are served by GET /v1/config (and stored in clearbook.toml for local nodes). Because there is no proxy, any protocol upgrade requires a new deployment at a new address — balances stay safely on the original contract until you withdraw. Markets are created lazily inside the first settleFill via MarketSpec; markets with zero fills never exist on chain. See Markets, Settlement, and Trust.

The constructor (usdc, priceOracle, operator, tradeAdmin, feeAccount) sets the EIP-712 domain to Arizal / 1 and separates three roles: the operator manages roles, the trade admin submits matched fills, and the fee account receives trading fees. Yes/No positions are ERC-1155 tokens — one token ID per market side (tokenId(marketId, side)) — freely transferable between wallets.

Contracts

ContractRole
ExchangeCustody, fills, fees, settlement, and ERC-1155 Yes/No position tokens.
PriceOracleResolution oracle for settle: reads one Chainlink Data Feed on chain (one PriceOracle per asset: BTC / USD, ETH / USD) — returning a round’s 8-decimal price and timestamp (roundPrice) or the price live at a timestamp (priceAt). Immutable and ownerless; to switch feeds, the Exchange operator calls proposeOracle → 7-day timelock → anyone calls applyOracle.
MockUSDC6-decimal demo USDC for local testing (faucet mints to caller).
MockAggregatorV3Local stand-in for a Chainlink feed (identical interface); the node publishes Binance spot to it. Production deployments point PriceOracle directly at Chainlink.

Exchange calls

CallWhoEffect
deposit / withdrawuserMove USDC in or out of that wallet’s balance.
cancelOrdersuserCancel your own signed orders on chain by EIP-712 hash: the contract refuses to fill them afterwards, whatever the exchange does. In the app: On-chain next to Cancel in Orders.
revokeAgentuserPermanently block a 1-click session address for the caller (compromise recovery).
split / mergeuserMint or burn a complete Yes+No set (ERC-1155).
safeTransferFrom / safeBatchTransferFrom / setApprovalForAlluserSend position tokens to another wallet (owner or approved operator). The node then cancels the sender’s sell orders, TP/SL and closing stops for that position (Position transferred).
redeemuserAfter resolution, $1 per winning share (losing dust is burned). After a void, $0.50 per Yes and per No share.
createMarkettrade adminOptional standalone open (tests / tooling). Passes backend startTs (same value in the market id). Usual path is lazy create inside settleFill via MarketSpec.
settleFillBatchtrade adminOne taker order against 1–50 maker orders in one transaction. With atomic off, a leg that fails (a maker withdrew, a seller moved its shares, …) is skipped with FillFailed and the other legs still settle; the taker’s gas fee is charged once for the whole batch. Each leg follows these rules: Two EIP-712 orders (signer = trader or off-chain ApproveAgent / AgentAuth), optional MarketSpec (includes backend startTs) if the market is missing. Each order signs action "Buy" or "Sell". Complementary Yes+No (both Buy) mints a $1 set. Same-side orders transfer inventory (close): the taker must be the signed Sell, the resting order a Buy. Charges taker takerFee (at most 0.04 × size × p × (1 − p) at the fill price, the base fee tier — FeeTooHigh above that; a mint debits each side’s net cost, so price improvement is never blocked by a looser limit) and the signed gasFee, which is a total per order: charged once across all of that order’s fills. The trading fee is credited to feeAccount, the gas fee to tradeAdmin (it pays the gas). No fill can land more than 1 hour after the market’s expiry (Expired). A fill matched before the market resolved may still settle up to LATE_SETTLE_WINDOW (1 hour) after settle(); later it reverts LateSettleWindowClosed(). Winners redeem those shares like any other.
settleanyoneSame call for every asset; each market uses the oracle it was created with, so an oracle change never re-decides an open market. Hit: Yes before expiry when the oracle price is through the barrier; at or after expiry, No. Above/Between: after expiry from the oracle price. Write-once.
voidMarketanyoneAbove/Between only: 7 days after expiry, if the oracle still cannot return a price, the market is voided and every share redeems for $0.50.
setTradeAdminoperatorOnly account that may create markets and call settleFill.
setFeeAccount / disableFeeAccountChangesoperatorName the fee account; optionally freeze further fee-account changes forever.
setOperator / acceptOperatoroperator / nomineeTwo-step handover of the operator role.
setURIoperatorERC-1155 metadata URI template.

Signatures & EIP-712 order struct

EOA wallets sign with standard ECDSA (malleable high-s signatures are rejected); smart-contract wallets (Safe, ERC-4337) sign via EIP-1271 isValidSignature. Because the domain includes chainId, signatures can never replay across forks or other networks. Domain name is Arizal, version 1, with the Exchange contract as verifyingContract.

Order(
  address trader,
  string marketId,
  string asset,
  string kind,
  string direction,
  int256 barrier,
  int256 barrierHigh,
  uint256 marketStart,
  uint256 marketExpiry,
  string side,
  string action,
  uint16 price,
  uint256 size,
  string orderType,
  string tif,
  uint256 nonce,
  uint256 salt,
  uint256 expiresAt,
  uint256 gasFee
)

Every order cryptographically commits to the full market terms — asset (e.g. "BTC"), kind ("Hit" / "Above" / "Between"), direction ("Up" / "Down" or empty), barrier / barrierHigh in the oracle’s 8 decimals (1e8 = $1; decimal strikes supported), marketStart, and marketExpiry — and every fill verifies them on chain (MarketTermsMismatch). side is "Yes" / "No", action is "Buy" / "Sell" ("Sell" for closes), and order type/TIF use human-readable strings for clear wallet prompts. Session wallets enable via off-chain ApproveAgent and revoke permanently on chain via revokeAgent(agent).