codeesura / 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.
MIT License
11 stars 5 forks source link

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:

  1. Receives an amount of Wrapped Ether (WETH) from the user.
  2. Buys UNI tokens on Uniswap using the received WETH.
  3. Sells the UNI tokens on Sushiswap and receives WETH.
  4. Sends the profit back to the user.

The contract uses the following interfaces:

Setup

  1. Install Node.js and npm.
  2. Install Truffle and Ganache for local development.
  3. Clone this repository.
  4. Install dependencies:
npm install
  1. Configure Truffle by editing the truffle-config.js file.

Deploying the Contract

  1. Start Ganache.
  2. Compile the smart contract:
truffle compile
  1. 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:

  1. Start the Truffle console:
truffle console --network development
  1. Get an instance of the deployed contract:
let myContract = await MyContract.deployed()
  1. 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

  1. Visit Remix IDE.
  2. Click the "Solidity" environment button.
  3. Create a new file by clicking the "+" icon and name it MyContract.sol.
  4. Copy the content of the provided smart contract and paste it into MyContract.sol.
  5. In the left sidebar, go to the "Solidity Compiler" tab and compile the smart contract.

Deploying the Contract

  1. In the left sidebar, go to the "Deploy & Run Transactions" tab.
  2. Select the appropriate environment, such as "Injected Web3" for MetaMask or "JavaScript VM" for a simulated environment.
  3. If using MetaMask, connect your wallet and choose the appropriate account.
  4. 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.

  1. Expand the deployed contract by clicking on the arrow next to its address.
  2. 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

image

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.