Architecture Overview
CloudBank is a decentralized prediction market platform on BNB Smart Chain (BSC). The system enables users to trade on the outcomes of real-world events using binary (YES/NO) and multi-outcome markets, with AI-powered settlement and gasless transactions.
System Architecture
┌─────────────────────────────────────────────────────────────┐
│ Frontend Layer │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Web App │ │ Admin │ │ Presale │ │ Docs │ │
│ │ React 19 │ │ Ant Dsn │ │ Next.js │ │VitePress │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └──────────┘ │
│ │ │ │ │
├───────┼──────────────┼──────────────┼────────────────────────┤
│ │ Backend Layer │ │
│ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────┐ │
│ │ Custodial Wallet Service │ │
│ │ Go + Gin + GORM + JWT │ │
│ │ ┌─────────┐ ┌────────────────┐ │ │
│ │ │Orderbook│ │ Signing/Auth │ │ │
│ │ │ Engine │ │ EIP-191/712 │ │ │
│ │ └─────────┘ └────────────────┘ │ │
│ └──────────┬───────────────────────────┘ │
│ │ │
├─────────────┼────────────────────────────────────────────────┤
│ │ Smart Contract Layer │
│ ▼ │
│ ┌──────────────────────────────────────┐ │
│ │ BSC (BNB Smart Chain) │ │
│ │ ┌──────────┐ ┌────────────────┐ │ │
│ │ │ Factory │ │ Optimistic │ │ │
│ │ │ Registry │ │ Controller │ │ │
│ │ └──────────┘ └────────────────┘ │ │
│ │ ┌──────────┐ ┌────────────────┐ │ │
│ │ │ Binary │ │ Sora Oracle │ │ │
│ │ │ CPMM │ │ + Adapters │ │ │
│ │ └──────────┘ └────────────────┘ │ │
│ │ ┌──────────┐ ┌────────────────┐ │ │
│ │ │ Gnosis │ │ Verifying │ │ │
│ │ │ CTF │ │ Paymaster │ │ │
│ │ └──────────┘ └────────────────┘ │ │
│ └──────────────────────────────────────┘ │
│ │
├──────────────────────────────────────────────────────────────┤
│ Indexing Layer │
│ ┌──────────────────────────────────────┐ │
│ │ The Graph (Goldsky hosted) │ │
│ │ AssemblyScript mappings │ │
│ │ GraphQL API │ │
│ └──────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘Technology Stack
| Layer | Technology | Purpose |
|---|---|---|
| Smart Contracts | Solidity ^0.8.19, Foundry | Market logic, AMM, oracle, paymaster |
| Backend | Go 1.23, Gin, GORM | Custodial wallet, orderbook engine, signing |
| Frontend | React 19, Vite, TanStack | Trading UI, admin panel |
| Presale | Next.js 16, wagmi | Node presale application |
| Database | MySQL (GORM), Redis | User data, sessions, rate limiting |
| Indexing | The Graph, Goldsky, AssemblyScript | On-chain event indexing, GraphQL API |
| Infrastructure | GitHub Actions, Cloudflare Pages, EC2 | CI/CD, static hosting, backend deployment |
| Wallet | wagmi, viem, EIP-191/712 | Wallet connection, signing |
| AA | ERC-4337, EntryPoint v0.6 | Account Abstraction for gasless transactions |
Module Map
- Smart Contracts — Solidity contracts, market lifecycle, CTF integration
- Orderbook & AMM — CPMM formula, orderbook engine, hybrid routing
- Settlement — Optimistic oracle, AI auto-settlement, dispute flow
- Gas Sponsorship — ERC-4337 AA, Paymaster, gasless transactions
- Backend Services — Go API, custodial wallet, authentication
- Frontend — React apps, wallet integration, state management
- Indexing — The Graph subgraph, GraphQL schema, event handlers
- Infrastructure — CI/CD, deployment, monorepo structure
- API Reference — REST API, contract ABI, GraphQL queries
Data Flow
A complete trading flow from user action to settlement:
User Action Backend Blockchain
──────────── ─────── ──────────
1. Connect Wallet →
2. Sign EIP-191 message → Verify signature
3. Receive JWT ← Issue JWT token
4. Place order → Validate + match
5. Submit transaction → Sign with custodial key → Execute on BSC
6. Confirm ← ← Tx receipt
7. Position updated ← Subgraph indexes event
...
8. Market expires → Oracle resolves
9. AI verifies result → Sora Keeper proposes → OptimisticController
10. Settlement ← ← CTF reports payouts
11. Redeem positions → → CTF.redeemPositionsExternal Dependencies
| Dependency | Purpose | Integration |
|---|---|---|
| Gnosis CTF | ERC-1155 conditional tokens | Position minting, splitting, merging, redemption |
| ERC-4337 EntryPoint v0.6 | Account Abstraction | UserOperation validation, gas sponsorship |
| Goldsky | Subgraph hosting | GraphQL API for indexed on-chain data |
| Alchemy | RPC provider | BSC node access (primary) |
| Cloudflare Pages | Static hosting | Frontend deployment |