Skip to content

Commit

Permalink
refactor: remove hookdata from initialize hook for both pool types
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed Oct 10, 2024
1 parent 4fe568f commit f9cacd0
Show file tree
Hide file tree
Showing 73 changed files with 339 additions and 405 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178321
178189
Original file line number Diff line number Diff line change
@@ -1 +1 @@
188513
188425
Original file line number Diff line number Diff line change
@@ -1 +1 @@
249529
184774
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
311511
311515
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
189812
189692
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerBytecodeSize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24232
24173
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133846
133833
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1870
1877
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32540
32518
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34988
34966
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142646
142629
Original file line number Diff line number Diff line change
@@ -1 +1 @@
289677
289662
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
127019
127005
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118785
118763
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasGetBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4105
4083
Original file line number Diff line number Diff line change
@@ -1 +1 @@
970507
970510
Original file line number Diff line number Diff line change
@@ -1 +1 @@
329818
329822
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337827
337829
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140377
140380
Original file line number Diff line number Diff line change
@@ -1 +1 @@
173336
173317
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179365
179345
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133367
133348
Original file line number Diff line number Diff line change
@@ -1 +1 @@
163762
163446
Original file line number Diff line number Diff line change
@@ -1 +1 @@
304784
304787
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34507
34485
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerBytecodeSize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21220
21216
Original file line number Diff line number Diff line change
@@ -1 +1 @@
347599
347609
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238356
238365
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150645
150173
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131089
131090
Original file line number Diff line number Diff line change
@@ -1 +1 @@
143342
143343
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
87973
87879
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31961
31971
6 changes: 3 additions & 3 deletions src/pool-bin/BinPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract BinPoolManager is IBinPoolManager, ProtocolFees, Extsload {
}

/// @inheritdoc IBinPoolManager
function initialize(PoolKey memory key, uint24 activeId, bytes calldata hookData)
function initialize(PoolKey memory key, uint24 activeId)
external
override
poolManagerMatch(address(key.poolManager))
Expand All @@ -121,7 +121,7 @@ contract BinPoolManager is IBinPoolManager, ProtocolFees, Extsload {
uint24 lpFee = key.fee.getInitialLPFee();
lpFee.validate(LPFeeLibrary.TEN_PERCENT_FEE);

BinHooks.beforeInitialize(key, activeId, hookData);
BinHooks.beforeInitialize(key, activeId);

PoolId id = key.toId();

Expand All @@ -133,7 +133,7 @@ contract BinPoolManager is IBinPoolManager, ProtocolFees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit Initialize(id, key.currency0, key.currency1, key.hooks, key.fee, key.parameters, activeId);

BinHooks.afterInitialize(key, activeId, hookData);
BinHooks.afterInitialize(key, activeId);
}

