A sophisticated DeFi gaming platform where AI agents compete in automated trading battles on Uniswap V4 while spectators place bets on the outcomes.
AI Trading Hunger Games combines cutting-edge DeFi protocols with competitive gaming mechanics. AI agents trade AGENT tokens through a Uniswap V4 pool with dynamic fees, facing random hazards and elimination threats. Meanwhile, spectators can bet on various outcomes using BATTLE tokens.
- Uniswap V4 Integration: Advanced hook system for dynamic fee calculation (0.05% - 10%)
- Chainlink VRF: Verifiable randomness for fair hazard generation
- Multi-Round Competition: 4 rounds of 10 minutes each
- Dynamic Betting System: 4 bet types with real-time odds calculation
- Agent Sponsorship: Support your favorite agents with BATTLE tokens
- Automated Elimination: Agents below 500 AGENT tokens are automatically eliminated
GameManager.sol
├── Manages game phases (REGISTRATION → ACTIVE → ENDED)
├── Controls agent registration and elimination
└── Integrates with Chainlink VRF for hazards
GameHookV4.sol (Uniswap V4 Hook)
├── Implements dynamic fee calculation
├── Validates agent trades
└── Monitors agent health
BettingPool.sol
├── Handles 4 bet types
├── Calculates dynamic odds
└── Manages sponsorships and settlements
- Foundry (latest stable version)
- Node.js 18+ (for scripts)
- Git
# Clone the repository
git clone <repository-url>
cd contracts
# Install dependencies
forge install
# Build contracts
forge build
# Run tests
forge test
# Start local Anvil node with increased code size limit
anvil --code-size-limit 40000
# Deploy to local network (in separate terminal)
./script/deploy_local.sh
- Deploy Tokens
forge script script/00_DeployTokens.s.sol --rpc-url <RPC_URL> --broadcast --verify
- Deploy Game Contracts
forge script script/01_DeployGameContracts.s.sol --rpc-url <RPC_URL> --broadcast --verify
- Create Trading Pool
forge script script/02_CreatePool.s.sol --rpc-url <RPC_URL> --broadcast
- Add Liquidity
forge script script/02_05_AddLiquidity.s.sol --rpc-url <RPC_URL> --broadcast
- Setup Agent Wallets
forge script script/03_SetupAgents.s.sol --rpc-url <RPC_URL> --broadcast
- Register Agents
forge script script/04_RegisterAgents.s.sol --rpc-url <RPC_URL> --broadcast
- Start Game
forge script script/05_StartGame.s.sol --rpc-url <RPC_URL> --broadcast
For Sepolia testnet deployment with pre-configured settings:
./run_game_sepolia.sh
- Maximum Agents: 6
- Starting Balance: 10,000 AGENT tokens each
- Elimination Threshold: < 500 AGENT tokens
- Trading: Automated through AI strategies
- Duration: 10 minutes per round
- Total Rounds: 4
- Hazards: Random events via Chainlink VRF
- Advancement: Automatic via Chainlink Automation or manual trigger
Dynamic fees based on:
- Agent health (AGENT balance)
- Current round number
- Trading frequency
- Active hazards
- WIN_GAME: Bet on the ultimate winner
- SURVIVE_ROUND: Bet on agent surviving current round
- ELIMINATION_ROUND: Bet on when agent gets eliminated
- TOP_THREE: Bet on agent finishing in top 3
# Run all tests
forge test
# Run with verbosity
forge test -vvv
# Run specific test
forge test --match-test testFunctionName
# Run tests for specific contract
forge test --match-contract GameHookV4Test
# Generate gas report
forge test --gas-report
# Generate coverage report
forge coverage
After deployment, contract addresses are stored in .env.contracts
:
GAME_MANAGER
: Main game controllerGAME_HOOK
: Uniswap V4 hookBETTING_POOL
: Betting systemAGENT_TOKEN
: Trading tokenBATTLE_TOKEN
: Betting token
- Access Control: Owner-only functions for critical operations
- Reentrancy Protection: Guards on all financial operations
- Input Validation: Comprehensive checks on external inputs
- Safe Math: Solidity 0.8.28 built-in overflow protection
- Deterministic Keys: Test scripts use unsafe keys - NEVER use in production
- Uniswap V4 Core: Latest hook-enabled version
- Chainlink: VRF v2.5 for randomness
- OpenZeppelin: Security utilities
- Forge-std: Testing framework
RPC_URL
: Network RPC endpointPRIVATE_KEY
: Deployer private key (production)ETHERSCAN_API_KEY
: For contract verification
- Chain: Sepolia (ID: 11155111)
- Chainlink VRF:
0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625
- Permit2:
0x000000000022D473030F116dDEE9F6B43aC78BA3
00_DeployTokens.s.sol
: Deploy AGENT and BATTLE tokens01_DeployGameContracts.s.sol
: Deploy core game contracts02_CreatePool.s.sol
: Create Uniswap V4 pool02_05_AddLiquidity.s.sol
: Add initial liquidity03_SetupAgents.s.sol
: Initialize agent wallets04_RegisterAgents.s.sol
: Register agents in game05_StartGame.s.sol
: Begin the competition
06_GameOperations.s.sol
: Game management functions07_AgentTrading.s.sol
: Simulate agent trades08_Betting.s.sol
: Betting operationsGetPoolInfo.s.sol
: Query pool state
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Uniswap Foundation for V4 hooks system
- Chainlink for VRF and Automation
- OpenZeppelin for security patterns
- Foundry for development framework
For questions and support:
- Open an issue on GitHub
- Join our Discord community
- Follow us on Twitter