You could deploy your own custom router contract. Easily fork one from the original Uniswap Router. Make every write function to be onlyOwner(). Then modify the swap function so instead of sending the token back to the sender wallet. The contract itself will receive and send the token.
Thus when selling you don't need any approval, because the contract is the owner of the token itself. For actual uses, you transfer WETH from your wallet to that contract first. Then use your custom function for swapping tokens. And don't forget to create a withdrawn function so you could call that and let the contract send WETH it has back to your wallet.
This is common practice use by bot. You can completely trade using this contract instead of Uniswap one unless the token only lets a specific address(eg. original router) call transfer.
TL;DR Sandwich bots work by having a buy transaction before the victim's buy transaction, then a sell transaction just after. They profit from the increase of price caused by the victim's buy transaction in the middle.
When you send a swap transaction to a DEX like Uniswap/Pancakeswap, you must also specify a slippage tolerance (in %). It is like saying "I want to buy 1 apple for 100$, but I am ok if, when the transaction is processed, the price is up to 102$ and I want the transaction to go through anyway." The bot exploit this slippage tolerance for profit.
Here is a very (very) simplified example:
- The bot will first buy the apple at 100$ for an amount that will
raise the price to 101$. The bot now has 1 apple paid 100$.
- The victim buys 1 apple. The victim wanted to pay 100$, but is still ok with a price of 101$ (slippage tolerance), so the transaction goes through. This purchase raises the price to 102$ after the transaction is processed.
- The bot sells its apple at the current price of 102$ for a 2$ profit. The price goes back down to 101$ after the transaction.
Basically, sandwich bots are extracting the slippage tolerance of traders.
What about the price discrepancy?
Your question seems to imply that the price reverts back to the original 100$ following those transactions. I don't think that it is the case. The net effect should be that the price of apples will rise because of the victim's transaction. Otherwise, the constant product formula (x*y=k) would not be upheld. If you saw the price revert back to 100$, it was most likely because of an arbitrage transaction somewhere else in the block, not the sandwich bot (but that is a subject for another day).
Best Answer
You cannot. That will destroy the purpose of using private txs / Flashbots. What's happening here is the tx was taken from the mempool, made into a bundle and sent to Flashbots. Etherscan will detect and tag the txs in the bundle as private txs, so even if they have the private tx tag, doesn't mean that they were actually private.