In a scenario where i want to perform a trade on a DEX using high slippage, and i can perform the trade via my own program and then use CPI to do the swap, what checks can i add to my program to make sure i wont get sandwiched?
I've seen a few developers add something to their programs to do this exact thing, but they're close source, so i'm wondering if there's some common method for this?
I was thinking of comparing pool state for unusual behavior (so in transaction i include pool state from before submitting the transaction, and within my program i fetch it again and compare against it) but im not sure if thats a good idea as i presume it would be hard to differentiate between major state change due to sandwich attack and popularity of the token.