Skip to content

Commit

Permalink
delete shadow vars in TWAMM
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz committed Dec 5, 2024
1 parent 39fe243 commit 9a8d927
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMM executTWAMMOrders 1 interval.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
489956
489927
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMM executTWAMMOrders 2 intervals.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
595446
595404
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMM executTWAMMOrders 3 intervals.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
692908
692853
Original file line number Diff line number Diff line change
@@ -1 +1 @@
262040
262033
Original file line number Diff line number Diff line change
@@ -1 +1 @@
294150
294134
Original file line number Diff line number Diff line change
@@ -1 +1 @@
256437
256430
Original file line number Diff line number Diff line change
@@ -1 +1 @@
290599
290583
26 changes: 7 additions & 19 deletions contracts/hooks/examples/TWAMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ contract TWAMM is BaseHook, ITWAMM {
if (orderPool0For1.sellRateCurrent != 0 && orderPool1For0.sellRateCurrent != 0) {
pool = _advanceToNewTimestamp(
self,
manager,
key,
AdvanceParams(
expirationInterval,
Expand All @@ -388,7 +387,6 @@ contract TWAMM is BaseHook, ITWAMM {
} else {
pool = _advanceTimestampForSinglePoolSell(
self,
manager,
key,
AdvanceSingleParams(
expirationInterval,
Expand All @@ -410,14 +408,12 @@ contract TWAMM is BaseHook, ITWAMM {
if (orderPool0For1.sellRateCurrent != 0 && orderPool1For0.sellRateCurrent != 0) {
pool = _advanceToNewTimestamp(
self,
manager,
key,
AdvanceParams(expirationInterval, block.timestamp, block.timestamp - prevTimestamp, pool)
);
} else {
pool = _advanceTimestampForSinglePoolSell(
self,
manager,
key,
AdvanceSingleParams(
expirationInterval,
Expand All @@ -443,12 +439,10 @@ contract TWAMM is BaseHook, ITWAMM {
PoolParamsOnExecute pool;
}

function _advanceToNewTimestamp(
State storage self,
IPoolManager manager,
PoolKey memory poolKey,
AdvanceParams memory params
) private returns (PoolParamsOnExecute memory) {
function _advanceToNewTimestamp(State storage self, PoolKey memory poolKey, AdvanceParams memory params)
private
returns (PoolParamsOnExecute memory)
{
uint160 finalSqrtPriceX96;
uint256 secondsElapsedX96 = params.secondsElapsed * FixedPoint96.Q96;

Expand All @@ -467,15 +461,12 @@ contract TWAMM is BaseHook, ITWAMM {
finalSqrtPriceX96 = TwammMath.getNewSqrtPriceX96(executionParams);

(bool crossingInitializedTick, int24 tick) =
_isCrossingInitializedTick(params.pool, manager, poolKey, finalSqrtPriceX96);
_isCrossingInitializedTick(params.pool, poolKey, finalSqrtPriceX96);
unchecked {
if (crossingInitializedTick) {
uint256 secondsUntilCrossingX96;
(params.pool, secondsUntilCrossingX96) = _advanceTimeThroughTickCrossing(
self,
manager,
poolKey,
TickCrossingParams(tick, params.nextTimestamp, secondsElapsedX96, params.pool)
self, poolKey, TickCrossingParams(tick, params.nextTimestamp, secondsElapsedX96, params.pool)
);
secondsElapsedX96 = secondsElapsedX96 - secondsUntilCrossingX96;
} else {
Expand Down Expand Up @@ -508,7 +499,6 @@ contract TWAMM is BaseHook, ITWAMM {

function _advanceTimestampForSinglePoolSell(
State storage self,
IPoolManager manager,
PoolKey memory poolKey,
AdvanceSingleParams memory params
) private returns (PoolParamsOnExecute memory) {
Expand All @@ -523,7 +513,7 @@ contract TWAMM is BaseHook, ITWAMM {
);

(bool crossingInitializedTick, int24 tick) =
_isCrossingInitializedTick(params.pool, manager, poolKey, finalSqrtPriceX96);
_isCrossingInitializedTick(params.pool, poolKey, finalSqrtPriceX96);

if (crossingInitializedTick) {
(, int128 liquidityNetAtTick) = manager.getTickLiquidity(poolKey.toId(), tick);
Expand Down Expand Up @@ -579,7 +569,6 @@ contract TWAMM is BaseHook, ITWAMM {

function _advanceTimeThroughTickCrossing(
State storage self,
IPoolManager manager,
PoolKey memory poolKey,
TickCrossingParams memory params
) private returns (PoolParamsOnExecute memory, uint256) {
Expand Down Expand Up @@ -622,7 +611,6 @@ contract TWAMM is BaseHook, ITWAMM {

function _isCrossingInitializedTick(
PoolParamsOnExecute memory pool,
IPoolManager manager,
PoolKey memory poolKey,
uint160 nextSqrtPriceX96
) internal view returns (bool crossingInitializedTick, int24 nextTickInit) {
Expand Down
2 changes: 1 addition & 1 deletion test/shared/implementation/TWAMMImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ contract TWAMMImplementation is TWAMM {
PoolKey memory poolKey,
uint160 nextSqrtPriceX96
) external view returns (bool crossingInitializedTick, int24 nextTickInit) {
return _isCrossingInitializedTick(pool, poolManager, poolKey, nextSqrtPriceX96);
return _isCrossingInitializedTick(pool, poolKey, nextSqrtPriceX96);
}
}

0 comments on commit 9a8d927

Please sign in to comment.