KyberSwap Docs
Search
K

Position

Maintains information about a Position. Contains additional methods that aids in calculating liquidity and token amoutns for the purposes of creating or closing positions.
GitHub File: position.ts

Properties

Public

Property
Type
Modifier
Description
pool
Pool
readonly
The pool in which the position was created.
tickLower
number
readonly
The lower tick of the position. The position is out-of-range if the pool's active tick is below this.
tickUpper
number
readonly
The upper tick of the position. The position is out-of-range if the pool's active tick is above this.
liquidity
JSBI
readonly
The current value of in-range liquidity.

Private

Property
Type
Description
_token0Amount
The position's token0 amount. Default is null.
_token1Amount
The position's token1 amount. Default is null.
_mintAmounts
Readonly<{ amount0: JSBI; amount1: JSBI }> | null
The amount of liquidity held by the position at the current price of the pool.

Constructor

Parameters

Params
Type
Description
{}
An object that that contains the following: pool = The pool in which the position was created. tickLower = The lower tick of the position. tickUpper = The upper tick of the position. liquidity = The current value of in-range liquidity.

Methods

token0PriceLower() - public get

Returns the price of token0 at the position's lower tick quoted in terms of token1.

Returns

Type
Description
Price of token0 at the lower tick.

token0PriceUpper() - public get

Returns the price of token0 at the position's upper tick quoted in terms of token1.

Returns

Type
Description
Price of token0 at the upper tick.

amount0() - public get

Returns the position's token0 balance at the current price. This is the token0 amount that can be withdrawn if the NFT representing the position is burned.

Returns

Type
Description
The position's token0 balance at the current price. Denominated in the token0 currency format.

amount1() - public get

Returns the position's token1 balance at the current price. This is the token1 amount that can be withdrawn if the NFT representing the position is burned.

Returns

Type
Description
The position's token1 balance at the current price. Denominated in the token1 currency format.

ratiosAfterSlippage() - private

Returns the lower and upper price boundaries given a slippage tolerance percentage value.

Parameters

Params
Type
Description
slippageTolerance
Percent
The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

Type
Description
{}
Object that consists of the lower and upper bounds for the transaction denoted in Q notation format to maximize gas efficiency: sqrtRatioX96Lower:JSBI = The lowest price for the trade below which the transaction will fail. sqrtRatioX96Upper:JSBI = The highest price for the trade below which the transaction will fail.
price=(sqrtRatioX96296)2price = (\frac{sqrtRatioX96}{2^{96}})^2

mintAmountsWithSlippage() - public

Given a slippage tolerance percentage value, returns the minimum amount of each pool token that is required for the position to be safely created (i.e. mint the position NFT).

Parameters

Params
Type
Description
slippageTolerance
Percent
The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

Type
Description
ReadOnly<{}>
A read only object that consists of: amount0:JSBI = The token0 amount required to safely create the position given a slippage tolerance percentage. amount1:JSBI = The token1 amount required to safely create the position given a slippage tolerance percentage.

burnAmountsWithSlippage() - public

Given a slippage tolerance percentage value, returns the minimum amount of each pool token that can be safely returned when the position is closed (i.e. burn the position NFT).

Parameters

Params
Type
Description
slippageTolerance
Percent
The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

Type
Description
ReadOnly<{}>
A read only object that consists of: amount0:JSBI = The token0 amount that can be safely returned when the position is closed given a slippage tolerance percentage. amount1:JSBI = The token1 amount that can be safely returned when the position is closed given a slippage tolerance percentage.

mintAmounts() - public get

Returns the minimum amount of each pool token that is required for the position to be safely created (i.e. mint the position NFT).

Returns

Type
Description
ReadOnly<{}>
A read only object that consists of: amount0:JSBI = The token0 amount required to safely create the position. amount1:JSBI = The token1 amount required to safely create the position.

fromAmounts() - public static

Given both token amounts and the position's tick range, calculates the maximum liquidity for the position being created. The result is returned as a new Position instance.

Parameters

Params
Type
Description
{}
object
An object consisting of: pool:Pool = The pool on which to create the position. tickLower: number = The lower tick of the position to be created. tickUpper: number =The upper tick of the position to be created. amount0:BigintIsh = The token0 amount that is being provided. amount1:BigintIsh = The token1 amount that is being provided. useFullPrecision: boolean = true -> Calculates theoretical max liquidity; false -> Calculates max liquidity according to what the router can support

Returns

Type
Description
Position
A new Position instance which consists of the max liquidity value.

fromAmount0() - public static

Given a token0 amount and the position's tick range, calculates the maximum liquidity for the position being created. Assumes an unlimited amount of token1. The result is returned as a new Position instance.

Parameters

Params
Type
Description
{}
object
An object consisting of: pool:Pool = The pool on which to create the position. tickLower: number = The lower tick of the position to be created. tickUpper: number =The upper tick of the position to be created. amount0:BigintIsh = The token0 amount that is being provided. useFullPrecision: boolean = true -> Calculates theoretical max liquidity; false -> Calculates max liquidity according to what the router can support

Returns

Type
Description
Position
A new Position instance which consists of the max liquidity value.

fromAmount1() - public static

Given a token1 amount and the position's tick range, calculates the maximum liquidity for the position being created. Assumes an unlimited amount of token0. The result is returned as a new Position instance.
Note that the function uses the full precision to calculate the liquidity amount.

Parameters

Params
Type
Description
{}
object
An object consisting of: pool:Pool = The pool on which to create the position. tickLower: number = The lower tick of the position to be created. tickUpper: number =The upper tick of the position to be created. amount1:BigintIsh = The token0 amount that is being provided.

Returns

Type
Description
Position
A new Position instance which consists of the max liquidity value.
Last modified 4mo ago