Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PositionManager mint #80

Closed
wants to merge 1 commit into from

Conversation

tinaszheng
Copy link
Contributor

No description provided.

@tinaszheng tinaszheng changed the title feat: PositionManager mint (WIP) feat: PositionManager mint Nov 28, 2023
contracts/NonfungiblePositionManagerV4.sol Outdated Show resolved Hide resolved
function lockAcquired(bytes calldata rawData) external returns (bytes memory) {
// TODO: implement this
require(msg.sender == address(poolManager));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use custom err here too?

@@ -133,7 +174,47 @@ contract NonfungiblePositionManagerV4 is
checkDeadline(params.deadline)
returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
{
// TODO: implement this
(tokenId, liquidity, amount0, amount1) = abi.decode(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it better if i split this out into two lines?

bytes result = poolManager.lock(abi.encode(CallbackData(CallbackAction.Mint, msg.sender, abi.encode(params))));
(tokenId, liquidity, amount0, amount1) = abi.decode(result, (uint256, uint128, uint256, uint256));

contracts/NonfungiblePositionManagerV4.sol Show resolved Hide resolved
contracts/NonfungiblePositionManagerV4.sol Outdated Show resolved Hide resolved
function cachePoolKey(PoolKey memory poolKey) private returns (PoolId poolId) {
poolId = poolKey.toId();
// uninitialized check
if (_poolIdToPoolKey[PoolId.unwrap(poolId)].tickSpacing == 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is checking for tickSpacing the right thing to do here? just want to check if this key exists in the mapping yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also big difference between this mapping vs the one that exists in v3:

  • in v3, there's a poolId indicator PER nft so during burn, we deleted the poolId from the mapping
  • but in v4, this is a poolId PER poolkey and there could be multiple NFTs per poolKey. we don't want to burn during mint, so this is essentially an ever-growing list. but it also means not every mint needs to store an extra poolId mapping

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea i think its a fair chec as tickSpacing can't be 0 in an initialized pool

@@ -120,7 +130,37 @@ contract NonfungiblePositionManagerV4 is
checkDeadline(params.deadline)
returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
{
// TODO: implement this
(liquidity, amount0, amount1) = addLiquidity(
AddLiquidityParams({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this re-defining of AddLiquidityParams is kinda ugly... i think i'd prefer either:

  1. We could have AddLiqParams as a sub-struct of MintParams like
struct MintParams {
   AddLiquidityParams addLiqParams
   address recipient
   uint256 deadline
}

orrrr
2. We could not even bother with the MintParams entirely and just have

function mint(AddLiquidityParams calldata params, address recipient, uint256 deadline)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then these 12 lines could just be like (liquidity, amount0, amount1) = addLiquidity(params); 😏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ option 2

})
);

tokenId = _nextId++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unchecked!

Copy link
Contributor

@marktoda marktoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tests for mint would be good?

function cachePoolKey(PoolKey memory poolKey) private returns (PoolId poolId) {
poolId = poolKey.toId();
// uninitialized check
if (_poolIdToPoolKey[PoolId.unwrap(poolId)].tickSpacing == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea i think its a fair chec as tickSpacing can't be 0 in an initialized pool

@@ -120,7 +130,37 @@ contract NonfungiblePositionManagerV4 is
checkDeadline(params.deadline)
returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
{
// TODO: implement this
(liquidity, amount0, amount1) = addLiquidity(
AddLiquidityParams({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ option 2

@hensha256 hensha256 added the posm position manager label Jun 26, 2024
@snreynolds
Copy link
Member

Closing in favor of #141

@snreynolds snreynolds closed this Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
posm position manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants