Skip to content

John0n1/0xBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ 0xBuilder MEV Bot πŸš€

License Contributions Welcome Python Version Geth Version Status

Table of Contents

✨ Introduction

0xBuilder Built for traders, developers, and researchers, 0xBuilder is your gateway to mastering MEV opportunities on the Ethereum network. engineered for high-frequency trading and maximum profit extraction. including:

  • ⚑️ Lightning-Fast Front-Running
  • πŸƒ Strategic Back-Running
  • πŸ₯ͺ Devastating Sandwich Attacks
  • πŸ’° Capital-Efficient Flashloan Arbitrage

0xBuilder Architecture Diagram

⚠️ Heads Up! 0xBuilder is under active development. Expect bugs – use with extreme caution and at your own risk.

⚑️ Key Features

  • Mempool Mastery: Relentlessly scans the Ethereum mempool, pinpointing lucrative arbitrage and MEV opportunities.
  • Strategic Arsenal: Deploy cutting-edge strategies like Front-Running, Back-Running, Sandwich Attacks, and Flashloan Arbitrage with surgical precision.
  • Flashloan Fury: Leverage flashloans from Aave V3 for maximum capital efficiency and zero upfront capital requirements.
  • Market Intelligence: Integrated market analysis, powered by real-time data from top-tier cryptocurrency APIs, ensuring data-driven decisions.
  • Gas Optimization: Dynamic gas price adjustments to conquer network congestion and maximize profitability.
  • Unbreakable Nonce Management: Advanced nonce handling to guarantee transaction success and prevent costly failures.
  • Ironclad Safety Net: Multi-layered safety checks and risk assessment protocols to safeguard your assets.
  • Transaction Bundling: Bundle transactions for atomic execution and front-running dominance.
  • DeFi Protocol Prowess: Seamlessly interacts with leading DeFi platforms like Uniswap, Sushiswap, Aave, and more.
  • Limitless Customization: Highly configurable architecture supporting multiple wallets, tokens, trading pairs, and adaptable strategies.
  • Crystal-Clear Logging: Comprehensive, detailed logs for in-depth performance analysis, debugging, and strategy refinement.

πŸ—οΈ Project Structure

/0xBuilder/
β”œβ”€β”€ abi/                      # Smart Contract ABIs (JSON)
β”‚   β”œβ”€β”€ uniswap_abi.json
β”‚   β”œβ”€β”€ erc20_abi.json
β”‚   └── aave_pool_abi.json
β”œβ”€β”€ contracts/              # Solidity Smart Contracts
β”‚   β”œβ”€β”€ SimpleFlashloan.sol
β”‚   └── IERC20.sol
β”œβ”€β”€ linear_regression/       # Machine Learning Models & Data
β”‚   β”œβ”€β”€ training_data.csv
β”‚   └── price_model.joblib
β”œβ”€β”€ python/                 # Core Python Scripts & Logic
β”‚   β”œβ”€β”€ safety_net.py         # Risk Management & Safety Checks
β”‚   β”œβ”€β”€ strategy_net.py       # MEV Strategy Implementation & Execution
β”‚   β”œβ”€β”€ mempool_monitor.py    # Ethereum Mempool Monitoring Engine
β”‚   β”œβ”€β”€ market_monitor.py     # Market Data Analysis & Prediction
β”‚   β”œβ”€β”€ main.py              # Main Bot Entry Point & Orchestration
β”‚   β”œβ”€β”€ transaction_core.py   # Transaction Building & Execution Engine
β”‚   β”œβ”€β”€ main_core.py          # Core Application Logic & Component Management
β”‚   β”œβ”€β”€ nonce_core.py         # Ethereum Nonce Management System
β”‚   β”œβ”€β”€ api_config.py         # Cryptocurrency API Integration & Data Handling
β”‚   β”œβ”€β”€ configuration.py      # Configuration Loading & Validation
|   β”œβ”€β”€ abi_registry.py       # Centralized ABI Registry
β”‚   β”œβ”€β”€ 0xBuilder.log        # Log File (Default)
|   β”œβ”€β”€ __init__.py           # Python Package Initialization
β”‚   └── pyutils/              # Python Utility Modules
β”‚    β”œβ”€β”€ strategyexecutionerror.py # Custom Strategy Execution Exception
β”‚    └── strategyconfiguration.py # Strategy Configuration Classes
β”œβ”€β”€ utils/                    # Utility JSON Configuration Files
β”‚   β”œβ”€β”€ token_addresses.json   # Monitored Token Addresses
β”‚   β”œβ”€β”€ erc20_signatures.json  # ERC20 Function Signatures
β”‚   └── token_symbols.json     # Token Symbol Mappings
β”œβ”€β”€ .env                      # Environment Variable Configuration File
└── requirements.txt          # Python Dependencies List

