diff --git a/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap b/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap index 192e3b80..f707246a 100644 --- a/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap +++ b/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap @@ -1 +1 @@ -32346 \ No newline at end of file +32358 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap b/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap index 5a675627..2f126024 100644 --- a/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap +++ b/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap @@ -1 +1 @@ -30536 \ No newline at end of file +35030 \ No newline at end of file diff --git a/test/pool-bin/BinPoolManager.t.sol b/test/pool-bin/BinPoolManager.t.sol index 65d6d941..bc3c2949 100644 --- a/test/pool-bin/BinPoolManager.t.sol +++ b/test/pool-bin/BinPoolManager.t.sol @@ -899,6 +899,16 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper { function testFuzz_SetMaxBinStep(uint16 binStep) public { vm.assume(binStep > poolManager.MIN_BIN_STEP()); + vm.expectEmit(); + emit SetMaxBinStep(binStep); + poolManager.setMaxBinStep(binStep); + + assertEq(poolManager.MAX_BIN_STEP(), binStep); + } + + function testGas_SetMaxBinStep() public { + uint16 binStep = 10; + vm.expectEmit(); emit SetMaxBinStep(binStep); snapStart("BinPoolManagerTest#testFuzz_SetMaxBinStep"); @@ -976,14 +986,38 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper { emit DynamicLPFeeUpdated(key.toId(), _lpFee); vm.prank(address(binFeeManagerHook)); - if (_lpFee != 0) { - // temp fix to only record gas if _lpFee !=0. todo use snapLastCall to make this part of code easier to read - snapStart("BinPoolManagerTest#testFuzzUpdateDynamicLPFee"); - poolManager.updateDynamicLPFee(key, _lpFee); - snapEnd(); - } else { - poolManager.updateDynamicLPFee(key, _lpFee); - } + poolManager.updateDynamicLPFee(key, _lpFee); + + (,, uint24 swapFee) = poolManager.getSlot0(key.toId()); + assertEq(swapFee, _lpFee); + } + + function testGasUpdateDynamicLPFee() public { + uint24 _lpFee = LPFeeLibrary.TEN_PERCENT_FEE / 2; + + uint16 bitMap = 0x0004; // 0000 0000 0000 0100 (before mint call) + BinFeeManagerHook binFeeManagerHook = new BinFeeManagerHook(poolManager); + binFeeManagerHook.setHooksRegistrationBitmap(bitMap); + + key = PoolKey({ + currency0: currency0, + currency1: currency1, + hooks: IHooks(address(binFeeManagerHook)), + poolManager: IPoolManager(address(poolManager)), + fee: LPFeeLibrary.DYNAMIC_FEE_FLAG, + parameters: bytes32(uint256(bitMap)).setBinStep(10) + }); + poolManager.initialize(key, activeId, new bytes(0)); + + binFeeManagerHook.setFee(_lpFee); + + vm.expectEmit(); + emit DynamicLPFeeUpdated(key.toId(), _lpFee); + + vm.prank(address(binFeeManagerHook)); + snapStart("BinPoolManagerTest#testFuzzUpdateDynamicLPFee"); + poolManager.updateDynamicLPFee(key, _lpFee); + snapEnd(); (,, uint24 swapFee) = poolManager.getSlot0(key.toId()); assertEq(swapFee, _lpFee); diff --git a/test/pool-cl/CLPoolManager.t.sol b/test/pool-cl/CLPoolManager.t.sol index e4c17f76..802fded8 100644 --- a/test/pool-cl/CLPoolManager.t.sol +++ b/test/pool-cl/CLPoolManager.t.sol @@ -2830,14 +2830,38 @@ contract CLPoolManagerTest is Test, NoIsolate, Deployers, TokenFixture, GasSnaps emit DynamicLPFeeUpdated(key.toId(), _swapFee); vm.prank(address(clFeeManagerHook)); - if (_swapFee != 0) { - // temp fix to only record gas if _swapFee !=0. todo use snapLastCall to make this part of code easier to read - snapStart("CLPoolManagerTest#testFuzzUpdateDynamicLPFee"); - poolManager.updateDynamicLPFee(key, _swapFee); - snapEnd(); - } else { - poolManager.updateDynamicLPFee(key, _swapFee); - } + poolManager.updateDynamicLPFee(key, _swapFee); + + (,,, uint24 swapFee) = poolManager.getSlot0(key.toId()); + assertEq(swapFee, _swapFee); + } + + function testGasUpdateDynamicLPFee() public { + uint24 _swapFee = LPFeeLibrary.ONE_HUNDRED_PERCENT_FEE / 2; + + uint16 bitMap = 0x0010; // 0000 0000 0001 0000 (before swap call) + clFeeManagerHook.setHooksRegistrationBitmap(bitMap); + + PoolKey memory key = PoolKey({ + currency0: currency0, + currency1: currency1, + fee: LPFeeLibrary.DYNAMIC_FEE_FLAG, + hooks: IHooks(address(clFeeManagerHook)), + poolManager: poolManager, + parameters: bytes32(uint256((10 << 16) | clFeeManagerHook.getHooksRegistrationBitmap())) + }); + + poolManager.initialize(key, TickMath.MIN_SQRT_RATIO, new bytes(0)); + + clFeeManagerHook.setFee(_swapFee); + + vm.expectEmit(); + emit DynamicLPFeeUpdated(key.toId(), _swapFee); + + vm.prank(address(clFeeManagerHook)); + snapStart("CLPoolManagerTest#testFuzzUpdateDynamicLPFee"); + poolManager.updateDynamicLPFee(key, _swapFee); + snapEnd(); (,,, uint24 swapFee) = poolManager.getSlot0(key.toId()); assertEq(swapFee, _swapFee);