Welcome to the Arbitrage-Bot repository — a comprehensive toolkit designed to demystify blockchain arbitrage strategies for developers. This project provides thoroughly documented code and detailed instructions to help you understand arbitrage concepts and develop your own effective strategies.
Telegram: https://t.me/opensea712
- What is Arbitrage?
- Why Blockchain Arbitrage?
- Verification and Security
- Getting Started
- Configuration Setup
- Development Environment
- Deployment Process
- Technical Details
- Bot Architecture and Flow
- Mainnet Monitoring
- Multi-Chain Adaptation
- Testing and Continuous Operation
- Community
- Support the Project
- License
Arbitrage is a sophisticated trading strategy that capitalizes on price discrepancies of identical assets across different markets. By simultaneously purchasing at lower prices and selling at higher prices, traders can secure risk-free profits while promoting market efficiency.
Blockchain arbitrage offers multiple advantages for developers:
- Financial Opportunity: Leverage price inefficiencies across decentralized exchanges
- Skill Enhancement: Develop advanced blockchain development expertise
- Market Efficiency: Contribute to price equilibrium across trading platforms
- Strategy Integration: Incorporate into broader algorithmic trading systems
- Liquidity Enhancement: Occasional improvement of market liquidity in emerging tokens
Every code modification undergoes rigorous verification and digital signing. This ensures the absolute integrity and authenticity of our codebase. We strongly advise against using any unverified modifications, as they may contain malicious elements.
git clone https://github.com/earthskyorg/Dex-Arbitrage-Bot.gitEnsure you have node.js and npm installed before running:
npm installCreate a .env file with the following parameters:
ARB_FOR="" # Token0 address
ARB_AGAINST="" # Token1 address
PRICE_DIFFERENCE="" # Target price difference between DEXs
UNITS="" # Price reporting units
GAS_LIMIT="" # Maximum gas limit
GAS_PRICE="" # Gwei priceUse addresses from trusted block explorers and tailor numerical values to the strategy you intend to test. Maintain strict privacy of your .env file and never share its contents.
-
Configure your deployment environment by forking your target network for the Hardhat node. We recommend using a personal RPC URL for optimal reliability. Create Web3 API keys at Infura.
-
Add the following to your
.envfile:
API_KEY="" # Your Web3 API key
PRIVATE_KEY="" # Hardhat wallet private keynpx hardhat nodenpx hardhat run --network localhost scripts/1_deploy.jsCopy the deployed contract address and update the ARBITRAGE_ADDRESS field in config.json.
node bot.jsSince the forked blockchain state remains static, we must simulate price movement to trigger arbitrage:
npx hardhat run --network localhost scripts/2_manipulate.jsNote: After running this script, you may need to restart your Hardhat node and redeploy contracts for subsequent tests.
This simulation only affects your local blockchain, not the actual network. For tokens other than the provided example (LINK/WETH), you'll need to:
- Identify and use a relevant whale address from block explorers
- Adjust token manipulation amounts
- Modify profitability parameters in the
executeTradefunction
The Server script establishes and maintains a local server instance for the application.
The current implementation demonstrates a basic strategy using the manipulate.js script to alter Uniswap prices. After price manipulation, the system:
- Fetches reserves from Uniswap and Sushiswap
- Determines the lower LINK amount
- Divides this amount by half for trade execution
This division approach is provided as an example and may not be optimal for all strategies.
The runtime logic in bot.js follows a deterministic flow that keeps the bot highly observable:
main(): Subscribes to Uniswap and Sushiswap swap events and orchestrates the remaining functions.checkPrice(): Fetches and logs price data from both venues, returning an actionablepriceDifference.determineDirection(): Builds the router path and decides the buy/sell order when the price delta exceeds your threshold.determineProfitability(): Performs gas-aware profitability checks and short-circuits if the trade would not be net-positive.executeTrade(): Calls the deployed contract to perform the flash-loan-based trade and records a report before resuming monitoring.
Helper utilities inside helpers/helpers.js support token metadata lookups, reserve calculations, and quote estimations that feed the flow above.
To observe production liquidity without deploying locally:
- In
.env, replace the Hardhat testing private key with the private key of the wallet that should sign mainnet transactions. - In
config.json, setisLocaltofalse. ToggleisDeployedtofalseif you only want to monitor opportunities without invoking a contract, ortrueif a contract address is configured and should execute trades. - Run
node bot.jsto listen for live swap events. The bot will stream opportunities yet will only execute trades when bothisDeployedistrueand profitability criteria are met.
When targeting another EVM-compatible chain:
- Update token addresses in
.envusing the appropriate explorers (for example: etherscan.io, arbiscan.io, polygonscan.com, avascan.info and their respective testnets such as Sepolia, Mumbai, or Fuji). - Revisit strategy thresholds (
PRICE_DIFFERENCE,UNITS,GAS_LIMIT,GAS_PRICE) to reflect the liquidity profile and fee market of the new chain. - Edit
config.jsonto provide the router and factory addresses that correspond to the exchanges you intend to arbitrage. Cross-reference documentation from the venue (for example Uniswap V2 forks). - Adjust
helpers/initialization.jswith a chain-specific WebSocket RPC URL, and updatehardhat.config.jsso the forked network URL matches the chain RPC you are targeting. - Review
contracts/Arbitrage.soland, if necessary, swap the flash-loan provider for one that is deployed on the target chain (Balancer currently supports Ethereum, Arbitrum, Optimism, Polygon, Gnosis, and Avalanche). - Re-test helper scripts and deployment steps, paying special attention to Uniswap math helpers such as
getReserves,getAmountsOut, andgetAmountsInto ensure assumptions remain valid.
- Unit and integration scenarios can be executed locally with:
npx hardhat test- Start the live bot with:
node bot.jsOnce the bot is running, allow the market to trigger swap events—manual token manipulation will not be detected until a real event fires. The determineProfitability function is wrapped in try/catch logic so that math or RPC issues log gracefully without interrupting the websocket listeners.
We welcome contributions to enhance this project. If you identify bugs, have feature suggestions, or wish to improve functionality, please open an issue or submit a pull request.
We continuously monitor the evolving DeFi ecosystem and will update this project to align with emerging developments and industry best practices.
Our project operates on principles of open source and privacy. We maintain no social media presence, conduct no marketing activities, and receive no compensation for our GitHub contributions. We have no affiliations with other projects.
This project is licensed under the MIT License - see the LICENSE file for details.