NonfungiblePositionManager
Variables
struct Position {
uint96 nonce;
address operator;
uint80 poolId;
int24 tickLower;
int24 tickUpper;
uint128 liquidity;
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
uint128 tokensOwed0;
uint128 tokensOwed1;
}Description:
Details about a specific NFT position within the pool. Each Position struct holds essential information about the liquidity, fee growth, and tokens owed.
Functions
function positions(uint256 tokenId) external view returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
)Description: Retrieves comprehensive details about a specific NFT position.
Parameters
tokenId
uint256
The ID of the NFT position.
Return Values
nonce
uint96
The nonce for permits.
operator
address
The address approved to manage this position.
token0
address
The first token of the pool.
token1
address
The second token of the pool.
fee
uint24
The fee tier of the pool.
tickLower
int24
The lower tick of the position's range.
tickUpper
int24
The upper tick of the position's range.
liquidity
uint128
The liquidity of the position.
feeGrowthInside0LastX128
uint256
The last recorded fee growth for token0 inside the range.
feeGrowthInside1LastX128
uint256
The last recorded fee growth for token1 inside the range.
tokensOwed0
uint128
The amount of token0 owed to the position.
tokensOwed1
uint128
The amount of token1 owed to the position.
Description: Creates a new NFT position by adding liquidity to a specified pool and tick range.
Parameters
params
MintParams
The parameters for minting the position (details below).
MintParams Struct Definition:
Return Values
tokenId
uint256
The ID of the newly minted NFT position.
liquidity
uint128
The amount of liquidity added to the position.
amount0
uint256
The actual amount of token0 used to mint the position. Matches the value from the callback.
amount1
uint256
The actual amount of token1 used to mint the position. Matches the value from the callback.
Description: Ensures that the caller is either the owner or an approved operator for the specified NFT token ID.
Description: Returns the metadata URI for a given NFT position. Utilizes the token descriptor contract to generate the URI.
Parameters
tokenId
uint256
The ID of the NFT position.
Return Values
URI
string memory
The metadata URI for the specified token.
Description: Returns the base URI for the NFT metadata. Note: Implementation is empty to save bytecode as it's unused.
Description: Increases the liquidity of an existing NFT position within its tick range.
Parameters
params
IncreaseLiquidityParams
The parameters for increasing liquidity (details below).
IncreaseLiquidityParams Struct Definition:
Return Values
liquidity
uint128
The additional liquidity added to the position.
amount0
uint256
The actual amount of token0 added.
amount1
uint256
The actual amount of token1 added.
Description: Decreases the liquidity of an existing NFT position within its tick range.
Parameters
params
DecreaseLiquidityParams
The parameters for decreasing liquidity (details below).
DecreaseLiquidityParams Struct Definition:
Return Values
amount0
uint256
The amount of token0 withdrawn from the position.
amount1
uint256
The amount of token1 withdrawn from the position.
Description: Collects tokens owed to an NFT position, including accumulated fees.
Parameters
params
CollectParams
The parameters for collecting tokens (details below).
CollectParams Struct Definition:
Return Values
amount0
uint256
The amount of token0 collected.
amount1
uint256
The amount of token1 collected.
Description: Burns an NFT position. The position must have zero liquidity and no tokens owed.
Parameters
tokenId
uint256
The ID of the NFT position to burn.
Description: Retrieves and increments the nonce for a specific NFT position. Used internally for permit functionality.
Parameters
tokenId
uint256
The ID of the NFT position.
Return Values
nonce
uint256
The current nonce value.
Description:
Overrides the ERC721 getApproved function to return the operator approved for a specific NFT position.
Parameters
tokenId
uint256
The ID of the NFT position.
Return Values
operator
address
The address approved to manage the token.
Modifiers
Description: Ensures that the caller is either the owner or an approved operator for the specified NFT token ID.
Parameters
tokenId
uint256
The ID of the NFT position.
Events
Description: Emitted when liquidity is added to an existing NFT position.
Parameters
tokenId
uint256
The ID of the NFT position.
liquidity
uint128
The amount of liquidity added.
amount0
uint256
The amount of token0 added.
amount1
uint256
The amount of token1 added.
Description: Emitted when tokens are collected from an NFT position.
Parameters
tokenId
uint256
The ID of the NFT position.
recipient
address
The address receiving the collected tokens.
amount0
uint256
The amount of token0 collected.
amount1
uint256
The amount of token1 collected.
Description: Emitted when liquidity is removed from an NFT position.
Parameters
tokenId
uint256
The ID of the NFT position.
liquidity
uint128
The amount of liquidity removed.
amount0
uint256
The amount of token0 withdrawn.
amount1
uint256
The amount of token1 withdrawn.
Usage Notes
Minting a New Position
Function:
mint()Description: Creates a new NFT representing a liquidity position within a specific pool and tick range.
Steps:
Define the desired token pair (
token0,token1) and fee tier.Specify the tick range (
tickLower,tickUpper).Provide the desired amounts of
token0andtoken1to add as liquidity.Call
mint()with the appropriate parameters.Receive an NFT (
tokenId) representing the position.
Increasing Liquidity
Function:
increaseLiquidity()Description: Adds additional liquidity to an existing NFT position.
Requirements:
The caller must be the owner or an approved operator of the NFT.
The specified liquidity must be added within the existing tick range.
Decreasing Liquidity
Function:
decreaseLiquidity()Description: Removes liquidity from an existing NFT position.
Requirements:
The caller must be the owner or an approved operator of the NFT.
The amount of liquidity to remove must not exceed the current liquidity of the position.
Tokens withdrawn are subject to slippage checks based on
amount0Minandamount1Min.
Collecting Fees
Function:
collect()Description: Harvests accumulated fees from an NFT position.
Requirements:
The caller must be the owner or an approved operator of the NFT.
At least one of
amount0Maxoramount1Maxmust be greater than zero.
Notes:
Fees are collected in proportion to the liquidity provided.
Collected tokens can be sent to the NFT position manager or a specified recipient.
Burning a Position
Function:
burn()Description: Destroys an NFT representing a liquidity position.
Requirements:
The position must have zero liquidity and no tokens owed.
The caller must be the owner or an approved operator of the NFT.
Retrieving Position Details
Function:
positions()Description: Fetches detailed information about a specific NFT position.
Usage:
Useful for front-end applications or analytics to display position metrics.
Metadata URI
Function:
tokenURI()Description: Provides the metadata URI for a given NFT, which includes information like position details and visual representations.
Usage:
Integrates with NFT marketplaces and wallets to display position information.