# Architecture

Ojo markets are CLOBs (Central Limit Order Book) built on the Gnosis Conditional Tokens Framework. There are a few disclaimers to note:

* We are in a **closed beta.** The platform is experimental software under active development.
* **There may be bugs in these smart contracts.** We make no assurances that there aren't! While we've worked with Octane Security to ensure they are as secure to the best of our knowledge that we can make them, **no one can ever make an assurance that code will be 100% bug-free.** You may lose all funds deposited into the platform.
* There is an **off-chain orderbook, with on-chain settlement**. **We never custody funds**. We use EIP-712 so that you can push signatures to our API authorizing trades, and then our API uses that to trade if it finds a matching order on the other side of the book.&#x20;
* **Prices can be volatile**. While we may run a seed of liquidity on the orderbook to enable trading, traders may set prices at different values.
* Market resolution depends on third-party oracle systems (UMA) which may fail or be disputed, or may misunderstand our smart contracts. Uma is used by top-tier products in the space, but **we make no assurances of this third-party oracle.**
* Markets may have insufficient liquidity, preventing you from exiting positions. We make no assurance that you will always be able to sell your position back.
* Prediction markets may be subject to changing regulatory treatment. US-based users and sanctioned entities are strictly prohibited from trading.
* **No Investment Advice** Nothing on this platform constitutes investment, financial, legal, or tax advice.

Here's the architecture:

**ConditionalTokensWithPermit** (CTF Fork)

* Modified Gnosis CTF with EIP-712 gasless signatures
* Manages ERC1155 outcome tokens (YES/NO positions)
* Handles splitting USDC → YES+NO tokens
* Handles merging YES+NO → USDC
* Added `setApprovalForAllWithPermit()` and `redeemPositionsWithPermit()` for gasless UX

**Market** (Per-market contracts)

* One deployed per prediction market
* Integrates UMA Optimistic Oracle V3 for resolution
* Stores market metadata (question, expiration, maker)
* Manages resolution lifecycle: propose → settle
* Reports payouts to CTF after UMA settlement
* Supports gasless resolution via `proposeResolutionWithPermit()`

**OrderBook** (EIP-712 signature verification)

* Stateless order matching (actual book is off-chain)
* Validates EIP-712 signed orders
* Tracks filled amounts and cancellations
* Price scaled to 1e6 (0.01 = 10,000)
* Nonce-based order invalidation

**Settlement** (Trade execution)

* Inherits from OrderBook
* Executes matched trades between signed orders
* 1% fee
* **Just-in-time position splitting**: If seller lacks YES tokens, auto-splits their USDC
* Supports gasless trading via `executeTradeWithPermit()` (EIP-2612 USDC permit)
* Guardian-controlled pause mechanism

**MarketFactory**

* Deploys new Market contracts
* Registers markets with Settlement
* Tracks all markets and their CTF token IDs

<br>
