Skip to content

the-axmc/Cairox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

124 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cairox - Starknet Ecosystem Prediction Protocol

Decentralized prediction markets for Starknet ecosystem analytics

Cairox is a prediction market protocol built on Starknet that allows users to trade on real-world and on-chain ecosystem metrics (DAU, TVL, transaction counts) using data from the Growthepie API.

Table of Contents

Overview

Cairox enables permissionless prediction markets for Starknet ecosystem metrics:

  • Binary Markets - YES/NO outcomes (e.g., "Will Starknet exceed 1M DAU?")
  • Categorical Markets - Multiple outcomes (e.g., "Which L2 will have highest TVL?")
  • Comparative Markets - Ranked outcomes

Markets are resolved using objective ecosystem data from Growthepie, eliminating oracle manipulation risks.

Tech Stack

Component Technology Version
Smart Contracts Cairo 2.8.0
Package Manager Scarb 2.8.0
Testing Framework Starknet Foundry (snforge) Latest
Local Devnet Starknet Devnet Latest
Oracle Agent Python 3.10+
HTTP Client requests >=2.28.0
Starknet SDK starknet-py >=0.5.0
Indexer Python 3.10+
Indexer SDKs starknet-py, aiohttp >=0.20.0

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        User Interface                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Smart Contracts (Starknet)              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Market    β”‚  β”‚  Collateralβ”‚  β”‚   Outcome Tokens     β”‚ β”‚
β”‚  β”‚  Factory    β”‚  β”‚   Vault    β”‚  β”‚   (ERC-1155)         β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚    LMSR     β”‚  β”‚  Oracle    β”‚  β”‚   Resolution         β”‚ β”‚
β”‚  β”‚ Market Makerβ”‚  β”‚            β”‚  β”‚   Verifier            β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Off-Chain Services                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  Oracle Agent   β”‚        β”‚      Indexer            β”‚    β”‚
β”‚  β”‚ (Growthepie API)β”‚        β”‚  (Event Processing)     β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Data Sources                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Growthepie API                         β”‚   β”‚
β”‚  β”‚     (https://api.growthepie.com/v1)                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Smart Contracts

The Cairox protocol consists of 12 core contracts:

Contract Purpose
MarketFactory Creates and manages prediction markets
Market Core market logic (minting, redemption, resolution)
CollateralVault Holds collateral deposits
OutcomeToken ERC-1155 tokens representing market outcomes
Oracle Stores data commitments from oracle agent
OptimisticOracle Challenge/response oracle workflow
ResolutionVerifier Verifies multi-user resolution claims
LMSRMarketMaker Automated market maker using LMSR pricing
LMSRMulti Multi-outcome LMSR implementation
Arbitration Dispute resolution for contested outcomes
LaunchConfig Configuration for market creation parameters
PriceOracle Price feed adapter for collateral
Stablecoin Protocol stablecoin for collateral and bonds

Key Features

  • Permissionless Market Creation: Anyone can create a market with collateral
  • Complete Set Minting: Users deposit collateral to mint equal amounts of all outcomes
  • LMSR Bonding Curve: Automated price discovery with constant liquidity
  • Deterministic Resolution: Markets resolve based on Growthepie data
  • Insolvency Prevention: Total collateral always covers outstanding tokens

Getting Started

Prerequisites

  • Rust (for Scarb)
  • Python 3.10+ (for oracle agent and indexer)
  • Docker (for local devnet)

Quick Start

# Clone the repository
git clone https://github.com/the-axmc/Cairox.git
cd Cairox

# Build contracts
cd contracts
scarb build

# Run tests
make test

# Start local devnet
make devnet-up

# Deploy contracts locally
make deploy-local

Oracle Agent Setup

cd oracle-agent

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp ../.env.sample .env
# Edit .env with your values

# Run oracle agent
python src/agent.py

Project Structure

Cairox/
β”œβ”€β”€ contracts/              # Cairo smart contracts (Scarb package)
β”‚   β”œβ”€β”€ Scarb.toml         # Package manifest
β”‚   β”œβ”€β”€ config.json        # Deployment/config inputs
β”‚   β”œβ”€β”€ scripts/           # Deployment/helpers
β”‚   β”œβ”€β”€ src/               # Contract source code
β”‚   β”‚   β”œβ”€β”€ lib.cairo      # Module declarations
β”‚   β”‚   β”œβ”€β”€ market.cairo
β”‚   β”‚   β”œβ”€β”€ market_factory.cairo
β”‚   β”‚   β”œβ”€β”€ collateral_vault.cairo
β”‚   β”‚   β”œβ”€β”€ outcome_token.cairo
β”‚   β”‚   β”œβ”€β”€ oracle.cairo
β”‚   β”‚   β”œβ”€β”€ optimistic_oracle.cairo
β”‚   β”‚   β”œβ”€β”€ price_oracle.cairo
β”‚   β”‚   β”œβ”€β”€ lmsr_market_maker.cairo
β”‚   β”‚   β”œβ”€β”€ lmsr_multi.cairo
β”‚   β”‚   β”œβ”€β”€ arbitration.cairo
β”‚   β”‚   β”œβ”€β”€ resolution_verifier.cairo
β”‚   β”‚   β”œβ”€β”€ launch_config.cairo
β”‚   β”‚   β”œβ”€β”€ stablecoin.cairo
β”‚   β”‚   β”œβ”€β”€ dummy_market.cairo
β”‚   β”‚   └── dummy_oracle.cairo
β”‚   └── tests/             # Integration tests
β”‚       β”œβ”€β”€ contracts/
β”‚       └── test_cairox.cairo
β”œβ”€β”€ oracle-agent/          # Python oracle for market resolution
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ agent.py       # Main agent logic
β”‚   β”‚   β”œβ”€β”€ growthepie.py  # Growthepie API client
β”‚   β”‚   β”œβ”€β”€ resolver.py    # Resolution logic
β”‚   β”‚   └── contracts.py   # Starknet bindings
β”‚   β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ specs/
β”‚   └── requirements.txt
β”œβ”€β”€ indexer/               # Off-chain event indexer
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ tests/
β”‚   └── requirements.txt
β”œβ”€β”€ bot/                   # Oracle feeder bot
β”‚   └── oracle_feeder.py
β”œβ”€β”€ scripts/               # Utility scripts
β”‚   β”œβ”€β”€ e2e_testnet_daa_cycle.py
β”‚   └── oracle_run_once.py
β”œβ”€β”€ specs/                 # Market specifications
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ DEPLOYMENT.md
β”‚   β”œβ”€β”€ MARKET_SPEC.md
β”‚   β”œβ”€β”€ INVARIANTS.md
β”‚   └── THREAT_MODEL.md
β”œβ”€β”€ zk/                    # ZK tooling and circuits
β”œβ”€β”€ .github/workflows/     # CI/CD
β”‚   └── ci.yml
β”œβ”€β”€ Makefile
β”œβ”€β”€ README.md
β”œβ”€β”€ SETUP.md
└── DEVNET.md

Data Integration

Growthepie API

Cairox uses the Growthepie API for objective ecosystem metrics:

Base URL: https://api.growthepie.com/v1

Available Endpoints:

  • /v1/master.json - Chain metadata
  • /v1/fundamentals.json?metric={metric}&chain={chain} - Historical metrics
  • /v1/export/{metric}.json - Metric exports

Supported Metrics:

  • daa - Daily Active Addresses
  • tvl - Total Value Locked
  • txcount - Transaction Count
  • gas_per_second - Gas usage

Supported Chains:

  • Ethereum, Starknet, Arbitrum, Base, Optimism
  • zkSync Era, Linea, Scroll, Mantle, and others

Example Query

curl "https://api.growthepie.com/v1/fundamentals.json?metric=daa&chain=starknet"

Running Tests

Contract Tests

cd contracts
make test

Or directly with snforge:

cd contracts
snforge test

Oracle Agent Tests

cd oracle-agent
source venv/bin/activate
pytest

Deployment

Local Devnet

make devnet-up
make deploy-local

Testnet (Sepolia)

See DEPLOYMENT.md for detailed instructions.

Mainnet

Mainnet deployment requires:

  1. External oracle (Growthepie API access)
  2. Treasury multisig
  3. Token bridge integration

CI/CD

The project uses GitHub Actions for continuous integration:

  • Contract Compilation: Scarb build verification
  • Tests: snforge unit tests
  • Formatting: Cairo format checks

Workflow runs on:

  • Push to master
  • Pull requests to master
  • Manual dispatch

Documentation

License

MIT License - See LICENSE for details.

Resources

About

Starknet-native prediction market protocol

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages