Smart Contract Layer
CloudBank's on-chain layer is built with Solidity ^0.8.19 and the Foundry toolchain (forge, cast, anvil). The architecture uses a factory-clone pattern to minimize deployment costs while maintaining full upgradeability of future market types.
Contract Hierarchy
The deployment hierarchy follows a registry-factory-clone structure:
- FactoryRegistry — Central registry that tracks all authorized factory contracts and their deployed markets. Serves as the single entry point for market discovery.
- DCPPFactory — Deploys binary prediction markets using the EIP-1167 Minimal Proxy pattern. Each call to
createMarketclones an OptimisticController implementation and pairs it with a BinaryCPMM liquidity pool. - OptimisticController — Per-market controller managing the lifecycle from trading through settlement. Deployed as a minimal proxy (clone) to reduce gas costs to ~45k gas per deployment.
- BinaryCPMM — Constant-product automated market maker for YES/NO outcome token trading.
- MultiOutcomeMarketFactory — Extends the system to N-option markets (e.g., "Who will win the election?" with multiple candidates), deploying a set of conditional outcome slots.
EIP-1167 Minimal Proxy Pattern
Rather than deploying full contract bytecode for every market, DCPPFactory uses OpenZeppelin's Clones library to deploy lightweight proxies that delegate all calls to a single implementation contract. This reduces per-market deployment cost by roughly 90%.
Conditional Token Framework
All outcome positions are represented as ERC-1155 tokens via the Gnosis Conditional Tokens Framework (CTF). This provides:
- Fungible outcome shares (YES and NO tokens) under a single contract
- Atomic splitting and merging of collateral into position sets
- Standardized redemption after market resolution
- Composability with other DeFi protocols that support ERC-1155
Oracle Integration
- SoraOracle — A minimal yes/no oracle contract where designated providers answer binary questions. Includes a 7-day refund period for dispute handling.
- SoraYesNoOracleAdapter — Bridges SoraOracle responses into the CTF's
reportPayoutsinterface, translating boolean answers into the payout vector format the framework expects.
Gas Sponsorship
CloudBankVerifyingPaymaster implements ERC-4337 paymaster logic, enabling the platform to sponsor gas fees for users. The paymaster validates off-chain ECDSA signatures to authorize sponsorship per UserOperation.
Market State Machine
Every market follows a deterministic state machine enforced on-chain by the OptimisticController:
- TRADING — Market is active; users can buy and sell outcome tokens.
- PROPOSED — The market creator has proposed an outcome. A liveness period begins during which anyone can dispute.
- DISPUTED — A dispute has been raised. Resolution escalates to the SoraOracle.
- RESOLVED — Final outcome is set. Position holders can redeem winning tokens.
- CANCELLED — Market is voided. All positions can be redeemed at original collateral value.
Market Creation Flow
The factory atomically deploys the controller clone, initializes the AMM pool, prepares the CTF condition, and registers the market in a single transaction. Initial liquidity provided by the creator is split into YES and NO tokens and deposited into the BinaryCPMM pool.
Security Considerations
- All contracts use OpenZeppelin's
ReentrancyGuardon state-modifying functions. - Access control follows an owner/admin pattern with explicit role separation.
- Market parameters (liveness period, minimum stake) are validated at creation time.
- The factory pattern ensures only authorized factories can register markets in the FactoryRegistry.