This is how you discover pools for your MEV trading bot 🤖

By akohad Apr8,2024

[ad_1]

Trading on a variety of pools is essential for the profitability of your MEV bot. The more different sources of liquidity your bot has access to, the likelier you are to land a profitable trade that other bots will have missed. Next to the quantity of pools, you will also probably want to filter out pools with a low liquidity, as these may cause your trades to fail.

Great, so how do you discover these pools? Well, there are two methods that I personally use for my MEV bot, which I will outline in this post.

  1. 🖥️ Using API’s / Scraping

A great way to collect trading pools is to use public API’s offering on-chain pool data. The two sources that I use the most are https://dexscreener.com/ and https://www.geckoterminal.com/. They both feature a public API for a many blockchains. The added benefit of using these sources is that they also include the liquidity of every pool, making it super easy to filter out pools with low liquidity!

Example of Optimism pools on Coingecko Terminal

2. 🔍 Following blockchain activity

The second method is rather intuitive. What better way to find pools than to get them right from the source? That’s right, you can discover a great deal of pools by following blockchain activity. Every time a new block gets published, you can run through the transactions and do a check on the target contract. Whether the transaction encapsulates a trade or the creation of a new pool, you will be able to verify if the target contract is a pool and add it to your collection.

The benefit of this method is that you are interacting with the source, and thus the latest data. You will be able to spot new pools as soon as possible and perhaps extend your existing collection with pools you did not discover before.

The general flow for discovering pools this way would look like this:

General workflow

For every transaction, you check the target contract for a signature. The signature is different for every type of pool. For a UniswapV2 pool, a good idea would be to check for the existence of a swap method in the deployed bytecode. On Etherscan, we can see that the following Uniswap pool has the swap method:

smart contract methods

The function selector of this method is 0x022c0d9f. If you are not familiar with function selectors, see here for more info. This contract has had its source code verified, so it is easy to tell that this is a Uniswap pool. Not all pools have their source code verified, far from actually. There are a lot of pools out there that have not been verified on Etherscan or other block explorers. To recognize these contracts as a Uniswap pool, you’ll have to do a search for the function selector in the deployed bytecode, which is always available.

bytecode matching

In this case, we can see that the function selector gets matched (note that we search for the selector without the ‘0x’ prefix). To avoid false positives, it’s worthwhile to match a few other methods as well. After this process, we can confidently identify pool smart contracts.

3. ✅Combining the methods

Both methods have their benefits, as a lot of things in engineering, no solution is perfect. Combining these two methods will give you the best results. Using the API’s will give you a head start. Over time, you can extend your collection of pools with data from blocks. This way, you will have an edge over your competition and have a better chance at landing that perfect trade 🚀!

[ad_2]

Source link

By akohad

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *