Skip to main content

Math Utilities

mostSignificantBit#

Returns the most significant bit of a positive integer, starting with first bit = 0

mostSignificantBit(
x: BigInt!
): UInt32!

encodeSqrtRatioX96#

Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0

encodeSqrtRatioX96(
amount1: BigInt! # The numerator amount i.e., the amount of token1
amount0: BigInt! # The denominator amount i.e., the amount of token0
): BigInt!

mulDivRoundingUp#

Returns (a * b) / denominator

mulDivRoundingUp(
a: BigInt!
b: BigInt!
denominator: BigInt!
): BigInt!

addDelta#

Returns x + y

addDelta(
x: BigInt!
y: BigInt!
): BigInt!

getAmount0Delta#

Used to facilitate liquidity math using sqrtRatioX96 values

getAmount0Delta(
sqrtRatioAX96: BigInt!
sqrtRatioBX96: BigInt!
liquidity: BigInt!
roundUp: Boolean!
): BigInt!

getAmount1Delta#

Used to facilitate liquidity math using sqrtRatioX96 values

getAmount1Delta(
sqrtRatioAX96: BigInt!
sqrtRatioBX96: BigInt!
liquidity: BigInt!
roundUp: Boolean!
): BigInt!

getNextSqrtPriceFromInput#

Used to facilitate liquidity math using sqrtRatioX96 values

getNextSqrtPriceFromInput(
sqrtPX96: BigInt!
liquidity: BigInt!
amountIn: BigInt!
zeroForOne: Boolean!
): BigInt!

getNextSqrtPriceFromOutput#

Used to facilitate liquidity math using sqrtRatioX96 values

getNextSqrtPriceFromOutput(
sqrtPX96: BigInt!
liquidity: BigInt!
amountOut: BigInt!
zeroForOne: Boolean!
): BigInt!