Skip to main content

Function: isSqrtPriceInRange

isSqrtPriceInRange(sqrtPrice, tickLower, tickUpper): boolean

isTickInRange for a pool's square-root price instead of its tick (a position row that carries sqrtPrice, tickLower and tickUpper). The tick is derived from the price exactly as the contract does (sqrtPriceToTick: the greatest tick whose square-root price is no greater than the price, exact to 60 digits), then the contract's rule applies: lower tick inclusive, upper tick exclusive. So a pool sitting exactly on tickLower's price is in range, and exactly on tickUpper's price is not, and no float rounding can flip either.

false for a price that is not positive and finite (not loaded, zero, NaN): it says nothing about the position, so an app that must show a neutral state checks for the missing price itself first. tickLower and tickUpper follow isTickInRange.

Parameters​

ParameterType
sqrtPriceValue
tickLowerTickInput
tickUpperTickInput

Returns​

boolean

Example​

const inRange = isSqrtPriceInRange(position.sqrtPrice, position.tickLower, position.tickUpper);