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

PropertyTypeModifierDescription

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

readonly

The current value of in-range liquidity.

Private

PropertyTypeDescription

_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

ParamsTypeDescription

{}

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

TypeDescription

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

TypeDescription

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

TypeDescription

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

TypeDescription

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

ParamsTypeDescription

slippageTolerance

The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

TypeDescription

{}


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

ParamsTypeDescription

slippageTolerance

The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

TypeDescription

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

ParamsTypeDescription

slippageTolerance

The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

TypeDescription

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

TypeDescription

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

ParamsTypeDescription

{}

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

TypeDescription

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

ParamsTypeDescription

{}

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

TypeDescription

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

ParamsTypeDescription

{}

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

TypeDescription

Position

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

Last updated