Skip to content

Commit

Permalink
change event name
Browse files Browse the repository at this point in the history
  • Loading branch information
rileydcampbell committed Dec 14, 2023
1 parent 43d5aea commit e408681
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 145 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Only the net balances owed to the pool (positive) or to the user (negative) are
Additionally, a pool may be initialized with a hook contract, that can implement any of the following callbacks in the lifecycle of pool actions:

- {before,after}Initialize
- {before,after}ModifyPosition
- {before,after}AddLiquidity
- {before,after}RemoveLiquidity
- {before,after}Swap
- {before,after}Donate

Expand Down
2 changes: 1 addition & 1 deletion src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {

key.hooks.afterModifyLiquidity(key, params, delta, hookData);

emit ModifyPosition(id, msg.sender, params.tickLower, params.tickUpper, params.liquidityDelta);
emit ModifyLiquidity(id, msg.sender, params.tickLower, params.tickUpper, params.liquidityDelta);
}

/// @inheritdoc IPoolManager
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface IPoolManager is IFees, IClaims {
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param liquidityDelta The amount of liquidity that was added or removed
event ModifyPosition(
event ModifyLiquidity(
PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta
);

Expand Down
4 changes: 2 additions & 2 deletions src/test/AccessLockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract AccessLockHook is Test, BaseTestHooks {
Take,
Donate,
Swap,
ModifyPosition,
ModifyLiquidity,
Burn,
Settle,
Initialize,
Expand Down Expand Up @@ -109,7 +109,7 @@ contract AccessLockHook is Test, BaseTestHooks {
}),
new bytes(0)
);
} else if (action == LockAction.ModifyPosition) {
} else if (action == LockAction.ModifyLiquidity) {
manager.modifyLiquidity(
key,
IPoolManager.ModifyLiquidityParams({tickLower: -60, tickUpper: 60, liquidityDelta: int256(amount)}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Hooks} from "../libraries/Hooks.sol";
import {Test} from "forge-std/Test.sol";
import {FeeLibrary} from "../libraries/FeeLibrary.sol";

contract PoolModifyPositionTest is Test, PoolTestBase {
contract PoolModifyLiquidityTest is Test, PoolTestBase {
using CurrencyLibrary for Currency;
using Hooks for IHooks;
using FeeLibrary for uint24;
Expand Down
108 changes: 55 additions & 53 deletions test/AccessLock.t.sol

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions test/Hooks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,79 +66,79 @@ contract HooksTest is Test, Deployers, GasSnapshot {

function test_beforeAfterAddLiquidity_beforeAfterRemoveLiquidity_succeedsWithHook() public {
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 1e18), new bytes(111));
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 1e18), new bytes(111));
assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111));
assertEq(mockHooks.afterAddLiquidityData(), new bytes(111));

modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, -1e18), new bytes(222));
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, -1e18), new bytes(222));
assertEq(mockHooks.beforeRemoveLiquidityData(), new bytes(222));
assertEq(mockHooks.afterRemoveLiquidityData(), new bytes(222));
}

function test_beforeAfterAddLiquidity_calledWithPositiveLiquidityDelta() public {
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 100), new bytes(111));
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 100), new bytes(111));
assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111));
assertEq(mockHooks.afterAddLiquidityData(), new bytes(111));
}

function test_beforeAfterRemoveLiquidity_calledWithZeroLiquidityDelta() public {
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 1e18), new bytes(111));
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 1e18), new bytes(111));
assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111));
assertEq(mockHooks.afterAddLiquidityData(), new bytes(111));

modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 0), new bytes(222));
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 0), new bytes(222));
assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111));
assertEq(mockHooks.afterAddLiquidityData(), new bytes(111));
assertEq(mockHooks.beforeRemoveLiquidityData(), new bytes(222));
assertEq(mockHooks.afterRemoveLiquidityData(), new bytes(222));
}

function test_beforeAfterRemoveLiquidity_calledWithPositiveLiquidityDelta() public {
modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 1e18), new bytes(111));
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, 1e18), new bytes(111));
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
modifyPositionRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, -1e18), new bytes(111));
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(0, 60, -1e18), new bytes(111));
assertEq(mockHooks.beforeRemoveLiquidityData(), new bytes(111));
assertEq(mockHooks.afterRemoveLiquidityData(), new bytes(111));
}

function test_beforeAddLiquidity_invalidReturn() public {
mockHooks.setReturnValue(mockHooks.beforeAddLiquidity.selector, bytes4(0xdeadbeef));
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
modifyPositionRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
modifyLiquidityRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
}

function test_beforeRemoveLiquidity_invalidReturn() public {
mockHooks.setReturnValue(mockHooks.beforeRemoveLiquidity.selector, bytes4(0xdeadbeef));
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
modifyPositionRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
modifyLiquidityRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
modifyPositionRouter.modifyLiquidity(key, REMOVE_LIQ_PARAMS, ZERO_BYTES);
modifyLiquidityRouter.modifyLiquidity(key, REMOVE_LIQ_PARAMS, ZERO_BYTES);
}

function test_afterAddLiquidity_invalidReturn() public {
mockHooks.setReturnValue(mockHooks.afterAddLiquidity.selector, bytes4(0xdeadbeef));
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
modifyPositionRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
modifyLiquidityRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
}

function test_afterRemoveLiquidity_invalidReturn() public {
mockHooks.setReturnValue(mockHooks.afterRemoveLiquidity.selector, bytes4(0xdeadbeef));
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18);
modifyPositionRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyLiquidityRouter), 1e18);
modifyLiquidityRouter.modifyLiquidity(key, LIQ_PARAMS, ZERO_BYTES);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
modifyPositionRouter.modifyLiquidity(key, REMOVE_LIQ_PARAMS, ZERO_BYTES);
modifyLiquidityRouter.modifyLiquidity(key, REMOVE_LIQ_PARAMS, ZERO_BYTES);
}

function test_swap_succeedsWithHook() public {
Expand Down
Loading

0 comments on commit e408681

Please sign in to comment.