/// @inheritdoc IBinPoolManager
Expand Down
10 changes: 2 additions & 8 deletions src/pool-bin/interfaces/IBinHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,15 @@ interface IBinHooks is IHooks {
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param activeId The binId of the pool, when the value is 2 ** 23, token price is 1:1
/// @param hookData Arbitrary data handed into the PoolManager by the initializer to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeInitialize(address sender, PoolKey calldata key, uint24 activeId, bytes calldata hookData)
external
returns (bytes4);
function beforeInitialize(address sender, PoolKey calldata key, uint24 activeId) external returns (bytes4);

/// @notice The hook called after the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param activeId The binId of the pool, when the value is 2 ** 23, token price is 1:1
/// @param hookData Arbitrary data handed into the PoolManager by the initializer to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function afterInitialize(address sender, PoolKey calldata key, uint24 activeId, bytes calldata hookData)
external
returns (bytes4);
function afterInitialize(address sender, PoolKey calldata key, uint24 activeId) external returns (bytes4);

/// @notice The hook called before adding liquidity
/// @param sender The initial msg.sender for the modify position call
Expand Down
2 changes: 1 addition & 1 deletion src/pool-bin/interfaces/IBinPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ interface IBinPoolManager is IProtocolFees, IPoolManager, IExtsload {
function getNextNonEmptyBin(PoolId id, bool swapForY, uint24 binId) external view returns (uint24 nextId);

/// @notice Initialize a new pool
function initialize(PoolKey memory key, uint24 activeId, bytes calldata hookData) external;
function initialize(PoolKey memory key, uint24 activeId) external;

/// @notice Add liquidity to a pool
/// @return delta BalanceDelta, will be negative indicating how much total amt0 and amt1 liquidity added
Expand Down
8 changes: 4 additions & 4 deletions src/pool-bin/libraries/BinHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ library BinHooks {
}
}

function beforeInitialize(PoolKey memory key, uint24 activeId, bytes calldata hookData) internal {
function beforeInitialize(PoolKey memory key, uint24 activeId) internal {
IBinHooks hooks = IBinHooks(address(key.hooks));

if (key.parameters.shouldCall(HOOKS_BEFORE_INITIALIZE_OFFSET, hooks)) {
Hooks.callHook(hooks, abi.encodeCall(IBinHooks.beforeInitialize, (msg.sender, key, activeId, hookData)));
Hooks.callHook(hooks, abi.encodeCall(IBinHooks.beforeInitialize, (msg.sender, key, activeId)));
}
}

function afterInitialize(PoolKey memory key, uint24 activeId, bytes calldata hookData) internal {
function afterInitialize(PoolKey memory key, uint24 activeId) internal {
IBinHooks hooks = IBinHooks(address(key.hooks));

if (key.parameters.shouldCall(HOOKS_AFTER_INITIALIZE_OFFSET, hooks)) {
Hooks.callHook(hooks, abi.encodeCall(IBinHooks.afterInitialize, (msg.sender, key, activeId, hookData)));
Hooks.callHook(hooks, abi.encodeCall(IBinHooks.afterInitialize, (msg.sender, key, activeId)));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/pool-cl/CLPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract CLPoolManager is ICLPoolManager, ProtocolFees, Extsload {
}

/// @inheritdoc ICLPoolManager
function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData)
function initialize(PoolKey memory key, uint160 sqrtPriceX96)
external
override
poolManagerMatch(address(key.poolManager))
Expand All @@ -106,7 +106,7 @@ contract CLPoolManager is ICLPoolManager, ProtocolFees, Extsload {
uint24 lpFee = key.fee.getInitialLPFee();
lpFee.validate(LPFeeLibrary.ONE_HUNDRED_PERCENT_FEE);

CLHooks.beforeInitialize(key, sqrtPriceX96, hookData);
CLHooks.beforeInitialize(key, sqrtPriceX96);

PoolId id = key.toId();
uint24 protocolFee = _fetchProtocolFee(key);
Expand All @@ -117,7 +117,7 @@ contract CLPoolManager is ICLPoolManager, ProtocolFees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit Initialize(id, key.currency0, key.currency1, key.hooks, key.fee, key.parameters, sqrtPriceX96, tick);

CLHooks.afterInitialize(key, sqrtPriceX96, tick, hookData);
CLHooks.afterInitialize(key, sqrtPriceX96, tick);
}

/// @inheritdoc ICLPoolManager
Expand Down
17 changes: 4 additions & 13 deletions src/pool-cl/interfaces/ICLHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,18 @@ interface ICLHooks is IHooks {
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @param hookData Arbitrary data handed into the PoolManager by the initializer to be be passed on to the hook
/// @return bytes4 The function selector for the hook

function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, bytes calldata hookData)
external
returns (bytes4);
function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);

/// @notice The hook called after the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @param tick The current tick after the state of a pool is initialized
/// @param hookData Arbitrary data handed into the PoolManager by the initializer to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function afterInitialize(
address sender,
PoolKey calldata key,
uint160 sqrtPriceX96,
int24 tick,
bytes calldata hookData
) external returns (bytes4);
function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
external
returns (bytes4);

/// @notice The hook called before liquidity is added
/// @param sender The initial msg.sender for the add liquidity call
Expand Down
4 changes: 1 addition & 3 deletions src/pool-cl/interfaces/ICLPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ interface ICLPoolManager is IProtocolFees, IPoolManager, IExtsload {
returns (CLPosition.Info memory position);

/// @notice Initialize the state for a given pool ID
function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData)
external
returns (int24 tick);
function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);

struct ModifyLiquidityParams {
// the lower and upper tick of the position
Expand Down
10 changes: 4 additions & 6 deletions src/pool-cl/libraries/CLHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ library CLHooks {
}
}

function beforeInitialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) internal {
function beforeInitialize(PoolKey memory key, uint160 sqrtPriceX96) internal {
ICLHooks hooks = ICLHooks(address(key.hooks));

if (key.parameters.shouldCall(HOOKS_BEFORE_INITIALIZE_OFFSET, hooks)) {
Hooks.callHook(hooks, abi.encodeCall(ICLHooks.beforeInitialize, (msg.sender, key, sqrtPriceX96, hookData)));
Hooks.callHook(hooks, abi.encodeCall(ICLHooks.beforeInitialize, (msg.sender, key, sqrtPriceX96)));
}
}

function afterInitialize(PoolKey memory key, uint160 sqrtPriceX96, int24 tick, bytes calldata hookData) internal {
function afterInitialize(PoolKey memory key, uint160 sqrtPriceX96, int24 tick) internal {
ICLHooks hooks = ICLHooks(address(key.hooks));

if (key.parameters.shouldCall(HOOKS_AFTER_INITIALIZE_OFFSET, hooks)) {
Hooks.callHook(
hooks, abi.encodeCall(ICLHooks.afterInitialize, (msg.sender, key, sqrtPriceX96, tick, hookData))
);
Hooks.callHook(hooks, abi.encodeCall(ICLHooks.afterInitialize, (msg.sender, key, sqrtPriceX96, tick)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/MockFeePoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract MockFeePoolManager is ProtocolFees {

constructor(IVault vault, uint256 controllerGasLimit) ProtocolFees(vault) {}

function initialize(PoolKey memory key, bytes calldata) external {
function initialize(PoolKey memory key) external {
PoolId id = key.toId();

uint24 protocolFee = _fetchProtocolFee(key);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fee/MockFeeManagerHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract MockFeeManagerHook is IHooks {
}

// swap fee for dynamic fee pool is 0 by default, so we need to update it after pool initialization
function afterInitialize(address, PoolKey calldata key, uint24, bytes calldata) external returns (bytes4) {
function afterInitialize(address, PoolKey calldata key, uint24) external returns (bytes4) {
IBinPoolManager(msg.sender).updateDynamicLPFee(key, swapfee);
return MockFeeManagerHook.afterInitialize.selector;
}
Expand Down
12 changes: 2 additions & 10 deletions src/test/pool-bin/MockBinHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {PoolId} from "../../types/PoolId.sol";
contract MockBinHooks is IBinHooks {
using Hooks for IBinHooks;

bytes public beforeInitializeData;
bytes public afterInitializeData;
bytes public beforeMintData;
bytes public afterMintData;
bytes public beforeSwapData;
Expand All @@ -35,18 +33,12 @@ contract MockBinHooks is IBinHooks {
return bitmap;
}

function beforeInitialize(address, PoolKey calldata, uint24, bytes calldata hookData) external returns (bytes4) {
beforeInitializeData = hookData;
function beforeInitialize(address, PoolKey calldata, uint24) external returns (bytes4) {
bytes4 selector = MockBinHooks.beforeInitialize.selector;
return returnValues[selector] == bytes4(0) ? selector : returnValues[selector];
}

function afterInitialize(address, PoolKey calldata, uint24, bytes calldata hookData)
external
override
returns (bytes4)
{
afterInitializeData = hookData;
function afterInitialize(address, PoolKey calldata, uint24) external override returns (bytes4) {
bytes4 selector = MockBinHooks.afterInitialize.selector;
return returnValues[selector] == bytes4(0) ? selector : returnValues[selector];
}
Expand Down
Loading

0 comments on commit f9cacd0

Please sign in to comment.