Skip to content

krissyawaters/Crypto_Arbitrage_Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Ethereum Arbitrage Trading Bot with Flashbots Integration

A secure and efficient arbitrage trading bot for Ethereum that leverages Flashbots bundles to execute MEV-protected trades across Uniswap V3, Sushiswap, Curve, and Balancer protocols.

This project implements an automated arbitrage system that monitors price differences between decentralized exchanges and executes profitable trades using flash loans. The bot includes advanced safety features, gas optimization, and a monitoring dashboard for real-time performance tracking. It uses Flashbots to prevent front-running and ensure private transaction execution.

Key features include:

  • Multi-DEX arbitrage opportunities scanning (Uniswap V3, Sushiswap, Curve, Balancer)
  • Flashbots integration for MEV protection
  • Flash loan integration with Balancer Vault
  • Real-time monitoring dashboard
  • Configurable safety parameters and kill switch
  • Gas price optimization
  • Comprehensive testing suite

Repository Structure

trading_bot_v3-master/
├── bot.js                 # Main bot implementation with core trading logic
├── config.json           # Configuration file for bot parameters and addresses
├── contracts/           # Smart contract directory
│   └── Arbitrage.sol    # Main arbitrage contract with flash loan functionality
├── helpers/             # Utility functions and initialization
│   ├── abi.js          # Contract ABIs for DEX interactions
│   ├── helpers.js      # Common helper functions
│   ├── initialization.js # Bot initialization logic
│   └── server.js       # Monitoring dashboard server
├── scripts/            # Deployment and management scripts
│   ├── arbitrage-bot.js # Main arbitrage execution logic
│   ├── deploy.js       # Contract deployment script
│   ├── flashbots-deploy.js # Flashbots-protected deployment
│   └── monitor.js      # Price monitoring implementation
└── test/              # Test suite directory
    ├── arbitrage-test.js # Contract tests
    └── bot-test.js     # Bot functionality tests

Usage Instructions

Prerequisites

  • Node.js v14+ and npm
  • Ethereum wallet with private key
  • Mainnet RPC URL (e.g., Infura or Alchemy)
  • Flashbots relay access
  • Sufficient ETH for deployment and trading

Required environment variables:

MAINNET_RPC_URL=
PRIVATE_KEY=
FLASHBOTS_PRIVATE_KEY=
ETHERSCAN_API_KEY=

Installation

  1. Clone the repository:
git clone <repository-url>
cd trading_bot_v3-master
  1. Install dependencies:
npm install
  1. Create configuration file:
cp config.example.json config.json
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your credentials

Quick Start

  1. Deploy the arbitrage contract:
npx hardhat run scripts/flashbots-deploy.js --network mainnet
  1. Start the monitoring dashboard:
node scripts/monitor.js
  1. Launch the trading bot:
node bot.js

More Detailed Examples

  1. Configure token pairs for arbitrage:
const pairs = [
    {
        tokenA: ADDRESSES.TOKENS.WETH,
        tokenB: ADDRESSES.TOKENS.USDC,
        fees: [FEE_TIERS.LOWEST, FEE_TIERS.LOW, FEE_TIERS.MEDIUM]
    }
];
  1. Set safety parameters:
await arbitrage.setupSafeParams();
await arbitrage.updateMaxSlippage(50); // 0.5%
await arbitrage.updateMaxGasPrice(ethers.utils.parseUnits("100", "gwei"));

Troubleshooting

  1. Insufficient Balance
Error: Insufficient balance for deployment

Solution: Ensure wallet has enough ETH for deployment and gas fees.

  1. High Gas Prices
Error: Gas price too high

Solution: Adjust MAX_GAS_PRICE in config.json or wait for lower gas prices.

  1. Failed Transactions
  • Enable debug mode in config.json:
{
    "DEBUG_MODE": true,
    "LOG_LEVEL": "debug"
}
  • Check logs in arbitrage_bot.log
  • Verify transaction simulation results before execution

Data Flow

The bot continuously monitors price differences across DEXs and executes arbitrage when profitable opportunities are found.

[Price Feeds] --> [Monitor Service] --> [Opportunity Scanner]
                                              |
                                      [Profit Calculator]
                                              |
                                    [Safety Checks & Validation]
                                              |
                                    [Flashbots Bundle Creation]
                                              |
                                    [Transaction Execution] --> [Results Dashboard]

Key component interactions:

  • Monitor Service polls DEX prices through RPC endpoints
  • Opportunity Scanner identifies potential arbitrage paths
  • Profit Calculator determines expected returns considering gas costs
  • Safety module validates trade parameters and checks kill switch
  • Flashbots bundle creator prepares MEV-protected transactions
  • Transaction executor handles flash loans and DEX interactions
  • Dashboard displays real-time performance metrics
  • Error handler manages failed transactions and logging

Infrastructure

Infrastructure diagram

Lambda Functions

  • flashbots-deploy: Deploys contract using Flashbots bundle
    • Type: nodejs14.x
    • Memory: 256MB
    • Timeout: 300s

Smart Contracts

  • Arbitrage.sol
    • Network: Ethereum Mainnet
    • Solidity: 0.8.18
    • Features: Flash loans, token whitelisting, safety controls

Deployment

Prerequisites:

  • Ethereum mainnet access
  • Flashbots relay access
  • Sufficient ETH for deployment

Deployment steps:

  1. Configure environment variables
  2. Deploy contract via Flashbots
  3. Verify on Etherscan
  4. Initialize safety parameters
  5. Whitelist initial tokens

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published