amountOutMinimum serve as protective measures for traders on Uniswap V3, but they operate at different levels and have distinct behavioral implications.
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
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
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.