diff --git a/.forge-snapshots/HooksShouldCallBeforeSwap.snap b/.forge-snapshots/HooksShouldCallBeforeSwap.snap index 3e932fe8f..d2c5ed212 100644 --- a/.forge-snapshots/HooksShouldCallBeforeSwap.snap +++ b/.forge-snapshots/HooksShouldCallBeforeSwap.snap @@ -1 +1 @@ -34 \ No newline at end of file +116 \ No newline at end of file diff --git a/.forge-snapshots/before swap hook, already cached dynamic fee.snap b/.forge-snapshots/before swap hook, already cached dynamic fee.snap index 065c3c3e8..5da886f37 100644 --- a/.forge-snapshots/before swap hook, already cached dynamic fee.snap +++ b/.forge-snapshots/before swap hook, already cached dynamic fee.snap @@ -1 +1 @@ -189798 \ No newline at end of file +190434 \ No newline at end of file diff --git a/.forge-snapshots/cached dynamic fee, no hooks.snap b/.forge-snapshots/cached dynamic fee, no hooks.snap index d25279b12..04ce39c8a 100644 --- a/.forge-snapshots/cached dynamic fee, no hooks.snap +++ b/.forge-snapshots/cached dynamic fee, no hooks.snap @@ -1 +1 @@ -145314 \ No newline at end of file +145735 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 1 token.snap b/.forge-snapshots/donate gas with 1 token.snap index 2bd9c1d42..623546e79 100644 --- a/.forge-snapshots/donate gas with 1 token.snap +++ b/.forge-snapshots/donate gas with 1 token.snap @@ -1 +1 @@ -134915 \ No newline at end of file +135307 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 2 tokens.snap b/.forge-snapshots/donate gas with 2 tokens.snap index 4fe05417c..24a60c70c 100644 --- a/.forge-snapshots/donate gas with 2 tokens.snap +++ b/.forge-snapshots/donate gas with 2 tokens.snap @@ -1 +1 @@ -186636 \ No newline at end of file +187028 \ No newline at end of file diff --git a/.forge-snapshots/gas overhead of no-op lock.snap b/.forge-snapshots/gas overhead of no-op lock.snap index 7bc046e9a..bdfce7265 100644 --- a/.forge-snapshots/gas overhead of no-op lock.snap +++ b/.forge-snapshots/gas overhead of no-op lock.snap @@ -1 +1 @@ -14918 \ No newline at end of file +14910 \ No newline at end of file diff --git a/.forge-snapshots/initialize.snap b/.forge-snapshots/initialize.snap index 9ac3a2a48..115f6a323 100644 --- a/.forge-snapshots/initialize.snap +++ b/.forge-snapshots/initialize.snap @@ -1 +1 @@ -53843 \ No newline at end of file +54228 \ No newline at end of file diff --git a/.forge-snapshots/mint with empty hook.snap b/.forge-snapshots/mint with empty hook.snap index d6003b2d1..3f1f67ab8 100644 --- a/.forge-snapshots/mint with empty hook.snap +++ b/.forge-snapshots/mint with empty hook.snap @@ -1 +1 @@ -319184 \ No newline at end of file +319684 \ No newline at end of file diff --git a/.forge-snapshots/mint with native token.snap b/.forge-snapshots/mint with native token.snap index 783a03fba..afd8579b2 100644 --- a/.forge-snapshots/mint with native token.snap +++ b/.forge-snapshots/mint with native token.snap @@ -1 +1 @@ -198926 \ No newline at end of file +199307 \ No newline at end of file diff --git a/.forge-snapshots/mint.snap b/.forge-snapshots/mint.snap index b81efe3e7..1582f29a3 100644 --- a/.forge-snapshots/mint.snap +++ b/.forge-snapshots/mint.snap @@ -1 +1 @@ -202041 \ No newline at end of file +202422 \ No newline at end of file diff --git a/.forge-snapshots/poolManager bytecode size.snap b/.forge-snapshots/poolManager bytecode size.snap index e2ace385d..c37220a65 100644 --- a/.forge-snapshots/poolManager bytecode size.snap +++ b/.forge-snapshots/poolManager bytecode size.snap @@ -1 +1 @@ -24805 \ No newline at end of file +25224 \ No newline at end of file diff --git a/.forge-snapshots/simple swap with native.snap b/.forge-snapshots/simple swap with native.snap index 38fb428ce..5bfc9970a 100644 --- a/.forge-snapshots/simple swap with native.snap +++ b/.forge-snapshots/simple swap with native.snap @@ -1 +1 @@ -190722 \ No newline at end of file +191143 \ No newline at end of file diff --git a/.forge-snapshots/simple swap.snap b/.forge-snapshots/simple swap.snap index d46a556a3..70c3bbcc7 100644 --- a/.forge-snapshots/simple swap.snap +++ b/.forge-snapshots/simple swap.snap @@ -1 +1 @@ -202425 \ No newline at end of file +202846 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity with native token.snap b/.forge-snapshots/swap against liquidity with native token.snap index cdf8b425d..cfe55cebc 100644 --- a/.forge-snapshots/swap against liquidity with native token.snap +++ b/.forge-snapshots/swap against liquidity with native token.snap @@ -1 +1 @@ -121318 \ No newline at end of file +121739 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity.snap b/.forge-snapshots/swap against liquidity.snap index d822c9d1b..d211d999c 100644 --- a/.forge-snapshots/swap against liquidity.snap +++ b/.forge-snapshots/swap against liquidity.snap @@ -1 +1 @@ -109143 \ No newline at end of file +109564 \ No newline at end of file diff --git a/.forge-snapshots/swap burn claim for input.snap b/.forge-snapshots/swap burn claim for input.snap index db9426bff..7d1fdf45b 100644 --- a/.forge-snapshots/swap burn claim for input.snap +++ b/.forge-snapshots/swap burn claim for input.snap @@ -1 +1 @@ -127882 \ No newline at end of file +128303 \ No newline at end of file diff --git a/.forge-snapshots/swap mint output as claim.snap b/.forge-snapshots/swap mint output as claim.snap index 470895cbb..8e9766737 100644 --- a/.forge-snapshots/swap mint output as claim.snap +++ b/.forge-snapshots/swap mint output as claim.snap @@ -1 +1 @@ -212594 \ No newline at end of file +213015 \ No newline at end of file diff --git a/.forge-snapshots/swap with dynamic fee.snap b/.forge-snapshots/swap with dynamic fee.snap index 478c6b86a..702337b3a 100644 --- a/.forge-snapshots/swap with dynamic fee.snap +++ b/.forge-snapshots/swap with dynamic fee.snap @@ -1 +1 @@ -189038 \ No newline at end of file +189521 \ No newline at end of file diff --git a/.forge-snapshots/swap with hooks.snap b/.forge-snapshots/swap with hooks.snap index fe90801ad..d60c83174 100644 --- a/.forge-snapshots/swap with hooks.snap +++ b/.forge-snapshots/swap with hooks.snap @@ -1 +1 @@ -109122 \ No newline at end of file +109543 \ No newline at end of file diff --git a/.forge-snapshots/update dynamic fee in before swap.snap b/.forge-snapshots/update dynamic fee in before swap.snap index 7ada52a85..902340927 100644 --- a/.forge-snapshots/update dynamic fee in before swap.snap +++ b/.forge-snapshots/update dynamic fee in before swap.snap @@ -1 +1 @@ -195628 \ No newline at end of file +196264 \ No newline at end of file diff --git a/src/PoolManager.sol b/src/PoolManager.sol index 97a9e144d..801951898 100644 --- a/src/PoolManager.sol +++ b/src/PoolManager.sol @@ -28,6 +28,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { using SafeCast for *; using Pool for *; using Hooks for IHooks; + using Hooks for PoolKey; using Position for mapping(bytes32 => Position.Info); using CurrencyLibrary for Currency; using FeeLibrary for uint24; @@ -108,12 +109,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { if (key.currency0 >= key.currency1) revert CurrenciesInitializedOutOfOrder(); if (!key.hooks.isValidHookAddress(key.fee)) revert Hooks.HookAddressNotValid(address(key.hooks)); - if (key.hooks.shouldCallBeforeInitialize()) { - if (key.hooks.beforeInitialize(msg.sender, key, sqrtPriceX96, hookData) != IHooks.beforeInitialize.selector) - { - revert Hooks.InvalidHookResponse(); - } - } + key.beforeInitialize(sqrtPriceX96, hookData); PoolId id = key.toId(); @@ -121,14 +117,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { tick = pools[id].initialize(sqrtPriceX96, _fetchProtocolFees(key), _fetchHookFees(key), swapFee); - if (key.hooks.shouldCallAfterInitialize()) { - if ( - key.hooks.afterInitialize(msg.sender, key, sqrtPriceX96, tick, hookData) - != IHooks.afterInitialize.selector - ) { - revert Hooks.InvalidHookResponse(); - } - } + key.afterInitialize(sqrtPriceX96, tick, hookData); // On intitalize we emit the key's fee, which tells us all fee settings a pool can have: either a static swap fee or dynamic swap fee and if the hook has enabled swap or withdraw fees. emit Initialize(id, key.currency0, key.currency1, key.fee, key.tickSpacing, key.hooks); @@ -185,14 +174,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { IPoolManager.ModifyPositionParams memory params, bytes calldata hookData ) external override noDelegateCall onlyByLocker returns (BalanceDelta delta) { - if (key.hooks.shouldCallBeforeModifyPosition()) { - if ( - key.hooks.beforeModifyPosition(msg.sender, key, params, hookData) - != IHooks.beforeModifyPosition.selector - ) { - revert Hooks.InvalidHookResponse(); - } - } + key.beforeModifyPosition(params, hookData); PoolId id = key.toId(); Pool.FeeAmounts memory feeAmounts; @@ -223,14 +205,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { } } - if (key.hooks.shouldCallAfterModifyPosition()) { - if ( - key.hooks.afterModifyPosition(msg.sender, key, params, delta, hookData) - != IHooks.afterModifyPosition.selector - ) { - revert Hooks.InvalidHookResponse(); - } - } + key.afterModifyPosition(params, delta, hookData); emit ModifyPosition(id, msg.sender, params.tickLower, params.tickUpper, params.liquidityDelta); } @@ -243,11 +218,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { onlyByLocker returns (BalanceDelta delta) { - if (key.hooks.shouldCallBeforeSwap()) { - if (key.hooks.beforeSwap(msg.sender, key, params, hookData) != IHooks.beforeSwap.selector) { - revert Hooks.InvalidHookResponse(); - } - } + key.beforeSwap(params, hookData); PoolId id = key.toId(); @@ -276,11 +247,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { } } - if (key.hooks.shouldCallAfterSwap()) { - if (key.hooks.afterSwap(msg.sender, key, params, delta, hookData) != IHooks.afterSwap.selector) { - revert Hooks.InvalidHookResponse(); - } - } + key.afterSwap(params, delta, hookData); emit Swap( id, msg.sender, delta.amount0(), delta.amount1(), state.sqrtPriceX96, state.liquidity, state.tick, swapFee @@ -295,21 +262,13 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims { onlyByLocker returns (BalanceDelta delta) { - if (key.hooks.shouldCallBeforeDonate()) { - if (key.hooks.beforeDonate(msg.sender, key, amount0, amount1, hookData) != IHooks.beforeDonate.selector) { - revert Hooks.InvalidHookResponse(); - } - } + key.beforeDonate(amount0, amount1, hookData); delta = _getPool(key).donate(amount0, amount1); _accountPoolBalanceDelta(key, delta); - if (key.hooks.shouldCallAfterDonate()) { - if (key.hooks.afterDonate(msg.sender, key, amount0, amount1, hookData) != IHooks.afterDonate.selector) { - revert Hooks.InvalidHookResponse(); - } - } + key.afterDonate(amount0, amount1, hookData); } /// @inheritdoc IPoolManager diff --git a/src/libraries/Hooks.sol b/src/libraries/Hooks.sol index 75ef2ee85..599531017 100644 --- a/src/libraries/Hooks.sol +++ b/src/libraries/Hooks.sol @@ -2,7 +2,10 @@ pragma solidity ^0.8.20; import {IHooks} from "../interfaces/IHooks.sol"; +import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {FeeLibrary} from "../libraries/FeeLibrary.sol"; +import {BalanceDelta} from "../types/BalanceDelta.sol"; +import {PoolKey} from "../types/PoolKey.sol"; /// @notice V4 decides whether to invoke specific hooks by inspecting the leading bits of the address that /// the hooks contract is deployed to. @@ -10,6 +13,7 @@ import {FeeLibrary} from "../libraries/FeeLibrary.sol"; /// has leading bits '1001' which would cause the 'before initialize' and 'after modify position' hooks to be used. library Hooks { using FeeLibrary for uint24; + using Hooks for IHooks; uint256 internal constant BEFORE_INITIALIZE_FLAG = 1 << 159; uint256 internal constant AFTER_INITIALIZE_FLAG = 1 << 158; @@ -44,12 +48,14 @@ library Hooks { /// @dev calls param is memory as the function will be called from constructors function validateHookAddress(IHooks self, Calls memory calls) internal pure { if ( - calls.beforeInitialize != shouldCallBeforeInitialize(self) - || calls.afterInitialize != shouldCallAfterInitialize(self) - || calls.beforeModifyPosition != shouldCallBeforeModifyPosition(self) - || calls.afterModifyPosition != shouldCallAfterModifyPosition(self) - || calls.beforeSwap != shouldCallBeforeSwap(self) || calls.afterSwap != shouldCallAfterSwap(self) - || calls.beforeDonate != shouldCallBeforeDonate(self) || calls.afterDonate != shouldCallAfterDonate(self) + calls.beforeInitialize != self.shouldCall(BEFORE_INITIALIZE_FLAG) + || calls.afterInitialize != self.shouldCall(AFTER_INITIALIZE_FLAG) + || calls.beforeModifyPosition != self.shouldCall(BEFORE_MODIFY_POSITION_FLAG) + || calls.afterModifyPosition != self.shouldCall(AFTER_MODIFY_POSITION_FLAG) + || calls.beforeSwap != self.shouldCall(BEFORE_SWAP_FLAG) + || calls.afterSwap != self.shouldCall(AFTER_SWAP_FLAG) + || calls.beforeDonate != self.shouldCall(BEFORE_DONATE_FLAG) + || calls.afterDonate != self.shouldCall(AFTER_DONATE_FLAG) ) { revert HookAddressNotValid(address(self)); } @@ -67,35 +73,79 @@ library Hooks { ); } - function shouldCallBeforeInitialize(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & BEFORE_INITIALIZE_FLAG != 0; + function validateHooksResponse(bytes4 selector, bytes4 expectedSelector) internal pure { + if (selector != expectedSelector) { + revert InvalidHookResponse(); + } + } + + function shouldCall(IHooks self, uint256 call) internal pure returns (bool) { + return uint256(uint160(address(self))) & call != 0; + } + + function beforeInitialize(PoolKey memory key, uint160 sqrtPriceX96, bytes memory hookData) internal { + if (!shouldCall(key.hooks, BEFORE_INITIALIZE_FLAG)) return; + validateHooksResponse( + key.hooks.beforeInitialize(msg.sender, key, sqrtPriceX96, hookData), IHooks.beforeInitialize.selector + ); } - function shouldCallAfterInitialize(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & AFTER_INITIALIZE_FLAG != 0; + function afterInitialize(PoolKey memory key, uint160 sqrtPriceX96, int24 tick, bytes memory hookData) internal { + if (!shouldCall(key.hooks, AFTER_INITIALIZE_FLAG)) return; + validateHooksResponse( + key.hooks.afterInitialize(msg.sender, key, sqrtPriceX96, tick, hookData), IHooks.afterInitialize.selector + ); } - function shouldCallBeforeModifyPosition(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & BEFORE_MODIFY_POSITION_FLAG != 0; + function beforeModifyPosition( + PoolKey memory key, + IPoolManager.ModifyPositionParams memory params, + bytes memory hookData + ) internal { + if (!key.hooks.shouldCall(BEFORE_MODIFY_POSITION_FLAG)) return; + validateHooksResponse( + key.hooks.beforeModifyPosition(msg.sender, key, params, hookData), IHooks.beforeModifyPosition.selector + ); } - function shouldCallAfterModifyPosition(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & AFTER_MODIFY_POSITION_FLAG != 0; + function afterModifyPosition( + PoolKey memory key, + IPoolManager.ModifyPositionParams memory params, + BalanceDelta delta, + bytes memory hookData + ) internal { + if (!key.hooks.shouldCall(AFTER_MODIFY_POSITION_FLAG)) return; + validateHooksResponse( + key.hooks.afterModifyPosition(msg.sender, key, params, delta, hookData), IHooks.afterModifyPosition.selector + ); } - function shouldCallBeforeSwap(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & BEFORE_SWAP_FLAG != 0; + function beforeSwap(PoolKey memory key, IPoolManager.SwapParams memory params, bytes memory hookData) internal { + if (!key.hooks.shouldCall(BEFORE_SWAP_FLAG)) return; + validateHooksResponse(key.hooks.beforeSwap(msg.sender, key, params, hookData), IHooks.beforeSwap.selector); } - function shouldCallAfterSwap(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & AFTER_SWAP_FLAG != 0; + function afterSwap( + PoolKey memory key, + IPoolManager.SwapParams memory params, + BalanceDelta delta, + bytes memory hookData + ) internal { + if (!key.hooks.shouldCall(AFTER_SWAP_FLAG)) return; + validateHooksResponse(key.hooks.afterSwap(msg.sender, key, params, delta, hookData), IHooks.afterSwap.selector); } - function shouldCallBeforeDonate(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & BEFORE_DONATE_FLAG != 0; + function beforeDonate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes memory hookData) internal { + if (!key.hooks.shouldCall(BEFORE_DONATE_FLAG)) return; + validateHooksResponse( + key.hooks.beforeDonate(msg.sender, key, amount0, amount1, hookData), IHooks.beforeDonate.selector + ); } - function shouldCallAfterDonate(IHooks self) internal pure returns (bool) { - return uint256(uint160(address(self))) & AFTER_DONATE_FLAG != 0; + function afterDonate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes memory hookData) internal { + if (!key.hooks.shouldCall(AFTER_DONATE_FLAG)) return; + validateHooksResponse( + key.hooks.afterDonate(msg.sender, key, amount0, amount1, hookData), IHooks.afterDonate.selector + ); } } diff --git a/src/test/HooksTest.sol b/src/test/HooksTest.sol index 460ed9a53..0b6624ac7 100644 --- a/src/test/HooksTest.sol +++ b/src/test/HooksTest.sol @@ -16,40 +16,40 @@ contract HooksTest { } function shouldCallBeforeInitialize(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallBeforeInitialize(); + return IHooks(hookAddress).shouldCall(Hooks.BEFORE_INITIALIZE_FLAG); } function shouldCallAfterInitialize(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallAfterInitialize(); + return IHooks(hookAddress).shouldCall(Hooks.AFTER_INITIALIZE_FLAG); } function shouldCallBeforeSwap(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallBeforeSwap(); + return IHooks(hookAddress).shouldCall(Hooks.BEFORE_SWAP_FLAG); } function shouldCallAfterSwap(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallAfterSwap(); + return IHooks(hookAddress).shouldCall(Hooks.AFTER_SWAP_FLAG); } function shouldCallBeforeModifyPosition(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallBeforeModifyPosition(); + return IHooks(hookAddress).shouldCall(Hooks.BEFORE_MODIFY_POSITION_FLAG); } function shouldCallAfterModifyPosition(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallAfterModifyPosition(); + return IHooks(hookAddress).shouldCall(Hooks.AFTER_MODIFY_POSITION_FLAG); } function shouldCallBeforeDonate(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallBeforeDonate(); + return IHooks(hookAddress).shouldCall(Hooks.BEFORE_DONATE_FLAG); } function shouldCallAfterDonate(address hookAddress) external pure returns (bool) { - return IHooks(hookAddress).shouldCallAfterDonate(); + return IHooks(hookAddress).shouldCall(Hooks.AFTER_DONATE_FLAG); } function getGasCostOfShouldCall(address hookAddress) external view returns (uint256) { uint256 gasBefore = gasleft(); - IHooks(hookAddress).shouldCallBeforeSwap(); + IHooks(hookAddress).shouldCall(Hooks.BEFORE_SWAP_FLAG); return gasBefore - gasleft(); } diff --git a/test/Hooks.t.sol b/test/Hooks.t.sol index cd2e9e557..89d9f51e2 100644 --- a/test/Hooks.t.sol +++ b/test/Hooks.t.sol @@ -143,14 +143,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeInitialize(uint152 addr) public { @@ -170,14 +170,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertTrue(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressAfterInitialize(uint152 addr) public { @@ -197,14 +197,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertTrue(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeAndAfterInitialize(uint152 addr) public { @@ -223,14 +223,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertTrue(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertTrue(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeModify(uint152 addr) public { @@ -249,14 +249,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertTrue(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressAfterModify(uint152 addr) public { @@ -275,14 +275,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeAndAfterModify(uint152 addr) public { @@ -302,14 +302,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertTrue(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeInitializeAfterModify(uint152 addr) public { @@ -329,14 +329,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertTrue(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeSwap(uint152 addr) public { @@ -355,14 +355,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressAfterSwap(uint152 addr) public { @@ -381,14 +381,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertTrue(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeAndAfterSwap(uint152 addr) public { @@ -407,14 +407,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallBeforeSwap(hookAddr)); - assertTrue(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeDonate(uint152 addr) public { @@ -433,14 +433,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: false }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertTrue(Hooks.shouldCallBeforeDonate(hookAddr)); - assertFalse(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressAfterDonate(uint152 addr) public { @@ -459,14 +459,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: true }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertFalse(Hooks.shouldCallBeforeDonate(hookAddr)); - assertTrue(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressBeforeAndAfterDonate(uint152 addr) public { @@ -485,14 +485,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: true }) ); - assertFalse(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertFalse(Hooks.shouldCallAfterInitialize(hookAddr)); - assertFalse(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertFalse(Hooks.shouldCallBeforeSwap(hookAddr)); - assertFalse(Hooks.shouldCallAfterSwap(hookAddr)); - assertTrue(Hooks.shouldCallBeforeDonate(hookAddr)); - assertTrue(Hooks.shouldCallAfterDonate(hookAddr)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertFalse(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressAllHooks(uint152 addr) public { @@ -511,14 +511,14 @@ contract HooksTest is Test, Deployers, GasSnapshot { afterDonate: true }) ); - assertTrue(Hooks.shouldCallBeforeInitialize(hookAddr)); - assertTrue(Hooks.shouldCallAfterInitialize(hookAddr)); - assertTrue(Hooks.shouldCallBeforeModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallAfterModifyPosition(hookAddr)); - assertTrue(Hooks.shouldCallBeforeSwap(hookAddr)); - assertTrue(Hooks.shouldCallAfterSwap(hookAddr)); - assertTrue(Hooks.shouldCallBeforeDonate(hookAddr)); - assertTrue(Hooks.shouldCallAfterDonate(hookAddr)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_INITIALIZE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_INITIALIZE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_MODIFY_POSITION_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_SWAP_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_SWAP_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.BEFORE_DONATE_FLAG)); + assertTrue(Hooks.shouldCall(hookAddr, Hooks.AFTER_DONATE_FLAG)); } function testValidateHookAddressFailsAllHooks(uint152 addr, uint8 mask) public { @@ -563,7 +563,7 @@ contract HooksTest is Test, Deployers, GasSnapshot { function testGas() public { snapStart("HooksShouldCallBeforeSwap"); - Hooks.shouldCallBeforeSwap(IHooks(address(0))); + Hooks.shouldCall(IHooks(address(0)), Hooks.BEFORE_SWAP_FLAG); snapEnd(); }