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
public
static
Returns the amount of token0 required to initialize the pool.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioInitX96 | The square root price of the pool upon initialization, denominated in Q notation. |
Returns
Type | Description |
---|---|
The amount of token0 required to initialize the pool. |
getAmount1Unlock() - public
static
public
static
Returns the amount of token1 required to initialize the pool.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioInitX96 | The square root price of the pool upon initialization, denominated in Q notation. |
Returns
Type | Description |
---|---|
The amount of token1 required to initialize the pool. |
getAmount0Delta() - public
static
public
static
Gets the liquidity delta between two token0 prices.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioAX96 | A sqrt price of token0. | |
sqrtRatioBX96 | Another sqrt price of token0. | |
liquidity | The amount of usable liquidity. | |
roundUp | boolean |
|
Returns
Type | Description |
---|---|
Amount of token0 required to cover a position of size liquidity between the two passed prices. |
getAmount1Delta() - public
static
public
static
Gets the liquidity delta between two token1 prices.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioAX96 | A sqrt price of token0. | |
sqrtRatioBX96 | Another sqrt price of token0. | |
liquidity | The amount of usable liquidity. | |
roundUp | boolean |
|
Returns
Type | Description |
---|---|
Amount of token1 required to cover a position of size liquidity between the two passed prices. |
getNextSqrtPriceFromInput() - public
static
public
static
Gets the next sqrt price given an input amount of token0 or token1.
Parameters
Params | Type | Description |
---|---|---|
sqrtPX96 | A sqrt price of token0. | |
liquidity | The amount of usable liquidity. | |
amounIn | The amount of tokens being swapped in. | |
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
The price after removing the output amount of token0 or token1 |
getNextSqrtPriceFromOutput() - public
static
public
static
Gets the next sqrt price given an output amount of token0 or token1.
Parameters
Params | Type | Description |
---|---|---|
sqrtPX96 | A sqrt price of token0. | |
liquidity | The amount of usable liquidity. | |
amountOut | The amount of tokens being swapped out. | |
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
The price after removing the output amount of token0 or token1 |
getNextSqrtPriceFromAmount0RoundingUp() - private
static
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 | The starting price of of token0. | |
liquidity | The amount of usable liquidity. | |
amount | The amount of token0 to add or remove from virtual reserves. | |
add | boolean |
|
Returns
Type | Description |
---|---|
The token0 price after adding or removing the amount specified. |
getNextSqrtPriceFromAmount1RoundingDown() - private
static
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 | The starting price of of token1. | |
liquidity | The amount of usable liquidity. | |
amount | The amount of token0 to add or remove from virtual reserves. | |
add | boolean |
|
Returns
Type | Description |
---|---|
The token1 price after adding or removing the amount specified. |
Last updated