Intro We have 2 tokens in our project and 3 liquidity pools ( "token1-ETH", "token2-ETH" & "token1-token2"). Token1 has ~5% of fees and includes reflection. Token2 allows users to acquire Token1 for half the fee (compared to direct buy using ETH).

Issue Immediately after launch, we are observing 2 (or so I think) kinds of MEV bots actively attacking our tokens. One of them is a sandwich MEV bot that is wrapping buy and sell around large trades. This one is a nuisance but generates more reflection and not as dangerous. The other one is draining the liquidity pool. It makes huge number of transaction within a single block and is somehow draining the ETH from Token2-ETH liquidity.

Any suggestion on what we can do to protect our users from these MEV bots?

Is there a way to detect MEV bot in solidity contract? Any suggestions on how we can tax the MEV bot higher or block or throttle the number of transaction within a block.

Any help would be greatly appreciated.

I did not share particular details about the contract to avoid making these contracts public and inviting more attacks. I can share these details if required. I have the transaction hashes of these attacks.

4 Answers 4


Sorry, there's not way to analyze block contents in Solidity, or to detect a MEV transaction.

You basically jut have to analyze what they do and how they do it, and then either accept it or try to come up with some countermeasures. But in my opinion MEV is a 'natural' part of the ecosystem and all projects should be prepared for having MEV amongst their token pools.

And, in my opinion, you shouldn't try to add MEV protections to your tokens themselves anyway. That's a losing battle, since it's a lot harder for you to modify your contracts than for the MEV drainers to find a new pattern. Tokens should be really simply and old include minimum logic.

  • In our case, this bot seems to be drain the liquidity pool. The danger is that one of the coin may fail. It's somehow able to make large amount of ETH transaction of buy and sell and extract some of the ETH on the LP, I am unable to understand how they do it. But after a buy/sell the price of the token tanks by 50% or so.
    – Ra Murd
    Commented Feb 26, 2023 at 0:29


You should try this MEVBLOCKER.

From the homepage:

  1. Add the RPC endpoint directly to your wallet
  2. Enjoy full, automatic protection from all types of MEV
  3. Get paid by searchers for your transactions

MEV Blocker is a tool that helps Ethereum users avoid the financial losses that can result from MEV attacks while also allowing them to profit from the same mechanisms that are used to exploit them.

Always be careful when using tools like this. This tool seems legit but some research is always recommended.

  • 1
    please edit to describe what this does and how it solves the problem in the question post.
    – starball
    Commented Apr 16, 2023 at 20:01
  • Those RPC could protect a wallet, but they won't protect a smart contract. The protection would be at best partial.
    – Ismael
    Commented Apr 17, 2023 at 21:20

I'm also concerned about MEV bots on my projects but not enough to implement this solution I devised. It would cause more headache than it's worth. Since a majority of MEV bots perform multiple transactions in a block, you could try detecting that. Code like this would kill a majority of MEV bots but will also affect regular users. You would need to add exchanges to your whitelist, which sucks. But I think this does technically answer your question.

mapping (address => uint256) lastTransactionBlock;

// anti MEV bot
function _update(address from, address to, uint256 value) internal override {
    // MEV protection
    if (to != from) updateLastTransaction(to);

    super._update(from, to, value);

function updateLastTransaction(address holder) internal {
    if (!whitelist[holder]) {
        require(lastTransactionBlock[holder] != block.number, "MEV Protection: Only 1 transaction per block allowed");
        lastTransactionBlock[holder] = block.number;


Of course there is a concern over some scenarios when a user may legitimately need to perform multiple transactions per block but on chains with short block times such as Polygon or Base with ~2 second block times I don't see that happening too often. This may also mean smart contracts not whitelisted would not be able to manage funds in and out in the same block. Overall this solution may degrade user experience if not implemented correctly and likely won't suit many production projects but it's really up to you if you are willing to make this trade-off.

Another thing to be concerned about is the potential abuse of this code. An attacker could send 1 wei to the targeted address every block making it impossible for the target to transact their tokens. You could also add in an amount to check since MEV bots typically buy and sell all their tokens in 1 block, meaning you could check for this to further filter for MEV bots, but as stated in another answer the MEV bots would wise up and change to a pattern that allows them to attack again.


Since the question was asked about a year ago and no answer mentioned COW Protocol it should not count as marketing, in my opinion.

CoW DAO, the developer cooperative behind the decentralised exchange CoW Swap, wants to make things easier for liquidity providers. It just launched a new so-called automated market maker — or AMM — to combat MEV bots and hopefully save liquidity providers an estimated $500 million every year.


What is a Searcher? Searchers are DeFi market participants, most often bots, that monitor pending Ethereum transactions for arbitrage opportunities.

Captured arbitrage is known as maximal extractable value (MEV), and it’s a pernicious form of price exploitation that occurs across all types of transactions. To date, MEV has cost traders over $1.5 billion in losses. Most of these losses have been facilitated by searchers who pocket a large portion of the arbitrage for themselves.

CoW Protocol is a meta DEX aggregator that relies on bonded third parties known as “solvers” to execute user trades. The protocol uses an intents-based trading system where user intents get grouped into batches. The solver that can execute the orders at the best price wins the right to settle the batch (find out more about how CoW Protocol works here.)

Solvers are compensated in COW tokens for settling batches, incentivizing them to compete to find better prices and win the right to execute user intents. In return for this compensation, solvers provide users with a number of benefits including:

Finding optimal prices for the trades in a batch Protecting users from MEV by executing transactions on their behalf Providing abstraction that allows for benefits like gasless trades, transaction bundles, directly tapping into LPs, and more


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.