Skip to content
jotel-devPublic

About

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

190 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Quiza ๐Ÿง  โ€” Stake. Play. Win.

High-throughput, non-custodial Web3 skill gaming on Stellar. Stake XLM or USDC, test your knowledge in 10 fast-paced trivia questions, and claim progressive payouts directly from a Soroban smart contract. Zero custody, sub-5-second finality, and negligible fees.

License: MIT PRs Welcome Vite React Fastify TypeScript Stellar Testnet Soroban Freighter Security Status


โš ๏ธ Security & Testnet Notice: Quiza is currently deployed on the Stellar Testnet for testing, evaluation, and demonstration purposes only. The smart contracts are unaudited. Do not risk real mainnet funds. Public contract IDs only are published below; no private keys or secrets (S...) are ever stored or committed to this repository.


๐ŸŒŸ Executive Overview

Quiza is an open-source decentralized trivia platform engineered for fast, mobile-friendly competitive gaming on the Stellar blockchain. Players stake native XLM or USDC across categories including Mathematics, Geography, History, and General Knowledge. Achieving 7 or more correct answers unlocks payouts up to 2.0x funded from an automated house liquidity pool managed entirely by a Soroban smart contract.

Architectural Highlights

  • ๐Ÿ”’ 100% Non-Custodial & Session Signing: Player secret keys (S...) are never requested or stored. All transactions and session challenges are signed directly inside the player's Freighter wallet extension using SEP-53 message signing with single-use nonces and 15-minute expiring session tokens (no repetitive popups for answering questions).
  • ๐Ÿ’พ Dual Database Engine: Fastify API in apps/api runs on PGlite locally (in-process WASM PostgreSQL with zero configuration or Docker required) and connects to PostgreSQL via DATABASE_URL in production.
  • ๐Ÿ“œ Soroban Smart Contract: Written in Rust in contracts/quiza, enforcing strict liquidity accounting invariants and mathematical payout bounds.
  • ๐Ÿ“ Strict Liquidity Accounting Invariant: Real token balances in the contract are mathematically bounded at all times: $$\text{Contract Balance} == \text{pool} + \text{locked} + \text{owed}$$
  • ๐Ÿ›ก๏ธ Guaranteed Timeout Refund: If a round remains unresolved after 2 hours (7,200 seconds), players can call claim_timeout directly on-chain to reclaim 100% of their stake without backend assistance.
  • ๐Ÿ•ต๏ธ Anti-Cheat Off-Chain Scoring: Trivia question answer keys never leave the server. Player answer selections are evaluated by the backend verifier, which signs and submits the on-chain settlement.
  • โšก Sub-5-Second Settlement: Native Stellar consensus ensures near-instant settlement without block reorgs.

๐ŸŽฎ Game Modes & Multiplier Tiers

Game Mode Mechanics Target Audience
Stake & Win Choose token (XLM / USDC), category, and stake amount. 10 timed questions. Competitive players seeking crypto payouts
Daily Challenge 10 synchronized daily questions. Global daily leaderboard competition. Daily active users & community ranking
Practice Mode Free-play mode without wallet popups or signatures. Newcomers exploring gameplay

Payout Multipliers

Final Score (out of 10) Payout Multiplier Net Profit
10 / 10 (Perfect) 2.0x +100% (Double your stake)
8 โ€“ 9 / 10 1.5x +50%
7 / 10 1.2x +20%
0 โ€“ 6 / 10 0.0x Stake retained in house liquidity pool

๐Ÿ—๏ธ System Architecture

