Say goodbye to MEV attacks and say hello 👋 to the best executed price with Slippage Protection
Topics covered on this page include:
Slippage Protection is a feature of the 0x API that finds the best routes for decentralized exchange (DEX) trades while avoiding slippage and MEV attacks.
Slippage Protection incorporates slippage forecasts into 0x API’s smart order routing algorithm to deliver the optimal trade route. With Slippage Protection activated, 0x API will enable developers to surface more reliable quotes and consistently deliver the best executed price to users. Slippage Protection is currently supported on Ethereum for the most active trading pairs (ETH-USDC, ETH-DAI, ETH-USDT, ETH-WBTC, WETH-USDC, WETH-DAI, WETH-USDT, WETH-WBTC)
The best executed price is the price users receive that’s inclusive of gas fees and slippage after taking into account all possible liquidity paths. This is an important distinction because many DeFi applications today show quoted prices which may be drastically different from the executed price.
Without Slippage Protection, the user is routed to Liquidity Source A because it offers the best quoted price. However, if Slippage Protection is enabled, 0x API’s smart order routing instead attempts to maximize the executed price, so the user is routed to Liquidity Source B instead.
Over the past couple of years, we’ve seen significant growth in adoption of DeFi products. In 2021 alone, DEXes reported more than $1 trillion in trading volume. While this volume growth has been incredible, we’ve also seen millions of dollars lost to MEV. Since 2020, bots have extracted over $650M from DEX users. These losses typically manifest as slippage, which is only visible after trade settlement (i.e. after the trade has been mined into a block). Slippage is typically left unreported to the afflicted user.
Slippage Protection ingests slippage measurements and their statistical properties to model and predict slippage outcomes for different liquidity sources, trading pairs, and trade sizes. These model predictions are then incorporated into 0x API’s smart order routing to identify the route(s) expected to yield the best executed price. The result is a more transparent and consistently better executed price than what users encounter today in wallets and DeFi applications.
In April 2022, we published a research piece that shows the extent of slippage experienced by DEX users and in which circumstances slippage is more likely to occur. We leveraged this research to develop Slippage Protection and protect users against slippage. The data we collected gives us the ability to measure and predict slippage from different liquidity sources, we then incorporate those predictions into our smart order routing. Over time, Slippage Protection will continue to evolve with more data sets and the algorithm will improve. With Slippage Protection activated, orders will be routed to avoid slippage and MEV attacks, find the lowest gas fees, and deliver the best executed price. The result is a more transparent and consistently better executed price than what users encounter today in DeFi applications. For more details on how Slippage Protection works, please read Introducing Slippage Protection for 0x API. Read about the performance Post-launch of Slippage Protection.
Slippage Protection is an auto-enabled feature of the 0x API, and no additional action is required to enable to implement it in your API request. It is controlled by the new
The following section includes a summary of the Request and Response changes related to Slippage Protection:
enableSlippageProtectionparameter (an Optional Boolean) has been added to the
- If it is set to
trueor not set, the quote will automatically adjust for MEV-aware slippage.
- If set to
false, the quote returned will not be adjusted for MEV-aware slippage.
We recommended meta-aggregators and integrators who compare the quoted price with other sources to set the
expectedSlippageresponse fields in the
/swap/priceendpoints are affected by this change
price: It should be noted that when
enableSlippageProtectionis not false, the
pricereturned will factor slippage in its routing.
expectedSlippage: This is the expected slippage used in routing calculations for the quote returned. It is the value of slippage that we estimate that the selected route will have:
- It can be used by integrators to calculate the Final Expected Amount for the asset: i.e. calculated as (
- It will only be returned when
enableSlippageProtectionis not set to