Pool
Maintains information about the pool from creation and is constantly updated whenever a swap takes place against the pool.
GitHub File: pool.ts
Properties
Public
Property | Type | Modifier | Description |
---|---|---|---|
token0 | readonly | Token0 of the pool. | |
token1 | readonly | Token1 of the pool. | |
fee | readonly | The fee tier (in bips) for the pool which determines the exact % trading fees that the pool charges. | |
sqrtRatioX96 | readonly | The price quoted in token0:token1 and stored in Q notation format to maximize gas efficiency. | |
liquidity | readonly | The current value of in-range liquidity. | |
reinvestLiquidity | readonly | The liquidity portion which has been reinvested into the reinvestment curve. | |
tickCurrent | number | readonly | The current tick of the pool. |
tickDataProvider | TickDataProvider | readonly | The data provider that can return tick data. |
Private
Constructor
Params | Type | Description |
---|---|---|
tokenA | Token to use as Token0 of the pool. | |
tokenB | Token to use as Token1 of the pool. | |
fee | The fee tier (in bips) for the pool which determines the exact % trading fees that the pool charges. | |
sqrtRatioX96 | The price quoted in token0:token1 and stored in Q notation format to maximize gas efficiency. | |
liquidity | The current value of in-range liquidity. | |
reinvestLiquidity | The liquidity portion which has been reinvested into the reinvestment curve. | |
tickCurrent | number | The current tick of the pool. |
tickDataProvider | TickDataProvider | (Tick | TickConstructorArgs)[] | The current state of the pool ticks or a data provider that can return tick data. |
Methods
involvesToken() - public
public
Returns true if the token passed in matches either token0 or token1 of the pool.
Parameters
Params | Type | Description |
---|---|---|
token | The token to check against the pool's tokens. |
Returns
Type | Description |
---|---|
boolean |
|
token0Price() - public
get
public
get
Accessor that returns the current mid price of the pool in terms of token0. In other words, this function gets the ratio of .
Returns
token1Price() - public
get
public
get
Accessor that returns the current mid price of the pool in terms of token1. In other words, this function gets the ratio of .
Returns
priceOf() - public
public
Returns the price of the given token in terms of the other token in the pool. That is, the price of token0 in terms of token1 if token0 is passed in and vice versa.
Parameters
Params | Type | Description |
---|---|---|
token | The token which to get the price. |
Returns
Type | Description |
---|---|
The price of the given token in terms of the corresponding token in the pool. |
chainId() - public
get
public
get
Accessor that returns the chainID of the tokens in pool (i.e. the chain which the tokens are deployed on).
Returns
Type | Description |
---|---|
number | The chainID of the underlying chain which the pools' tokens are deployed on. |
getOutputAmount() - public
async
public
async
Returns the other token output amount given an input amount of one of the pool's tokens. The updated pool state following the trade is also returned.
Parameters
Params | Type | Description |
---|---|---|
inputAmount | The amount of input tokens to be traded. | |
sqrtPriceLimitX96 | The price limit for the swap. If swapping from token0 to token1, the price cannot be less than this value after the swap and vice versa. |
Returns
Type | Description |
---|---|
Promise<[CurrencyAmount<Token>, Pool]> | A promise array whose index consists of:
|
getOutputAmountProMM() - public
async
public
async
Returns the other token output amount given an input amount of one of the pool's tokens. The updated pool state following the trade is also returned which includes the base and reinvestment liquidity.
Parameters
Params | Type | Description |
---|---|---|
inputAmount | The amount of input tokens to be traded. | |
sqrtPriceLimitX96 | The price limit for the swap. If swapping from token0 to token1, the price cannot be less than this value after the swap and vice versa. |
Returns
Type | Description |
---|---|
Promise<[CurrencyAmount<Token>, Pool]> | A promise array whose index consists of:
|
swapProMM() - private
async
private
async
Replicates the smart contract tick math in order to calculate the swap output and pool state changes following a swap. This function is similar to swap()
but also calculates the base and reinvestment liquidity following an Elastic swap.
Parameters
Params | Type | Description |
---|---|---|
zeroForOne | boolean |
|
amountSpecified | The amount of input tokens to be traded. | |
sqrtPriceLimitX96 | The price limit for the swap. If swapping from token0 to token1, the price cannot be less than this value after the swap and vice versa. |
Returns
Type | Description |
---|---|
Promise<{ amountCalculated: JSBI; sqrtRatioX96: JSBI; liquidity: JSBI; tickCurrent: number }> | A promise object which consists of:
|
swap() - private
async
private
async
Replicates the smart contract tick math in order to calculate the swap output and pool state changes following a swap.
Parameters
Params | Type | Description |
---|---|---|
zeroForOne | boolean |
|
amountSpecified | The amount of input tokens to be traded. | |
sqrtPriceLimitX96 | The price limit for the swap. If swapping from token0 to token1, the price cannot be less than this value after the swap and vice versa. |
Returns
Type | Description |
---|---|
Promise<{ amountCalculated: JSBI; sqrtRatioX96: JSBI; liquidity: JSBI; tickCurrent: number }> | A promise object which consists of:
|
tickSpacing() - public
get
public
get
Returns the tick spacing that corresponds to the pool's configured fee.
Returns
Type | Description |
---|---|
number | The tick spacing of the pool. |
Last updated