Skip to content

Commit

Permalink
Merge branch 'main' into posm-modifyLiquiditiesWithoutUnlock-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Aug 5, 2024
2 parents c31e24c + af688af commit c75bcf5
Show file tree
Hide file tree
Showing 52 changed files with 100 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BaseActionsRouter_mock10commands.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61794
61749
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47224
47170
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 @@
47041
46988
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123166
123220
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122673
122727
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130244
130298
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129752
129805
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141601
141690
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150449
150538
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150449
150538
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149821
149910
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108756
108827
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115992
116081
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115364
115453
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134324
134377
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127063
127116
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128708
128797
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 @@
116525
116614
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152577
152488
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151579
151490
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134377
134288
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130432
130387
Original file line number Diff line number Diff line change
@@ -1 +1 @@
171214
171303
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141216
141259
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337055
340631
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345547
349123
Original file line number Diff line number Diff line change
@@ -1 +1 @@
344849
348425
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315037
318613
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315679
319255
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
241261
244837
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371079
374655
Original file line number Diff line number Diff line change
@@ -1 +1 @@
321055
324631
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372355
375931
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371495
375071
Original file line number Diff line number Diff line change
@@ -1 +1 @@
416851
420405
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2398
2376
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8543
8455
2 changes: 1 addition & 1 deletion .forge-snapshots/StateView_extsload_getLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1509
1487
2 changes: 1 addition & 1 deletion .forge-snapshots/StateView_extsload_getPositionInfo.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2927
2905
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1746
1724
2 changes: 1 addition & 1 deletion .forge-snapshots/StateView_extsload_getSlot0.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1606
1584
2 changes: 1 addition & 1 deletion .forge-snapshots/StateView_extsload_getTickBitmap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1704
1682
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2756
2734
2 changes: 1 addition & 1 deletion .forge-snapshots/StateView_extsload_getTickInfo.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3090
3068
2 changes: 1 addition & 1 deletion .forge-snapshots/StateView_extsload_getTickLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1901
1879
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8446
8454
2 changes: 1 addition & 1 deletion lib/v4-core
Submodule v4-core updated 58 files
+1 −1 .forge-snapshots/add liquidity to already existing position with salt.snap
+1 −1 .forge-snapshots/addLiquidity CA fee.snap
+1 −1 .forge-snapshots/addLiquidity with empty hook.snap
+1 −1 .forge-snapshots/addLiquidity with native token.snap
+1 −1 .forge-snapshots/clear.snap
+1 −1 .forge-snapshots/create new liquidity to a position with salt.snap
+1 −1 .forge-snapshots/donate gas with 1 token.snap
+1 −1 .forge-snapshots/donate gas with 2 tokens.snap
+1 −1 .forge-snapshots/erc20 collect protocol fees.snap
+1 −1 .forge-snapshots/extsload getFeeGrowthGlobals.snap
+1 −1 .forge-snapshots/extsload getFeeGrowthInside.snap
+1 −1 .forge-snapshots/extsload getLiquidity.snap
+1 −1 .forge-snapshots/extsload getPositionInfo.snap
+1 −1 .forge-snapshots/extsload getPositionLiquidity.snap
+1 −1 .forge-snapshots/extsload getSlot0.snap
+1 −1 .forge-snapshots/extsload getTickBitmap.snap
+1 −1 .forge-snapshots/extsload getTickFeeGrowthOutside.snap
+1 −1 .forge-snapshots/extsload getTickInfo.snap
+1 −1 .forge-snapshots/extsload getTickLiquidity.snap
+1 −1 .forge-snapshots/getReserves.snap
+1 −1 .forge-snapshots/initialize.snap
+1 −1 .forge-snapshots/native collect protocol fees.snap
+1 −1 .forge-snapshots/poolManager bytecode size.snap
+1 −1 .forge-snapshots/removeLiquidity CA fee.snap
+1 −1 .forge-snapshots/removeLiquidity with empty hook.snap
+1 −1 .forge-snapshots/removeLiquidity with native token.snap
+1 −1 .forge-snapshots/simple addLiquidity second addition same range.snap
+1 −1 .forge-snapshots/simple addLiquidity.snap
+1 −1 .forge-snapshots/simple removeLiquidity some liquidity remains.snap
+1 −1 .forge-snapshots/simple removeLiquidity.snap
+1 −1 .forge-snapshots/simple swap with native.snap
+1 −1 .forge-snapshots/simple swap.snap
+1 −1 .forge-snapshots/swap CA custom curve + swap noop.snap
+1 −1 .forge-snapshots/swap CA fee on unspecified.snap
+1 −1 .forge-snapshots/swap against liquidity with native token.snap
+1 −1 .forge-snapshots/swap against liquidity.snap
+1 −1 .forge-snapshots/swap burn 6909 for input.snap
+1 −1 .forge-snapshots/swap burn native 6909 for input.snap
+1 −1 .forge-snapshots/swap mint native output as 6909.snap
+1 −1 .forge-snapshots/swap mint output as 6909.snap
+1 −1 .forge-snapshots/swap skips hook call if hook is caller.snap
+1 −1 .forge-snapshots/swap with dynamic fee.snap
+1 −1 .forge-snapshots/swap with hooks.snap
+1 −1 .forge-snapshots/swap with lp fee and protocol fee.snap
+1 −1 .forge-snapshots/swap with return dynamic fee.snap
+1 −1 .forge-snapshots/update dynamic fee in before swap.snap
+2 −4 src/PoolManager.sol
+0 −6 src/interfaces/IPoolManager.sol
+8 −7 src/libraries/CustomRevert.sol
+2 −2 src/libraries/Hooks.sol
+4 −4 src/libraries/StateLibrary.sol
+2 −4 src/test/ProxyPoolManager.sol
+6 −6 src/types/Currency.sol
+8 −3 test/DynamicFees.t.sol
+5 −1 test/PoolManager.t.sol
+4 −4 test/PoolManagerInitialize.t.sol
+6 −2 test/libraries/Hooks.t.sol
+15 −3 test/types/Currency.t.sol
4 changes: 3 additions & 1 deletion src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ contract PositionManager is
BalanceDelta liquidityDelta = _modifyLiquidity(config, liquidity.toInt256(), bytes32(tokenId), hookData);
liquidityDelta.validateMaxIn(amount0Max, amount1Max);
positionConfigs.setConfigId(tokenId, config);

