The maximum value that may be taken out of a block is known as MEV, or maximum extractable value. Previously, miners were the only ones who could take advantage of this opportunity, which is why it was occasionally referred to as Miner Extractable Value. However, as the mempool has become more accessible, traders now have more chances to extract value by deciding what is included in a block. By examining what’s currently in the mempool and then timing and pricing their transactions accordingly, MEV Searchers may easily influence which transactions are included and excluded, or even modify the sequence of transactions in a block.
Read More: mev bot
These Searchers usually use bots to automatically report any successful transactions to the network after running algorithms to find valuable MEV chances. This blog describes my attempt to build one of these bots and the things I discovered along the process. You may use this as a starting point to assist you start coming up with new ideas and techniques that are exclusive to you.
Please be aware that this blog’s script and smart contract are just meant to be instructive. Before investing any of your own funds in any opportunity, please conduct your own investigation since you will not be making any money with this code. Since the Ethereum mainnet is so competitive, elite bots in the ecosystem frequently share this viewpoint.
In the context of MEV, what does an arbitrage strategy mean?
Traders can profit from price disparities between the same item in multiple marketplaces by using the MEV approach of arbitrage. This offers the chance to conduct two transactions in the conventional financial sector in order to bring the two exchanges into balance and turn a little profit in the process.
Starting with asset A, you would sell it on the exchange for asset B, as asset B is the more affordable option. After that, you would take asset B and sell it on the other exchange for asset A, making a larger profit than you had initially. In conventional banking, there is fierce competition among High Frequency Traders to be the first to execute the arbitrage opportunity, as seen by this simple example.
Things are a little bit more tricky in the realm of MEVs. In cryptocurrency, transactions are sent to the mempool, which is mostly accessible to the public, in order to be included in the subsequent block. As a result, traders are able to view pending transactions in the mempool and are aware of the consequences before they are completed on-chain.
This enhanced visibility results in MEV arbitrage operating somewhat differently than traditional arbitrage since traders don’t need to wait until transactions are on-chain to discover an opportunity. For this reason, in order to examine each transaction as it is received, MEV searchers require a real-time data feed of the mempool.
You can transmit your two transactions that will complete the arbitrage opportunity straight into the mempool or to the flashbots private relay as a bundle after you identify a transaction that could result in a chance for arbitrage when it arrives on-chain. If done properly, this implies that your two transactions and the mempool transaction that generates the opportunity will all be mined in the same block. Therefore, the following two transactions—your two transactions—complete that arbitrage opportunity as soon as it arises.
looking for chances to engage in arbitrage
I came discovered a pre-built smart contract in this fantastic github repository when researching the different MEV chances. It guides you through the process of determining the ideal amount to arbitrage between two Uniswap V2 DEXs, such as Uniswap V2 and Sushiswap.
This repository was ideal for obtaining a proof of concept because the project wasn’t particularly about delving further into solidity. This smart contract’s main feature is its ability to receive two pools—a Uniswap pool and a Sushiswap pool—and provide information on whether there is any profit made by arbitraging the two pools. But the computation is being performed by examining the two pools’ current reserves (i.e., the most recent block state).
But what if, before the following block, you knew how those pools were going to change? In such case, you might place your arbitrage transaction in the ideal position to take advantage of these possibilities as you would be aware of arbitrage opportunities before they arise on-chain. My objective for this project was to now create a simple script that updates this smart contract to effectively identify arbitrage opportunities by utilizing the net balance change computation of the Blocknative Simulation Platform.
Creating a simple script for arbitrage
This is not a piece to educate readers on solidity. There are many excellent papers and courses available, but you need to know some solidity if you want to be competitive for MEV chances (at least in the EVM realm).
Having said that, I modified the smart contract to meet my needs using what little I knew about Solidity. I would need to find a means to feed my getProfit function with an adjustment on a liquidity pool in order to compute the real-time profit of an arbitrage opportunity. This change is made in the event that I see a swap transaction in the mempool that affects the liquidity pool for either Sushiswap or Uniswap.
When I compute the profit potential for the arbitrage opportunity, I take the mempool transaction into account. I made a new struct named “Adjustments” to hold the pool that needed to be modified, the direction it needed to be adjusted in, and the quantity of adjustments that needed to be made to each token in the token pair in order to integrate this adjustment. Then you’ll see that in order to determine each pool’s reserves and the appropriate trade direction, getProfit depends on getOrderedReserves. In order to ensure that when getProfit was called, it would include the mempool data rather than just the most recent chain state, I added some logic to getOrderedReserves that would take in the mempool data of a token swap on Uniswap or Sushiswap and then update the token reserves of that pair.