πŸ› οΈ Prerequisites

Prepare your system and environment to harness the full potential of 0xBuilder.

System

  • Operating System: Linux (Ubuntu 20.04+ Recommended), Windows 10/11, macOS 12+
  • Blazing Network:
    • Internet: Minimum 50Mbps, 100Mbps recommended for optimal performance
  • Robust Hardware:
    • CPU: 4+ Cores, 3.0GHz+ (Intel i7/Ryzen 7 or better for peak efficiency)
    • RAM: Minimum 16GB, 32GB recommended for heavy-duty operations
    • Storage: 1.3TB NVMe SSD minimum, 2TB for optimal data handling

Software Arsenal

  • Ethereum Execution Client: Choose your weapon:
  • Python Dependencies: Arm your environment with packages from requirements.txt

Ethereum Node

Set up your Ethereum Execution and Beacon clients for seamless blockchain interaction.

Choose Your Execution Client:

Client Language OS Support Networks Sync Methods
Geth Go Linux, Windows, macOS Mainnet, Sepolia, Holesky Snap, Full
Nethermind C#/.NET Linux, Windows, macOS Mainnet, Sepolia, Holesky Snap, Fast, Full
Besu Java Linux, Windows, macOS Mainnet, Sepolia, Holesky Snap, Fast, Full
Erigon Go Linux, Windows, macOS Mainnet, Sepolia, Holesky Full
Reth Rust Linux, Windows, macOS Mainnet, Sepolia, Holesky Full
EthereumJS TypeScript Linux, Windows, macOS Sepolia, Holesky Full

Example: Geth Configuration

  1. Install Geth: Follow the official guide.

  2. Launch Geth Node:

    ./geth --mainnet --syncmode snap --http --http.api eth,net,admin,web3,txpool --ws --ws.api eth,net,admin,web3,txpool --maxpeers 100 --cache 16000 --ipcpath ~/0xBuilder/geth.ipc --allow-insecure-unlock --http.corsdomain "*"
  3. Monitor Sync:

    geth attach ipc:/path/to/geth.ipc
    > eth.syncing

Set up a Beacon Node (Optional, but recommended for advanced monitoring and future features):

  1. Install Prysm: Follow the Prysm guide.

    curl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh --output prysm.sh
    chmod +x prysm.sh
  2. Launch Prysm Beacon Chain:

    ./prysm.sh beacon-chain --accept-terms-of-use --execution-endpoint ~/0xBuilder/geth.ipc --mainnet --checkpoint-sync-url https://beaconstate.info --genesis-beacon-api-url https://beaconstate.info

Alternative Beacon Clients:

πŸš€ Installation - Get Started in Minutes

Clone the 0xBuilder

git clone https://github.com/John0n1/0xBuilder.git
cd 0xBuilder

Forge a Virtual Environment

Isolate your bot's dependencies:

# Linux/MacOS
python3 -m venv venv
source venv/bin/activate

Install Python Dependencies

Install required Python packages:

python -m pip install --upgrade pip
pip install -r requirements.txt

βš™οΈ Configuration - Tailor 0xBuilder to Your Strategy

Environment Variables

  1. Create .env File:

    # Linux/MacOS
    cp .env.example .env
    
    # Windows
    copy .env.example .env
  2. Edit .env: Configure API keys, node endpoints, wallet details, and more.

  3. Secure Your Secrets:

    ls -la .env
    chmod 600 .env 

Example .env: (Refer to .env.example for a full list of variables)

# API Configuration
ETHERSCAN_API_KEY=YOUR_ETHERSCAN_API_KEY
INFURA_PROJECT_ID=YOUR_INFURA_PROJECT_ID
COINGECKO_API_KEY=YOUR_COINGECKO_API_KEY
COINMARKETCAP_API_KEY=YOUR_COINMARKETCAP_API_KEY
CRYPTOCOMPARE_API_KEY=YOUR_CRYPTOCOMPARE_API_KEY

# Ethereum Node Configuration
HTTP_ENDPOINT=http://127.0.0.1:8545
WS_ENDPOINT=wss://127.0.0.1:8546
IPC_ENDPOINT=/path/to/geth.ipc

# Wallet Configuration
WALLET_ADDRESS=0xYourWalletAddress
WALLET_KEY=YOUR_PRIVATE_KEY

