Skip to content

Commit

Permalink
merge in main
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Aug 7, 2024
2 parents 4919675 + bf3b8ad commit d0fac81
Show file tree
Hide file tree
Showing 38 changed files with 94 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123220
123226
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122727
122733
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130298
130304
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129805
129812
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141690
141698
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150538
150546
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150538
150546
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149910
149918
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108827
108833
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116081
116089
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115453
115461
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134377
134384
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127116
127123
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128797
128805
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 @@
116614
116622
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152488
152496
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151490
151498
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134288
134296
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130387
130395
Original file line number Diff line number Diff line change
@@ -1 +1 @@
171303
171311
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141259
141267
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
340665
340673
Original file line number Diff line number Diff line change
@@ -1 +1 @@
349157
349165
Original file line number Diff line number Diff line change
@@ -1 +1 @@
348459
348467
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
318647
318655
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
319289
319297
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
244871
244879
Original file line number Diff line number Diff line change
@@ -1 +1 @@
374689
374697
Original file line number Diff line number Diff line change
@@ -1 +1 @@
324665
324673
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
375965
375973
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
375105
375113
Original file line number Diff line number Diff line change
@@ -1 +1 @@
420416
420424
12 changes: 10 additions & 2 deletions src/base/Notifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {PositionConfig} from "../libraries/PositionConfig.sol";
import {BipsLibrary} from "../libraries/BipsLibrary.sol";
import {INotifier} from "../interfaces/INotifier.sol";
import {CustomRevert} from "@uniswap/v4-core/src/libraries/CustomRevert.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";

import {PositionConfig, PositionConfigLibrary} from "../libraries/PositionConfig.sol";

Expand Down Expand Up @@ -87,12 +88,19 @@ abstract contract Notifier is INotifier {
return positionConfigs().hasSubscriber(tokenId);
}

