Skip to content

Commit

Permalink
chore: gas tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Apr 29, 2024
1 parent 8624ae1 commit 0ba3f32
Show file tree
Hide file tree
Showing 44 changed files with 64 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142950
143903
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134297
135247
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108533
109118
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
300345
301295
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138390
139320
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93346
90617
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68539
65810
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152077
149365
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
69718
66989
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55313
52582
Original file line number Diff line number Diff line change
@@ -1 +1 @@
971345
968582
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122859
120096
Original file line number Diff line number Diff line change
@@ -1 +1 @@
340528
337772
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57589
54833
Original file line number Diff line number Diff line change
@@ -1 +1 @@
92098
89370
Original file line number Diff line number Diff line change
@@ -1 +1 @@
94083
91355
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73587
70859
Original file line number Diff line number Diff line change
@@ -1 +1 @@
322235
319479
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
44517
41726
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20863
19494
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42510
37255
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42175
39359
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25539
22739
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8153
8148
Original file line number Diff line number Diff line change
@@ -1 +1 @@
351744
349002
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62292
59550
Original file line number Diff line number Diff line change
@@ -1 +1 @@
245337
242595
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
85388
82660
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55350
52622
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41952
36693
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45262
42520
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57550
54818
Original file line number Diff line number Diff line change
@@ -1 +1 @@
103626
100894
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25043336
25040604
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38750
36018
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104388
101656
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
44489
41733
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38753
36021
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22231
19431
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42902
37643
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32427
29618
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24680
21883
20 changes: 10 additions & 10 deletions src/pool-bin/BinPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
uint24 swapFee = key.fee.getInitialSwapFee();
if (swapFee.isSwapFeeTooLarge(SwapFeeLibrary.TEN_PERCENT_FEE)) revert FeeTooLarge();

if (key.parameters.shouldCall(HOOKS_BEFORE_INITIALIZE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_INITIALIZE_OFFSET, hooks)) {
if (hooks.beforeInitialize(msg.sender, key, activeId, hookData) != IBinHooks.beforeInitialize.selector) {
revert Hooks.InvalidHookResponse();
}
Expand All @@ -120,7 +120,7 @@ contract BinPoolManager is IBinPoolManager, Fees, 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.fee, binStep, hooks);

