Skip to content

Commit

Permalink
actions with no unlock (#231)
Browse files Browse the repository at this point in the history
* actions with no unlock

* Test lockless posm via hooks (#266)

* test hook which modifiesLiquidities in beforeSwap

* test hook modifying liquidity

* minor cleanups

* test that hooks cannot re-enter modifyLiquidities

* hook mints liquidity with modifyLiquidities

* PR cmments

* rename

* rename

* Update src/interfaces/IPositionManager.sol

Co-authored-by: Sara Reynolds <30504811+snreynolds@users.noreply.github.com>

* misc code comments

---------

Co-authored-by: saucepoint <saucepoint@protonmail.com>
Co-authored-by: saucepoint <98790946+saucepoint@users.noreply.github.com>
Co-authored-by: Sara Reynolds <30504811+snreynolds@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 5, 2024
1 parent ea5f9ec commit f402aa7
Show file tree
Hide file tree
Showing 72 changed files with 466 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BaseActionsRouter_mock10commands.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61756
61794
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133519
133557
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135555
135593
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128029
128067
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128167
128205
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47176
47224
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 @@
46993
47041
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122988
123036
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122698
122746
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130067
130115
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129776
129824
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141379
141439
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150227
150287
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150227
150287
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149852
149912
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108578
108626
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115770
115830
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115395
115455
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134146
134194
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126885
126933
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128486
128546
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 @@
116625
116685
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152333
152393
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151588
151648
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134133
134193
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130372
130432
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170992
171052
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140972
141032
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
336811
336871
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345280
345340
Original file line number Diff line number Diff line change
@@ -1 +1 @@
344835
344895
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
314793
314853
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315435
315495
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
241017
241077
Original file line number Diff line number Diff line change
@@ -1 +1 @@
370973
371033
Original file line number Diff line number Diff line change
@@ -1 +1 @@
320811
320871
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372111
372171
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371504
371564
Original file line number Diff line number Diff line change
@@ -1 +1 @@
416486
416622
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8438
8446
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119534
119572
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118729
118767
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127601
127639
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134431
134469
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185972
186010
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
177907
177945
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
237494
237532
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229453
229491
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133519
133557
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118622
118660
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117800
117838
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125192
125230
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119470
119508
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128342
128380
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133143
133181
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185287
185325
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
182137
182175
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
237427
237465
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
234301
234339
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
228579
228617
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131940
131978
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123989
124027
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118280
118318
12 changes: 10 additions & 2 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ contract PositionManager is
_;
}

/// @param unlockData is an encoding of actions, params, and currencies
/// @param deadline is the timestamp at which the unlockData will no longer be valid
/// @inheritdoc IPositionManager
function modifyLiquidities(bytes calldata unlockData, uint256 deadline)
external
payable
Expand All @@ -104,6 +103,15 @@ contract PositionManager is
_executeActions(unlockData);
}

/// @inheritdoc IPositionManager
function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params)
external
payable
isNotLocked
{
_executeActionsWithoutUnlock(actions, params);
}

/// @inheritdoc INotifier
function subscribe(uint256 tokenId, PositionConfig calldata config, address subscriber, bytes calldata data)
external
Expand Down
6 changes: 4 additions & 2 deletions src/base/BaseActionsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ abstract contract BaseActionsRouter is SafeCallback {
function _unlockCallback(bytes calldata data) internal override returns (bytes memory) {
// abi.decode(data, (bytes, bytes[]));
(bytes calldata actions, bytes[] calldata params) = data.decodeActionsRouterParams();
_executeActionsWithoutUnlock(actions, params);
return "";
}

function _executeActionsWithoutUnlock(bytes calldata actions, bytes[] calldata params) internal {
uint256 numActions = actions.length;
if (numActions != params.length) revert InputLengthMismatch();

Expand All @@ -41,8 +45,6 @@ abstract contract BaseActionsRouter is SafeCallback {

_handleAction(action, params[actionIndex]);
}

return "";
}

/// @notice function to handle the parsing and execution of an action and its parameters
Expand Down
11 changes: 10 additions & 1 deletion src/interfaces/IPositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ interface IPositionManager is INotifier {
error DeadlinePassed();
error IncorrectPositionConfigForTokenId(uint256 tokenId);

/// @notice Batches many liquidity modification calls to pool manager
/// @notice Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity
/// @dev This is the standard entrypoint for the PositionManager
/// @param payload is an encoding of actions, and parameters for those actions
/// @param deadline is the deadline for the batched actions to be executed
function modifyLiquidities(bytes calldata payload, uint256 deadline) external payable;

/// @notice Batches actions for modifying liquidity without unlocking v4 PoolManager
/// @dev This must be called by a contract that has already unlocked the v4 PoolManager
/// @param actions the actions to perform
/// @param params the parameters to provide for the actions
function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable;

/// @notice Used to get the ID that will be used for the next minted liquidity position
/// @return uint256 The next token ID
function nextTokenId() external view returns (uint256);

/// @param tokenId the ERC721 tokenId
Expand Down
Loading

0 comments on commit f402aa7

Please sign in to comment.