This folder contains the Soroban smart contracts for the Stellarcade platform. All contracts are written in Rust using the Soroban SDK.
contracts/
├── shared/ # Common types and utilities
├── prize-pool/ # Manages deposits, fees, and distributions
├── treasury/ # Platform treasury for fund allocation
├── random-generator/ # Provably fair RNG contract
├── coin-flip/ # Head-or-tails game
├── daily-trivia/ # Trivia game with reward settlement
├── leaderboard/ # Score tracking and rankings
├── governance-token/ # Platform utility and voting token
├── cross-chain-bridge/ # Asset transfers between chains
├── access-control/ # Role-based access management
├── achievement-badge/ # NFT achievement badges
├── ... # Additional game and utility contracts
└── Cargo.toml # Workspace configuration
Core Infrastructure:
shared/- Common types, traits, and utilitiesaccess-control/- Role-based permissionstreasury/- Fund management and allocation
Gaming Contracts:
coin-flip/- Classic coin flip gamedaily-trivia/- Daily trivia challengesdice-roll/- Dice rolling gamenumber-guess/- Number guessing gamepattern-puzzle/- Pattern matching puzzleswordle-clone/- Wordle-style game
Platform Features:
prize-pool/- Prize pool managementleaderboard/- Global rankingsachievement-badge/- Achievement NFTsgovernance-token/- Governance and votingstaking/- Token staking rewards
Utilities:
random-generator/- Provably fair randomnesscross-chain-bridge/- Cross-chain asset transfersemergency-pause/- Circuit breaker functionality
- Rust (latest stable)
- Soroban CLI
wasm32-unknown-unknowntarget
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install Soroban CLI
cargo install --locked stellar-cli
# Or on macOS
brew install stellar-cli
# Add wasm32 target
rustup target add wasm32-unknown-unknown
# Verify installation
stellar --version
rustc --versionFrom the contracts/ directory:
# Build all contracts in the workspace
soroban contract build
# Or using cargo directly
cargo build --target wasm32-unknown-unknown --releasecd prize-pool
# Build the contract
cargo build --target wasm32-unknown-unknown --release
# Or using Soroban CLI
stellar contract build# Run all contract tests
cargo test
# Run tests for a specific contract
cd prize-pool && cargo test
# Run tests with output
cargo test -- --nocapture
# Run a specific test
cargo test test_deposit# Generate contract documentation
cargo doc --no-deps
# Open documentation in browser
cargo doc --no-deps --open# Build all contracts
soroban contract build
# Run all tests
cargo test
# Run tests with verbose output
cargo test --verbose
# Check code without building
cargo check
# Format code
cargo fmt
# Lint code
cargo clippy -- -D warnings
# Generate documentation
cargo doc --no-deps# Create new contract directory
mkdir my-game
cd my-game
# Initialize Rust project
cargo init --name my_game
# Add Soroban SDK dependency
cargo add stellar-contract --git https://github.com/stellar/rs-soroban-sdk --rev main
cargo add stellar-contract-env --git https://github.com/stellar/rs-soroban-sdk --rev main#![no_std]
use soroban_sdk::{contract, contractimpl, Env, Symbol, Address};
#[contract]
pub struct MyContract;
#[contractimpl]
impl MyContract {
pub fn hello(env: Env, to: Address) -> Symbol {
Symbol::new(&env, "Hello, World!")
}
}#[cfg(test)]
mod test {
use super::*;
use soroban_sdk::{Env, Address};
#[test]
fn test_hello() {
let env = Env::default();
let contract_id = env.register_contract(None, MyContract);
let client = MyContractClient::new(&env, &contract_id);
let to = Address::generate(&env);
let result = client.hello(&to);
assert_eq!(result, Symbol::new(&env, "Hello, World!"));
}
}# Build
cargo build --target wasm32-unknown-unknown --release
# Test
cargo testAll contracts follow security best practices:
- Authorization: Use Soroban's built-in authorization framework
- Overflow Protection: Enable overflow checks in release builds
- Access Control: Implement role-based permissions where needed
- Input Validation: Validate all external inputs
- Event Logging: Emit events for important state changes
- Gas Optimization: Minimize storage and compute usage
- All arithmetic operations use checked arithmetic
- External calls use proper authorization
- State changes emit events
- Access control is properly implemented
- No recursive calls that could exceed compute limits
- Storage keys are properly namespaced
- All tests pass including edge cases
To add a new contract to the workspace:
- Create the contract in a new directory
- Add it to
Cargo.tomlworkspace members:
[workspace]
members = [
# ... existing members
"my-new-contract",
]- Build and test to verify integration
After working with contracts:
- All contracts build without errors
- All tests pass (
cargo test) - Code is formatted (
cargo fmt) - No clippy warnings (
cargo clippy) - Documentation is up to date
- Security considerations are addressed
Error: cannot find type 'Env' in this scope
Solution: Ensure you have the correct imports:
use soroban_sdk::Env;Error: target wasm32-unknown-unknown is not installed
Solution:
rustup target add wasm32-unknown-unknownError: overflow checking requires panic = "abort"
Solution: Add to Cargo.toml:
[profile.release]
panic = "abort"
overflow-checks = trueError: Tests fail with authorization errors
Solution: Ensure proper test setup with mocked authorization:
let env = Env::default();
env.mock_all_auths();Error: stellar: command not found
Solution:
# Install or update
cargo install --locked stellar-cli
# Or update if already installed
stellar --version- Complete Setup Guide - End-to-end local development setup
- Architecture - System design overview
- Game Rules - Game mechanics
- Deployment Guide - Production deployment
- Soroban Documentation - Official Soroban docs
| Contract | Status | Tests | Audit |
|---|---|---|---|
| prize-pool | ✅ Complete | ✅ Passing | ⏳ Pending |
| treasury | ✅ Complete | ✅ Passing | ⏳ Pending |
| random-generator | ✅ Complete | ✅ Passing | ⏳ Pending |
| coin-flip | ✅ Complete | ✅ Passing | ⏳ Pending |
| daily-trivia | ✅ Complete | ✅ Passing | ⏳ Pending |
| leaderboard | ✅ Complete | ✅ Passing | ⏳ Pending |
| governance-token | 🚧 In Progress | 🔄 WIP | ⏳ Pending |
For more details, see the README in each contract subdirectory.
Built with ❤️ for the Stellarcade community.