# Token Configuration (Paths to JSON files)
TOKEN_ADDRESSES=utils/token_addresses.json
TOKEN_SYMBOLS=utils/token_symbols.json
ERC20_SIGNATURES=utils/erc20_signatures.json

# DEX Router Addresses
UNISWAP_ADDRESS=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D # Uniswap V2 Router
SUSHISWAP_ADDRESS=0xd9e1cE17F2641f24aE83637ab66a2cca9C378B9F # Sushiswap Router

# ABI Paths (Paths to ABI JSON files)
UNISWAP_ABI=abi/uniswap_abi.json
SUSHISWAP_ABI=abi/sushiswap_abi.json
ERC20_ABI=abi/erc20_abi.json

# Flashloan Configuration
AAVE_FLASHLOAN_ADDRESS=0xYourFlashloanContractAddress # Your deployed Flashloan contract
AAVE_POOL_ADDRESS=0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 # Aave V3 Pool Address 

Configuration Files

Validate and customize JSON configuration files in the utils/ directory:

File Description Format
token_addresses.json Monitored token contract addresses {"SYMBOL": "ADDRESS", ...}
token_symbols.json Token symbol to address mappings {"SYMBOL": "API_ID", ...}
erc20_signatures.json ERC20 function signatures {"function_name": "selector"}

Deploy Your Flashloan Contract

Maximize capital with a flashloan contract.

Deployment via Remix IDE (Recommended)

  1. Open Remix: Go to Remix IDE.

  2. Create Contract: Create a new file SimpleFlashloan.sol.

  3. Paste Code: Copy and paste the provided Solidity code into Remix.

  4. Compile: Compile using Solidity v0.8.19 or later.

  5. Deploy: Deploy to Ethereum using MetaMask or your preferred wallet.

  6. Update .env: Add your deployed contract address to .env:

    AAVE_FLASHLOAN_ADDRESS=0xYourDeployedContractAddress

Example Flashloan Contract (AAVE V3):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "https://github.com/aave/aave-v3-core/blob/master/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPoolAddressesProvider.sol";
import "https://github.com/aave/aave-v3-core/blob/master/contracts/dependencies/openzeppelin/contracts/IERC20.sol";

contract SimpleFlashLoan is FlashLoanSimpleReceiverBase {
    address payable public owner;

    event FlashLoanRequested(address token, uint256 amount);
    event FlashLoanExecuted(address token, uint256 amount, uint256 premium, bool success);

    constructor(address _addressProvider) FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider)) {
        owner = payable(msg.sender);
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Not contract owner");
        _;
    }

    function fn_RequestFlashLoan(address _token, uint256 _amount) public onlyOwner {
        emit FlashLoanRequested(_token, _amount);
        POOL.flashLoanSimple(address(this), _token, _amount, "", 0);
    }

    function executeOperation(
        address asset,
        uint256 amount,
        uint256 premium,
        address initiator,
        bytes calldata params
    ) external override returns (bool) {
        require(IERC20(asset).approve(address(POOL), amount + premium), "Approval failed");
        emit FlashLoanExecuted(asset, amount, premium, true);
        return true;
    }

    function withdrawToken(address _tokenAddress) public onlyOwner {
        IERC20 token = IERC20(_tokenAddress);
        uint256 balance = token.balanceOf(address(this));
        require(balance > 0, "No tokens to withdraw");
        token.transfer(owner, balance);
    }

    function withdrawETH() public onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "No ETH to withdraw");
        owner.transfer(balance);
    }

    receive() external payable {}
}

πŸ”‘ Register for API Keys

Register for API keys from these essential services and add them to your .env file:

  1. Infura: Your gateway to Ethereum node infrastructure.
  2. Etherscan: For on-chain data and transaction insights.
  3. CoinGecko: Real-time and historical crypto market data.
  4. CoinMarketCap: Comprehensive cryptocurrency market data.
  5. CryptoCompare: Another robust source for crypto market data.
  6. Binance (Optional): For Binance-specific market data and volume analysis.

πŸ•ΉοΈ Run the Bot - Engage the Engines

Prepare for liftoff and execute 0xBuilder!

Pre-Flight Checklist:

  • πŸš€ Ethereum Node: Ensure your node is fully synchronized and running.
  • πŸ›°οΈ Beacon Node: (Optional) Verify your beacon node is active.
  • πŸ”‘ Configuration: Double-check .env variables and JSON config files.
  • β›½ ETH Balance: Fund your wallet with enough ETH to cover gas costs.

Launch Sequence:

  1. Activate Virtual Environment:

    source venv/bin/activate
  2. Start 0xBuilder:

    python python/main.py

