Skip to content

francescoguarino/arbitrage-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Arbitrage Bot - Uniswap V2/V3 Arbitrage Finder ๐Ÿš€

A professional automated cryptocurrency arbitrage bot that identifies and analyzes profitable arbitrage opportunities across multiple DEXes (Uniswap V2, Uniswap V3, SushiSwap, 1inch) on Ethereum mainnet.

โš ๏ธ Disclaimer: This is an educational project. Use at your own risk. Always test thoroughly on testnet before mainnet deployment.

Features โœจ

  • Multi-DEX Scanning: Monitors Uniswap V2, Uniswap V3, SushiSwap, and 1inch
  • Real-time Price Monitoring: Continuously polls for price mismatches
  • Flash Loan Integration: Potential profitability even with small capital
  • Gas Cost Analysis: Calculates actual gas costs in both ETH and USD
  • Persistent Database: Stores all opportunities for historical analysis
  • REST API: Express backend for fetching opportunities and stats
  • React Frontend: Beautiful UI for monitoring opportunities
  • Configurable Thresholds: Adjust minimum profit, gas prices, and more

Tech Stack ๐Ÿ› ๏ธ

Backend:

  • Node.js + Express
  • ethers.js - Ethereum interaction
  • Uniswap SDK
  • SQLite - Local database
  • dotenv - Environment configuration

Frontend:

  • React 18
  • Tailwind CSS
  • Axios

Prerequisites ๐Ÿ“‹

Installation ๐Ÿ”ง

  1. Clone the repository

    git clone https://github.com/francescoguarino/arbitrage-bot.git
    cd arbitrage-bot
  2. Set up environment variables

    cp .env.example .env

    Edit .env and add your Infura API key:

    RPC_URL=https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY_HERE
    
  3. Install root dependencies

    npm install
  4. Install backend dependencies

    cd backend
    npm install
    cd ..
  5. Install frontend dependencies

    cd frontend
    npm install
    cd ..

Configuration โš™๏ธ

Edit the .env file to configure:

Variable Default Description
RPC_URL - Your Infura mainnet RPC URL
POLLING_INTERVAL 7000 Milliseconds between price checks
GAS_USED 300000 Estimated gas for swap transaction
GAS_PRICE_GWEI 30 Current gas price in Gwei
MIN_PROFIT_ETH 0.001 Minimum profitable profit in ETH
FLASH_LOAN_FEE_PCT 0.0009 Flash loan fee percentage (0.09%)
ETH_USD_PRICE 3500 Current ETH price in USD

Usage ๐Ÿš€

Development Mode

Terminal 1 - Start Backend:

cd backend
npm start

Terminal 2 - Start Frontend:

cd frontend
npm start

The frontend will open at http://localhost:3000
The backend API runs at http://localhost:5000

Production Build

# Build frontend
cd frontend
npm run build

# Backend deployment
cd backend
NODE_ENV=production npm start

Project Structure ๐Ÿ“

arbitrage-bot/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ config.js                 # Configuration loader (uses .env)
โ”‚   โ”œโ”€โ”€ server.js                 # Express server setup
โ”‚   โ”œโ”€โ”€ db.js                      # SQLite database management
โ”‚   โ”œโ”€โ”€ index.cjs                  # Main entry point
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ arbitrageRunner.js    # Core arbitrage detection
โ”‚   โ”‚   โ”œโ”€โ”€ priceCollector.js     # Price fetching
โ”‚   โ”‚   โ”œโ”€โ”€ quoteOrchestrator.js  # Quote aggregation
โ”‚   โ”‚   โ””โ”€โ”€ PriceService.js       # Price calculations
โ”‚   โ”œโ”€โ”€ dexFetchers/
โ”‚   โ”‚   โ”œโ”€โ”€ UniswapV3Fetcher.js   # Uniswap V3 integration
โ”‚   โ”‚   โ”œโ”€โ”€ SushiswapFetcher.js   # SushiSwap integration
โ”‚   โ”‚   โ””โ”€โ”€ oneInch.js             # 1inch API integration
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ Token.js              # Token model
โ”‚   โ”‚   โ””โ”€โ”€ Pair.js               # Trading pair model
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ ammMath.js            # AMM calculations
โ”‚   โ”‚   โ”œโ”€โ”€ gasAndFee.js          # Gas and fee calculations
โ”‚   โ”‚   โ””โ”€โ”€ helpers.js            # Utility functions
โ”‚   โ””โ”€โ”€ abis/
โ”‚       โ”œโ”€โ”€ UniswapV2Factory.json
โ”‚       โ””โ”€โ”€ UniswapV2Pair.json
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.js                # Main React component
โ”‚   โ”‚   โ”œโ”€โ”€ index.js              # React entry point
โ”‚   โ”‚   โ””โ”€โ”€ App.css               # Styling
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ .env.example                   # Environment template
โ”œโ”€โ”€ .gitignore                      # Git ignore rules
โ”œโ”€โ”€ package.json                    # Root package configuration
โ””โ”€โ”€ README.md                       # This file

API Endpoints ๐Ÿ“ก

  • GET /api/opportunities - Latest opportunities found
  • GET /api/opportunities/history - Historical opportunities
  • POST /api/execute - Execute arbitrage (development only)

Database Schema ๐Ÿ—„๏ธ

Opportunities are stored with:

  • Token pair information (tokenA, tokenB, decimals)
  • Best buy/sell DEX with prices
  • Profit calculations (gross, net, gas costs)
  • Timestamp and error logs

Risks & Considerations โš ๏ธ

  • Gas Costs: High gas prices can eliminate profitability
  • MEV: Miners/validators can extract value from pending transactions
  • Liquidity: Slippage may exceed expected profit
  • Price Latency: Price feeds may lag real market prices
  • Smart Contract Risk: Audit recommended before mainnet use
  • Capital Requirements: Flash loans have fees (0.09% for Aave)

Improvements & Future Work ๐Ÿ”ฎ

  • Add Aave flash loan support
  • Integrate real-time transaction simulation
  • Add Balancer, Curve DEX support
  • Web3 wallet integration for live execution
  • Advanced filtering and strategy parameters
  • Telegram/Discord notifications
  • Performance monitoring dashboard

Security Notes ๐Ÿ”’

  • Never commit .env file - Use only .env.example
  • Never hardcode API keys - Always use environment variables
  • Test on Goerli testnet first - Before mainnet
  • Use a separate wallet for bot transactions
  • Start with small amounts to test
  • Monitor gas prices carefully

Troubleshooting ๐Ÿ›

"RPC_URL not configured"

โ†’ Check .env file has valid Infura API key

"No opportunities found"

โ†’ Adjust MIN_PROFIT_ETH lower or increase POLLING_INTERVAL

"Database locked"

โ†’ Stop all bot instances and remove *.db file

High gas costs

โ†’ Update GAS_PRICE_GWEI in .env or run during low-gas periods

Contributing ๐Ÿค

Pull requests are welcome! For major changes, please open an issue first.

License ๐Ÿ“„

MIT License - see LICENSE file for details

Disclaimer โš–๏ธ

This software is provided "as is" without warranty of any kind. Use at your own risk. The author is not responsible for any financial losses or damages resulting from the use of this software. Always do your own research and test thoroughly.

Author

Created by Franceso Guarino

guarinofrancesco42@gmail.com

Support ๐Ÿ’ฌ

For issues, questions, or suggestions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review code comments

Made with โค๏ธ for the DeFi community

About

Automated cryptocurrency arbitrage bot for Uniswap

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors