Slippage and MEV preventation in trades
Closed this issue · 3 comments
Creaet a function that calculates amountIn
and amountOut
values for buy/sell with a specific slippage.
See this question for details:
https://ethereum.stackexchange.com/questions/99404/pancakeswap-anti-front-run
First for Uniswap v2, as its dog eats dog frontrun battle at BNB Chain.
Can you make a this kind of unit test
- prepare a trade where I set the max slippage to 1%, making the signed transaction ready
- then trade in the pool so that the price moves more than 1%
- now try to broadcast the transaction so that it revets (there would be too much slippage, the trade is not allowed to execute)
As a bonus, trade analyzer should able to tell if the trade was reverted because of slippage. Though not sure how we can pick up this from the transaction receipt, I believe is going to be quite hard. The ”real” EVM nodes do not store the revert reason for very long time (few hundreds of blocks) and one might need to replay the transaction.
https://snakecharmers.ethereum.org/web3py-revert-reason-parsing/