Flashbots — Project: Two-Pool UniswapV2 Arbitrage Bot
In Pursuit of Greater Than Zero Profits on Ethereum
It’s time to build another project!
We have checked off a number of prerequisites and now have the tools to build a fully-functional Ethereum bot doing simple 2-pool arbitrage using the Flashbots relay.
This lesson will not be the final one in the Flashbots series, but will serve as a nice foundation for some highly technical posts that will follow.
You should understand and have worked through the following lessons prior to beginning through this project:
And these Flashbots-specific lessons:
There are many steps necessary to build this new bot, and I will only briefly cover each step. If you need more detail, review the previous lesson on that topic since the concepts apply everywhere.
To avoid getting bogged down, I will divide this into several sections. The project will consist of several preparatory steps, followed by implementation of the bot itself.
I am running a local Ethereum node full-time now, and I recommend doing the same. If you want to use this bot with an external RPC, you will likely encounter significant latency issues because of the depth of Ethereum’s mempool and the need to fetch tens of thousands of pending transactions per day.
The bot will monitor and execute very familiar UniswapV2-style two-pool arbitrage. It monitors WETH pairs on UniswapV2 and Sushiswap, and is written to execute a flash borrow / LP swap arbitrage. It uses a bundle executor smart contract combined with a UniswapV2 callback function to deliver arbitrary payloads without using contract storage.
The contract will be deployed on Ethereum mainnet, so expect to pay about $50 in gas to deploy it even during periods of low activity.
Playing on Ethereum is not cheap, so beware! Spend lots of time working on a local fork before deploying because mistakes are painful.
This strategy is relatively simple (for MEV, this is about as easy as it gets), so do not expect to make any money on this. The key is that since you’re using Flashbots, you will not lose any money on discarded bundles which is a huge relief.
You should use this project as a building block to implement more sophisticated strategies.
I've made some small improvements to the degenbot code base, so run
git pull inside that directory to sync up to the latest on Github.
Make sure you have updated your Vyper compiler to at least version 0.3.4, which supports dynamic arrays and includes some important bug fixes.