sequenceDiagram
    autonumber
    actor Player as ๐Ÿง‘ Player (Freighter Wallet)
    participant UI as ๐Ÿ–ฅ๏ธ Vite Frontend (React 19)
    participant API as โšก Fastify Backend (Port 3001)
    participant DB as ๐Ÿ’พ Database (PGlite / PostgreSQL)
    participant Contract as ๐Ÿ“œ QuizaContract (Soroban Testnet)

    Note over Player,UI: 1. Authentication & Staking
    Player->>Contract: stake(player, token, amount) [Signed in Freighter]
    Contract-->>Player: RoundOpened (round_id)
    Player->>API: GET /api/challenge?address=G...
    API-->>Player: Challenge Nonce
    Player->>Player: Sign nonce via Freighter SEP-53
    Player->>API: POST /api/session (address, nonce, signature)
    API-->>Player: 15-min HMAC Session Token

    Note over Player,API: 2. Gameplay & Off-Chain Scoring
    Player->>API: POST /api/round-questions [Bearer Token]
    API->>DB: Fetch 10 questions (answers hidden)
    API-->>Player: Deliver 10 questions
    Player->>API: POST /api/verify-round [Bearer Token]
    API->>API: Score answers against source-of-truth bank
    
    Note over API,Contract: 3. Settlement & Payout
    API->>Contract: resolve(round_id, won, score) [Signed by Verifier]
    Contract->>Contract: Update Invariant (locked -= stake, owed += payout)
    Contract-->>API: RoundResolved Event
    API-->>Player: Final Score, Payout Status & Tx URL
    
    Note over Player,Contract: 4. Non-Custodial Withdrawal
    Player->>Contract: withdraw(player, token) [Signed in Freighter]
    Contract->>Player: Transfer token payout to player wallet
Loading

๐Ÿ—‚ Monorepo Layout

quiza/
โ”œโ”€โ”€ apps/
โ”‚   โ””โ”€โ”€ api/                   # Fastify + TypeScript backend API (PGlite locally, PostgreSQL in prod)
โ”‚       โ”œโ”€โ”€ src/               # Routes, challenge auth, worker queue, retry sweeper
โ”‚       โ”œโ”€โ”€ test/              # Vitest API integration & security test suite
โ”‚       โ””โ”€โ”€ Dockerfile         # Production container definition for Render / Railway
โ”œโ”€โ”€ contracts/
โ”‚   โ””โ”€โ”€ quiza/                 # Soroban Rust smart contract (contracts/quiza)
โ”‚       โ”œโ”€โ”€ src/lib.rs         # Staking, accounting invariant, timeout, withdrawal
โ”‚       โ”œโ”€โ”€ src/test.rs        # Comprehensive Soroban SDK test suite
โ”‚       โ””โ”€โ”€ Cargo.toml         # Contract dependencies & compiler flags
โ”œโ”€โ”€ docs/                      # Technical documentation & architecture guides
โ”‚   โ”œโ”€โ”€ deploying.md           # Production deployment guide (Vercel + Render / PostgreSQL)
โ”‚   โ”œโ”€โ”€ contract-interface.md  # Detailed Soroban contract specifications & error codes
โ”‚   โ”œโ”€โ”€ architecture.md        # Deep dive into system components & data flows
โ”‚   โ”œโ”€โ”€ smart-contracts.md     # Soroban contract API, storage layout & invariants
โ”‚   โ”œโ”€โ”€ api.md                 # REST API endpoints, schemas & authentication
โ”‚   โ”œโ”€โ”€ mobile.md              # Responsive layout & Freighter mobile roadmap
โ”‚   โ”œโ”€โ”€ development.md         # Local development setup & dev-runner guide
โ”‚   โ”œโ”€โ”€ testing.md             # Vitest, Cargo, and mock testing guides
โ”‚   โ”œโ”€โ”€ troubleshooting.md     # Common error diagnostics & solutions
โ”‚   โ”œโ”€โ”€ coding-standards.md    # Style guides, linting, and error handling
โ”‚   โ”œโ”€โ”€ design-decisions.md    # Architecture Decision Records (ADRs)
โ”‚   โ””โ”€โ”€ known-limits.md        # Documented protocol constraints
โ”œโ”€โ”€ src/                       # Vite + React 19 frontend application
โ”‚   โ”œโ”€โ”€ components/            # UI components (StakeModal, ShareModal, Navbar)
โ”‚   โ”œโ”€โ”€ lib/quizaContract.js   # Soroban RPC client, Freighter bridge, timeout recovery
โ”‚   โ””โ”€โ”€ pages/                 # Views (Home, Quiz, Results, Profile, Leaderboard)
โ”œโ”€โ”€ scripts/                   # Development orchestrator & deployment scripts
โ”‚   โ””โ”€โ”€ dev-runner.js          # Concurrent Fastify + Vite process runner
โ”œโ”€โ”€ .github/                   # CI/CD workflows, issue templates, community files
โ”œโ”€โ”€ CONTRIBUTING.md            # Contributor onboarding & PR conventions
โ”œโ”€โ”€ CODE_OF_CONDUCT.md         # Contributor Covenant v2.1
โ”œโ”€โ”€ SECURITY.md                # Security policy & coordinated disclosure process
โ”œโ”€โ”€ GOVERNANCE.md              # Project governance & RFC lifecycle
โ”œโ”€โ”€ CHANGELOG.md               # Keep a Changelog version history
โ”œโ”€โ”€ ROADMAP.md                 # Technical milestones & future phases
โ”œโ”€โ”€ SUPPORT.md                 # Support channels & community guidelines
โ”œโ”€โ”€ FAQ.md                     # Comprehensive player and developer FAQ
โ”œโ”€โ”€ LICENSE                    # MIT License
โ””โ”€โ”€ package.json               # Root scripts and workspace dependencies