function _notifyModifyLiquidity(uint256 tokenId, PositionConfig memory config, int256 liquidityChange) internal {
function _notifyModifyLiquidity(
uint256 tokenId,
PositionConfig memory config,
int256 liquidityChange,
BalanceDelta feesAccrued
) internal {
ISubscriber _subscriber = subscriber[tokenId];

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

if (!success) {
Expand Down
5 changes: 3 additions & 2 deletions src/base/PositionActionsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ contract PositionActionsRouter is
bytes32 salt,
bytes calldata hookData
) internal returns (BalanceDelta liquidityDelta) {
(liquidityDelta,) = poolManager.modifyLiquidity(
BalanceDelta feesAccrued;
(liquidityDelta, feesAccrued) = poolManager.modifyLiquidity(
config.poolKey,
IPoolManager.ModifyLiquidityParams({
tickLower: config.tickLower,
Expand All @@ -297,7 +298,7 @@ contract PositionActionsRouter is
);

if (_positionConfigs.hasSubscriber(uint256(salt))) {
_notifyModifyLiquidity(uint256(salt), config, liquidityChange);
_notifyModifyLiquidity(uint256(salt), config, liquidityChange, feesAccrued);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/interfaces/ISubscriber.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.24;

import {PositionConfig} from "../libraries/PositionConfig.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";

/// @notice Interface that a Subscriber contract should implement to receive updates from the v4 position manager
interface ISubscriber {
Expand All @@ -16,7 +17,13 @@ interface ISubscriber {
/// @param tokenId the token ID of the position
/// @param config details about the position
/// @param liquidityChange the change in liquidity on the underlying position
function notifyModifyLiquidity(uint256 tokenId, PositionConfig memory config, int256 liquidityChange) external;
/// @param feesAccrued the fees to be collected from the position as a result of the modifyLiquidity call
function notifyModifyLiquidity(
uint256 tokenId,
PositionConfig memory config,
int256 liquidityChange,
BalanceDelta feesAccrued
) external;
/// @param tokenId the token ID of the position
/// @param previousOwner address of the old owner
/// @param newOwner address of the new owner
Expand Down
5 changes: 3 additions & 2 deletions test/mocks/MockBadSubscribers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.20;
import {ISubscriber} from "../../src/interfaces/ISubscriber.sol";
import {PositionConfig} from "../../src/libraries/PositionConfig.sol";
import {PositionManager} from "../../src/PositionManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";

/// @notice A subscriber contract that returns values from the subscriber entrypoints
contract MockReturnDataSubscriber is ISubscriber {
Expand Down Expand Up @@ -44,7 +45,7 @@ contract MockReturnDataSubscriber is ISubscriber {
}
}

function notifyModifyLiquidity(uint256, PositionConfig memory, int256) external onlyByPosm {
function notifyModifyLiquidity(uint256, PositionConfig memory, int256, BalanceDelta) external onlyByPosm {
notifyModifyLiquidityCount++;
}

Expand Down Expand Up @@ -86,7 +87,7 @@ contract MockRevertSubscriber is ISubscriber {
revert TestRevert("notifyUnsubscribe");
}

function notifyModifyLiquidity(uint256, PositionConfig memory, int256) external view onlyByPosm {
function notifyModifyLiquidity(uint256, PositionConfig memory, int256, BalanceDelta) external view onlyByPosm {
revert TestRevert("notifyModifyLiquidity");
}

Expand Down
10 changes: 9 additions & 1 deletion test/mocks/MockSubscriber.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.20;
import {ISubscriber} from "../../src/interfaces/ISubscriber.sol";
import {PositionConfig} from "../../src/libraries/PositionConfig.sol";
import {PositionManager} from "../../src/PositionManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";

/// @notice A subscriber contract that ingests updates from the v4 position manager
contract MockSubscriber is ISubscriber {
Expand All @@ -13,6 +14,8 @@ contract MockSubscriber is ISubscriber {
uint256 public notifyUnsubscribeCount;
uint256 public notifyModifyLiquidityCount;
uint256 public notifyTransferCount;
int256 public liquidityChange;
BalanceDelta public feesAccrued;

bytes public subscribeData;
bytes public unsubscribeData;
Expand Down Expand Up @@ -40,8 +43,13 @@ contract MockSubscriber is ISubscriber {
unsubscribeData = data;
}

function notifyModifyLiquidity(uint256, PositionConfig memory, int256) external onlyByPosm {
function notifyModifyLiquidity(uint256, PositionConfig memory, int256 _liquidityChange, BalanceDelta _feesAccrued)
external
onlyByPosm
{
notifyModifyLiquidityCount++;
liquidityChange = _liquidityChange;
feesAccrued = _feesAccrued;
}

function notifyTransfer(uint256, address, address) external onlyByPosm {
Expand Down
29 changes: 29 additions & 0 deletions test/position-managers/PositionManager.notifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {Plan, Planner} from "../shared/Planner.sol";
import {Actions} from "../../src/libraries/Actions.sol";
import {INotifier} from "../../src/interfaces/INotifier.sol";
import {MockReturnDataSubscriber, MockRevertSubscriber} from "../mocks/MockBadSubscribers.sol";
import {BalanceDelta, toBalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";

contract PositionManagerNotifierTest is Test, PosmTestSetup, GasSnapshot {
using PoolIdLibrary for PoolKey;
Expand Down Expand Up @@ -127,6 +128,34 @@ contract PositionManagerNotifierTest is Test, PosmTestSetup, GasSnapshot {
assertEq(sub.notifyModifyLiquidityCount(), 10);
}

function test_notifyModifyLiquidity_args() public {
uint256 tokenId = lpm.nextTokenId();
mint(config, 100e18, alice, ZERO_BYTES);

// donate to generate fee revenue, to be checked in subscriber
uint256 feeRevenue0 = 1e18;
uint256 feeRevenue1 = 0.1e18;
donateRouter.donate(config.poolKey, feeRevenue0, feeRevenue1, ZERO_BYTES);

// approve this contract to operate on alices liq
vm.startPrank(alice);
lpm.approve(address(this), tokenId);
vm.stopPrank();

lpm.subscribe(tokenId, config, address(sub), ZERO_BYTES);

assertEq(lpm.hasSubscriber(tokenId), true);
assertEq(address(lpm.subscriber(tokenId)), address(sub));

uint256 liquidityToAdd = 10e18;
increaseLiquidity(tokenId, config, liquidityToAdd, ZERO_BYTES);

assertEq(sub.notifyModifyLiquidityCount(), 1);
assertEq(sub.liquidityChange(), int256(liquidityToAdd));
assertEq(int256(sub.feesAccrued().amount0()), int256(feeRevenue0) - 1 wei);
assertEq(int256(sub.feesAccrued().amount1()), int256(feeRevenue1) - 1 wei);
}

function test_notifyTransfer_withTransferFrom_succeeds() public {
uint256 tokenId = lpm.nextTokenId();
mint(config, 100e18, alice, ZERO_BYTES);
Expand Down

0 comments on commit d0fac81

Please sign in to comment.