3

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.

2
  • 1
    This is the limit price, not the average sales price
    – kfx
    Commented Oct 31, 2023 at 9:45
  • If you'd like to expand on this with examples I think it would make for a nice answer.
    – Nat
    Commented Nov 1, 2023 at 13:45

1 Answer 1

3

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.

11
  • sqrtPriceLimitX96 and partial prices are useful for arbitration, as one can say "give me any amount of token X at a price Y". Commented Oct 31, 2023 at 9:48
  • @kfx I use ChatGPT to improve my wording and structure, don't see anything wrong with that. Also amountOutMinimum is not on the core UniswapV3Pool#swap function but on the SwapRouter#exactInputSingle function which is a periphery contract.
    – MShakeG
    Commented Oct 31, 2023 at 11:55
  • @kfx sqrtPriceLimitX96 is a parameter to the UniswapV3Pool#swap function. github.com/Uniswap/v3-core/blob/…
    – MShakeG
    Commented Oct 31, 2023 at 16:39
  • So if you breach the sqrt price limit you get the error "SPL" which rolls back the entire transaction as well. So I do not think this is accurate. github.com/Uniswap/v3-core/blob/…. Also ChatGPT is horrible when it comes to uniswap question in my experience.
    – Nat
    Commented Nov 1, 2023 at 13:43
  • 1
    @Nat it only reverts with SPL if the starting spot price for the pool already exceeds the input limit price in the swap's direction, but if it does not then the swap will proceed until either amountSpecified is entirely used(if amountIn)/given(if amount out) or until the sqrtPriceLimitX96 is reached. So SPL is more of a pre-validation check.
    – MShakeG
    Commented Nov 1, 2023 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.