@@ -138,9 +138,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
138138 /// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize
139139 /// check
140140 function balance0 () private view returns (uint256 ) {
141- (bool success , bytes memory data ) = token0.staticcall (
142- abi.encodeWithSelector (IERC20Minimal .balanceOf.selector , address (this ))
143- );
141+ (bool success , bytes memory data ) =
142+ token0.staticcall (abi.encodeWithSelector (IERC20Minimal .balanceOf.selector , address (this )));
144143 require (success && data.length >= 32 );
145144 return abi.decode (data, (uint256 ));
146145 }
@@ -149,9 +148,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
149148 /// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize
150149 /// check
151150 function balance1 () private view returns (uint256 ) {
152- (bool success , bytes memory data ) = token1.staticcall (
153- abi.encodeWithSelector (IERC20Minimal .balanceOf.selector , address (this ))
154- );
151+ (bool success , bytes memory data ) =
152+ token1.staticcall (abi.encodeWithSelector (IERC20Minimal .balanceOf.selector , address (this )));
155153 require (success && data.length >= 32 );
156154 return abi.decode (data, (uint256 ));
157155 }
@@ -209,14 +207,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
209207 );
210208 } else if (_slot0.tick < tickUpper) {
211209 uint32 time = _blockTimestamp ();
212- (int56 tickCumulative , uint160 secondsPerLiquidityCumulativeX128 ) = observations.observeSingle (
213- time,
214- 0 ,
215- _slot0.tick,
216- _slot0.observationIndex,
217- liquidity,
218- _slot0.observationCardinality
219- );
210+ (int56 tickCumulative , uint160 secondsPerLiquidityCumulativeX128 ) =
211+ observations.observeSingle (
212+ time,
213+ 0 ,
214+ _slot0.tick,
215+ _slot0.observationIndex,
216+ liquidity,
217+ _slot0.observationCardinality
218+ );
220219 return (
221220 tickCumulative - tickCumulativeLower - tickCumulativeUpper,
222221 secondsPerLiquidityCumulativeX128 -
@@ -260,10 +259,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
260259 noDelegateCall
261260 {
262261 uint16 observationCardinalityNextOld = slot0.observationCardinalityNext; // for the event
263- uint16 observationCardinalityNextNew = observations.grow (
264- observationCardinalityNextOld,
265- observationCardinalityNext
266- );
262+ uint16 observationCardinalityNextNew =
263+ observations.grow (observationCardinalityNextOld, observationCardinalityNext);
267264 slot0.observationCardinalityNext = observationCardinalityNextNew;
268265 if (observationCardinalityNextOld != observationCardinalityNextNew)
269266 emit IncreaseObservationCardinalityNext (observationCardinalityNextOld, observationCardinalityNextNew);
@@ -396,14 +393,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
396393 bool flippedUpper;
397394 if (liquidityDelta != 0 ) {
398395 uint32 time = _blockTimestamp ();
399- (int56 tickCumulative , uint160 secondsPerLiquidityCumulativeX128 ) = observations.observeSingle (
400- time,
401- 0 ,
402- slot0.tick,
403- slot0.observationIndex,
404- liquidity,
405- slot0.observationCardinality
406- );
396+ (int56 tickCumulative , uint160 secondsPerLiquidityCumulativeX128 ) =
397+ observations.observeSingle (
398+ time,
399+ 0 ,
400+ slot0.tick,
401+ slot0.observationIndex,
402+ liquidity,
403+ slot0.observationCardinality
404+ );
407405
408406 flippedLower = ticks.update (
409407 tickLower,
@@ -438,13 +436,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
438436 }
439437 }
440438
441- (uint256 feeGrowthInside0X128 , uint256 feeGrowthInside1X128 ) = ticks.getFeeGrowthInside (
442- tickLower,
443- tickUpper,
444- tick,
445- _feeGrowthGlobal0X128,
446- _feeGrowthGlobal1X128
447- );
439+ (uint256 feeGrowthInside0X128 , uint256 feeGrowthInside1X128 ) =
440+ ticks.getFeeGrowthInside (tickLower, tickUpper, tick, _feeGrowthGlobal0X128, _feeGrowthGlobal1X128);
448441
449442 position.update (liquidityDelta, feeGrowthInside0X128, feeGrowthInside1X128);
450443
@@ -469,14 +462,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
469462 bytes calldata data
470463 ) external override lock returns (uint256 amount0 , uint256 amount1 ) {
471464 require (amount > 0 );
472- (, int256 amount0Int , int256 amount1Int ) = _modifyPosition (
473- ModifyPositionParams ({
474- owner: recipient,
475- tickLower: tickLower,
476- tickUpper: tickUpper,
477- liquidityDelta: int256 (amount).toInt128 ()
478- })
479- );
465+ (, int256 amount0Int , int256 amount1Int ) =
466+ _modifyPosition (
467+ ModifyPositionParams ({
468+ owner: recipient,
469+ tickLower: tickLower,
470+ tickUpper: tickUpper,
471+ liquidityDelta: int256 (amount).toInt128 ()
472+ })
473+ );
480474
481475 amount0 = uint256 (amount0Int);
482476 amount1 = uint256 (amount1Int);
@@ -525,14 +519,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
525519 int24 tickUpper ,
526520 uint128 amount
527521 ) external override lock returns (uint256 amount0 , uint256 amount1 ) {
528- (Position.Info storage position , int256 amount0Int , int256 amount1Int ) = _modifyPosition (
529- ModifyPositionParams ({
530- owner: msg .sender ,
531- tickLower: tickLower,
532- tickUpper: tickUpper,
533- liquidityDelta: - int256 (amount).toInt128 ()
534- })
535- );
522+ (Position.Info storage position , int256 amount0Int , int256 amount1Int ) =
523+ _modifyPosition (
524+ ModifyPositionParams ({
525+ owner: msg .sender ,
526+ tickLower: tickLower,
527+ tickUpper: tickUpper,
528+ liquidityDelta: - int256 (amount).toInt128 ()
529+ })
530+ );
536531
537532 amount0 = uint256 (- amount0Int);
538533 amount1 = uint256 (- amount1Int);
@@ -619,26 +614,28 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
619614
620615 slot0.unlocked = false ;
621616
622- SwapCache memory cache = SwapCache ({
623- liquidityStart: liquidity,
624- blockTimestamp: _blockTimestamp (),
625- feeProtocol: zeroForOne ? (slot0Start.feeProtocol % 16 ) : (slot0Start.feeProtocol >> 4 ),
626- secondsPerLiquidityCumulativeX128: 0 ,
627- tickCumulative: 0 ,
628- computedLatestObservation: false
629- });
617+ SwapCache memory cache =
618+ SwapCache ({
619+ liquidityStart: liquidity,
620+ blockTimestamp: _blockTimestamp (),
621+ feeProtocol: zeroForOne ? (slot0Start.feeProtocol % 16 ) : (slot0Start.feeProtocol >> 4 ),
622+ secondsPerLiquidityCumulativeX128: 0 ,
623+ tickCumulative: 0 ,
624+ computedLatestObservation: false
625+ });
630626
631627 bool exactInput = amountSpecified > 0 ;
632628
633- SwapState memory state = SwapState ({
634- amountSpecifiedRemaining: amountSpecified,
635- amountCalculated: 0 ,
636- sqrtPriceX96: slot0Start.sqrtPriceX96,
637- tick: slot0Start.tick,
638- feeGrowthGlobalX128: zeroForOne ? feeGrowthGlobal0X128 : feeGrowthGlobal1X128,
639- protocolFee: 0 ,
640- liquidity: cache.liquidityStart
641- });
629+ SwapState memory state =
630+ SwapState ({
631+ amountSpecifiedRemaining: amountSpecified,
632+ amountCalculated: 0 ,
633+ sqrtPriceX96: slot0Start.sqrtPriceX96,
634+ tick: slot0Start.tick,
635+ feeGrowthGlobalX128: zeroForOne ? feeGrowthGlobal0X128 : feeGrowthGlobal1X128,
636+ protocolFee: 0 ,
637+ liquidity: cache.liquidityStart
638+ });
642639
643640 // continue swapping as long as we haven't used the entire input/output and haven't reached the price limit
644641 while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != sqrtPriceLimitX96) {
@@ -709,14 +706,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
709706 );
710707 cache.computedLatestObservation = true ;
711708 }
712- int128 liquidityNet = ticks.cross (
713- step.tickNext,
714- (zeroForOne ? state.feeGrowthGlobalX128 : feeGrowthGlobal0X128),
715- (zeroForOne ? feeGrowthGlobal1X128 : state.feeGrowthGlobalX128),
716- cache.secondsPerLiquidityCumulativeX128,
717- cache.tickCumulative,
718- cache.blockTimestamp
719- );
709+ int128 liquidityNet =
710+ ticks.cross (
711+ step.tickNext,
712+ (zeroForOne ? state.feeGrowthGlobalX128 : feeGrowthGlobal0X128),
713+ (zeroForOne ? feeGrowthGlobal1X128 : state.feeGrowthGlobalX128),
714+ cache.secondsPerLiquidityCumulativeX128,
715+ cache.tickCumulative,
716+ cache.blockTimestamp
717+ );
720718 // if we're moving leftward, we interpret liquidityNet as the opposite sign
721719 // safe because liquidityNet cannot be type(int128).min
722720 if (zeroForOne) liquidityNet = - liquidityNet;
@@ -733,14 +731,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
733731
734732 // update tick and write an oracle entry if the tick change
735733 if (state.tick != slot0Start.tick) {
736- (uint16 observationIndex , uint16 observationCardinality ) = observations.write (
737- slot0Start.observationIndex,
738- cache.blockTimestamp,
739- slot0Start.tick,
740- cache.liquidityStart,
741- slot0Start.observationCardinality,
742- slot0Start.observationCardinalityNext
743- );
734+ (uint16 observationIndex , uint16 observationCardinality ) =
735+ observations.write (
736+ slot0Start.observationIndex,
737+ cache.blockTimestamp,
738+ slot0Start.tick,
739+ cache.liquidityStart,
740+ slot0Start.observationCardinality,
741+ slot0Start.observationCardinalityNext
742+ );
744743 (slot0.sqrtPriceX96, slot0.tick, slot0.observationIndex, slot0.observationCardinality) = (
745744 state.sqrtPriceX96,
746745 state.tick,
0 commit comments