2

this code is from the docs:

ISwapRouter.ExactInputSingleParams memory params = ISwapRouter
        .ExactInputSingleParams({
            tokenIn: LINK,
            tokenOut: USDC,
            fee: poolFee,
            recipient: address(this),
            deadline: block.timestamp,
            amountIn: amountIn,
            amountOutMinimum: 0,                
            sqrtPriceLimitX96: 0
        });

I understand what each parameter means but sqrtPriceLimitX96. same docs say this:

sqrtPriceLimitX96: We set this to zero - which makes this parameter inactive. In production, this value can be used to set the limit for the price the swap will push the pool to, which can help protect against price impact or for setting up logic in a variety of price-relevant mechanisms.

Can someone explain what this is for? Why is this inactive?

2 Answers 2

1

sqrtPriceLimitX96 at production level it used to determine limits on the pool prices. which cannot be exceeded by the swap. and in test level you can set it to 0, than it's ignored.

Actually in real scenarios we need to set price limit for swap, because every swap has impact on price and this change in price will change your use case and effect so by sqrtPriceLimitX96, we can limit the swap

1
  • you mean the ratio? sqrtPriceX96 represents the ratio between two tokens. so we are telling if, after swap, if price ratio exceeds the sqrtPriceLimitX96 do not execute it. And in development price impact is not important. Am I correct?
    – Yilmaz
    Feb 27 at 2:41
0

Here is the comment for sqrtPriceLimitX96 in uniswapV3-core

    // @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap

when swap zero for one,

Price = Amount1/Amount0 Amount1 = Amount0 * Price

Only do this swap when the Price is not less than the limit(sqrtPriceX96) —— we'll get enough Asset1

Your Answer

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

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