SwapMath
Handles the swap maths within ticks.
GitHub File: swapMath.ts
Constructor
Private constructor that cannot be constructed.
Methods
computeSwapStepPromm() - public
static
public
static
Returns the price and token amounts resulting from an Elastic swap.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |
sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |
liquidity | The amount of usable liquidity. | |
amountRemaining | Remaining amount of tokens that needs to be swapped in or out. | |
feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |
exactIn | boolean |
|
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
An array consisting of the following value by index:
|
calcReachAmount() - public
static
public
static
Returns the amount of tokens used in the swap in order to reach the target price.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |
sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |
liquidity | The amount of usable liquidity. | |
feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |
exactIn | boolean |
|
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
The amount of tokens used in the swap in order to reach the target price. |
calcReturnedAmount() - public
static
public
static
Returns the output token amount from the swap.
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |
sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |
liquidity | The amount of usable liquidity. | |
deltaL | The liquidity delta due to the swap. | |
feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |
exactIn | boolean |
|
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
Swap output token amount. |
calcIncrementalLiquidity() - public
static
public
static
Returns the incremental liquidity in the case where the resulting pool price after the swap is non-zero (i.e. target price was reached within the pool).
Parameters
Params | Type | Description |
---|---|---|
sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |
sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |
liquidity | The amount of usable liquidity. | |
absAmount | The absolute amount of tokens used for the swap. | |
exactIn | boolean |
|
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
The incremental liquidity amount following a swap. |
estimateIncrementalLiquidity() - public
static
public
static
Returns the estimated incremental liquidity in the case where the resulting pool price after the swap is zero (i.e. target price is outside the pool).
Parameters
Params | Type | Description |
---|---|---|
absAmount | The absolute amount of tokens used for the swap. | |
liquidity | The amount of usable liquidity. | |
sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |
feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |
exactIn | boolean |
|
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
The estimated incremental liquidity amount following a swap. |
calcFinalPrice() - public
static
public
static
Returns the final price following the swap.
Parameters
Params | Type | Description |
---|---|---|
absAmount | The absolute amount of tokens used for the swap. | |
liquidity | The amount of usable liquidity. | |
deltaL | The liquidity delta due to the swap. | |
sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |
feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |
exactIn | boolean |
|
zeroForOne | boolean |
|
Returns
Type | Description |
---|---|
The final price following the swap. |
Last updated