Swapexactethfortokens being sandwiched even if AmountOutMin is added properly.
Why this is happening i have no clue..As i think AmountOutMin does cover slippage
swapExactEthForTokens
is still vulnerable to a sandwich attack, amountOutMin
as the name indicates is the minimum tokens to receive, setting it correctly only means that you will receive at least that amount of tokens.
suppose that the market liquidity is at 1000 TKA, 500 TKB, swapping 10 TKA for TKB gives you ~4,95 TKB (ignoring fees)
then you call swapExactEthForTokens
with a min of 4 TKB, there is still the difference left.
Thats correct but look at the figure and you will understand it quite large amount which is taken out by attacking bot
Red is my trade and blue is attacking bot
probably you are setting amountOutMin
too low. the transaction should fail if you are not getting at least that amount of tokens
The AmountOutMin value set by script is 7.7718260852084E+28 and actual out tokens are 7.80587814230317E+28.
So i do not think value are low
So you say you are being sandwiched, but your Min amount out is correct. Then there is no problem as if your min amount out is correct then a sandwich attack does nothing and won’t even be tried by a bot. So you must be either mistaken and you are not being sandwiched or you are not setting the amount out correctly.
Your screenshot is very unclear and doesn’t provide a lot to go on. What exactly are you expecting ? What exactly are you sending? What are the transaction id’s. Which transactions are yours?