├── LICENSE ├── README.md └── arbitrage.sol /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 codeesura 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arbitrage Bot on Uniswap and Sushiswap 2 | 3 | This is a smart contract that allows for arbitrage trading between Uniswap and Sushiswap decentralized exchanges. The contract buys a token on Uniswap with ETH, and then sells the token on Sushiswap for a profit. 4 | 5 | ## Getting Started 6 | 7 | To get started with this contract, you will need the following: 8 | 9 | - An Ethereum wallet with some ETH and the token you want to trade 10 | - Knowledge of how to interact with smart contracts on the Ethereum network 11 | - Access to the Uniswap and Sushiswap exchanges 12 | 13 | ## Installation 14 | 15 | There is no installation required for this contract. Simply deploy it on the Ethereum network using Remix or another Ethereum IDE. 16 | 17 | ## Usage 18 | 19 | To use this contract, follow these steps: 20 | 21 | 1. Send the token you want to trade to the contract address 22 | 2. Call the `swap` function on the contract, passing in the address of the token you want to trade and the amount of the token you want to trade. 23 | 3. The contract will buy the token on Uniswap with ETH, and then sell the token on Sushiswap for a profit. 24 | 4. The profit will be sent to your wallet. 25 | 26 | ## Contract Details 27 | 28 | The contract uses the following interfaces: 29 | 30 | - `IUniswapV2Router`: This is the interface for the Uniswap router contract, which allows for trading on Uniswap. 31 | - `ISushiSwapRouter`: This is the interface for the Sushiswap router contract, which allows for trading on Sushiswap. 32 | - `IWETH9`: This is the interface for the Wrapped ETH token, which is used for trading on Uniswap and Sushiswap. 33 | 34 | The contract also uses the following constants: 35 | 36 | - `WETH_ADDRESS`: This is the address of the Wrapped ETH token contract. 37 | - `UNISWAP_ROUTER_ADDRESS`: This is the address of the Uniswap router contract. 38 | - `SUSHISWAP_ROUTER_ADDRESS`: This is the address of the Sushiswap router contract. 39 | 40 | The `swap` function takes in two parameters: `_address` and `_amountIn`. `_address` is the address of the token you want to trade, and `_amountIn` is the amount of the token you want to trade. 41 | 42 | The function does the following: 43 | 44 | 1. Transfers the token from the sender to the contract. 45 | 2. Approves the Uniswap router to spend the token. 46 | 3. Buys the token on Uniswap with ETH. 47 | 4. Approves the Sushiswap router to spend the token. 48 | 5. Sells the token on Sushiswap for ETH. 49 | 6. Sends the profit to the sender. 50 | 51 | ## Examples 52 | 53 | Ekran Resmi 2023-03-03 00 52 30 54 | 55 | 56 | Ekran Resmi 2023-02-23 01 18 04 57 | 58 | 59 | ## License 60 | 61 | This code is licensed under the MIT license. 62 | -------------------------------------------------------------------------------- /arbitrage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IUniswapV2Router { 5 | function swapExactTokensForETH(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external returns (uint[] memory amounts); 6 | function getAmountsOut(uint amountIn, address[] memory path) external view returns (uint[] memory amounts); 7 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); 8 | function swapETHForExactTokens(uint amountOut,address[] calldata path,address to,uint deadline) external payable returns (uint[] memory amounts); 9 | function swapExactETHForTokens(uint amountOutMin,address[] calldata path,address to,uint deadline) external payable returns (uint[] memory amounts); 10 | } 11 | 12 | interface ISushiSwapRouter { 13 | function swapExactETHForTokens(uint amountOutMin,address[] calldata path,address to,uint deadline) external payable returns (uint[] memory amounts); 14 | function getAmountsOut(uint amountIn, address[] memory path) external view returns (uint[] memory amounts); 15 | function swapTokensForExactTokens(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); 16 | function swapExactTokensForETH(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external returns (uint[] memory amounts); 17 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); 18 | } 19 | 20 | interface IWETH9 { 21 | function deposit() external payable; 22 | function withdraw(uint256 wad) external; 23 | function approve(address guy, uint256 wad) external returns (bool); 24 | function transfer(address dst, uint256 wad) external returns (bool); 25 | function transferFrom(address src, address dst, uint256 wad) external returns (bool); 26 | function totalSupply() external view returns (uint256); 27 | function balanceOf(address src) external view returns (uint256); 28 | function allowance(address src, address guy) external view returns (uint256); 29 | 30 | event Approval(address indexed src, address indexed guy, uint256 wad); 31 | event Transfer(address indexed src, address indexed dst, uint256 wad); 32 | event Deposit(address indexed dst, uint256 wad); 33 | event Withdrawal(address indexed src, uint256 wad); 34 | } 35 | 36 | contract MyContract { 37 | address constant WETH_ADDRESS = 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6; 38 | address constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; 39 | address constant SUSHISWAP_ROUTER_ADDRESS = 0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506; 40 | IUniswapV2Router private uniswapRouter; 41 | ISushiSwapRouter private sushiswapRouter; 42 | 43 | constructor() { 44 | uniswapRouter = IUniswapV2Router(UNISWAP_ROUTER_ADDRESS); 45 | sushiswapRouter = ISushiSwapRouter(SUSHISWAP_ROUTER_ADDRESS); 46 | } 47 | 48 | function swap(address _address,uint256 _amountIn) external { 49 | IWETH9(WETH_ADDRESS).transferFrom(msg.sender, address(this), _amountIn); 50 | IWETH9(WETH_ADDRESS).approve(address(UNISWAP_ROUTER_ADDRESS) ,_amountIn); 51 | // Buy the token on Uniswap with ETH 52 | address[] memory path = new address[](2); 53 | path[0] = WETH_ADDRESS; 54 | path[1] = _address; 55 | // Get the amount of tokens received 56 | uint256[] memory amounts = uniswapRouter.swapExactTokensForTokens(_amountIn, 0, path, address(this), block.timestamp); 57 | uint256 amountOut = amounts[1]; 58 | // Sell the token on Sushiswap with _address 59 | IWETH9(_address).approve(address(SUSHISWAP_ROUTER_ADDRESS) ,amountOut); 60 | path[0] = _address; 61 | path[1] = WETH_ADDRESS; 62 | uint256[] memory amounts_1 = sushiswapRouter.swapExactTokensForTokens(amountOut,0, path, msg.sender, block.timestamp); 63 | uint256 amountOut_1 = amounts_1[1]; 64 | require(amountOut_1 > _amountIn , "Arbitrage fail !"); 65 | 66 | } 67 | } 68 | --------------------------------------------------------------------------------