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

PropertyTypeModifierDescription

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. price=(sqrtRatioX96296)2price = (\frac{sqrtRatioX96}{2^{96}})^2

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

PropertyTypeDescription

_token0Price

_token1Price

Constructor

ParamsTypeDescription

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. price=(sqrtRatioX96296)2price = (\frac{sqrtRatioX96}{2^{96}})^2

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

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

ParamsTypeDescription

token

The token to check against the pool's tokens.

Returns

TypeDescription

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

TypeDescription

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

TypeDescription

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

ParamsTypeDescription

token

The token which to get the price.

Returns

TypeDescription

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

TypeDescription

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

ParamsTypeDescription

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

TypeDescription

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

ParamsTypeDescription

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

TypeDescription

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

ParamsTypeDescription

zeroForOne

boolean

true = Swap is for token0 -> token1 false = Swap is for token1 -> token0

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

TypeDescription

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

ParamsTypeDescription

zeroForOne

boolean

true = Swap is for token0 -> token1 false = Swap is for token1 -> token0

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

TypeDescription

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

TypeDescription

number

The tick spacing of the pool.

Last updated