Skip to content

logiccrafterdz/Base-native-Trading-Bot-Framework

Base-native Trading Bot Framework

License: MIT Base Mainnet Solidity ^0.8.19 CI/CD Security: Audited ✅ Gas Optimized

A production-ready, fully onchain trading bot framework built natively for Base L2. Designed for traders and developers who demand complete sovereignty over their funds with emergency-ready offline capabilities and transparent execution.

✨ Key Features

  • 🔗 Fully Onchain Logic - All trading decisions executed transparently on Base L2
  • 🔒 Offline Emergency Mode - Sign critical operations offline with replay protection
  • 📊 Multi-Oracle Price Validation - Pyth Network + RedStone Finance + TWAP aggregation
  • 📱 Multi-Channel Alerts - Telegram, SMS, Discord, and Farcaster notifications
  • 🔐 Account Abstraction Ready - ERC-4337 + EOA support with smart wallet integration
  • 🏠 Local Sovereignty - Private keys never leave your device (OS Secure Enclave)
  • Gas Efficient - Optimized for Base L2 (< $0.01 per trade)
  • 🛡️ MEV Protection - Built-in slippage protection and deadline validation
  • 🔄 Auto-Broadcast - Automatic retry with exponential backoff for failed operations
  • 📈 Strategy Registry - Pluggable external strategies with bytecode validation

🏗️ Architecture Overview

graph TB
    subgraph "Desktop Application (Tauri)"
        UI[React Frontend]
        Rust[Rust Backend]
        Store[Secure Storage<br/>OS Keychain/DPAPI]
    end
    
    subgraph "Offchain Services"
        Executor[Executor Node<br/>TypeScript]
        Notifier[Notification Service<br/>Multi-channel]
    end
    
    subgraph "Base L2 Blockchain"
        Bot[BotController.sol]
        Emergency[EmergencyModule.sol]
        Registry[StrategyRegistry.sol]
    end
    
    subgraph "Oracle Network"
        Pyth[Pyth Network]
        RedStone[RedStone Finance]
        TWAP[Uniswap V3 TWAP]
    end
    
    subgraph "External Integrations"
        Telegram[Telegram Bot]
        Discord[Discord Webhook]
        SMS[Twilio SMS]
        Farcaster[Warpcast API]
    end
    
    UI <--> Rust
    Rust <--> Store
    Rust <--> Executor
    Executor <--> Bot
    Executor <--> Pyth
    Executor <--> RedStone
    Executor <--> TWAP
    Bot <--> Emergency
    Bot <--> Registry
    Executor <--> Notifier
    Notifier --> Telegram
    Notifier --> Discord
    Notifier --> SMS
    Notifier --> Farcaster
    
    classDef secure fill:#e1f5fe
    classDef onchain fill:#f3e5f5
    classDef oracle fill:#fff3e0
    classDef external fill:#e8f5e8
    
    class Store,Rust secure
    class Bot,Emergency,Registry onchain
    class Pyth,RedStone,TWAP oracle
    class Telegram,Discord,SMS,Farcaster external
Loading

🔐 Security Highlights

Our framework has been audited and approved for mainnet deployment with the following security guarantees:

  • Private Keys in OS Secure Enclave - DPAPI (Windows), Keychain (macOS), Secret Service (Linux)
  • Emergency Operations Protected - uniqueId + nonce + EIP-712 signatures + expiry timestamps
  • Bytecode Hash Validation - All external strategies verified before execution
  • Zero Cloud Key Exposure - Private keys never transmitted to Executor or cloud services
  • Replay Attack Prevention - Nonce-based protection with automatic increment
  • Gas Limit Enforcement - 200k gas limit per strategy execution via delegatecall
  • Multi-Oracle Validation - Price manipulation protection through aggregated feeds
  • Slippage & Deadline Protection - Configurable limits on all trades

📋 Full Security Audit Report: SECURITY_AUDIT_REPORT.md

🚀 Quick Start (Local Development)

Prerequisites

  • Node.js 18+ and npm
  • Rust 1.70+ (for Tauri desktop app)
  • Git

Installation

# Clone the repository
git clone https://github.com/your-org/base-trading-bot.git
cd base-trading-bot

# Install root dependencies
npm install

