Skip to content

Commit

Permalink
optimization: cache memory variable in clpool#swap
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed May 9, 2024
1 parent 2a02631 commit 76244d4
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148799
148772
Original file line number Diff line number Diff line change
@@ -1 +1 @@
177249
177222
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25086651
25086624
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
78894
78867
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158466
158439
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95401
95374
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
78897
78870
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32281
32293
7 changes: 3 additions & 4 deletions src/pool-cl/libraries/CLPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ library CLPool {
bool exactInput = params.amountSpecified > 0;

{
uint16 protocolFee = params.zeroForOne
? slot0Start.protocolFee.getZeroForOneFee()
: slot0Start.protocolFee.getOneForZeroFee();
uint16 protocolFee =
zeroForOne ? slot0Start.protocolFee.getZeroForOneFee() : slot0Start.protocolFee.getOneForZeroFee();

state = SwapState({
amountSpecifiedRemaining: params.amountSpecified,
Expand All @@ -228,7 +227,7 @@ library CLPool {
tick: slot0Start.tick,
swapFee: protocolFee == 0 ? slot0Start.lpFee : uint24(protocolFee).calculateSwapFee(slot0Start.lpFee),
protocolFee: protocolFee,
feeGrowthGlobalX128: params.zeroForOne ? self.feeGrowthGlobal0X128 : self.feeGrowthGlobal1X128,
feeGrowthGlobalX128: zeroForOne ? self.feeGrowthGlobal0X128 : self.feeGrowthGlobal1X128,
feeForProtocol: 0,
liquidity: liquidityStart
});
Expand Down

0 comments on commit 76244d4

Please sign in to comment.