Uniswap V3 – Difference Between sqrtPriceLimitX96 and amountOutMinimum Explained

amountoutminimummevsqrtpricelimitx96uniswapuniswapv3

The sqrtPriceLimitX96 is just a price limit which cannot be exceeded by the trade.

At the same time, the amountOutMinimum appears to do the same thing in that you can achieve maximum price by taking:

amountIn / amountOutMinimum

So let's say we're talking about WETH/USDC on arbitrum. Arbitrum is easier because it's USDC/WETH (token 1 / token 0) for price. So let's say price is currently $1,500.

If you are willing to put in $1,600 USDC for an amount out minimum of 1 WETH then the worst price you're willing to accept is $1,600 USDC per WETH.

This to me is the same as using a $1,600 USDC / 1 WETH price limit.

Can someone please explain the difference. The ever wonderful miss Rachel in the dev discord was unfortunately unable to explain this, though I assume the uni devs have a very good reason for this as they do for most things.

Best Answer

Both sqrtPriceLimitX96 and amountOutMinimum serve as protective measures for traders on Uniswap V3, but they operate at different levels and have distinct behavioral implications.

sqrtPriceLimitX96:

Operational Level: This parameter is integrated into the core UniswapV3Pool contract, which handles the fundamental operations of liquidity provision and swaps.

Function: It establishes a price boundary for a swap. During a trade on Uniswap V3, as liquidity is utilized and price shifts, the sqrtPriceLimitX96 ensures the price doesn't go beyond this pre-defined limit. If the sqrtPriceX96 at the very start of the swap exceeds the sqrtPriceLimitX96 in the swap direction then the swap will revert with SPL.

Behavioral Implication: This parameter allows for partial trades. Meaning, if the trade would breach this price before exhausting the amountSpecified, the system will only trade up to the limit, potentially using less than the full amountSpecified.

amountOutMinimum:

Operational Level: This parameter is employed at the higher-level SwapRouter interface, which interacts with the core pool contracts and offers an abstracted method for users to conduct trades.

Function: It mandates a minimum amount of the output token the trader must receive for the swap to be valid. After the swap is executed, the resultant amount of the output token is compared to this value.

Behavioral Implication: It acts as an all-or-nothing check post-swap. If the resultant output from the swap is less than the amountOutMinimum, the entire transaction is reverted. This is independent of whether the sqrtPriceLimitX96 was adhered to during the swap.

Summary: While both parameters help traders define the bounds of their trades, they do so in different ways. The sqrtPriceLimitX96 offers low-level control, allowing partial trades up to a specified price, whereas amountOutMinimum provides a high-level post-trade check ensuring the trader receives a minimum desired return.

By using both, Uniswap V3 offers traders a combination of precise control (through sqrtPriceLimitX96) and a safety check (through amountOutMinimum), optimizing both flexibility and security.

Related Topic