Skip to content

Commit

Permalink
pr commmeeennnnttsss
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Aug 29, 2024
1 parent ec14729 commit 21ae901
Show file tree
Hide file tree
Showing 29 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
49954
49976
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
49954
49976
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126207
126229
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125704
125727
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133103
133125
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132600
132623
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146341
146373
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154961
154993
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154961
154993
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154345
154377
Original file line number Diff line number Diff line change
@@ -1 +1 @@
112548
112573
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120504
120536
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119888
119920
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135944
135992
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129048
129096
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133220
133252
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_take_take.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121037
121069
Original file line number Diff line number Diff line change
@@ -1 +1 @@
159211
159243
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158237
158269
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141239
141271
Original file line number Diff line number Diff line change
@@ -1 +1 @@
137356
137388
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178272
178304
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148228
148260
14 changes: 7 additions & 7 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ contract PositionManager is
uint128 amount1Max,
bytes calldata hookData
) internal onlyIfApproved(msgSender(), tokenId) {
(PositionInfo info, PoolKey memory poolKey) = getPoolAndPositionInfo(tokenId);
(PoolKey memory poolKey, PositionInfo info) = getPoolAndPositionInfo(tokenId);

// Note: The tokenId is used as the salt for this position, so every minted position has unique storage in the pool manager.
(BalanceDelta liquidityDelta, BalanceDelta feesAccrued) =
Expand All @@ -249,7 +249,7 @@ contract PositionManager is
uint128 amount1Min,
bytes calldata hookData
) internal onlyIfApproved(msgSender(), tokenId) {
(PositionInfo info, PoolKey memory poolKey) = getPoolAndPositionInfo(tokenId);
(PoolKey memory poolKey, PositionInfo info) = getPoolAndPositionInfo(tokenId);

// Note: the tokenId is used as the salt.
(BalanceDelta liquidityDelta, BalanceDelta feesAccrued) =
Expand Down Expand Up @@ -298,7 +298,7 @@ contract PositionManager is
internal
onlyIfApproved(msgSender(), tokenId)
{
(PositionInfo info, PoolKey memory poolKey) = getPoolAndPositionInfo(tokenId);
(PoolKey memory poolKey, PositionInfo info) = getPoolAndPositionInfo(tokenId);

uint256 liquidity = uint256(_getLiquidity(tokenId, poolKey, info.tickLower(), info.tickUpper()));

Expand Down Expand Up @@ -396,12 +396,12 @@ contract PositionManager is
}

/// @notice an internal helper used by Notifier
function _setSubscribe(uint256 tokenId) internal override {
function _setSubscribed(uint256 tokenId) internal override {
positionInfo[tokenId] = positionInfo[tokenId].setSubscribe();
}

/// @notice an internal helper used by Notifier
function _setUnsubscribe(uint256 tokenId) internal override {
function _setUnsubscribed(uint256 tokenId) internal override {
positionInfo[tokenId] = positionInfo[tokenId].setUnsubscribe();
}

Expand All @@ -412,14 +412,14 @@ contract PositionManager is
}

/// @inheritdoc IPositionManager
function getPoolAndPositionInfo(uint256 tokenId) public view returns (PositionInfo info, PoolKey memory poolKey) {
function getPoolAndPositionInfo(uint256 tokenId) public view returns (PoolKey memory poolKey, PositionInfo info) {
info = positionInfo[tokenId];
poolKey = poolKeys[info.poolId()];
}

/// @inheritdoc IPositionManager
function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity) {
(PositionInfo info, PoolKey memory poolKey) = getPoolAndPositionInfo(tokenId);
(PoolKey memory poolKey, PositionInfo info) = getPoolAndPositionInfo(tokenId);
liquidity = _getLiquidity(tokenId, poolKey, info.tickLower(), info.tickUpper());
}

Expand Down
8 changes: 4 additions & 4 deletions src/base/Notifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ abstract contract Notifier is INotifier {

modifier onlyIfApproved(address caller, uint256 tokenId) virtual;

function _setUnsubscribe(uint256 tokenId) internal virtual;
function _setUnsubscribed(uint256 tokenId) internal virtual;

function _setSubscribe(uint256 tokenId) internal virtual;
function _setSubscribed(uint256 tokenId) internal virtual;

/// @inheritdoc INotifier
function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data)
Expand All @@ -45,7 +45,7 @@ abstract contract Notifier is INotifier {

if (_subscriber != NO_SUBSCRIBER) revert AlreadySubscribed(address(_subscriber));

_setSubscribe(tokenId);
_setSubscribed(tokenId);
subscriber[tokenId] = ISubscriber(newSubscriber);

bool success = _call(address(newSubscriber), abi.encodeCall(ISubscriber.notifySubscribe, (tokenId, data)));
Expand All @@ -62,7 +62,7 @@ abstract contract Notifier is INotifier {
ISubscriber _subscriber = subscriber[tokenId];

if (_subscriber == NO_SUBSCRIBER) revert AlreadyUnsubscribed();
_setUnsubscribe(tokenId);
_setUnsubscribed(tokenId);

delete subscriber[tokenId];

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IPositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ interface IPositionManager is INotifier {
/// @param tokenId the ERC721 tokenId
/// @return PositionInfo a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
/// @return poolKey the pool key of the position
function getPoolAndPositionInfo(uint256 tokenId) external view returns (PositionInfo, PoolKey memory);
function getPoolAndPositionInfo(uint256 tokenId) external view returns (PoolKey memory, PositionInfo);
}
1 change: 1 addition & 0 deletions src/libraries/PositionInfoLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ library PositionInfoLibrary {
uint8 internal constant TICK_LOWER_OFFSET = 8;
uint8 internal constant TICK_UPPER_OFFSET = 32;

/// @dev This poolId is NOT compatible with the poolId used in UniswapV4 core. It is truncated to 25 bytes, and just used to lookup PoolKey in the poolKeys mapping.
function poolId(PositionInfo info) internal pure returns (bytes25 _poolId) {
assembly ("memory-safe") {
_poolId := and(MASK_UPPER_200_BITS, info)
Expand Down
4 changes: 2 additions & 2 deletions test/libraries/PositionInfoLibrary.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract PositionInfoLibraryTest is Test {
assertEq(info.hasSubscriber(), false);
}

function test_fuzz_initialize_setSubscribe(PoolKey memory poolKey, int24 tickLower, int24 tickUpper) public pure {
function test_fuzz_initialize_setSubscribed(PoolKey memory poolKey, int24 tickLower, int24 tickUpper) public pure {
PositionInfo info = PositionInfoLibrary.initialize(poolKey, tickLower, tickUpper);
assertEq(info.hasSubscriber(), false);
info = info.setSubscribe();
Expand All @@ -31,7 +31,7 @@ contract PositionInfoLibraryTest is Test {
assertEq(info.poolId(), bytes25(PoolId.unwrap(poolKey.toId())));
}

function test_fuzz_initialize_setUnsubscribe(PoolKey memory poolKey, int24 tickLower, int24 tickUpper)
function test_fuzz_initialize_setUnsubscribed(PoolKey memory poolKey, int24 tickLower, int24 tickUpper)
public
pure
{
Expand Down
3 changes: 2 additions & 1 deletion test/mocks/MockCalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
// we need to use a mock contract to make the calls happen in calldata not memory
contract MockCalldataDecoder {
using CalldataDecoder for bytes;


// This is used to avoid compiling with via-ir.
struct MintParams {
PoolKey poolKey;
int24 tickLower;
Expand Down

0 comments on commit 21ae901

Please sign in to comment.