# Install service dependencies
cd executor-node && npm install && cd ..
cd notification-service && npm install && cd ..
cd desktop-app && npm install && cd ..

# Set up environment variables
cp .env.example .env
cp executor-node/.env.example executor-node/.env
cp notification-service/.env.example notification-service/.env

# Configure your .env files with RPC URLs and API keys

Development Setup

# Compile smart contracts
npx hardhat compile

# Run tests
npm test                    # All contract tests
npm run test:unit          # Unit tests only
npm run test:fork          # Fork tests (requires Base RPC)

# Deploy to Base Sepolia testnet
npm run deploy:sepolia

# Start the desktop application
cd desktop-app
npm run tauri dev

Production Deployment

# Deploy contracts to Base Mainnet
npm run deploy:mainnet

# Build desktop application
cd desktop-app
npm run tauri build

# Deploy services with Docker
docker-compose up -d

📖 Documentation

Core Components

Guides

🔧 Configuration

Environment Variables

# Base RPC Configuration
BASE_MAINNET_RPC_URL=https://mainnet.base.org
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org

# Contract Addresses (auto-populated after deployment)
BOT_CONTROLLER_ADDRESS=0x...
EMERGENCY_MODULE_ADDRESS=0x...
STRATEGY_REGISTRY_ADDRESS=0x...

# Oracle Configuration
PYTH_ENDPOINT=https://hermes.pyth.network
REDSTONE_API_URL=https://api.redstone.finance

# Notification Channels
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
DISCORD_WEBHOOK_URL=your_discord_webhook_url
TWILIO_ACCOUNT_SID=your_twilio_account_sid

Trading Parameters

// Example configuration in desktop app
const config = {
  gasLimit: 200000,              // Max gas per strategy execution
  slippageTolerance: 0.005,      // 0.5% slippage tolerance
  maxPriorityFee: "0.001",       // Base L2 priority fee in ETH
  emergencyModeTimeout: 3600,    // 1 hour emergency mode timeout
  autoReconnect: true,           // Auto-reconnect WebSocket
  maxReconnectAttempts: 5        // Max reconnection attempts
};

🧪 Testing

Smart Contract Tests

# Run all tests
npm test

# Run with gas reporting
REPORT_GAS=true npm test

# Run coverage analysis
npm run coverage

# Fork testing against Base Mainnet
npm run test:fork

Service Tests

# Executor Node tests
cd executor-node && npm test

# Notification Service tests
cd notification-service && npm test

# Desktop App tests (Rust)
cd desktop-app/src-tauri && cargo test

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run the test suite: npm test
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Code Standards

  • Solidity: Follow Solidity Style Guide
  • TypeScript: ESLint + Prettier configuration included
  • Rust: Standard rustfmt formatting
  • React: Functional components with hooks

📊 Performance Metrics

Metric Base Sepolia Base Mainnet
Average Gas Cost ~45,000 gas ~45,000 gas
Transaction Cost ~$0.001 ~$0.008
Strategy Execution <200ms <200ms
Oracle Aggregation <500ms <500ms
Emergency Op Signing <100ms <100ms

🌐 Network Support

Base L2 Networks

  • Base Mainnet (Chain ID: 8453) - Production deployment
  • Base Sepolia (Chain ID: 84532) - Testnet deployment

Supported Wallets

  • EOA Wallets: MetaMask, WalletConnect, Coinbase Wallet
  • Smart Wallets: ERC-4337 compatible (Biconomy, Alchemy, etc.)
  • Hardware Wallets: Ledger, Trezor (via WalletConnect)

📄 License

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

🆘 Support

🙏 Acknowledgments

  • Base Team - For building an amazing L2 platform
  • Pyth Network - For reliable oracle infrastructure
  • RedStone Finance - For flexible oracle solutions
  • Tauri Team - For the excellent desktop app framework
  • OpenZeppelin - For battle-tested smart contract libraries

⚠️ Disclaimer: This software is provided "as is" without warranty. Trading cryptocurrencies involves substantial risk of loss. Only trade with funds you can afford to lose. The developers are not responsible for any financial losses incurred through the use of this software.

🔒 Security: Always verify contract addresses and audit any external strategies before deployment. Never share your private keys or seed phrases.

About

“Open-source Base-native trading bot framework — decentralized, verifiable, and locally sovereign.”

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors