Position

Function Interface introduction

1. Increase Liquidity

  • Contract Interface

    • struct IncreaseLiquidityParams {
          uint256 tokenId;
          uint256 amount0Desired;
          uint256 amount1Desired;
          uint256 amount0Min;
          uint256 amount1Min;
          uint256 deadline;
      }
      
      /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
      /// @param params tokenId The ID of the token for which liquidity is being increased,
      /// amount0Desired The desired amount of token0 to be spent,
      /// amount1Desired The desired amount of token1 to be spent,
      /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
      /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
      /// deadline The time by which the transaction must be included to effect the change
      /// @return liquidity The new liquidity amount as a result of the increase
      /// @return amount0 The amount of token0 to acheive resulting liquidity
      /// @return amount1 The amount of token1 to acheive resulting liquidity
      function increaseLiquidity(IncreaseLiquidityParams calldata params)
          external
          payable
          returns (
              uint128 liquidity,
              uint256 amount0,
              uint256 amount1
          );
  • Param Explanation

    • tokenId (uint256): Identifier of the token position for which liquidity is being increased. This ID is unique to the position within the liquidity pool and is used to track and manage the corresponding liquidity.

    • amount0Desired (uint256): The desired amount of token0 that the caller wishes to contribute to the liquidity pool. This value represents how much of token0 the caller is willing to spend to increase liquidity.

    • amount1Desired (uint256): Similar to amount0Desired, this is the desired amount of token1 that the caller is willing to contribute to the pool.

    • amount0Min (uint256): The minimum acceptable amount of token0 that must be spent to prevent significant price slippage. This parameter is crucial for ensuring that the caller does not experience unfavorable trade conditions due to market volatility.

    • amount1Min (uint256): The minimum acceptable amount of token1 that must be spent, serving the same purpose as amount0Min for token1.

    • deadline (uint256): A UNIX timestamp specifying the latest time by which the transaction must be mined for the liquidity increase to take effect. This safeguard prevents the transaction from being executed under possibly changed market conditions

2. Mint(Open Position)

  • Contract Interface

struct MintParams {
    address token0;
    address token1;
    uint24 fee;
    int24 tickLower;
    int24 tickUpper;
    uint256 amount0Desired;
    uint256 amount1Desired;
    uint256 amount0Min;
    uint256 amount1Min;
    address recipient;
    uint256 deadline;
}

/// @notice Creates a new position wrapped in a NFT
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
/// a method does not exist, i.e. the pool is assumed to be initialized.
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
/// @return tokenId The ID of the token that represents the minted position
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(MintParams calldata params)
    external
    payable
    returns (
        uint256 tokenId,
        uint128 liquidity,
        uint256 amount0,
        uint256 amount1
    );
  • Param Explanation

    • token0 (address): The contract address of the first token in the token pair for which liquidity is being provided.

    • token1 (address): The contract address of the second token in the pair.

    • fee (uint24): The fee tier of the pool to which liquidity is being added. Fees are typically specified in basis points (e.g., 500 for a 0.05% fee).

    • tickLower (int24): The lower bound of the desired price range for the position. In the Uniswap v3 context, ticks are used to define price ranges within which liquidity is active.

    • tickUpper (int24): The upper bound of the price range.

    • amount0Desired (uint256): The desired amount of token0 to be contributed to the pool.

    • amount1Desired (uint256): The desired amount of token1 to be contributed.

    • amount0Min (uint256): The minimum amount of token0 that must be contributed, serving as a protection against slippage.

    • amount1Min (uint256): The minimum amount of token1 that must be contributed, similarly serving as slippage protection.

    • recipient (address): The address that will receive the NFT representing the liquidity position.

    • deadline (uint256): A UNIX timestamp indicating the latest time by which the transaction must be executed

3. Decrease Liquidity

  • Contract Interface

struct DecreaseLiquidityParams {
    uint256 tokenId;
    uint128 liquidity;
    uint256 amount0Min;
    uint256 amount1Min;
    uint256 deadline;
}

/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
    external
    payable
    returns (uint256 amount0, uint256 amount1);
  • Param Explanation

    • tokenId (uint256): The identifier of the token position from which liquidity is being withdrawn. This unique ID is associated with a specific liquidity provision within the pool.

    • liquidity (uint128): The magnitude of liquidity to be removed from the position. This value dictates how much of the position's current liquidity will be decreased.

    • amount0Min (uint256): The minimum amount of token0 that must be received for the liquidity being removed. This serves as a safeguard against slippage, ensuring that the liquidity provider does not receive less than this threshold.

    • amount1Min (uint256): Similar to amount0Min, this is the minimum amount of token1 that must be accounted for when the specified liquidity is removed from the pool.

    • deadline (uint256): A UNIX timestamp indicating the latest time by which the transaction must be executed to apply the liquidity decrease. This parameter is crucial for timing the operation according to market conditions and the liquidity provider's strategy.

4. Collect Fee

  • Contract Interface

struct CollectParams {
    uint256 tokenId;
    address recipient;
    uint128 amount0Max;
    uint128 amount1Max;
}

/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
/// @param params tokenId The ID of the NFT for which tokens are being collected,
/// recipient The account that should receive the tokens,
/// amount0Max The maximum amount of token0 to collect,
/// amount1Max The maximum amount of token1 to collect
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
  • Param Explanation

    • tokenId (uint256): The identifier of the NFT representing the liquidity position from which fees are being collected. This NFT ID is unique and directly correlates with a specific liquidity provision within the pool.

    • recipient (address): The address to which the collected fees will be sent. This allows the fees to potentially be directed to a different account than the one executing the transaction.

    • amount0Max (uint128): The maximum amount of the first token (token0) in the pair that should be collected as fees. This acts as a cap to prevent accidental collection of unexpected amounts.

    • amount1Max (uint128): Similar to amount0Max, this is the maximum amount of the second token (token1) that should be collected as fees.

5. Close position (burn)

  • Contract Interface

/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens    
/// must be collected first.    
/// @param tokenId The ID of the token that is being burned    
function burn(uint256 tokenId) external payable;
  • Param Explanation

    • tokenId (uint256): The unique identifier of the NFT that is to be burned. This ID corresponds to a specific liquidity position or other forms of representation within the NFT contract.

6. Stake

  • Contract Interface function safeTransferFrom(

        function safeTransferFrom(
            address from,
            address to,
            uint256 tokenId
        ) internal {
        }
  • Param Explannation

    • from(address): The address of user.

    • to(address): The contract address of MasterChefV3.

    • tokenId(address): The unique identifier of the NFT that is to be staked. This ID corresponds to a specific liquidity position or other forms of representation within the NFT contract.

7. Collect Reward

  • Contract Interface

function harvest(uint256 _tokenId, address _to) external returns (uint256 reward)
  • Param Explannation

    • _to(address): The address of user.

    • _tokenId(uint256): The unique identifier of the NFT that is to collect reward. This ID corresponds to a specific liquidity position or other forms of representation within the NFT contract.

8. Unstake

  • Contract Interface

function withdraw(uint256 _tokenId, address _to) external returns (uint256 reward)
  • Param Explannation

    • _tokenId(uint256): The unique identifier of the NFT that is to unstake. This ID corresponds to a specific liquidity position or other forms of representation within the NFT contract.

    • _to(address): The address of user.

Last updated