diff --git a/src/test/PoolModifyPositionTest.sol b/src/test/PoolModifyPositionTest.sol index d0c7e9e4b..c68eacf30 100644 --- a/src/test/PoolModifyPositionTest.sol +++ b/src/test/PoolModifyPositionTest.sol @@ -45,8 +45,7 @@ contract PoolModifyPositionTest is Test, PoolTestBase { CallbackData memory data = abi.decode(rawData, (CallbackData)); - BalanceDelta delta; - delta = manager.modifyPosition(data.key, data.params, data.hookData); + BalanceDelta delta = manager.modifyPosition(data.key, data.params, data.hookData); // Checks that the current hook is cleared if there is an access lock. Note that if this router is ever used in a nested lock this will fail. assertEq(address(manager.getCurrentHook()), address(0)); @@ -57,11 +56,11 @@ contract PoolModifyPositionTest is Test, PoolTestBase { // These assertions only apply in non lock-accessing pools. if (!data.key.hooks.hasPermission(Hooks.ACCESS_LOCK_FLAG)) { if (data.params.liquidityDelta >= 0) { - require(delta0 > 0 || delta1 > 0 || data.key.hooks.hasPermission(Hooks.NO_OP_FLAG), "assert 1 failed"); - require(!(delta0 < 0 || delta1 < 0), "assert 2 failed"); + assert(delta0 > 0 || delta1 > 0 || data.key.hooks.hasPermission(Hooks.NO_OP_FLAG)); + assert(!(delta0 < 0 || delta1 < 0)); } else { - require(delta0 < 0 || delta1 < 0 || data.key.hooks.hasPermission(Hooks.NO_OP_FLAG), "assert 3 failed"); - require(!(delta0 > 0 || delta1 > 0), "assert 4 failed"); + assert(delta0 < 0 || delta1 < 0 || data.key.hooks.hasPermission(Hooks.NO_OP_FLAG)); + assert(!(delta0 > 0 || delta1 > 0)); } } diff --git a/test/AccessLock.t.sol b/test/AccessLock.t.sol index 04566b968..50f81e4a3 100644 --- a/test/AccessLock.t.sol +++ b/test/AccessLock.t.sol @@ -241,37 +241,13 @@ contract AccessLockTest is Test, Deployers { assertGt(balanceOfAfter1, balanceOfBefore1); } - function test_beforeRemoveLiquidity_swap_succeedsWithAccessLock() public { - // Add liquidity so there is something to swap over. - modifyPositionRouter.modifyPosition( - key, - IPoolManager.ModifyPositionParams({tickLower: -120, tickUpper: 120, liquidityDelta: 100 * 10e18}), - ZERO_BYTES - ); - - uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this)); - uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this)); - - // Essentially "no-op"s the modifyLiquidity call and executes a swap before hand, applying the deltas from the swap to the locker. - modifyPositionRouter.modifyPosition( - key, IPoolManager.ModifyPositionParams(-120, 120, 0), abi.encode(amount, AccessLockHook.LockAction.Swap) - ); - uint256 balanceOfAfter0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this)); - uint256 balanceOfAfter1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this)); - - // Balance decreases because we are swapping currency0 for currency1. - assertLt(balanceOfAfter0, balanceOfBefore0); - // Balance should be greater in currency1. - assertGt(balanceOfAfter1, balanceOfBefore1); - } - function test_beforeAddLiquidity_addLiquidity_succeedsWithAccessLock() public { uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this)); uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this)); modifyPositionRouter.modifyPosition( key, - IPoolManager.ModifyPositionParams(-120, 120, 1 * 10 ** 18), + IPoolManager.ModifyPositionParams(-120, 120, 10e18), abi.encode(amount, AccessLockHook.LockAction.ModifyPosition) ); uint256 balanceOfAfter0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this)); @@ -356,9 +332,7 @@ contract AccessLockTest is Test, Deployers { function test_beforeAddLiquidity_initialize_succeedsWithAccessLock() public { // The hook intitializes a new pool with the new key at Constants.SQRT_RATIO_1_2; modifyPositionRouter.modifyPosition( - key, - IPoolManager.ModifyPositionParams(-120, 120, 1 * 10 ** 18), - abi.encode(0, AccessLockHook.LockAction.Initialize) + key, IPoolManager.ModifyPositionParams(-120, 120, 1e18), abi.encode(0, AccessLockHook.LockAction.Initialize) ); PoolKey memory newKey = PoolKey({ @@ -604,9 +578,7 @@ contract AccessLockTest is Test, Deployers { uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this)); uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this)); - donateRouter.donate( - key, 1 * 10 ** 18, 1 * 10 ** 18, abi.encode(amount, AccessLockHook.LockAction.ModifyPosition) - ); + donateRouter.donate(key, 1e18, 1e18, abi.encode(amount, AccessLockHook.LockAction.ModifyPosition)); uint256 balanceOfAfter0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this)); uint256 balanceOfAfter1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this)); @@ -842,7 +814,7 @@ contract AccessLockTest is Test, Deployers { ) ); delta = modifyPositionRouter.modifyPosition( - keyAccessLockHook2, IPoolManager.ModifyPositionParams(0, 60, 1 * 10 ** 18), abi.encode(true, key) + keyAccessLockHook2, IPoolManager.ModifyPositionParams(0, 60, 1e18), abi.encode(true, key) ); } @@ -854,18 +826,18 @@ contract AccessLockTest is Test, Deployers { initPool(currency0, currency1, IHooks(accessLockHook2), Constants.FEE_MEDIUM, SQRT_RATIO_1_1, ZERO_BYTES); modifyPositionRouter.modifyPosition( - keyAccessLockHook2, IPoolManager.ModifyPositionParams(0, 60, 1 * 10 ** 18), abi.encode(false, keyWithNoHook) + keyAccessLockHook2, IPoolManager.ModifyPositionParams(0, 60, 1e18), abi.encode(false, keyWithNoHook) ); assertEq(manager.balanceOf(address(accessLockHook2), currency1), 10); } function test_onlyByLocker_revertsWhenThereIsNoOutsideLock() public { - modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 1 * 10 ** 18), ZERO_BYTES); + modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 1e18), ZERO_BYTES); assertEq(address(manager.getCurrentHook()), address(0)); vm.expectRevert(abi.encodeWithSelector(IPoolManager.LockedBy.selector, address(0), address(0))); vm.prank(address(key.hooks)); - manager.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 1 * 10 ** 18), ZERO_BYTES); + manager.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 1e18), ZERO_BYTES); } function test_getCurrentHook_isClearedAfterNestedLock() public { @@ -886,7 +858,7 @@ contract AccessLockTest is Test, Deployers { // Asserts are in the AccessLockHook3. modifyPositionRouter.modifyPosition( - keyAccessLockHook3, IPoolManager.ModifyPositionParams(0, 60, 1 * 10 ** 18), ZERO_BYTES + keyAccessLockHook3, IPoolManager.ModifyPositionParams(0, 60, 1e18), ZERO_BYTES ); } diff --git a/test/Hooks.t.sol b/test/Hooks.t.sol index cb80e4004..570d44f41 100644 --- a/test/Hooks.t.sol +++ b/test/Hooks.t.sol @@ -65,9 +65,9 @@ contract HooksTest is Test, Deployers, GasSnapshot { } function test_beforeAfterAddLiquidity_beforeAfterRemoveLiquidity_succeedsWithHook() public { - MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); - modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 10 ** 18), new bytes(111)); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); + modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 1e18), new bytes(111)); assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111)); assertEq(mockHooks.afterAddLiquidityData(), new bytes(111)); @@ -77,17 +77,17 @@ contract HooksTest is Test, Deployers, GasSnapshot { } function test_beforeAfterAddLiquidity_calledWithPositiveLiquidityDelta() public { - MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 100), new bytes(111)); assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111)); assertEq(mockHooks.afterAddLiquidityData(), new bytes(111)); } function test_beforeAfterAddLiquidity_calledWithZeroLiquidityDelta() public { - MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); - modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 10 ** 18), new bytes(111)); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); + modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 1e18), new bytes(111)); assertEq(mockHooks.beforeAddLiquidityData(), new bytes(111)); assertEq(mockHooks.afterAddLiquidityData(), new bytes(111)); @@ -97,9 +97,9 @@ contract HooksTest is Test, Deployers, GasSnapshot { } function test_beforeAfterRemoveLiquidity_calledWithPositiveLiquidityDelta() public { - modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 10 ** 18), new bytes(111)); - MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); + modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(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.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, -1e18), new bytes(111)); assertEq(mockHooks.beforeRemoveLiquidityData(), new bytes(111)); assertEq(mockHooks.afterRemoveLiquidityData(), new bytes(111)); @@ -107,16 +107,16 @@ contract HooksTest is Test, Deployers, GasSnapshot { function test_beforeAddLiquidity_invalidReturn() public { mockHooks.setReturnValue(mockHooks.beforeAddLiquidity.selector, bytes4(0xdeadbeef)); - MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); vm.expectRevert(Hooks.InvalidHookResponse.selector); modifyPositionRouter.modifyPosition(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), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); modifyPositionRouter.modifyPosition(key, LIQ_PARAMS, ZERO_BYTES); vm.expectRevert(Hooks.InvalidHookResponse.selector); modifyPositionRouter.modifyPosition(key, REMOVE_LIQ_PARAMS, ZERO_BYTES); @@ -124,16 +124,16 @@ contract HooksTest is Test, Deployers, GasSnapshot { function test_afterAddLiquidity_invalidReturn() public { mockHooks.setReturnValue(mockHooks.afterAddLiquidity.selector, bytes4(0xdeadbeef)); - MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); vm.expectRevert(Hooks.InvalidHookResponse.selector); modifyPositionRouter.modifyPosition(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), 10 ** 18); - MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18); + MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 1e18); + MockERC20(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 1e18); modifyPositionRouter.modifyPosition(key, LIQ_PARAMS, ZERO_BYTES); vm.expectRevert(Hooks.InvalidHookResponse.selector); modifyPositionRouter.modifyPosition(key, REMOVE_LIQ_PARAMS, ZERO_BYTES); @@ -174,7 +174,7 @@ contract HooksTest is Test, Deployers, GasSnapshot { } function test_donate_succeedsWithHook() public { - donateRouter.donate(key, 10, 200, new bytes(333)); + donateRouter.donate(key, 100, 200, new bytes(333)); assertEq(mockHooks.beforeDonateData(), new bytes(333)); assertEq(mockHooks.afterDonateData(), new bytes(333)); } diff --git a/test/PoolManager.t.sol b/test/PoolManager.t.sol index a85addda6..384d003b5 100644 --- a/test/PoolManager.t.sol +++ b/test/PoolManager.t.sol @@ -96,7 +96,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { address(modifyPositionRouter), LIQ_PARAMS.tickLower, LIQ_PARAMS.tickUpper, - int128(int256(LIQ_PARAMS.liquidityDelta)) + LIQ_PARAMS.liquidityDelta ); modifyPositionRouter.modifyPosition(key, LIQ_PARAMS, ZERO_BYTES); @@ -109,9 +109,9 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { emit ModifyPosition( key.toId(), address(modifyPositionRouter), - LIQ_PARAMS.tickLower, - LIQ_PARAMS.tickUpper, - -int128(int256(LIQ_PARAMS.liquidityDelta)) + REMOVE_LIQ_PARAMS.tickLower, + REMOVE_LIQ_PARAMS.tickUpper, + REMOVE_LIQ_PARAMS.liquidityDelta ); modifyPositionRouter.modifyPosition(key, REMOVE_LIQ_PARAMS, ZERO_BYTES); @@ -126,7 +126,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { address(modifyPositionRouter), LIQ_PARAMS.tickLower, LIQ_PARAMS.tickUpper, - int128(int256(LIQ_PARAMS.liquidityDelta)) + LIQ_PARAMS.liquidityDelta ); modifyPositionRouter.modifyPosition{value: 1 ether}(nativeKey, LIQ_PARAMS, ZERO_BYTES); @@ -139,9 +139,9 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { emit ModifyPosition( nativeKey.toId(), address(modifyPositionRouter), - LIQ_PARAMS.tickLower, - LIQ_PARAMS.tickUpper, - -int128(int256(LIQ_PARAMS.liquidityDelta)) + REMOVE_LIQ_PARAMS.tickLower, + REMOVE_LIQ_PARAMS.tickUpper, + REMOVE_LIQ_PARAMS.liquidityDelta ); modifyPositionRouter.modifyPosition{value: 1 ether}(nativeKey, REMOVE_LIQ_PARAMS, ZERO_BYTES); @@ -267,7 +267,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { address(modifyPositionRouter), LIQ_PARAMS.tickLower, LIQ_PARAMS.tickUpper, - int128(int256(LIQ_PARAMS.liquidityDelta)) + LIQ_PARAMS.liquidityDelta ); modifyPositionRouter.modifyPosition(key, LIQ_PARAMS, ZERO_BYTES); @@ -292,7 +292,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { address(modifyPositionRouter), REMOVE_LIQ_PARAMS.tickLower, REMOVE_LIQ_PARAMS.tickUpper, - int128(REMOVE_LIQ_PARAMS.liquidityDelta) + REMOVE_LIQ_PARAMS.liquidityDelta ); modifyPositionRouter.modifyPosition(key, REMOVE_LIQ_PARAMS, ZERO_BYTES);