π€ Immortal AI Trading Bot
An autonomous AI trading agent for BNB Chain that learns and evolves through decentralized memory storage.
Built on: Inspired by hkirat/ai-trading-agent and adapted specifically for BNB Chain with PancakeSwap spot trading and BNB Greenfield immortal memory.
π Features
- AI-Powered Trading: Uses OpenRouter LLMs (GPT-4o-mini) for intelligent trading decisions
- Immortal Memory: Stores trade history on BNB Greenfield for persistent learning
- PancakeSwap Integration: Automated spot trading on BNB Chain DEX
- Risk Management: Built-in stop-loss, position sizing, and safeguards
- Real-Time Alerts: Telegram notifications for trades and events
- $IMMBOT Token: Utility token with staking rewards from bot profits
- Learning Loop: Bot improves by analyzing past successful/failed trades
ποΈ Architecture
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β DexScreener ββββββββββΆβ AI Engine ββββββββββΆβ PancakeSwap β
β (Market β β (OpenRouter)β β (Trades) β
β Data) β ββββββββββββββββ βββββββββββββββ
βββββββββββββββ β β
β β
βΌ βΌ
ββββββββββββββββββββ βββββββββββββββββββ
β BNB Greenfield β β Smart Contracts β
β (Immortal Memory)β β ($IMMBOT) β
ββββββββββββββββββββ βββββββββββββββββββ
π Prerequisites
- Bun (v1.0+): Fast JavaScript runtime
- Node.js 18+ (alternative to Bun)
- BNB Chain Wallet: With testnet BNB for testing
- API Keys:
- OpenRouter API key (https://openrouter.ai)
- Telegram Bot Token (optional, from @BotFather)
π Quick Start
1. Installation
# Clone the repository
git clone https://github.com/YOUR_USERNAME/immortal-bnb.git
cd immortal-bnb
# Install dependencies
bun install
# Copy environment template
cp .env.example .env
2. Configuration
Edit .env with your credentials:
# OpenRouter API Key (get from https://openrouter.ai/signup)
OPENROUTER_API_KEY=your_key_here
# BNB Chain RPC (testnet for development)
BNB_RPC=https://bsc-testnet.bnbchain.org
# Your wallet private key (NEVER share this!)
WALLET_PRIVATE_KEY=your_test_wallet_private_key
# Telegram (optional)
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Network
NETWORK=testnet
3. Get Testnet BNB
Get free testnet BNB from the faucet:
4. Run the Bot
# Start bot in development mode (auto-reload)
bun run dev
# Or run production mode
bun run start
π― How It Works
Trading Loop (Every 5 Minutes)
- Fetch Market Data: Gets token prices, volume, liquidity from DexScreener
- Fetch Memories: Retrieves past trade outcomes from Greenfield storage
- AI Decision: Analyzes data + memories to decide: buy/sell/hold
- Execute Trade: If confidence > 50%, executes on PancakeSwap
- Store Memory: Records trade details in immortal storage
- Alert User: Sends Telegram notification
Example AI Decision
{
"action": "buy",
"amount": 0.05,
"confidence": 0.82,
"reason": "Strong buy pressure (+0.45), high volume ($500K), similar to profitable memory #12",
"riskLevel": "medium",
"stopLoss": 0.000098
}
Memory Learning
The bot learns by:
- Storing every trade outcome (profit/loss)
- Analyzing market conditions during success/failure
- Including past memories in future AI prompts
- Adapting strategies based on historical performance
π $IMMBOT Token
Token Features
- Symbol: IMMBOT
- Tax: 2% on transfers (1% burn, 1% liquidity)
- Utility: Stake to earn from bot trading profits
- Governance: Future DAO voting rights
Staking Tiers
| Duration | APY | Min Stake |
|---|---|---|
| 30 days | 5% | 1000 |
| 90 days | 15% | 1000 |
| 180 days | 30% | 1000 |
| 365 days | 50% | 1000 |
Deploy Contracts
- Open Remix IDE: https://remix.ethereum.org
- Copy
contracts/IMMBotToken.solandcontracts/Staking.sol - Install OpenZeppelin:
npm install @openzeppelin/contracts - Compile with Solidity 0.8.20+
- Deploy to BNB Testnet via MetaMask
- Update
.envwith deployed addresses:IMMBOT_TOKEN_ADDRESS=0x...
π Configuration
Trading Parameters
Edit src/config.ts:
MAX_TRADE_AMOUNT_BNB: 0.1, // Max BNB per trade
STOP_LOSS_PERCENTAGE: 5, // Auto-sell if -5%
MAX_SLIPPAGE_PERCENTAGE: 2, // Max price slippage
BOT_LOOP_INTERVAL_MS: 300000, // 5 minutes
Token Watchlist
Add tokens to monitor:
DEFAULT_WATCHLIST: [
'0x...', // Token address 1
'0x...', // Token address 2
]
Or leave empty to auto-track trending tokens.
π§ͺ Testing
# Run unit tests
bun test
# Test specific module
bun test src/agent/aiDecision.test.ts
π± Telegram Setup
- Create bot: Talk to @BotFather on Telegram
- Get token:
/newbotβ Follow prompts - Get chat ID: Send message to bot, then:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates - Add to
.env
π‘οΈ Safety Features
- Stop-Loss: Auto-sells at configured loss threshold
- Position Sizing: Limits based on account balance
- Cooldowns: Prevents over-trading same token
- Rate Limiting: Respects API limits
- Gas Estimation: Checks costs before execution
- Slippage Protection: Rejects unfavorable prices
π Monitoring
Logs
Logs are saved in logs/:
combined.log: All logserror.log: Errors only
Telegram Alerts
Receive notifications for:
- AI decisions
- Trade executions
- Profit/loss outcomes
- Errors and warnings
π Frontend Dashboard (Optional)
cd apps/frontend
bun install
bun dev
Access at: http://localhost:3000
Features:
- Connect wallet
- View active positions
- See trade history
- Monitor bot status
π BNB Hackathon Submission
This bot targets the Unibase Challenge:
- β Autonomous AI agent
- β On-chain execution (PancakeSwap)
- β Decentralized memory (Greenfield)
- β Learning/evolution capabilities
- β Token economy ($IMMBOT)
π οΈ Development
Project Structure
immortal-bnb/
βββ src/
β βββ agent/ # AI decision engine
β βββ blockchain/ # Trade execution & memory
β βββ data/ # Market data fetching
β βββ utils/ # Helpers & safeguards
β βββ alerts/ # Telegram notifications
β βββ config.ts # Configuration
β βββ index.ts # Main bot loop
βββ contracts/ # Solidity smart contracts
βββ apps/frontend/ # Next.js dashboard
βββ tests/ # Unit tests
βββ logs/ # Runtime logs
Adding New Features
- New Trading Strategy: Modify
src/agent/aiDecision.ts - Additional DEX: Create new executor in
src/blockchain/ - Custom Indicators: Add to
src/data/marketFetcher.ts
β οΈ Disclaimer
This is experimental software for educational purposes.
- Use at your own risk
- Start with testnet
- Never invest more than you can afford to lose
- Crypto trading is highly risky
- Bot performance is not guaranteed
- Always do your own research (DYOR)
π License
MIT License - see LICENSE file
π€ Contributing
Contributions welcome! Please:
- Fork the repo
- Create feature branch
- Make changes
- Submit PR
π Links
- GitHub: https://github.com/YOUR_USERNAME/immortal-bnb
- BNB Chain Docs: https://docs.bnbchain.org
- PancakeSwap: https://pancakeswap.finance
- OpenRouter: https://openrouter.ai
- BNB Greenfield: https://greenfield.bnbchain.org
π Support
- Issues: GitHub Issues
- Telegram: [Your community channel]
- Twitter: @arhansubasi0
Built with β€οΈ for the BNB Hackathon π
"An AI that never forgets"
Description
Languages
TypeScript
94.9%
JavaScript
2.7%
Shell
1.9%
Python
0.2%
Dockerfile
0.1%