Published On Apr 9, 2023
Get my free EthersJS cheatsheet to master Web3!
👉 https://blockman-codes.ck.page/91b29a...
------------------------------------------
Courses:
👉 Build a Uniswap V3 interface that can do swaps: https://bit.ly/3JkXYqL
------------------------------------------
How do you programmatically check for arbitrage between swap pairs on Uniswap V2 and SushiSwap with code.
Uniswap V2 and SushiSwap use the same router contract code, so out of all arbitrage implementations, this is a good introduction.
In this tutorial we compute if an arbitrage opportunity exists between the protocols for a pair of tokens.
------------------------------------------
Starter Code
```
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/abc');
const token0 = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH
const token1 = '0x6b175474e89094c44da98b954eedeac495271d0f'; // DAI
const uniRouterAddress = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d';
const sushiRouterAddress = '0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F'
const PATH = [token0, token1]
const routerAbi = [
'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
]
const uniRouter = new ethers.Contract(uniRouterAddress, routerAbi, provider);
const sushiRouter = new ethers.Contract(sushiRouterAddress, routerAbi, provider);
const amountIn = ethers.utils.parseEther('1');
```