A privacy-preserving Dollar-Cost Averaging (DCA) bot with transaction batching using the Zama Confidential Blockchain Protocol. This bot executes automated strategies while maintaining user privacy through a novel batching mechanism.
- Privacy-Preserving DCA: Encrypted strategy parameters using FHE
- Transaction Batching: Aggregates multiple users' orders for anonymity
- MEV Protection: Prevents front-running through batching
- Telegram Bot Interface: Easy-to-use bot for strategy management
- Real-time Monitoring: Track strategies and batch execution
- ๐ FHE Encryption: All strategy parameters encrypted on-chain
- ๐ Batch Anonymity: Individual amounts hidden within batches
- ๐ No Strategy Exposure: Individual strategies never revealed
- ๐ MEV Protection: Large batch transactions prevent front-running
/start- Welcome and overview/create- Create new DCA strategy/status- View active strategies/portfolio- Portfolio overview/batches- Batch execution status/price- Current ETH/USDC price/gas- Network gas prices/stats- Bot statistics/help- Complete command reference
PrivacyDCABot.sol: Core DCA logic with FHE integrationUniswapIntegration.sol: DEX interaction for token swapsFHEUtils.sol: FHE operation utilities
- Main Bot: User interaction and command handling
- Blockchain Service: Smart contract integration
- Batch Service: Transaction batching management
- Configuration: Centralized settings management
- Strategy Creation: Parameters encrypted using FHE
- Batch Formation: Encrypted amounts aggregated
- Execution: Single decrypted swap on DEX
- Distribution: Proportional token distribution
- Node.js 18+ and npm
- Telegram Bot Token (from @BotFather)
- Ethereum wallet with Sepolia testnet ETH
- Access to Sepolia RPC endpoint
# Clone repository
git clone <repository-url>
cd privacy-dca-bot
# Install dependencies
npm install
# Copy environment configuration
cp env.example .env
# Edit .env with your settings
nano .env# Required settings
TELEGRAM_BOT_TOKEN=your_bot_token_here
RPC_URL=https://sepolia.infura.io/v3/YOUR_PROJECT_ID
PRIVATE_KEY=your_wallet_private_key
# Optional settings
NETWORK=sepolia
LOG_LEVEL=info
BATCH_SIZE=10
BATCH_TIMEOUT=300# Compile smart contracts
npm run build
# Deploy to local network
npm run deploy:local
# Deploy to Sepolia testnet
npm run deploy
# Start Telegram bot
npm run bot- Start a chat with the bot on Telegram
- Send
/createto begin strategy creation - Follow the step-by-step wizard:
- Set total budget in USDC
- Define purchase amount per interval
- Choose frequency (daily/weekly/monthly)
- Set timeframe or make indefinite
- Optionally enable dynamic conditions
- Strategy is automatically encrypted and deployed
- Budget: Total USDC amount to invest
- Purchase Amount: Amount per interval
- Frequency: Time between purchases
- Timeframe: Strategy duration
- Dynamic Conditions: Optional "buy the dip" logic
/status- View active strategies/portfolio- Check performance metrics/batches- Monitor batch execution/price- Current market prices/gas- Network conditions
- All strategy parameters encrypted before blockchain submission
- Encrypted data stored on-chain using Zama's FHEVM
- Computations performed on encrypted values
- Only aggregated totals decrypted for DEX execution
- Multiple users' orders aggregated into single transactions
- Individual amounts and timing concealed within batches
- Provides k-anonymity (where k = batch size)
- Prevents MEV attacks and portfolio tracking
- Individual Strategy Privacy: No single user's strategy revealed
- Amount Privacy: Individual purchase amounts hidden
- Timing Privacy: Purchase timing concealed through batching
- Pattern Privacy: Trading patterns obfuscated
# Run all tests
npm test
# Run specific test file
npx hardhat test test/PrivacyDCABot.test.js# Start bot in development mode
npm run bot:dev
# Test commands via Telegram
# Check logs for errors
tail -f logs/bot.log// Batch configuration
BATCH_SIZE=10 // Target batch size
BATCH_TIMEOUT=300 // Timeout in seconds
MIN_BATCH_SIZE=3 // Minimum batch size
MAX_BATCH_SIZE=20 // Maximum batch size
// Network settings
NETWORK=sepolia // Target network
RPC_URL=your_rpc_url // RPC endpoint
PRIVATE_KEY=your_key // Wallet private keyMAX_FEE_PER_GAS=30000000000 // 30 Gwei
MAX_PRIORITY_FEE_PER_GAS=2000000000 // 2 Gweinpm run bot:dev# Set environment
NODE_ENV=production
# Start bot
npm run bot
# Or use PM2
pm2 start bot/telegram-bot.js --name "privacy-dca-bot"# Build image
docker build -t privacy-dca-bot .
# Run container
docker run -d --name dca-bot --env-file .env privacy-dca-bot- Configurable batch sizes (3-20 users)
- Automatic execution triggers
- Timeout-based fallback execution
- Parallel batch processing
- Real-time batch status updates
- Performance metrics tracking
- Error logging and alerting
- User engagement analytics
- Multi-chain support (Polygon, Arbitrum)
- Advanced dynamic conditions
- Portfolio rebalancing
- Social trading features
- Mobile app integration
- Database integration
- Redis caching layer
- Load balancing
- Microservices architecture
- Kubernetes deployment
- Technical Design - Detailed architecture and implementation
- Bot Documentation - Telegram bot setup and usage
- Smart Contract API - Contract function reference
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This is experimental software implementing privacy-preserving DeFi strategies. Use at your own risk. Never use with real funds until thoroughly tested and audited.
- Create an issue for bugs or feature requests
- Check the documentation for common questions
- Join our community for discussions and help
Built with โค๏ธ using Zama's FHE technology for a more private DeFi future.