From ad34755eaca373ea11f9804374a76757b9f8a3d4 Mon Sep 17 00:00:00 2001 From: Tina Zheng Date: Wed, 29 Nov 2023 12:14:13 -0500 Subject: [PATCH] update position manager skeleton with liquidity management file --- contracts/NonfungiblePositionManagerV4.sol | 7 +----- contracts/base/LiquidityManagement.sol | 22 +++++++++++++++++++ contracts/interfaces/ILiquidityManagement.sol | 20 +++++++++++++++++ .../INonfungiblePositionManagerV4.sol | 16 ++------------ 4 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 contracts/base/LiquidityManagement.sol create mode 100644 contracts/interfaces/ILiquidityManagement.sol diff --git a/contracts/NonfungiblePositionManagerV4.sol b/contracts/NonfungiblePositionManagerV4.sol index f2f5fb58..469334b7 100644 --- a/contracts/NonfungiblePositionManagerV4.sol +++ b/contracts/NonfungiblePositionManagerV4.sol @@ -65,8 +65,6 @@ contract NonfungiblePositionManagerV4 is /// @dev The address of the token descriptor contract, which handles generating token URIs for position tokens address private immutable _tokenDescriptor; - // TODO: does it still need WETH address in the constructor here? - // TODO: use ERC721Permit2 here constructor(IPoolManager _poolManager, address _tokenDescriptor_) PeripheryImmutableState(_poolManager) ERC721("Uniswap V4 Positions NFT-V1", "UNI-V4-POS") @@ -113,10 +111,6 @@ contract NonfungiblePositionManagerV4 is ); } - function lockAcquired(bytes calldata rawData) external returns (bytes memory) { - // TODO: implement this - } - /// @inheritdoc INonfungiblePositionManagerV4 function createAndInitializePoolIfNecessary(PoolKey memory poolkey, uint160 sqrtPriceX96, bytes memory initData) external @@ -134,6 +128,7 @@ contract NonfungiblePositionManagerV4 is returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) { // TODO: implement this + // will do something like return mintEntry(params) } modifier isAuthorizedForToken(uint256 tokenId) { diff --git a/contracts/base/LiquidityManagement.sol b/contracts/base/LiquidityManagement.sol new file mode 100644 index 00000000..019687e6 --- /dev/null +++ b/contracts/base/LiquidityManagement.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.19; + +import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol"; +import {ILockCallback} from "@uniswap/v4-core/contracts/interfaces/callback//ILockCallback.sol"; +import {IPeripheryPayments} from "../interfaces/IPeripheryPayments.sol"; +import {ILiquidityManagement} from "../interfaces/ILiquidityManagement.sol"; +import {PeripheryImmutableState} from "./PeripheryImmutableState.sol"; + +abstract contract LiquidityManagement is ILockCallback, ILiquidityManagement, PeripheryImmutableState { + function mintEntry(MintParams memory params) + internal + returns (uint256 tokenId, uint128 liquidity, BalanceDelta delta) + { + // poolManager.lock call here + } + + function lockAcquired(bytes calldata rawData) external override returns (bytes memory) { + // TODO: handle mint/add liquidity here + return abi.encode(0); + } +} diff --git a/contracts/interfaces/ILiquidityManagement.sol b/contracts/interfaces/ILiquidityManagement.sol new file mode 100644 index 00000000..02c4f2dd --- /dev/null +++ b/contracts/interfaces/ILiquidityManagement.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.19; + +import {ILockCallback} from "@uniswap/v4-core/contracts/interfaces/callback//ILockCallback.sol"; +import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; + +interface ILiquidityManagement is ILockCallback { + struct MintParams { + PoolKey poolKey; + int24 tickLower; + int24 tickUpper; + uint256 amount0Desired; + uint256 amount1Desired; + uint256 amount0Min; + uint256 amount1Min; + address recipient; + uint256 deadline; + bytes hookData; + } +} diff --git a/contracts/interfaces/INonfungiblePositionManagerV4.sol b/contracts/interfaces/INonfungiblePositionManagerV4.sol index 990bbd42..2c40ffac 100644 --- a/contracts/interfaces/INonfungiblePositionManagerV4.sol +++ b/contracts/interfaces/INonfungiblePositionManagerV4.sol @@ -3,18 +3,18 @@ pragma solidity ^0.8.19; import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; -import {ILockCallback} from "@uniswap/v4-core/contracts/interfaces/callback//ILockCallback.sol"; import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol"; import {IPeripheryPayments} from "./IPeripheryPayments.sol"; +import {ILiquidityManagement} from "./ILiquidityManagement.sol"; import {IPeripheryImmutableState} from "./IPeripheryImmutableState.sol"; /// @title Non-fungible token for positions /// @notice Wraps Uniswap V4 positions in a non-fungible token interface which allows for them to be transferred /// and authorized. interface INonfungiblePositionManagerV4 is - ILockCallback, + ILiquidityManagement, IPeripheryPayments, IPeripheryImmutableState, IERC721Metadata, @@ -82,18 +82,6 @@ interface INonfungiblePositionManagerV4 is uint128 tokensOwed1 ); - struct MintParams { - PoolKey poolKey; - 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.