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
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
- 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=
- Clone the repository:
git clone <repository-url>
cd trading_bot_v3-master
- Install dependencies:
npm install
- Create configuration file:
cp config.example.json config.json
- Set up environment variables:
cp .env.example .env
# Edit .env with your credentials
- Deploy the arbitrage contract:
npx hardhat run scripts/flashbots-deploy.js --network mainnet
- Start the monitoring dashboard:
node scripts/monitor.js
- Launch the trading bot:
node bot.js
- 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]
}
];
- Set safety parameters:
await arbitrage.setupSafeParams();
await arbitrage.updateMaxSlippage(50); // 0.5%
await arbitrage.updateMaxGasPrice(ethers.utils.parseUnits("100", "gwei"));
- Insufficient Balance
Error: Insufficient balance for deployment
Solution: Ensure wallet has enough ETH for deployment and gas fees.
- High Gas Prices
Error: Gas price too high
Solution: Adjust MAX_GAS_PRICE in config.json or wait for lower gas prices.
- 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
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
flashbots-deploy
: Deploys contract using Flashbots bundle- Type:
nodejs14.x
- Memory: 256MB
- Timeout: 300s
- Type:
- Arbitrage.sol
- Network: Ethereum Mainnet
- Solidity: 0.8.18
- Features: Flash loans, token whitelisting, safety controls
Prerequisites:
- Ethereum mainnet access
- Flashbots relay access
- Sufficient ETH for deployment
Deployment steps:
- Configure environment variables
- Deploy contract via Flashbots
- Verify on Etherscan
- Initialize safety parameters
- Whitelist initial tokens