DexModule7579

Solves the common MEV attack when attacker tries to insert his transactions in front of you.

Solution

The DexModule7579 facilitates asset swaps on the uniswap v3 with built-in protection against MEV (Maximal Extractable Value) attacks, specifically designed for account abstraction. When account invokes DexModule7579, it passes the swap parameters with the allowed deviation between the asset’s spot price and the oracle price stored in the target pool. This deviation is calculated as the average over a specified time period, ensuring that the swap can be fulfilled without slippage tolerance while still reverting in case of the slippage attack. The module enables deferred execution of the swap without explicitly providing the slippage comparing the resulted price with the weighted average and protecting against MEV attacks.

Note: To successfully protect against MEV attacks, it is necessary to increase the maximum number of liquidity observations. Pay attention to the cardinalityInit function in the tests. You can find more information about oracle's work in the Uniswap Oracle documentation.

Example

You want to exchange Ether for USDC. But before your swap, a MEV attack was committed, which will not allow you to make an exchange at the desired price. The module has built-in protection against MEV attacks. The current spot price is compared with the weighted average price for the last 60 seconds, if the delta is greater than the deviation threshold, then the transaction reverts explicitly protecting from sandwiching.

Last updated