๐Ÿš€ Quick Start (Local Development)

Prerequisites

Tool Version Requirement Purpose
Node.js >= 20.0.0 (LTS) Frontend and Backend runtime
npm >= 10.0.0 Package manager
Freighter Wallet Browser extension Stellar Testnet non-custodial wallet
Rust & Cargo Stable (1.80+) (Optional) Building Soroban contract in contracts/quiza
Stellar CLI >= 22.0.0 (Optional) Testing and deploying Soroban contract

๐Ÿ’ก Zero Database Setup Locally: apps/api automatically initializes an embedded PGlite (in-process WASM PostgreSQL) instance in development. You do not need Docker or an external PostgreSQL database running locally. In production, configure DATABASE_URL pointing to PostgreSQL.

1. Clone & Install

# Clone the repository
git clone https://github.com/jotel-dev/Quiza.git
cd Quiza

# Install root dependencies and API dependencies
npm install
npm --prefix apps/api install

2. Configure Environment

Copy the example configuration to .env:

Windows (PowerShell):

Copy-Item .env.example .env

macOS / Linux:

cp .env.example .env

3. Start Development Servers

Run both the Fastify backend and Vite frontend concurrently via the unified runner:

Windows (PowerShell) / Cross-Platform:

npm run dev

๐Ÿงช Testing & Quality Assurance

Quiza enforces automated testing across all layers:

# 1. Run Root Frontend & Client Recovery Tests (Vitest)
npm test

# 2. Run Backend API Integration & Security Tests (Vitest)
npm --prefix apps/api test

# 3. Run Frontend Production Build & Oxlint Linter
npm run lint
npm run build

# 4. Run Soroban Smart Contract Tests (Cargo)
cd contracts/quiza ; cargo test ; cd ../..

# 5. Run Soroban Clippy Linter
cd contracts/quiza ; cargo clippy -- -D warnings ; cd ../..

๐Ÿ“œ Deployed Smart Contracts (Stellar Testnet)

โš ๏ธ Testnet-Only & Unaudited: Quiza is deployed strictly on the Stellar Testnet for evaluation and demonstration purposes. Smart contracts are unaudited. Public contract IDs only are listed belowโ€”no private keys or secrets are ever stored in this repository.

Network Contract Identifier Explorer
Stellar Testnet (Quiza) CBD7PCUZDB22HJV7LHO4QHRIEZXSWED5OHJ256623PVLT46XGSKSC7IV Stellar Expert (Testnet) โ†—
Native XLM (SAC) CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC Stellar Expert (Testnet) โ†—
USDC (SAC) CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA Stellar Expert (Testnet) โ†—
  • Contract Specification: Detailed interface methods, accounting invariant, and refund mechanics are documented in docs/contract-interface.md.
  • Deployment Guide: Production deployment on Vercel and Render/PostgreSQL is documented in docs/deploying.md.

๐Ÿค Contributing

We welcome contributions from open-source developers worldwide! Please review our Contributing Guide and Code of Conduct before submitting pull requests.


๐Ÿ’ฌ Community & Support


๐Ÿ“„ License

This project is licensed under the MIT License.

About

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages