ankanz1/Mango.Tree

A decentralized betting game built on Celo with intent-based cross-chain payouts.

β˜… 0Forks 0TypeScriptGitHub β†—Compare

Project website β†—

README

🌳 Mango Tree - Decentralized Betting Platform

A fully functional, cross-chain, decentralized betting platform built on Celo with cross-chain payout intents powered by Axelar.

image

πŸš€ Features

✨ Core Features

  • 🎲 Multi-Game Betting: CoinFlip, LuckyDice, MangoSpin games
  • πŸŒ‰ Cross-Chain Payouts: Transfer winnings to any supported blockchain
  • ⚑ Real-Time Updates: Live feed with WebSocket connections
  • πŸ† Leaderboards: Track top performers and statistics
  • πŸ”’ Secure Escrow: Smart contract-based fund management
  • πŸ“± Responsive Design: Beautiful dark theme with animations

πŸ”§ Technical Features

  • Smart Contracts: Deployed on Celo with Solidity
  • Cross-Chain Bridge: Axelar integration for multi-chain transfers
  • Real-Time API: WebSocket-powered live updates
  • Wallet Integration: Valora, MetaMask, WalletConnect support
  • Database: MongoDB for data persistence
  • Security: Role-based access control and audit trails

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   Blockchain    β”‚
β”‚   (Next.js)     │◄──►│   (Node.js)     │◄──►│   (Hardhat)     β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ React/Next.js β”‚    β”‚ β€’ Express API   β”‚    β”‚ β€’ Solidity      β”‚
β”‚ β€’ Wagmi/Rainbow β”‚    β”‚ β€’ WebSocket     β”‚    β”‚ β€’ Axelar Bridge β”‚
β”‚ β€’ Framer Motion β”‚    β”‚ β€’ MongoDB       β”‚    β”‚ β€’ Event Listenersβ”‚
β”‚ β€’ Tailwind CSS  β”‚    β”‚ β€’ Real-time     β”‚    β”‚ β€’ Solver Serviceβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

Mango.Tree/
β”œβ”€β”€ Backend/                 # Node.js API Server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/     # API Controllers
β”‚   β”‚   β”œβ”€β”€ routes/          # Express Routes
β”‚   β”‚   β”œβ”€β”€ services/        # Business Logic
β”‚   β”‚   β”œβ”€β”€ blockchain/      # Blockchain Integration
β”‚   β”‚   β”œβ”€β”€ models/          # Database Models
β”‚   β”‚   └── utils/           # Utilities
β”‚   └── package.json
β”œβ”€β”€ Frontend/                # Next.js Frontend
β”‚   β”œβ”€β”€ app/                 # App Router
β”‚   β”œβ”€β”€ components/          # React Components
β”‚   β”œβ”€β”€ hooks/               # Custom Hooks
β”‚   β”œβ”€β”€ lib/                 # Utilities
β”‚   └── package.json
β”œβ”€β”€ Blockchain/              # Smart Contracts
β”‚   β”œβ”€β”€ contracts/           # Solidity Contracts
β”‚   β”œβ”€β”€ scripts/             # Deployment Scripts
β”‚   β”œβ”€β”€ services/            # Blockchain Services
β”‚   └── package.json
└── scripts/                 # Deployment Scripts

🎯 Current Status

βœ… LIVE DEPLOYMENT

  • Network: Celo Sepolia Testnet (Chain ID: 11142220)
  • Status: All 7 contracts deployed and functional
  • Total Gas Used: 8,262,422
  • Deployment Cost: 0.8262422 CELO
  • Deployer: 0xC0Aa6fb8641c2b014d86112dB098AAb17bcc9b13

πŸ“‹ Deployment Checklist

  • βœ… Smart Contracts Deployed
  • βœ… Contract Addresses Generated
  • βœ… CeloScan Links Available
  • πŸ”„ Backend Integration (In Progress)
  • πŸ”„ Frontend Integration (In Progress)
  • πŸ”„ Cross-Chain Bridge Setup (Planned)

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or pnpm
  • Git
  • MongoDB (for backend)
  • Wallet with testnet funds

1. Clone Repository

git clone https://github.com/your-username/mango-tree.git
cd mango-tree

2. Install Dependencies

# Install all dependencies
npm run install:all

# Or install individually
cd Backend && npm install
cd ../Frontend && npm install
cd ../Blockchain && npm install

3. Setup Environment

# Copy environment files
cp Backend/.env.example Backend/.env
cp Blockchain/env.example Blockchain/.env
cp Frontend/.env.example Frontend/.env.local

# Update with your configuration

4. Deploy Smart Contracts

# Deploy all contracts to Celo Sepolia
cd Blockchain
npm run mango:deploy-all

5. Start Development Servers

# Start Backend (Terminal 1)
cd Backend && npm run dev

# Start Frontend (Terminal 2)  
cd Frontend && npm run dev

6. Access the Platform

πŸ”§ Manual Setup

Backend Setup

cd Backend
npm install
npm run dev

Frontend Setup

cd Frontend
npm install
npm run dev

Blockchain Setup

cd Blockchain
npm install
npm run compile
npm run mango:deploy-all  # Deploy all contracts to Celo Sepolia

πŸ“š API Documentation

Bet Management

  • POST /api/bets - Create a new bet
  • POST /api/bets/:id/join - Join an existing bet
  • POST /api/bets/:id/resolve - Resolve a bet
  • GET /api/bets - Get active bets
  • GET /api/bets/user/:address - Get user's bets

Payout System

  • POST /api/payout/payout-intent - Create payout intent
  • POST /api/payout/confirm-payout - Confirm payout
  • GET /api/payout/payout-intents/:address - Get user's payouts

Leaderboard

  • GET /api/leaderboard - Get leaderboard
  • GET /api/leaderboard/user/:address/rank - Get user rank
  • GET /api/leaderboard/top-performers - Get top performers

Real-Time Feed

  • GET /api/feed/live - Get live activity feed
  • GET /api/feed/recent - Get recent activity
  • GET /api/feed/stats - Get feed statistics

πŸ”— Smart Contracts

Core Contracts

  • BetContract: Main betting logic and fund management
  • BetEscrow: Secure escrow for bet funds
  • IntentRouter: Cross-chain payout intent management
  • GameLogic: Game mechanics and VRF integration
  • VRFConsumer: Verifiable Random Function consumer
  • MockToken: Test ERC20 token for development
  • MangoTree: Treasury and fund management contract

Deployment Addresses

// Celo Sepolia (Testnet) - LIVE βœ…
BetContract: "0x9c4Ab9bdb97342A31cf0e2632610957cF633978C"
BetEscrow: "0x070021DC542C5b5b7e9aeBDB72aa6Cabda88905D"
IntentRouter: "0x0CFe46e97865ece06b0CfaD2CB8069833399986a"
MockToken: "0xD51Aa28401Ccf5ed584D5c1520857FD6Cd067A0a"
GameLogic: "0x6fbBe3dCb9E2110aA5aaf0198d34880f6639bEA4"
VRFConsumer: "0x10Ae60ADe4F5223C89EF958E1Df017737D0f0c8E"
MangoTree: "0x1bdE57E8Bfa994E4998F82Fa267b9f62fE6Ee9e4"

// Network: Celo Sepolia (Chain ID: 11142220)
// Deployer: 0xC0Aa6fb8641c2b014d86112dB098AAb17bcc9b13
// Total Gas Used: 8,262,422
// Total Cost: 0.8262422 CELO

πŸ”— Direct Contract Links

🌐 Supported Networks

Network Chain ID Status RPC URL
Celo 42220 πŸ”„ Planned https://forno.celo.org
Celo Sepolia 11142220 βœ… LIVE https://forno.celo-sepolia.celo-testnet.org
Celo Alfajores 44787 πŸ”„ Planned https://alfajores-forno.celo-testnet.org
Polygon 137 πŸ”„ Planned https://polygon-rpc.com
Polygon Mumbai 80001 πŸ”„ Planned https://rpc-mumbai.maticvigil.com
Ethereum 1 πŸ”„ Planned https://mainnet.infura.io/v3/YOUR_KEY
Base 8453 πŸ”„ Planned https://mainnet.base.org

πŸ”’ Security Features

Smart Contract Security

  • βœ… Reentrancy Protection: All external calls protected
  • βœ… Access Control: Role-based permissions
  • βœ… Input Validation: Comprehensive parameter validation
  • βœ… Emergency Functions: Pause/unpause capabilities
  • βœ… Fee Limits: Maximum fee caps (10%)

Backend Security

  • βœ… Input Sanitization: All inputs validated
  • βœ… Rate Limiting: API rate limiting
  • βœ… CORS Protection: Cross-origin request protection
  • βœ… Authentication: Wallet-based authentication
  • βœ… Audit Logging: Comprehensive event logging

πŸ“Š Monitoring & Analytics

Real-Time Metrics

  • Live bet activity
  • Cross-chain transfer status
  • User leaderboard rankings
  • Platform statistics

WebSocket Events

// Bet Events
'bet:created' - New bet created
'bet:joined' - User joined bet
'bet:resolved' - Bet resolved

// Payout Events
'payout:intent:created' - Payout intent created
'payout:completed' - Payout completed

// Leaderboard Events
'leaderboard:update' - Leaderboard updated

πŸ§ͺ Testing

Smart Contract Tests

cd Blockchain
npm test
npm run test:coverage

Backend API Tests

cd Backend
npm test

Frontend Tests

cd Frontend
npm test

πŸš€ Deployment

Production Deployment

# Deploy smart contracts to Celo Sepolia
cd Blockchain && npm run mango:deploy-all

# Deploy backend
cd Backend && npm run build && npm start

# Deploy frontend  
cd Frontend && npm run build && npm start

Environment Variables

# Backend
MONGODB_URI=mongodb://localhost:27017/mango-tree
RPC_URL=https://forno.celo-sepolia.celo-testnet.org
PRIVATE_KEY=your_private_key
INTENT_ROUTER_ADDRESS=0x0CFe46e97865ece06b0CfaD2CB8069833399986a
BET_CONTRACT_ADDRESS=0x9c4Ab9bdb97342A31cf0e2632610957cF633978C

# Frontend
NEXT_PUBLIC_API_URL=http://localhost:5000
NEXT_PUBLIC_WS_URL=ws://localhost:5000
NEXT_PUBLIC_CHAIN_ID=11142220
NEXT_PUBLIC_BET_CONTRACT=0x9c4Ab9bdb97342A31cf0e2632610957cF633978C

# Blockchain
PRIVATE_KEY=your_private_key
CELO_RPC_URL=https://forno.celo-sepolia.celo-testnet.org
CELOSCAN_API_KEY=your_celoscan_key

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸ™ Acknowledgments


Decentralized betting for the future of gaming 🎲🌳

Contributors

ankanz1

Issues