It is a common sense that sandwich attacks are impossible to 100 % prevent from happening. But say to prevent a sandwich attack happens on a uniswap(v2) trading, I have a thought, I wonder if it would work.
say I deployed a token contract and created pair and added liquidity. But within my token code I have changed a few things about transferFrom function based on a normal ERC20 standard.
mapping (address =>uint)public timeLockMapping;
address public pairAddress;
function transferFrom(address from, address to, uint amount) external override{
if (from ==pairAddress){timeLock[to] = block.timeStamp + 10;}
...(other logics for transferFrom)
require (block.timeStamp >= timeLock[from])
...(other logics for transferFrom)
}
First I check If the buyer is buying the token from pair, if yes, I would use the timeLockMapping to give the buyer a time stamp (10 seconds in the future), as his time lock. And if this buyer sells the token within the time limit(10 seconds) to the pair, it shall be reverted due to the time lock is still on.
To a very popular token, which means there's a lot of transactions which are happening every second. A 10 second delay would sabotage the mevBot, because the price could ulter in anyway, I assume. And of course to a less popular token, maybe there are no transactions at all within 10 seconds, the mevBot can still profit. But I guess at least this could work.
And form what I have learned, some of the mevBots are established on flashBot, which usually requires all 3 transactions(2 from attackers, and in between is the victim's transaction) shall be in the same block, otherwise the attackers will cancel the 2 attacking transactions.
Now I wonder if you are the attacker, is their any other way to bypass this time lock to still perform a sandwich attack? or is there any potential problem in this SUPER-EASY strategy.
I had this idea and want to check if it is practical. thank you ahead.