Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mahmudsudo/dca_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Privacy-Preserving DCA Bot

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.

๐Ÿš€ Features

Core Functionality

  • 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

Privacy Features

  • ๐Ÿ”’ 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

Bot Commands

  • /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

๐Ÿ—๏ธ Architecture

Smart Contracts

  • PrivacyDCABot.sol: Core DCA logic with FHE integration
  • UniswapIntegration.sol: DEX interaction for token swaps
  • FHEUtils.sol: FHE operation utilities

Telegram Bot

  • Main Bot: User interaction and command handling
  • Blockchain Service: Smart contract integration
  • Batch Service: Transaction batching management
  • Configuration: Centralized settings management

Privacy Implementation

  1. Strategy Creation: Parameters encrypted using FHE
  2. Batch Formation: Encrypted amounts aggregated
  3. Execution: Single decrypted swap on DEX
  4. Distribution: Proportional token distribution

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Telegram Bot Token (from @BotFather)
  • Ethereum wallet with Sepolia testnet ETH
  • Access to Sepolia RPC endpoint

Installation

# 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

Environment Configuration

# 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

Deployment

# 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

๐Ÿ“ฑ Usage

Creating a DCA Strategy

  1. Start a chat with the bot on Telegram
  2. Send /create to begin strategy creation
  3. 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
  4. Strategy is automatically encrypted and deployed

Strategy Parameters

  • 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

Monitoring

  • /status - View active strategies
  • /portfolio - Check performance metrics
  • /batches - Monitor batch execution
  • /price - Current market prices
  • /gas - Network conditions

๐Ÿ”’ How Privacy Works

FHE Encryption

  • 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

Transaction Batching

  • 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

Privacy Guarantees

  • 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

๐Ÿงช Testing

Smart Contract Tests

# Run all tests
npm test

# Run specific test file
npx hardhat test test/PrivacyDCABot.test.js

Bot Testing

# Start bot in development mode
npm run bot:dev

# Test commands via Telegram
# Check logs for errors
tail -f logs/bot.log

๐Ÿ“Š Configuration

Bot Settings

// 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 key

Gas Settings

MAX_FEE_PER_GAS=30000000000        // 30 Gwei
MAX_PRIORITY_FEE_PER_GAS=2000000000 // 2 Gwei

๐Ÿš€ Deployment

Development

npm run bot:dev

Production

# Set environment
NODE_ENV=production

# Start bot
npm run bot

# Or use PM2
pm2 start bot/telegram-bot.js --name "privacy-dca-bot"

Docker

# Build image
docker build -t privacy-dca-bot .

# Run container
docker run -d --name dca-bot --env-file .env privacy-dca-bot

๐Ÿ“ˆ Performance

Batch Processing

  • Configurable batch sizes (3-20 users)
  • Automatic execution triggers
  • Timeout-based fallback execution
  • Parallel batch processing

Monitoring

  • Real-time batch status updates
  • Performance metrics tracking
  • Error logging and alerting
  • User engagement analytics

๐Ÿ”ฎ Future Enhancements

Planned Features

  • Multi-chain support (Polygon, Arbitrum)
  • Advanced dynamic conditions
  • Portfolio rebalancing
  • Social trading features
  • Mobile app integration

Scalability Improvements

  • Database integration
  • Redis caching layer
  • Load balancing
  • Microservices architecture
  • Kubernetes deployment

๐Ÿ“š Documentation

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โš ๏ธ Disclaimer

This is experimental software implementing privacy-preserving DeFi strategies. Use at your own risk. Never use with real funds until thoroughly tested and audited.

๐Ÿ†˜ Support

  • 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.

About

a privacy-preserving DCA bot with transaction batching using the Zama Protocol

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published