Monitor & Control:

  • Logs: Track bot activity and performance in python/0xBuilder.log.
  • Console: Monitor real-time status updates in your terminal.
  • Shutdown: Press Ctrl+C in the console to initiate a graceful shutdown.

Performance Tuning:

  • Node Sync: Maintain a fully synchronized Ethereum node for optimal performance.
  • API Limits: Monitor API usage and respect rate limits; consider upgrading API tiers for higher limits.
  • ETH Balance: Ensure your wallet has sufficient ETH to cover transaction fees.
  • Log Analysis: Regularly review logs to identify and resolve issues, and optimize strategies.
  • Dependency Updates: Keep Python dependencies updated to benefit from performance improvements and security patches.

🎯 Strategies

0xBuilder is armed with a suite of powerful MEV strategies:

  • Aggressive Front-Running: Seize immediate profit opportunities by front-running pending transactions with speed and precision.
  • Predictive Front-Running: Leverage advanced price prediction models to anticipate market movements and front-run strategically.
  • Volatility Front-Running: Capitalize on high market volatility with front-running techniques optimized for volatile tokens.
  • Advanced Front-Running: A multi-faceted strategy combining risk assessment, market analysis, and intelligent decision-making for sophisticated front-running executions.
  • Price Dip Back-Running: Back-run transactions that trigger price dips, profiting from post-dip rebounds.
  • Flashloan Back-Running: Execute back-running strategies with zero upfront capital using flashloans for maximum efficiency.
  • High Volume Back-Running: Target high-volume tokens for back-running, leveraging volume for increased profit potential.
  • Advanced Back-Running: Employ comprehensive market analysis and condition assessment for optimized back-running executions.
  • Flash Profit Sandwich Attack: Maximize profit extraction with sandwich attacks powered by flashloans, minimizing risk and maximizing capital utilization.
  • Price Boost Sandwich Attack: Exploit price momentum with sandwich attacks, capitalizing on tokens exhibiting strong upward price action.
  • Arbitrage Sandwich Attack: Combine sandwich attacks with arbitrage detection to profit from both MEV and arbitrage opportunities in a single, powerful strategy.
  • Advanced Sandwich Attack: Deploy risk-managed sandwich attacks using advanced market condition analysis and dynamic parameter adjustments for optimal execution and profit.
  • High-Value ETH Transfer: Intercept and capitalize on high-value ETH transfers, leveraging strategic positioning for MEV extraction.

πŸ”­ Logging

0xBuilder provides detailed logs in python/0xBuilder.log to keep you informed:

  • Transaction Insights: Real-time detection of profitable transactions in the mempool.
  • Strategy Performance: Track the execution and success of each strategy, with detailed profit metrics.
  • Error & Exception Tracking: Immediate alerts for any errors or exceptions, enabling rapid troubleshooting.
  • Detailed Activity Logs: Comprehensive logs of bot activities, transactions, and market analysis for in-depth performance review.

Customize logging verbosity and formatting in python/main_core.py using the setup_logging() function.

πŸ› οΈ Troubleshooting

Common Pitfalls & Solutions:

Issue Solution
Node Connection Failures Verify Ethereum node is running and endpoints are correct
API Rate Limit Reached Implement request throttling; consider upgrading API tiers
Insufficient Gas Balance Fund your wallet with adequate ETH for transaction fees
Nonce Synchronization Errors Reset Nonce Core or manually synchronize nonce with node
Node Synchronization Status Ensure your Ethereum node is fully synchronized with network

Debugging:

  1. Verbose Logging: Increase logging level to DEBUG for detailed output.
  2. Dependency Sanity Check: Ensure all dependencies in requirements.txt are up-to-date and correctly installed.
  3. Contract Explorer: Verify your flashloan contract is deployed and functioning correctly using a block explorer (e.g., Etherscan).
  4. Testnet Trials: Thoroughly test strategies and configurations on testnets like Sepolia or Holesky before deploying to mainnet.

🀝 Contributing - Join the 0xBuilder Guild

Become a part of the 0xBuilder community! Contributions are welcome and highly encouraged! ❀️❀️

Contribution Guidelines:

  • Fork & Branch: Fork the repository and create a dedicated feature branch for your contributions.
  • Code Style: Adhere to PEP 8 guidelines for Python code style.
  • Unit Tests: Include comprehensive unit tests to ensure the quality and reliability of your contributions.
  • Pull Requests: Submit well-documented pull requests with clear descriptions of your changes and their benefits.

For detailed contribution guidelines, please review CONTRIBUTING.md.

πŸ“œ License

0xBuilder is released under the MIT License.