emit MintPosition(tokenId, config);
}

/// @dev this is overloaded with ERC721Permit_v4._burn
Expand Down Expand Up @@ -358,7 +360,7 @@ contract PositionManager is
}

/// @dev overrides solmate transferFrom in case a notification to subscribers is needed
function transferFrom(address from, address to, uint256 id) public override {
function transferFrom(address from, address to, uint256 id) public virtual override {
super.transferFrom(from, to, id);
if (positionConfigs.hasSubscriber(id)) _notifyTransfer(id, from, to);
}
Expand Down
41 changes: 30 additions & 11 deletions src/base/Notifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ pragma solidity ^0.8.24;
import {ISubscriber} from "../interfaces/ISubscriber.sol";
import {PositionConfig} from "../libraries/PositionConfig.sol";
import {BipsLibrary} from "../libraries/BipsLibrary.sol";
import {INotifier, PositionConfig} from "../interfaces/INotifier.sol";
import {INotifier} from "../interfaces/INotifier.sol";
import {CustomRevert} from "@uniswap/v4-core/src/libraries/CustomRevert.sol";

/// @notice Notifier is used to opt in to sending updates to external contracts about position modifications or transfers
/// TODO: Use CustomRevert library when it supports subcontext's addresss
abstract contract Notifier is INotifier {
using BipsLibrary for uint256;
using CustomRevert for bytes4;
Expand All @@ -35,10 +34,14 @@ abstract contract Notifier is INotifier {
if (_subscriber != NO_SUBSCRIBER) revert AlreadySubscribed(address(_subscriber));
subscriber[tokenId] = ISubscriber(newSubscriber);

try ISubscriber(newSubscriber).notifySubscribe(tokenId, config, data) {}
catch (bytes memory reason) {
revert Wrap__SubsciptionReverted(newSubscriber, reason);
bool success = _call(
address(newSubscriber), abi.encodeWithSelector(ISubscriber.notifySubscribe.selector, tokenId, config, data)
);

if (!success) {
Wrap__SubsciptionReverted.selector.bubbleUpAndRevertWith(address(newSubscriber));
}

emit Subscribed(tokenId, address(newSubscriber));
}

Expand All @@ -56,17 +59,33 @@ abstract contract Notifier is INotifier {

function _notifyModifyLiquidity(uint256 tokenId, PositionConfig memory config, int256 liquidityChange) internal {
ISubscriber _subscriber = subscriber[tokenId];
try _subscriber.notifyModifyLiquidity(tokenId, config, liquidityChange) {}
catch (bytes memory reason) {
revert Wrap__ModifyLiquidityNotificationReverted(address(_subscriber), reason);

bool success = _call(
address(_subscriber),
abi.encodeWithSelector(ISubscriber.notifyModifyLiquidity.selector, tokenId, config, liquidityChange)
);

if (!success) {
Wrap__ModifyLiquidityNotificationReverted.selector.bubbleUpAndRevertWith(address(_subscriber));
}
}

function _notifyTransfer(uint256 tokenId, address previousOwner, address newOwner) internal {
ISubscriber _subscriber = subscriber[tokenId];
try _subscriber.notifyTransfer(tokenId, previousOwner, newOwner) {}
catch (bytes memory reason) {
revert Wrap__TransferNotificationReverted(address(_subscriber), reason);

bool success = _call(
address(_subscriber),
abi.encodeWithSelector(ISubscriber.notifyTransfer.selector, tokenId, previousOwner, newOwner)
);

if (!success) {
Wrap__TransferNotificationReverted.selector.bubbleUpAndRevertWith(address(_subscriber));
}
}

function _call(address target, bytes memory encodedCall) internal returns (bool success) {
assembly ("memory-safe") {
success := call(gas(), target, 0, add(encodedCall, 0x20), mload(encodedCall), 0, 0)
}
}
}
2 changes: 2 additions & 0 deletions src/interfaces/IPositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface IPositionManager is INotifier {
error DeadlinePassed();
error IncorrectPositionConfigForTokenId(uint256 tokenId);

event MintPosition(uint256 indexed tokenId, PositionConfig config);

/// @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityF
// should revert because hook is not approved
vm.expectRevert(
abi.encodeWithSelector(
Hooks.FailedHookCall.selector,
Hooks.Wrap__FailedHookCall.selector,
address(hookModifyLiquidities),
abi.encodeWithSelector(IPositionManager.NotApproved.selector, address(hookModifyLiquidities))
)
);
Expand All @@ -237,7 +238,8 @@ contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityF
// should revert because hook is not approved
vm.expectRevert(
abi.encodeWithSelector(
Hooks.FailedHookCall.selector,
Hooks.Wrap__FailedHookCall.selector,
address(hookModifyLiquidities),
abi.encodeWithSelector(IPositionManager.NotApproved.selector, address(hookModifyLiquidities))
)
);
Expand All @@ -257,7 +259,8 @@ contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityF
// should revert because hook is not approved
vm.expectRevert(
abi.encodeWithSelector(
Hooks.FailedHookCall.selector,
Hooks.Wrap__FailedHookCall.selector,
address(hookModifyLiquidities),
abi.encodeWithSelector(IPositionManager.NotApproved.selector, address(hookModifyLiquidities))
)
);
Expand Down Expand Up @@ -495,7 +498,9 @@ contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityF
// should revert because hook is re-entering modifyLiquiditiesWithoutUnlock
vm.expectRevert(
abi.encodeWithSelector(
Hooks.FailedHookCall.selector, abi.encodeWithSelector(ReentrancyLock.ContractLocked.selector)
Hooks.Wrap__FailedHookCall.selector,
address(hookModifyLiquidities),
abi.encodeWithSelector(ReentrancyLock.ContractLocked.selector)
)
);
lpm.modifyLiquidities(calls, _deadline);
Expand Down
9 changes: 9 additions & 0 deletions test/position-managers/PositionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -935,5 +935,14 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
assertLt(uint256(int256(deltaDecrease.amount1())), uint256(int256(-deltaMint.amount1()))); // amount1 in the second position was greater than amount1 in the first position
}

function test_mint_emits_event() public {
PositionConfig memory config = PositionConfig({poolKey: key, tickLower: -60, tickUpper: 60});
uint256 tokenId = lpm.nextTokenId();

vm.expectEmit(true, false, false, true, address(lpm));
emit IPositionManager.MintPosition(tokenId, config);
mint(config, 1e18, ActionConstants.MSG_SENDER, ZERO_BYTES);
}

function test_mint_slippageRevert() public {}
}

0 comments on commit c75bcf5

Please sign in to comment.