immortal-bnb/.env.example
Claude a4de72f0c1 feat: Implement production database schema, smart contract integration, and monitoring stack
## Phase 1 Implementation Complete: Database & Smart Contract Infrastructure

### ๐Ÿ—„๏ธ Database Schema (Prisma)
- **14 production-ready models** covering all platform features
- User management with profiles, settings, and privacy controls
- Trading: Trade, Position, Order models with full lifecycle tracking
- AI Agents: Agent and AgentDecision models with performance metrics
- Staking: StakingPosition model with APY and lock period support
- Token: TokenHolder model for IMMBOT token tracking
- Social: CopyTrading and Follow models for social trading
- DeFi: ArbitrageExecution model for flash loan tracking
- Notifications: Multi-channel notification system
- **Strategic indexes** on all high-query fields for performance
- **Backward compatibility** maintained with existing Models, Invocations, ToolCalls

### ๐Ÿ”— Smart Contract Integration
- **Contract ABIs** extracted for IMMBotToken, Staking, FlashLoanArbitrage
- **TypeScript types** generated from ABIs for type-safe contract calls
- **ContractService** class providing clean abstraction for:
  - Token operations (transfer, approve, balanceOf, token info)
  - Staking operations (stake, withdraw, claim rewards, get pools)
  - Arbitrage operations (simulate, execute flash loans)
  - Utility methods (gas estimation, balance checks)
- **Singleton pattern** for global contract service access
- **Comprehensive error handling** and logging

### ๐Ÿณ Docker Infrastructure
- **PostgreSQL 15** with automated backups and health checks
- **Redis 7** for caching with persistence
- **Prometheus** for metrics collection
- **Grafana** for dashboards and visualization
- **Networked services** with proper dependencies and health checks
- **Volume management** for data persistence

### ๐Ÿ“ Environment Configuration
- Added DATABASE_URL for PostgreSQL connection
- Added REDIS_URL for cache configuration
- Added POLYGON_RPC_URL for Polymarket CLOB
- Added contract addresses (IMMBOT_TOKEN_CONTRACT, STAKING_CONTRACT, etc.)
- Added monitoring credentials (Grafana admin)
- Updated both .env.example and .env.development

### ๐Ÿ“š Documentation
- **DATABASE_SETUP.md** - Comprehensive 500+ line setup guide covering:
  - Quick start instructions
  - Database schema overview
  - Migration strategies
  - Seeding examples
  - Production deployment checklist
  - Performance optimization tips
  - Monitoring and troubleshooting
  - Backup and recovery procedures
- Includes code examples for all common operations
- Production security checklist
- Connection pooling strategies

### ๐Ÿ—๏ธ Architecture Improvements
- Service-oriented architecture with clear separation of concerns
- Type-safe contract interactions with ethers.js
- Prepared for horizontal scaling with Redis caching
- Ready for metrics collection with Prometheus
- Foundation for monitoring dashboards with Grafana

### ๐Ÿ“Š Database Models Summary
**Users & Social:**
- User (with stats, settings, profile)
- Follow (social graph)
- CopyTrading (copy trading relationships)

**Trading:**
- Trade (execution history with fees, gas, slippage)
- Position (current holdings with PnL tracking)
- Order (advanced order types: limit, stop-loss, take-profit)

**AI & Automation:**
- Agent (strategy configs, performance metrics)
- AgentDecision (decision logs with reasoning)

**DeFi:**
- StakingPosition (lock periods, APY, rewards)
- TokenHolder (IMMBOT holder tracking)
- ArbitrageExecution (flash loan PnL tracking)

**System:**
- Notification (multi-channel alerts)

### ๐Ÿ”œ Next Steps (Phase 1 Remaining)
1. Initialize contract service in API server
2. Create token backend endpoints (/api/token/*)
3. Create staking backend endpoints (/api/staking/*)
4. Set up Prometheus metrics collection
5. Create Grafana dashboards
6. Build token frontend (/token)
7. Build staking frontend (/staking)

### ๐Ÿ“ฆ Files Changed
- prisma/schema.prisma (67 โ†’ 600 lines, 14 new models)
- docker-compose.yml (added postgres, redis, prometheus, grafana)
- .env.example (added database, redis, contracts, monitoring config)
- .env.development (added same configurations)
- src/contracts/abis.ts (NEW - 3 contract ABIs)
- src/services/contractService.ts (NEW - 500+ lines)
- DATABASE_SETUP.md (NEW - comprehensive setup guide)

This commit completes the foundational infrastructure for production deployment.
All smart contracts can now be integrated with type-safe calls.
Database is ready for migration and seeding.
Monitoring stack is configured and ready to deploy.
2025-11-17 21:27:26 +00:00

126 lines
4.3 KiB
Plaintext

# OpenRouter API Key (get from https://openrouter.ai/signup)
OPENROUTER_API_KEY=your_openrouter_api_key_here
# BNB Chain RPC URLs
BNB_RPC=https://bsc-testnet.bnbchain.org
BNB_MAINNET_RPC=https://bsc-dataseed.bnbchain.org
# opBNB Layer 2 Configuration (Faster & Cheaper - Recommended!)
# opBNB Testnet (for development - 1s blocks, $0.001 gas)
OPBNB_RPC=https://opbnb-testnet-rpc.bnbchain.org
OPBNB_WSS=wss://opbnb-testnet-rpc.bnbchain.org
OPBNB_CHAIN_ID=5611
# opBNB Mainnet (for production)
# OPBNB_RPC=https://opbnb-mainnet-rpc.bnbchain.org
# OPBNB_WSS=wss://opbnb-mainnet-rpc.bnbchain.org
# OPBNB_CHAIN_ID=204
# Choose which network to use for trading (bnb or opbnb)
TRADING_NETWORK=opbnb
# Wallet Configuration (NEVER commit .env with real keys!)
WALLET_PRIVATE_KEY=your_test_wallet_private_key_here
# Telegram Bot Configuration (get from @BotFather on Telegram)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
TELEGRAM_CHAT_ID=your_telegram_chat_id_here
# PancakeSwap Router Addresses (BNB Chain)
PANCAKE_ROUTER_V2=0x10ED43C718714eb63d5aA57B6Da2929C30bC095c
PANCAKE_ROUTER_V3=0x1b81D678ffb9C0263b24A97847620C99d213eB14
# PancakeSwap Addresses (opBNB) - V3 for optimized swaps
OPBNB_PANCAKE_FACTORY=0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865
OPBNB_PANCAKE_ROUTER=0x1b81D678ffb9C0263b24A97847620C99d213eB14
OPBNB_PANCAKE_SMART_ROUTER=0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86
# Token Addresses (BNB Chain)
WBNB_ADDRESS=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
IMMBOT_TOKEN_ADDRESS=your_deployed_token_address_here
# Token Addresses (opBNB)
OPBNB_WBNB_ADDRESS=0x4200000000000000000000000000000000000006
# Trading Configuration
MAX_TRADE_AMOUNT_BNB=0.1
STOP_LOSS_PERCENTAGE=5
MAX_SLIPPAGE_PERCENTAGE=2
# BNB Greenfield Configuration (for immortal memory)
# Testnet RPC (recommended for development)
GREENFIELD_RPC_URL=https://gnfd-testnet-fullnode-tendermint-ap.bnbchain.org
GREENFIELD_CHAIN_ID=5600
GREENFIELD_BUCKET_NAME=immortal-bot-memory
# For mainnet, use:
# GREENFIELD_RPC_URL=https://greenfield-chain.bnbchain.org
# GREENFIELD_CHAIN_ID=1017
# DexScreener API (no key needed for basic usage)
DEXSCREENER_API_URL=https://api.dexscreener.com/latest/dex
# Bot Configuration
BOT_LOOP_INTERVAL_MS=300000
ENABLE_CROSS_CHAIN=false
# API Server Configuration
API_PORT=3001
# Logging Configuration
LOG_LEVEL=info
# Network (testnet or mainnet)
NETWORK=testnet
# ============================================================================
# DATABASE CONFIGURATION
# ============================================================================
# PostgreSQL Database URL
# Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE
# Development (local):
DATABASE_URL=postgresql://immortal:immortal_dev_password@localhost:5432/immortal_bnb
# Production example:
# DATABASE_URL=postgresql://immortal:STRONG_PASSWORD@your-db-host:5432/immortal_bnb
# Database Password (used by docker-compose)
DATABASE_PASSWORD=immortal_dev_password
# ============================================================================
# REDIS CONFIGURATION
# ============================================================================
# Redis URL for caching
# Development (local):
REDIS_URL=redis://localhost:6379
# Production with password:
# REDIS_URL=redis://:password@your-redis-host:6379
# ============================================================================
# SMART CONTRACT CONFIGURATION
# ============================================================================
# Deployed Contract Addresses (BSC/opBNB)
IMMBOT_TOKEN_CONTRACT=your_deployed_token_address_here
STAKING_CONTRACT=your_deployed_staking_address_here
FLASH_LOAN_ARBITRAGE_CONTRACT=your_deployed_arbitrage_address_here
# Contract Deployment Network
CONTRACT_NETWORK=opbnb-testnet # or bsc-testnet, opbnb, bsc
# ============================================================================
# BLOCKCHAIN RPC CONFIGURATION
# ============================================================================
# Polygon RPC (for Polymarket CLOB)
POLYGON_RPC_URL=https://polygon-rpc.com
POLYGON_WALLET_PRIVATE_KEY=your_polygon_wallet_private_key_here
# ============================================================================
# MONITORING CONFIGURATION
# ============================================================================
# Grafana Admin Credentials
GRAFANA_ADMIN_USER=admin
GRAFANA_ADMIN_PASSWORD=admin