Skip to content

Commit

Permalink
Fix code style issues with Prettier (Uniswap#629)
Browse files Browse the repository at this point in the history
Co-authored-by: Lint Action <[email protected]>
  • Loading branch information
ewilz and lint-action authored Mar 16, 2023
1 parent 05c10bf commit c5ccf4d
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 239 deletions.
17 changes: 5 additions & 12 deletions audits/tob/contracts/crytic/echidna/E2E_mint_burn.sol
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,11 @@ contract E2E_mint_burn {

function test_mint(uint128 _amount) public {
if (!inited) _init(_amount);
(int24 _tL, int24 _tU) = forgePosition(
_amount,
poolParams.tickSpacing,
poolParams.tickCount,
poolParams.maxTick
);

(UniswapMinter.MinterStats memory bfre, UniswapMinter.MinterStats memory aftr) = minter.doMint(
_tL,
_tU,
_amount
);
(int24 _tL, int24 _tU) =
forgePosition(_amount, poolParams.tickSpacing, poolParams.tickCount, poolParams.maxTick);

(UniswapMinter.MinterStats memory bfre, UniswapMinter.MinterStats memory aftr) =
minter.doMint(_tL, _tU, _amount);
storeUsedTicks(_tL, _tU);

check_mint_invariants(_tL, _tU, bfre, aftr);
Expand Down
28 changes: 8 additions & 20 deletions audits/tob/contracts/crytic/echidna/E2E_swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,8 @@ contract E2E_swap {
uint160 sqrtPriceLimitX96 = get_random_zeroForOne_priceLimit(_amount);
// console.log('sqrtPriceLimitX96 = %s', sqrtPriceLimitX96);

(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) = swapper.doSwap(
true,
_amountSpecified,
sqrtPriceLimitX96
);
(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) =
swapper.doSwap(true, _amountSpecified, sqrtPriceLimitX96);

check_swap_invariants(
bfre.tick,
Expand Down Expand Up @@ -397,11 +394,8 @@ contract E2E_swap {
uint160 sqrtPriceLimitX96 = get_random_oneForZero_priceLimit(_amount);
// console.log('sqrtPriceLimitX96 = %s', sqrtPriceLimitX96);

(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) = swapper.doSwap(
false,
_amountSpecified,
sqrtPriceLimitX96
);
(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) =
swapper.doSwap(false, _amountSpecified, sqrtPriceLimitX96);

check_swap_invariants(
bfre.tick,
Expand Down Expand Up @@ -434,11 +428,8 @@ contract E2E_swap {
uint160 sqrtPriceLimitX96 = get_random_zeroForOne_priceLimit(_amount);
// console.log('sqrtPriceLimitX96 = %s', sqrtPriceLimitX96);

(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) = swapper.doSwap(
true,
_amountSpecified,
sqrtPriceLimitX96
);
(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) =
swapper.doSwap(true, _amountSpecified, sqrtPriceLimitX96);

check_swap_invariants(
bfre.tick,
Expand Down Expand Up @@ -471,11 +462,8 @@ contract E2E_swap {
uint160 sqrtPriceLimitX96 = get_random_oneForZero_priceLimit(_amount);
// console.log('sqrtPriceLimitX96 = %s', sqrtPriceLimitX96);

(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) = swapper.doSwap(
false,
_amountSpecified,
sqrtPriceLimitX96
);
(UniswapSwapper.SwapperStats memory bfre, UniswapSwapper.SwapperStats memory aftr) =
swapper.doSwap(false, _amountSpecified, sqrtPriceLimitX96);

check_swap_invariants(
bfre.tick,
Expand Down
163 changes: 81 additions & 82 deletions contracts/UniswapV3Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
/// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize
/// check
function balance0() private view returns (uint256) {
(bool success, bytes memory data) = token0.staticcall(
abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this))
);
(bool success, bytes memory data) =
token0.staticcall(abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this)));
require(success && data.length >= 32);
return abi.decode(data, (uint256));
}
Expand All @@ -149,9 +148,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
/// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize
/// check
function balance1() private view returns (uint256) {
(bool success, bytes memory data) = token1.staticcall(
abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this))
);
(bool success, bytes memory data) =
token1.staticcall(abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this)));
require(success && data.length >= 32);
return abi.decode(data, (uint256));
}
Expand Down Expand Up @@ -209,14 +207,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
);
} else if (_slot0.tick < tickUpper) {
uint32 time = _blockTimestamp();
(int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) = observations.observeSingle(
time,
0,
_slot0.tick,
_slot0.observationIndex,
liquidity,
_slot0.observationCardinality
);
(int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) =
observations.observeSingle(
time,
0,
_slot0.tick,
_slot0.observationIndex,
liquidity,
_slot0.observationCardinality
);
return (
tickCumulative - tickCumulativeLower - tickCumulativeUpper,
secondsPerLiquidityCumulativeX128 -
Expand Down Expand Up @@ -260,10 +259,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
noDelegateCall
{
uint16 observationCardinalityNextOld = slot0.observationCardinalityNext; // for the event
uint16 observationCardinalityNextNew = observations.grow(
observationCardinalityNextOld,
observationCardinalityNext
);
uint16 observationCardinalityNextNew =
observations.grow(observationCardinalityNextOld, observationCardinalityNext);
slot0.observationCardinalityNext = observationCardinalityNextNew;
if (observationCardinalityNextOld != observationCardinalityNextNew)
emit IncreaseObservationCardinalityNext(observationCardinalityNextOld, observationCardinalityNextNew);
Expand Down Expand Up @@ -396,14 +393,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
bool flippedUpper;
if (liquidityDelta != 0) {
uint32 time = _blockTimestamp();
(int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) = observations.observeSingle(
time,
0,
slot0.tick,
slot0.observationIndex,
liquidity,
slot0.observationCardinality
);
(int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) =
observations.observeSingle(
time,
0,
slot0.tick,
slot0.observationIndex,
liquidity,
slot0.observationCardinality
);

flippedLower = ticks.update(
tickLower,
Expand Down Expand Up @@ -438,13 +436,8 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
}
}

(uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = ticks.getFeeGrowthInside(
tickLower,
tickUpper,
tick,
_feeGrowthGlobal0X128,
_feeGrowthGlobal1X128
);
(uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) =
ticks.getFeeGrowthInside(tickLower, tickUpper, tick, _feeGrowthGlobal0X128, _feeGrowthGlobal1X128);

position.update(liquidityDelta, feeGrowthInside0X128, feeGrowthInside1X128);

Expand All @@ -469,14 +462,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
bytes calldata data
) external override lock returns (uint256 amount0, uint256 amount1) {
require(amount > 0);
(, int256 amount0Int, int256 amount1Int) = _modifyPosition(
ModifyPositionParams({
owner: recipient,
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: int256(amount).toInt128()
})
);
(, int256 amount0Int, int256 amount1Int) =
_modifyPosition(
ModifyPositionParams({
owner: recipient,
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: int256(amount).toInt128()
})
);

amount0 = uint256(amount0Int);
amount1 = uint256(amount1Int);
Expand Down Expand Up @@ -525,14 +519,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
int24 tickUpper,
uint128 amount
) external override lock returns (uint256 amount0, uint256 amount1) {
(Position.Info storage position, int256 amount0Int, int256 amount1Int) = _modifyPosition(
ModifyPositionParams({
owner: msg.sender,
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: -int256(amount).toInt128()
})
);
(Position.Info storage position, int256 amount0Int, int256 amount1Int) =
_modifyPosition(
ModifyPositionParams({
owner: msg.sender,
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: -int256(amount).toInt128()
})
);

amount0 = uint256(-amount0Int);
amount1 = uint256(-amount1Int);
Expand Down Expand Up @@ -619,26 +614,28 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {

slot0.unlocked = false;

SwapCache memory cache = SwapCache({
liquidityStart: liquidity,
blockTimestamp: _blockTimestamp(),
feeProtocol: zeroForOne ? (slot0Start.feeProtocol % 16) : (slot0Start.feeProtocol >> 4),
secondsPerLiquidityCumulativeX128: 0,
tickCumulative: 0,
computedLatestObservation: false
});
SwapCache memory cache =
SwapCache({
liquidityStart: liquidity,
blockTimestamp: _blockTimestamp(),
feeProtocol: zeroForOne ? (slot0Start.feeProtocol % 16) : (slot0Start.feeProtocol >> 4),
secondsPerLiquidityCumulativeX128: 0,
tickCumulative: 0,
computedLatestObservation: false
});

bool exactInput = amountSpecified > 0;

SwapState memory state = SwapState({
amountSpecifiedRemaining: amountSpecified,
amountCalculated: 0,
sqrtPriceX96: slot0Start.sqrtPriceX96,
tick: slot0Start.tick,
feeGrowthGlobalX128: zeroForOne ? feeGrowthGlobal0X128 : feeGrowthGlobal1X128,
protocolFee: 0,
liquidity: cache.liquidityStart
});
SwapState memory state =
SwapState({
amountSpecifiedRemaining: amountSpecified,
amountCalculated: 0,
sqrtPriceX96: slot0Start.sqrtPriceX96,
tick: slot0Start.tick,
feeGrowthGlobalX128: zeroForOne ? feeGrowthGlobal0X128 : feeGrowthGlobal1X128,
protocolFee: 0,
liquidity: cache.liquidityStart
});

// continue swapping as long as we haven't used the entire input/output and haven't reached the price limit
while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != sqrtPriceLimitX96) {
Expand Down Expand Up @@ -709,14 +706,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
);
cache.computedLatestObservation = true;
}
int128 liquidityNet = ticks.cross(
step.tickNext,
(zeroForOne ? state.feeGrowthGlobalX128 : feeGrowthGlobal0X128),
(zeroForOne ? feeGrowthGlobal1X128 : state.feeGrowthGlobalX128),
cache.secondsPerLiquidityCumulativeX128,
cache.tickCumulative,
cache.blockTimestamp
);
int128 liquidityNet =
ticks.cross(
step.tickNext,
(zeroForOne ? state.feeGrowthGlobalX128 : feeGrowthGlobal0X128),
(zeroForOne ? feeGrowthGlobal1X128 : state.feeGrowthGlobalX128),
cache.secondsPerLiquidityCumulativeX128,
cache.tickCumulative,
cache.blockTimestamp
);
// if we're moving leftward, we interpret liquidityNet as the opposite sign
// safe because liquidityNet cannot be type(int128).min
if (zeroForOne) liquidityNet = -liquidityNet;
Expand All @@ -733,14 +731,15 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {

// update tick and write an oracle entry if the tick change
if (state.tick != slot0Start.tick) {
(uint16 observationIndex, uint16 observationCardinality) = observations.write(
slot0Start.observationIndex,
cache.blockTimestamp,
slot0Start.tick,
cache.liquidityStart,
slot0Start.observationCardinality,
slot0Start.observationCardinalityNext
);
(uint16 observationIndex, uint16 observationCardinality) =
observations.write(
slot0Start.observationIndex,
cache.blockTimestamp,
slot0Start.tick,
cache.liquidityStart,
slot0Start.observationCardinality,
slot0Start.observationCardinalityNext
);
(slot0.sqrtPriceX96, slot0.tick, slot0.observationIndex, slot0.observationCardinality) = (
state.sqrtPriceX96,
state.tick,
Expand Down
11 changes: 2 additions & 9 deletions contracts/libraries/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,8 @@ library Oracle {

uint32 target = time - secondsAgo;

(Observation memory beforeOrAt, Observation memory atOrAfter) = getSurroundingObservations(
self,
time,
target,
tick,
index,
liquidity,
cardinality
);
(Observation memory beforeOrAt, Observation memory atOrAfter) =
getSurroundingObservations(self, time, target, tick, index, liquidity, cardinality);

if (target == beforeOrAt.blockTimestamp) {
// we're at the left boundary
Expand Down
22 changes: 16 additions & 6 deletions contracts/libraries/Position.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ library Position {
}

// calculate accumulated fees
uint128 tokensOwed0 = uint128(
FullMath.mulDiv(feeGrowthInside0X128 - _self.feeGrowthInside0LastX128, _self.liquidity, FixedPoint128.Q128)
);
uint128 tokensOwed1 = uint128(
FullMath.mulDiv(feeGrowthInside1X128 - _self.feeGrowthInside1LastX128, _self.liquidity, FixedPoint128.Q128)
);
uint128 tokensOwed0 =
uint128(
FullMath.mulDiv(
feeGrowthInside0X128 - _self.feeGrowthInside0LastX128,
_self.liquidity,
FixedPoint128.Q128
)
);
uint128 tokensOwed1 =
uint128(
FullMath.mulDiv(
feeGrowthInside1X128 - _self.feeGrowthInside1LastX128,
_self.liquidity,
FixedPoint128.Q128
)
);

// update the position
if (liquidityDelta != 0) self.liquidity = liquidityNext;
Expand Down
Loading

0 comments on commit c5ccf4d

Please sign in to comment.