I'm wondering whether I can stop / impair the 'standard' frontrunner / sandwich bots from frontrunning my (pretty standard) ERC20 token contract.
I'm thinking to add a mapping called "lastBuyBlock" for each address that buys (the 'to' address of the called _transfer function, when 'from' == pairAddress), which stores the block.number of an address' last buy tx.
Example:
mapping(address => uint256) private lastBuyBlock;
if (from == pairAddress) { lastBuyBlock(to) = block.number; }
Each sell or transfer tx (when 'from' != pairAddress), the current block.number will be compared to the "lastBuyBlock" of the 'from' address in the called _transfer function.
If the current block number equals the lastBuyBlock(from) --> 'from' is a confirmed frontrunner bot and thus action can be taken accordingly (for example revert the tx):
if (from != pairAddress && block.number == lastBuyBlock(from)) { revert(); }
Would this be a good / useful approach? Any arguments as to why I would not implement it this way? I think the 'added gas costs' to perform this frontrunner check on ETH network are fairly low, compared to the benefit of cutting out frontrunner bots. Am I missing something here (as I'm wondering why other tokens haven't implemented a comparable check like this already long time ago) ?
I do realize the bot owners could change their bot code to bypass this check (if they buy -> transfer to different address -> sell from that different address in the same block), but the above example would make that impossible as well.
Any reasons / input as to why I would or would not implement this check, are greatly appreciated!