Skip to content

0x0Glitch/plutus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

plutus

MEV Arbitrage Bot

Welcome to MEV Arbitrage Bot, our first dive into the fascinating world of decentralized finance (DeFi), blockchain development, and Miner Extractable Value (MEV). This project aims to provide an automated arbitrage bot that identifies profitable opportunities across multiple decentralized exchanges (DEXs), executes trades, and integrates Flashbots for efficient transaction bundling. Built on Python with FastAPI, this project serves as a stepping stone into blockchain-powered arbitrage trading.


Key Features

  • Real-Time Arbitrage Detection: The bot scans token prices across DEXs (e.g., Uniswap, SushiSwap) to identify arbitrage opportunities.
  • Flashbots Integration: Leverages Flashbots to submit private transaction bundles to miners, preventing frontrunning and reducing gas fees.
  • Testnet Support: Fully functional on Ethereum testnets like Sepolia for safe experimentation.
  • REST API: Expose endpoints for real-time interaction via a FastAPI-powered backend.
  • Dynamic Logging: Track every step of the process, from token price fetching to transaction execution.

Technologies Used

Backend

  • Python: Core programming language.
  • FastAPI: Framework for building REST APIs.
  • Web3.py: For blockchain interaction.
  • Flashbots: For transaction bundling and miner communication.

Blockchain Providers

  • Alchemy: Ethereum RPC URL for Sepolia Testnet.

Tools and Libraries

  • dotenv: Manage environment variables.
  • requests: HTTP requests for price fetching.
  • pydantic: Data validation.
  • Uvicorn: ASGI server to run the API.

Project Structure

mev_arbitrage_bot/
├── contracts/                  # Smart contracts for interacting with DEXs (optional for future enhancements)
├── strategies/                 # Arbitrage strategies
│   ├── base_strategy.py        # Base class for arbitrage strategies
│   └── uniswap_sushi_strategy.py # Example: Arbitrage between Uniswap and SushiSwap
├── utils/                      # Utility functions
│   ├── logger.py               # Custom logging setup
│   └── constants.py            # Common constants
├── dex_service.py              # Fetch prices from multiple DEXs
├── flashbots_service.py        # Flashbots integration
├── main.py                     # Main FastAPI application
├── requirements.txt            # Python dependencies
├── .env                        # Environment variables (add this to .gitignore!)
└── README.md                   # Documentation

Getting Started

Prerequisites

Ensure you have the following installed:

  • Python 3.11
  • Node.js (optional for additional tools)

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/mev-arbitrage-bot.git
    cd mev-arbitrage-bot
  2. Create and activate a virtual environment:

    python3.11 -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up your .env file:

    WEB3_PROVIDER_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY
    PRIVATE_KEY=0xYourPrivateKey
    FLASHBOTS_RELAY_URL=https://relay.flashbots.net
    
  5. Run the server:

    uvicorn main:app --host 0.0.0.0 --port 8000 --reload

API Endpoints

GET /

Description: Check if the bot is online.

Response:

{
  "message": "MEV Arbitrage Bot (Testnet) is online!"
}

POST /arbitrage

Description: Execute an arbitrage strategy.

Request Body:

{
  "tokenA": "ETH",
  "tokenB": "DAI",
  "amount": 1
}

Response (Example):

{
  "message": "Arbitrage executed successfully",
  "tx_hashes": ["0x1234...", "0x5678..."],
  "profit_estimate": 0.05
}

Testing

  1. Test the / endpoint:

    curl -X GET http://127.0.0.1:8000/
  2. Test the /arbitrage endpoint:

    curl -X POST http://127.0.0.1:8000/arbitrage \
      -H "Content-Type: application/json" \
      -d '{"tokenA": "ETH", "tokenB": "DAI", "amount": 1}'

How It Works

  1. Price Fetching:

    • The bot fetches token prices from Uniswap and SushiSwap using the dex_service.py module.
  2. Arbitrage Calculation:

    • The bot identifies profitable opportunities using the logic in uniswap_sushi_strategy.py.
  3. Transaction Submission:

    • Profitable trades are submitted either as normal transactions or as Flashbots bundles to miners.
  4. Logging:

    • All key events (price fetching, profit calculations, transaction hashes) are logged in the console.

Future Enhancements

  • More DEX Integrations: Expand support to Curve, Balancer, etc.
  • Cross-Chain Arbitrage: Identify opportunities across different blockchains.
  • AI-Driven Strategies: Use AI models to predict arbitrage opportunities.
  • Frontend Integration: Build a React-based UI to monitor and control the bot.

Contributors

  • Sachin Bansal (PureBl00d): Developer and Blockchain enthusiast
  • Anshuman Yadav (0xTokenSmith): Developer and Blockchain Enthusiast

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published