-
Notifications
You must be signed in to change notification settings - Fork 495
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; | |
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol"; | ||
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; | ||
import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol"; | ||
import {Position} from "@uniswap/v4-core/contracts/libraries/Position.sol"; | ||
|
||
import {INonfungiblePositionManagerV4} from "./interfaces/INonfungiblePositionManagerV4.sol"; | ||
import {PeripheryValidation} from "./base/PeripheryValidation.sol"; | ||
|
@@ -112,6 +113,15 @@ contract NonfungiblePositionManagerV4 is | |
); | ||
} | ||
|
||
/// @dev Caches a pool key | ||
function cachePoolKey(PoolKey memory poolKey) private returns (PoolId poolId) { | ||
poolId = poolKey.toId(); | ||
// uninitialized check | ||
if (_poolIdToPoolKey[PoolId.unwrap(poolId)].tickSpacing == 0) { | ||
_poolIdToPoolKey[PoolId.unwrap(poolId)] = poolKey; | ||
} | ||
} | ||
|
||
/// @inheritdoc INonfungiblePositionManagerV4 | ||
function mint(MintParams calldata params) | ||
external | ||
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
orrrr
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then these 12 lines could just be like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ option 2 |
||
poolKey: params.poolKey, | ||
tickLower: params.tickLower, | ||
tickUpper: params.tickUpper, | ||
amount0Desired: params.amount0Desired, | ||
amount1Desired: params.amount1Desired, | ||
amount0Min: params.amount0Min, | ||
amount1Min: params.amount1Min, | ||
hookData: params.hookData | ||
}) | ||
); | ||
|
||
tokenId = _nextId++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unchecked! |
||
_mint(params.recipient, tokenId); | ||
|
||
PoolId poolId = cachePoolKey(params.poolKey); | ||
Position.Info memory positionInfo = | ||
poolManager.getPosition(poolId, address(this), params.tickLower, params.tickUpper); | ||
_positions[tokenId] = TokenPosition({ | ||
nonce: 0, | ||
tinaszheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
operator: address(0), | ||
poolId: poolId, | ||
tickLower: params.tickLower, | ||
tickUpper: params.tickUpper, | ||
liquidity: liquidity, | ||
feeGrowthInside0LastX128: positionInfo.feeGrowthInside0LastX128, | ||
feeGrowthInside1LastX128: positionInfo.feeGrowthInside1LastX128, | ||
tokensOwed0: 0, | ||
tokensOwed1: 0 | ||
}); | ||
} | ||
|
||
/// @inheritdoc INonfungiblePositionManagerV4 | ||
|
There was a problem hiding this comment.
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 yetThere was a problem hiding this comment.
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:
mint
needs to store an extra poolId mappingThere was a problem hiding this comment.
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