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.
function mint(MintParams calldata params) external payable returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
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:
struct MintParams {
address token0;
address token1;
uint24 fee;
address recipient;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
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.
modifier isAuthorizedForToken(uint256 tokenId)
Description: Ensures that the caller is either the owner or an approved operator for the specified NFT token ID.
function tokenURI(uint256 tokenId) public view returns (string memory)
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.
function baseURI() public pure returns (string memory)
Description: Returns the base URI for the NFT metadata. Note: Implementation is empty to save bytecode as it's unused.
function increaseLiquidity(IncreaseLiquidityParams calldata params) external payable returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
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:
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
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.
function decreaseLiquidity(DecreaseLiquidityParams calldata params) external payable returns (
uint256 amount0,
uint256 amount1
)
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:
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
Return Values
amount0
uint256
The amount of token0
withdrawn from the position.
amount1
uint256
The amount of token1
withdrawn from the position.
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1)
Description: Collects tokens owed to an NFT position, including accumulated fees.
Parameters
params
CollectParams
The parameters for collecting tokens (details below).
CollectParams Struct Definition:
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
Return Values
amount0
uint256
The amount of token0
collected.
amount1
uint256
The amount of token1
collected.
function burn(uint256 tokenId) external payable
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.
function _getAndIncrementNonce(uint256 tokenId) internal returns (uint256)
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.
function getApproved(uint256 tokenId) public view returns (address)
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
modifier isAuthorizedForToken(uint256 tokenId)
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
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
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.
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1)
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.
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
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
token0
andtoken1
to 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
amount0Min
andamount1Min
.
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
amount0Max
oramount1Max
must 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.