With frontrunning in the headlines these days due to raids on platforms like Uniswap I was wondering from a technical point of view how these guys are able to do it ? I'm still learning Ethereum with all the pros and cons, especially with subjects such as the txpool.
I've watched the successful bots closely and they all seem to be using smart contracts. My initial guess was that everything was done on-chain, however, after learning that smart contracts cannot listen to events of other smart contracts, I'm not so sure that is the case anymore. How can a smart contract trigger a trade if it is not notified by some event of doing so ?
So all that I can think of is that an off-chain bot is going through every single pending transaction in the txpool and when it detects what it's looking for, it calls the on-chain smart contract to execute the trade.
Is my thinking correct on this ?
My second question would be is there a way to stop them?
I did not mark a correct answer below as both answers add a lot of value and completed the picture in my opinion