Last active
October 20, 2023 08:07
-
-
Save BedrosovaYulia/9486f5ee369ce9c2b61b00e7498fb625 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("dotenv").config() | |
const Web3 = require('web3'); | |
const abis = require('./abis'); | |
const { mainnet: addresses } = require('./addresses'); | |
const web3 = new Web3( | |
new Web3.providers.WebsocketProvider(process.env.INFURA_URL) | |
); | |
const quickswap = new web3.eth.Contract( | |
abis.quickswap, | |
addresses.quickswap.router | |
) | |
const sushi = new web3.eth.Contract( | |
abis.quickswap, | |
addresses.sushi.router | |
) | |
const AMOUNT_IN_WEI = web3.utils.toBN(web3.utils.toWei('1000')); | |
let badPairs = []; | |
const init = async () => { | |
while (true) { | |
for (var tokenAName in addresses.tokens) { | |
for (var tokenBName in addresses.tokens) { | |
if (tokenAName != tokenBName) { | |
if (!badPairs.includes(tokenAName + ' ' + tokenBName)) { | |
console.log('Pair: ' + tokenAName + ' ' + tokenBName); | |
let tokenAAddress = addresses.tokens[tokenAName]; | |
let tokenBAddress = addresses.tokens[tokenBName]; | |
try { | |
const amountsOut1 = await sushi.methods.getAmountsOut(AMOUNT_IN_WEI, [tokenAAddress, tokenBAddress]).call(); | |
const amountsOut2 = await quickswap.methods.getAmountsOut(amountsOut1[1], [tokenBAddress, tokenAAddress]).call(); | |
const amountsOut3 = await quickswap.methods.getAmountsOut(AMOUNT_IN_WEI, [tokenAAddress, tokenBAddress]).call(); | |
const amountsOut4 = await sushi.methods.getAmountsOut(amountsOut3[1], [tokenBAddress, tokenAAddress]).call(); | |
console.log(`Sushi -> quickswap. input / output: | |
${web3.utils.fromWei(AMOUNT_IN_WEI.toString())} / | |
${web3.utils.fromWei(amountsOut2[1].toString())}`); | |
console.log(`quickswap -> Sushi. input / output: | |
${web3.utils.fromWei(AMOUNT_IN_WEI.toString())} / | |
${web3.utils.fromWei(amountsOut4[1].toString())}`); | |
if (web3.utils.fromWei(amountsOut2[1].toString()) < 500) { | |
badPairs.push(tokenAName + ' ' + tokenBName); | |
console.log("bad pair"); | |
} | |
if (web3.utils.fromWei(amountsOut4[1].toString()) < 500) { | |
badPairs.push(tokenAName + ' ' + tokenBName); | |
console.log("bad pair"); | |
} | |
const resultFromQuickSwap = web3.utils.toBN(amountsOut2[1]) | |
const resultFromSushiSwap = web3.utils.toBN(amountsOut4[1]) | |
if (resultFromQuickSwap.gt(AMOUNT_IN_WEI)) { | |
const profit = resultFromQuickSwap.sub(AMOUNT_IN_WEI); | |
if (profit > 0) { | |
console.log('Arb opportunity found SushiSwap -> QuickSwap!'); | |
console.log('Expected profit: ' + web3.utils.fromWei(profit).toString() + " " + tokenAName); | |
} | |
} | |
if (resultFromSushiSwap.gt(AMOUNT_IN_WEI)) { | |
const profit = resultFromSushiSwap.sub(AMOUNT_IN_WEI); | |
if (profit > 0) { | |
console.log('Arb opportunity found QuickSwap -> SushiSwap!'); | |
console.log('Expected profit: ' + web3.utils.fromWei(profit).toString() + " " + tokenAName); | |
} | |
} | |
} | |
catch (e) { | |
badPairs.push(tokenAName + ' ' + tokenBName); | |
console.log('some error'); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment