KyberSwap Docs
Search
K

SqrtPriceMath

Compute deltas based on liquidity and square root price data.
GitHub File: sqrtPriceMath.ts

Constructor

Private constructor that cannot be constructed.

Methods

getAmount0Unlock() - public static

Returns the amount of token0 required to initialize the pool.

Parameters

Params
Type
Description
sqrtRatioInitX96
JSBI
The square root price of the pool upon initialization, denominated in Q notation.

Returns

Type
Description
JSBI
The amount of token0 required to initialize the pool.

getAmount1Unlock() - public static

Returns the amount of token1 required to initialize the pool.

Parameters

Params
Type
Description
sqrtRatioInitX96
JSBI
The square root price of the pool upon initialization, denominated in Q notation.

Returns

Type
Description
JSBI
The amount of token1 required to initialize the pool.

getAmount0Delta() - public static

Gets the liquidity delta between two token0 prices.

Parameters

Params
Type
Description
sqrtRatioAX96
JSBI
A sqrt price of token0.
sqrtRatioBX96
JSBI
Another sqrt price of token0.
liquidity
JSBI
The amount of usable liquidity.
roundUp
boolean
true = Result is rounded up to the nearest integer. false = Result is not rounded down to the ne

Returns

Type
Description
JSBI
Amount of token0 required to cover a position of size liquidity between the two passed prices.

getAmount1Delta() - public static

Gets the liquidity delta between two token1 prices.

Parameters

Params
Type
Description
sqrtRatioAX96
JSBI
A sqrt price of token0.
sqrtRatioBX96
JSBI
Another sqrt price of token0.
liquidity
JSBI
The amount of usable liquidity.
roundUp
boolean
true = Result is rounded up to the nearest integer. false = Result is not rounded down to the ne

Returns

Type
Description
JSBI
Amount of token1 required to cover a position of size liquidity between the two passed prices.

getNextSqrtPriceFromInput() - public static

Gets the next sqrt price given an input amount of token0 or token1.

Parameters

Params
Type
Description
sqrtPX96
JSBI
A sqrt price of token0.
liquidity
JSBI
The amount of usable liquidity.
amounIn
JSBI
The amount of tokens being swapped in.
zeroForOne
boolean
true = Amount in is in token1. false = Amount in is in token0.

Returns

Type
Description
JSBI
The price after removing the output amount of token0 or token1

getNextSqrtPriceFromOutput() - public static

Gets the next sqrt price given an output amount of token0 or token1.

Parameters

Params
Type
Description
sqrtPX96
JSBI
A sqrt price of token0.
liquidity
JSBI
The amount of usable liquidity.
amountOut
JSBI
The amount of tokens being swapped out.
zeroForOne
boolean
true = Amount out is in token1. false = Amount out is in token0.

Returns

Type
Description
JSBI
The price after removing the output amount of token0 or token1

getNextSqrtPriceFromAmount0RoundingUp() - private static

Gets the next sqrt price given a delta of token0. The token0 price is rounded up to ensure that the virtual reserves never falls below 0 and the output amount is always achieved.

Parameters

Params
Type
Description
sqrtPX96
JSBI
The starting price of of token0.
liquidity
JSBI
The amount of usable liquidity.
amount
JSBI
The amount of token0 to add or remove from virtual reserves.
add
boolean
true = Amount is added to the virtual reserve. false = Amount is removed from the virtual reserve.

Returns

Type
Description
JSBI
The token0 price after adding or removing the amount specified.

getNextSqrtPriceFromAmount1RoundingDown() - private static

Gets the next sqrt price given a delta of token1. The token1 price is rounded down to ensure that the virtual reserves never falls below 0 and the output amount is always achieved.

Parameters

Params
Type
Description
sqrtPX96
JSBI
The starting price of of token1.
liquidity
JSBI
The amount of usable liquidity.
amount
JSBI
The amount of token0 to add or remove from virtual reserves.
add
boolean
true = Amount is added to the virtual reserve. false = Amount is removed from the virtual reserve.

Returns

Type
Description
JSBI
The token1 price after adding or removing the amount specified.
Last modified 4mo ago