1
                    (
                        _zeroForOne
                            ? step.sqrtPriceNextX96 < _sqrtPriceLimitX96
                            : step.sqrtPriceNextX96 > _sqrtPriceLimitX96
                    )
                        ? _sqrtPriceLimitX96
                        : step.sqrtPriceNextX96

I am explaining this code, tell me if im right or wrong:

If _zeroForOne is true i.e if we selling token0 then step.sqrtPriceNextX96 is less than _sqrtPriceLimitX96, if false then step.sqrtPriceNextX96 > _sqrtPriceLimitX96. Suppose _zeroForOne is true but step.sqrtPriceNextX96 is not less than _sqrtPriceLimitX96 then the () portion will be false, then we will get step.sqrtPriceNextX96 as result.

If _zeroForOne is false i.e we are buying token0 then if step.sqrtPriceNextX96 > _sqrtPriceLimitX96 then the () portion will be true and _sqrtPriceLimitX96 will be result or if step.sqrtPriceNextX96 not greater than _sqrtPriceLimitX96 then the () portion will be false and the result will be step.sqrtPriceNextX96.

If i am wrong then what is right explanation??

1 Answer 1

0

You understood the code correctly.

Here's a simple, step-by-step explanation:

Selling token0 (_zeroForOne is true):

  • If "price is less than limit", result: limit.
  • If not, result: price.

Buying token0 (_zeroForOne is false):

  • If "price is greater than limit", result: limit.
  • If not, result: price.
1
  • Thanks ......😊
    – Hacek
    Commented Apr 12, 2023 at 19:01

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.