if (key.parameters.shouldCall(HOOKS_AFTER_INITIALIZE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_INITIALIZE_OFFSET, hooks)) {
if (hooks.afterInitialize(msg.sender, key, activeId, hookData) != IBinHooks.afterInitialize.selector) {
revert Hooks.InvalidHookResponse();
}
Expand All @@ -139,7 +139,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
_checkPoolInitialized(id);

IBinHooks hooks = IBinHooks(address(key.hooks));
if (key.parameters.shouldCall(HOOKS_BEFORE_SWAP_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_SWAP_OFFSET, hooks)) {
bytes4 selector = hooks.beforeSwap(msg.sender, key, swapForY, amountIn, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand Down Expand Up @@ -170,7 +170,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
emit Swap(id, msg.sender, delta.amount0(), delta.amount1(), activeId, swapFee, feeForProtocol);
}

if (key.parameters.shouldCall(HOOKS_AFTER_SWAP_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_SWAP_OFFSET, hooks)) {
if (hooks.afterSwap(msg.sender, key, swapForY, amountIn, delta, hookData) != IBinHooks.afterSwap.selector) {
revert Hooks.InvalidHookResponse();
}
Expand Down Expand Up @@ -241,7 +241,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
_checkPoolInitialized(id);

IBinHooks hooks = IBinHooks(address(key.hooks));
if (key.parameters.shouldCall(HOOKS_BEFORE_MINT_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_MINT_OFFSET, hooks)) {
bytes4 selector = hooks.beforeMint(msg.sender, key, params, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand Down Expand Up @@ -274,7 +274,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit Mint(id, msg.sender, mintArray.ids, mintArray.amounts, compositionFee, feeForProtocol);

if (key.parameters.shouldCall(HOOKS_AFTER_MINT_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_MINT_OFFSET, hooks)) {
if (hooks.afterMint(msg.sender, key, params, delta, hookData) != IBinHooks.afterMint.selector) {
revert Hooks.InvalidHookResponse();
}
Expand All @@ -292,7 +292,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
_checkPoolInitialized(id);

IBinHooks hooks = IBinHooks(address(key.hooks));
if (key.parameters.shouldCall(HOOKS_BEFORE_BURN_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_BURN_OFFSET, hooks)) {
bytes4 selector = hooks.beforeBurn(msg.sender, key, params, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand All @@ -312,7 +312,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit Burn(id, msg.sender, binIds, amountRemoved);

if (key.parameters.shouldCall(HOOKS_AFTER_BURN_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_BURN_OFFSET, hooks)) {
if (hooks.afterBurn(msg.sender, key, params, delta, hookData) != IBinHooks.afterBurn.selector) {
revert Hooks.InvalidHookResponse();
}
Expand All @@ -330,7 +330,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
_checkPoolInitialized(id);

IBinHooks hooks = IBinHooks(address(key.hooks));
if (key.parameters.shouldCall(HOOKS_BEFORE_DONATE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_DONATE_OFFSET, hooks)) {
bytes4 selector = hooks.beforeDonate(msg.sender, key, amount0, amount1, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand All @@ -347,7 +347,7 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit Donate(id, msg.sender, delta.amount0(), delta.amount1(), binId);

if (key.parameters.shouldCall(HOOKS_AFTER_DONATE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_DONATE_OFFSET, hooks)) {
if (hooks.afterDonate(msg.sender, key, amount0, amount1, hookData) != IBinHooks.afterDonate.selector) {
revert Hooks.InvalidHookResponse();
}
Expand Down
26 changes: 12 additions & 14 deletions src/pool-cl/CLPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
uint24 swapFee = key.fee.getInitialSwapFee();
if (swapFee.isSwapFeeTooLarge(SwapFeeLibrary.ONE_HUNDRED_PERCENT_FEE)) revert FeeTooLarge();

if (key.parameters.shouldCall(HOOKS_BEFORE_INITIALIZE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_INITIALIZE_OFFSET, hooks)) {
if (hooks.beforeInitialize(msg.sender, key, sqrtPriceX96, hookData) != ICLHooks.beforeInitialize.selector) {
revert Hooks.InvalidHookResponse();
}
Expand All @@ -114,7 +114,7 @@ contract CLPoolManager is ICLPoolManager, Fees, 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.fee, tickSpacing, hooks);

if (key.parameters.shouldCall(HOOKS_AFTER_INITIALIZE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_INITIALIZE_OFFSET, hooks)) {
if (
hooks.afterInitialize(msg.sender, key, sqrtPriceX96, tick, hookData)
!= ICLHooks.afterInitialize.selector
Expand All @@ -138,17 +138,16 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {

ICLHooks hooks = ICLHooks(address(key.hooks));

if (params.liquidityDelta > 0 && key.parameters.shouldCall(HOOKS_BEFORE_ADD_LIQUIDITY_OFFSET, key.hooks)) {
if (params.liquidityDelta > 0 && key.parameters.shouldCall(HOOKS_BEFORE_ADD_LIQUIDITY_OFFSET, hooks)) {
bytes4 selector = hooks.beforeAddLiquidity(msg.sender, key, params, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
return BalanceDeltaLibrary.MAXIMUM_DELTA;
} else if (selector != ICLHooks.beforeAddLiquidity.selector) {
revert Hooks.InvalidHookResponse();
}
} else if (
params.liquidityDelta <= 0 && key.parameters.shouldCall(HOOKS_BEFORE_REMOVE_LIQUIDITY_OFFSET, key.hooks)
) {
} else if (params.liquidityDelta <= 0 && key.parameters.shouldCall(HOOKS_BEFORE_REMOVE_LIQUIDITY_OFFSET, hooks))
{
bytes4 selector = hooks.beforeRemoveLiquidity(msg.sender, key, params, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand All @@ -173,15 +172,14 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit ModifyLiquidity(id, msg.sender, params.tickLower, params.tickUpper, params.liquidityDelta);

if (params.liquidityDelta > 0 && key.parameters.shouldCall(HOOKS_AFTER_ADD_LIQUIDITY_OFFSET, key.hooks)) {
if (params.liquidityDelta > 0 && key.parameters.shouldCall(HOOKS_AFTER_ADD_LIQUIDITY_OFFSET, hooks)) {
if (
hooks.afterAddLiquidity(msg.sender, key, params, delta, hookData) != ICLHooks.afterAddLiquidity.selector
) {
revert Hooks.InvalidHookResponse();
}
} else if (
params.liquidityDelta <= 0 && key.parameters.shouldCall(HOOKS_AFTER_REMOVE_LIQUIDITY_OFFSET, key.hooks)
) {
} else if (params.liquidityDelta <= 0 && key.parameters.shouldCall(HOOKS_AFTER_REMOVE_LIQUIDITY_OFFSET, hooks))
{
if (
hooks.afterRemoveLiquidity(msg.sender, key, params, delta, hookData)
!= ICLHooks.afterRemoveLiquidity.selector
Expand All @@ -204,7 +202,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {

ICLHooks hooks = ICLHooks(address(key.hooks));

if (key.parameters.shouldCall(HOOKS_BEFORE_SWAP_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_SWAP_OFFSET, hooks)) {
bytes4 selector = hooks.beforeSwap(msg.sender, key, params, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand Down Expand Up @@ -247,7 +245,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
state.protocolFee
);

if (key.parameters.shouldCall(HOOKS_AFTER_SWAP_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_SWAP_OFFSET, hooks)) {
if (hooks.afterSwap(msg.sender, key, params, delta, hookData) != ICLHooks.afterSwap.selector) {
revert Hooks.InvalidHookResponse();
}
Expand All @@ -266,7 +264,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
_checkPoolInitialized(id);

ICLHooks hooks = ICLHooks(address(key.hooks));
if (key.parameters.shouldCall(HOOKS_BEFORE_DONATE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_BEFORE_DONATE_OFFSET, hooks)) {
bytes4 selector = hooks.beforeDonate(msg.sender, key, amount0, amount1, hookData);
if (key.parameters.isValidNoOpCall(HOOKS_NO_OP_OFFSET, selector)) {
// Sentinel return value used to signify that a NoOp occurred.
Expand All @@ -283,7 +281,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
/// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one
emit Donate(id, msg.sender, amount0, amount1, tick);

if (key.parameters.shouldCall(HOOKS_AFTER_DONATE_OFFSET, key.hooks)) {
if (key.parameters.shouldCall(HOOKS_AFTER_DONATE_OFFSET, hooks)) {
if (hooks.afterDonate(msg.sender, key, amount0, amount1, hookData) != ICLHooks.afterDonate.selector) {
revert Hooks.InvalidHookResponse();
}
Expand Down

0 comments on commit 0ba3f32

Please sign in to comment.