Ethereum Arbitrage Bot
This repository contains a smart contract for a simple Ethereum-based arbitrage bot that takes advantage of price differences between Uniswap and Sushiswap decentralized exchanges. The contract is written in Solidity and uses the UniswapV2 and SushiSwap Router interfaces.
Table of Contents
Overview
Arbitrage is the process of taking advantage of price differences between markets, in this case, decentralized exchanges (DEXs). This contract automates the process of buying tokens on one DEX and selling them on another to profit from the price difference.
Smart Contract Description
The smart contract MyContract
performs the following steps:
- Receives an amount of Wrapped Ether (WETH) from the user.
- Buys UNI tokens on Uniswap using the received WETH.
- Sells the UNI tokens on Sushiswap and receives WETH.
- Sends the profit back to the user.
The contract uses the following interfaces:
- IUniswapV2Router: The interface for interacting with the Uniswap V2 router contract.
- ISushiSwapRouter: The interface for interacting with the SushiSwap router contract.
- IWETH9: The interface for interacting with the Wrapped Ether (WETH) contract.
Setup
- Install Node.js and npm.
- Install Truffle and Ganache for local development.
- Clone this repository.
- Install dependencies:
npm install
- Configure Truffle by editing the
truffle-config.js
file.
Deploying the Contract
- Start Ganache.
- Compile the smart contract:
truffle compile
- Deploy the smart contract to the local development network:
truffle migrate --network development
Interacting with the Contract
Use Truffle console or a web3 library like web3.js or ethers.js to interact with the deployed contract.
Example using Truffle console:
- Start the Truffle console:
truffle console --network development
- Get an instance of the deployed contract:
let myContract = await MyContract.deployed()
- Call the
swap
function with the desired amount of WETH:
await myContract.swap(web3.utils.toWei("1", "ether"), {from: accounts[0]})
Using Remix IDE
You can also use Remix IDE, a web-based development environment for writing, testing, and deploying Solidity smart contracts, to work with this arbitrage bot contract.
Setup
- Visit Remix IDE.
- Click the "Solidity" environment button.
- Create a new file by clicking the "+" icon and name it
MyContract.sol
.
- Copy the content of the provided smart contract and paste it into
MyContract.sol
.
- In the left sidebar, go to the "Solidity Compiler" tab and compile the smart contract.
Deploying the Contract
- In the left sidebar, go to the "Deploy & Run Transactions" tab.
- Select the appropriate environment, such as "Injected Web3" for MetaMask or "JavaScript VM" for a simulated environment.
- If using MetaMask, connect your wallet and choose the appropriate account.
- Click the "Deploy" button to deploy the smart contract.
Interacting with the Contract
Once the contract is deployed, you can interact with it using the "Deployed Contracts" section in the "Deploy & Run Transactions" tab.
- Expand the deployed contract by clicking on the arrow next to its address.
- Use the provided input fields and buttons to call the functions of the contract. For example, call the
swap
function and provide the amount of WETH you want to use for the arbitrage.
Output
Disclaimer
This project is for educational purposes only. Arbitrage opportunities are not guaranteed and can be highly volatile. The author is not responsible for any financial losses incurred from using this code. Use at your own risk.