⚔️ AI-powered trading bot for MortalCoin PvP battles ⚔️
🎮 Play MortalCoin • 🌐 Website • 📄 Whitepaper • 📚 Smart Contracts • 🛠️ CLI Tool
AI-powered trading bot for MortalCoin game using Alith AI for intelligent decision making.
- 🤖 AI-Powered Trading: Uses Alith AI to make intelligent trading decisions
- 🔄 Automated Game Management: Monitors and joins games automatically
- 📊 Real-time Price Analysis: Analyzes Uniswap V2 pool prices in real-time
- 💾 Trade History: Maintains complete history of games and positions
- 🔐 Secure: All signatures obtained through backend API
- 🐳 Docker Support: Easy deployment with Docker
- Game Manager: Handles game lifecycle and coordination
- Alith AI Client: Integrates with Alith AI for trading decisions
- Backend Client: Communicates with MortalCoin backend API for signatures
- Price Feed: Monitors Uniswap V2 pools for real-time price data
- Database: SQLite storage for game and position history
- Blockchain Module: Self-contained blockchain interaction utilities
- Python 3.8+
- Ethereum wallet with ETH for gas and betting
- Alith AI API credentials
- Access to MortalCoin backend API
-
Clone the repository:
git clone https://github.com/MortalCoin/mortalcoin_alith_bot cd mortalcoin_alith_bot -
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
cp env.example .env # Edit .env with your settings -
Required environment variables:
MORTALCOIN_RPC_URL: Ethereum RPC endpointMORTALCOIN_CONTRACT_ADDRESS: MortalCoin contract addressMORTALCOIN_BOT_PRIVATE_KEY: Bot's private key (with or without 0x prefix)MORTALCOIN_HEADLESS_AUTH: Enable headless EIP-191 auth (1/0, default 1)MORTALCOIN_HEADLESS_MESSAGE: Message to sign for headless auth (default: Login MortalCoin headless)MORTALCOIN_PRIVY_USER_ID: Optional Privy user id for backend mapping when using headless authMORTALCOIN_PRIVY_KEY: Legacy Privy key (required only if headless is disabled or as fallback)MORTALCOIN_BACKEND_API_URL: Backend API URL (default: https://testapi.mortalcoin.app)OPENAI_API_KEY: Your OpenAI API key (used by Alith)MORTALCOIN_BOT_POOL_ADDRESS: Bot's whitelisted pool address
python main.py runpython main.py statuspython main.py history --limit 10python test_bot.pydocker build -t mortalcoin_alith_bot .
docker run --env-file .env mortalcoin_alith_botdocker-compose up -dMORTALCOIN_BET_AMOUNT: Bet amount in ETH (default: 0.0001)MORTALCOIN_POSITION_HOLD_MIN:Minimum position hold time in seconds (default: 10)Removed - no minimum hold time restrictionMORTALCOIN_POSITION_HOLD_MAX: Maximum position hold time in seconds (default: 50)
ALITH_MODEL: AI model to use (default: gpt-4)- Custom prompts can be configured in
alith_client.py
- Game Discovery: Bot monitors the blockchain for available games
- Signature Exchange: Obtains join signatures from backend API
- Game Entry: Joins games with appropriate bet amount
- Market Analysis: Monitors Uniswap V2 pool prices in real-time
- AI Decision Making: Alith AI analyzes market conditions and opponent behavior
- Position Management: Opens/closes positions based on AI recommendations
- Game Completion: Handles game ending and settlement
This bot uses Alith AI - a decentralized AI network for building autonomous agents.
Alith AI is part of the Laz AI ecosystem, providing:
- Decentralized AI Agents: Run AI models without centralized control
- Customizable Behavior: Fine-tune agent responses and strategies
- Real-time Decision Making: Fast inference for time-sensitive trading
- Secure Execution: Your strategies remain private
The bot leverages Alith AI to:
- Analyze Market Conditions: Evaluate price trends and volatility
- Assess Opponent Behavior: Understand opponent's trading patterns
- Make Trading Decisions: Determine when to open/close positions
- Risk Management: Balance aggressive vs conservative strategies
Learn more about Alith AI:
/api/v1/games/join-signature/- Get signature for joining games/api/v1/games/position-signature/- Get signature for posting positions/api/v1/games/available/- Get available games to join/api/v1/pools/{pool_address}/price/- Get price data for pools
The bot includes a self-contained blockchain module that handles:
- Web3 connection management
- Contract interaction
- Transaction building and signing
- Gas estimation and optimization
game_id: Unique game identifierbot_address: Bot's wallet addressopponent_address: Opponent's wallet addressbet_amount: Bet amount in ETHstarted_at: Game start timestampended_at: Game end timestampstatus: Game status (active/completed/error)role: Bot's role (player1/player2)
game_id: Associated game IDdirection: Position direction (Long/Short)nonce: Random nonce for positionopened_at: Position open timestampclosed_at: Position close timestampentry_price: Entry priceexit_price: Exit pricepnl: Position P&Lreasoning: AI reasoning for the position
- Signature Management: All signatures (join game, post position) are now obtained through the backend API
- No Backend Private Key: The bot no longer needs the backend private key
- API Endpoints:
/api/v1/games/join-signature/- Get signature for joining games/api/v1/games/position-signature/- Get signature for posting positions/api/v1/games/available/- Get available games to join/api/v1/pools/{pool_address}/price/- Get price data for pools
- Real Price Data: Prices are calculated directly from Uniswap V2 pool reserves
- Stable Token Support: Handles different stable token positions (token0 or token1)
- Price History: Maintains local price history for trend analysis
- 60 Second Games: All games have a fixed duration of 60 seconds
- Automatic Timeout: Games automatically end after 60 seconds
- API Dependencies: Requires backend API to be available for signatures
- Single Bot Instance: Designed for single bot instance. Multi-bot would need coordination
- Pool Whitelist: Bot can only use whitelisted pools
- Real Price Feeds: Integrate with Chainlink or other oracle services
- Advanced Strategies: Implement more sophisticated trading strategies
- Multi-Game Optimization: Optimize decisions across multiple concurrent games
- Performance Metrics: Add detailed analytics and performance tracking
- Connection errors: Check RPC URL and network connectivity
- Signature failures: Verify backend API is accessible
- Transaction failures: Ensure sufficient ETH for gas
- Pool errors: Verify pool is whitelisted in contract
Bot logs are written to console and can be redirected:
python main.py run > bot.log 2>&1- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MortalCoin is a revolutionary Web3 trading game where players battle using real cryptocurrencies. Think of it as "Mortal Kombat meets DeFi Trading".
- Real Stakes: Players bet actual ETH, not virtual currency
- Winner Takes All: Better price prediction wins the entire pot
- 60-Second Battles: Quick, intense trading duels
- Multiple Pools: Trade on any whitelisted Uniswap V2 pool
- Play Now: stage.mortalcoin.app
- Documentation: docs.mortalcoin.app
- Smart Contracts: github.com/MortalCoin/mortalcoin-evm
- Community: Join us on Telegram and Twitter
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for the MortalCoin ecosystem
- Powered by Alith AI
- Uses Uniswap V2 for price feeds