KyberSwap Docs
Search
K

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
Token
readonly
Token0 of the pool.
token1
Token
readonly
Token1 of the pool.
fee
FeeAmount
readonly
The fee tier (in bips) for the pool which determines the exact % trading fees that the pool charges.
sqrtRatioX96
JSBI
readonly
The price quoted in token0:token1 and stored in Q notation format to maximize gas efficiency.
price=(sqrtRatioX96296)2price = (\frac{sqrtRatioX96}{2^{96}})^2
liquidity
JSBI
readonly
The current value of in-range liquidity.
reinvestLiquidity
JSBI
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

Property
Type
Description
_token0Price
_token1Price

Constructor

Params
Type
Description
tokenA
Token
Token to use as Token0 of the pool.
tokenB
Token
Token to use as Token1 of the pool.
fee
FeeAmount
The fee tier (in bips) for the pool which determines the exact % trading fees that the pool charges.
sqrtRatioX96
BigintIsh
The price quoted in token0:token1 and stored in Q notation format to maximize gas efficiency.
price=(sqrtRatioX96296)2price = (\frac{sqrtRatioX96}{2^{96}})^2
liquidity
BigintIsh
The current value of in-range liquidity.
reinvestLiquidity
BigintIsh
The liquidity portion which has been reinvested into the reinvestment curve.
tickCurrent
number
The current tick of the pool.
tickDataProvider
The current state of the pool ticks or a data provider that can return tick data.

Methods

involvesToken() - public

Returns true if the token passed in matches either token0 or token1 of the pool.

Parameters

Params
Type
Description
token
Token
The token to check against the pool's tokens.

Returns

Type
Description
boolean
true = The token matches either token0 or token1 of the pool. false = The token is not part of the pool.

token0Price() - 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
token1token0\frac{token_1}{token_0}
.

Returns

Type
Description
The current mid price of the pool in terms of token0.

token1Price() - 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
token0token1\frac{token_0}{token_1}
.

Returns

Type
Description
The current mid price of the pool in terms of token1.

priceOf() - 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
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

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

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
JSBI
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
A promise array whose index consists of: 0 = A quote of the raw amount of the other token that will result from this trade. 1 = The updated pool state following the trade.

getOutputAmountProMM() - 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
JSBI
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
A promise array whose index consists of: 0 = The raw amount of the other token that will result from this trade. 1 = The updated pool state following the trade which includes Elastic's base and reinvestment liquidity.

swapProMM() - 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
true = Swap is for token0 -> token1 false = Swap is for token1 -> token0
amountSpecified
JSBI
The amount of input tokens to be traded.
sqrtPriceLimitX96
JSBI
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: amountCalculated = The raw amount of the other token that will result from this trade. sqrtRatioX96 = The resulting price of the pool following the trade. baseL = The base liquidity value of the pool following the trade. reinvestL = The reinvest liquidity value of the pool following the trade. tickCurrent = The active tick of the pool following the trade.

swap() - 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
true = Swap is for token0 -> token1 false = Swap is for token1 -> token0
amountSpecified
JSBI
The amount of input tokens to be traded.
sqrtPriceLimitX96
JSBI
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: amountCalculated = The raw amount of the other token that will result from this trade. sqrtRatioX96 = The resulting price of the pool following the trade. liquidity = The liquidity value of the pool following the trade. tickCurrent = The active tick of the pool following the trade.

tickSpacing() - 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 modified 5mo ago