From 55ea6cb224c42ad9c39a96ec698f8b786d89bf24 Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Fri, 30 Aug 2024 00:44:02 -0400 Subject: [PATCH 1/2] response to 848 comments --- src/PoolManager.sol | 2 +- src/libraries/Pool.sol | 12 ++++++------ src/libraries/Position.sol | 10 +++++----- src/libraries/StateLibrary.sol | 8 ++++---- src/test/ProxyPoolManager.sol | 2 +- test/libraries/Position.t.sol | 12 ++++++------ 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/PoolManager.sol b/src/PoolManager.sol index 7b117eae1..3385943ce 100644 --- a/src/PoolManager.sol +++ b/src/PoolManager.sol @@ -81,7 +81,7 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim using SafeCast for *; using Pool for *; using Hooks for IHooks; - using Position for mapping(bytes32 => Position.Info); + using Position for mapping(bytes32 => Position.State); using CurrencyDelta for Currency; using LPFeeLibrary for uint24; using CurrencyReserves for Currency; diff --git a/src/libraries/Pool.sol b/src/libraries/Pool.sol index b6395d758..522efc1d2 100644 --- a/src/libraries/Pool.sol +++ b/src/libraries/Pool.sol @@ -20,8 +20,8 @@ import {CustomRevert} from "./CustomRevert.sol"; library Pool { using SafeCast for *; using TickBitmap for mapping(int16 => uint256); - using Position for mapping(bytes32 => Position.Info); - using Position for Position.Info; + using Position for mapping(bytes32 => Position.State); + using Position for Position.State; using Pool for State; using ProtocolFeeLibrary for *; using LPFeeLibrary for uint24; @@ -84,7 +84,7 @@ library Pool { uint128 liquidity; mapping(int24 => TickInfo) ticks; mapping(int16 => uint256) tickBitmap; - mapping(bytes32 => Position.Info) positions; + mapping(bytes32 => Position.State) positions; } /// @dev Common checks for valid tick inputs. @@ -184,7 +184,7 @@ library Pool { (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = getFeeGrowthInside(self, tickLower, tickUpper); - Position.Info storage position = self.positions.get(params.owner, tickLower, tickUpper, params.salt); + Position.State storage position = self.positions.get(params.owner, tickLower, tickUpper, params.salt); (uint256 feesOwed0, uint256 feesOwed1) = position.update(liquidityDelta, feeGrowthInside0X128, feeGrowthInside1X128); @@ -237,9 +237,9 @@ library Pool { } } - // the results after a swap, written to storage and returned + // Tracks the state of a pool throughout a swap, and bubbles these values up at the end of the swap struct SwapResult { - // the final current sqrt(price) + // the final sqrt(price) uint160 sqrtPriceX96; // the tick associated with the current price int24 tick; diff --git a/src/libraries/Position.sol b/src/libraries/Position.sol index d72bcb308..40821ae31 100644 --- a/src/libraries/Position.sol +++ b/src/libraries/Position.sol @@ -16,7 +16,7 @@ library Position { error CannotUpdateEmptyPosition(); // info stored for each user's position - struct Info { + struct State { // the amount of liquidity owned by this position uint128 liquidity; // fee growth per unit of liquidity as of the last update to liquidity or fees owed @@ -24,17 +24,17 @@ library Position { uint256 feeGrowthInside1LastX128; } - /// @notice Returns the Info struct of a position, given an owner and position boundaries + /// @notice Returns the State struct of a position, given an owner and position boundaries /// @param self The mapping containing all user positions /// @param owner The address of the position owner /// @param tickLower The lower tick boundary of the position /// @param tickUpper The upper tick boundary of the position /// @param salt A unique value to differentiate between multiple positions in the same range /// @return position The position info struct of the given owners' position - function get(mapping(bytes32 => Info) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt) + function get(mapping(bytes32 => State) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt) internal view - returns (Info storage position) + returns (State storage position) { bytes32 positionKey = calculatePositionKey(owner, tickLower, tickUpper, salt); position = self[positionKey]; @@ -74,7 +74,7 @@ library Position { /// @return feesOwed0 The amount of currency0 owed to the position owner /// @return feesOwed1 The amount of currency1 owed to the position owner function update( - Info storage self, + State storage self, int128 liquidityDelta, uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128 diff --git a/src/libraries/StateLibrary.sol b/src/libraries/StateLibrary.sol index c884a07b0..5edb930ed 100644 --- a/src/libraries/StateLibrary.sol +++ b/src/libraries/StateLibrary.sol @@ -24,7 +24,7 @@ library StateLibrary { /// @notice index of tickBitmap mapping in Pool.State uint256 public constant TICK_BITMAP_OFFSET = 5; - /// @notice index of Position.Info mapping in Pool.State: mapping(bytes32 => Position.Info) positions; + /// @notice index of Position.State mapping in Pool.State: mapping(bytes32 => Position.State) positions; uint256 public constant POSITIONS_OFFSET = 6; /** @@ -255,7 +255,7 @@ library StateLibrary { { bytes32 slot = _getPositionInfoSlot(poolId, positionId); - // read all 3 words of the Position.Info struct + // read all 3 words of the Position.State struct bytes32[] memory data = manager.extsload(slot, 3); assembly ("memory-safe") { @@ -284,7 +284,7 @@ library StateLibrary { /** * @notice Calculate the fee growth inside a tick range of a pool - * @dev pools[poolId].feeGrowthInside0LastX128 in Position.Info is cached and can become stale. This function will calculate the up to date feeGrowthInside + * @dev pools[poolId].feeGrowthInside0LastX128 in Position.State is cached and can become stale. This function will calculate the up to date feeGrowthInside * @param manager The pool manager contract. * @param poolId The ID of the pool. * @param tickLower The lower tick of the range. @@ -337,7 +337,7 @@ library StateLibrary { // slot key of Pool.State value: `pools[poolId]` bytes32 stateSlot = _getPoolStateSlot(poolId); - // Pool.State: `mapping(bytes32 => Position.Info) positions;` + // Pool.State: `mapping(bytes32 => Position.State) positions;` bytes32 positionMapping = bytes32(uint256(stateSlot) + POSITIONS_OFFSET); // slot of the mapping key: `pools[poolId].positions[positionId] diff --git a/src/test/ProxyPoolManager.sol b/src/test/ProxyPoolManager.sol index 4eac21b30..cdd6249b6 100644 --- a/src/test/ProxyPoolManager.sol +++ b/src/test/ProxyPoolManager.sol @@ -32,7 +32,7 @@ contract ProxyPoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909 using SafeCast for *; using Pool for *; using Hooks for IHooks; - using Position for mapping(bytes32 => Position.Info); + using Position for mapping(bytes32 => Position.State); using CurrencyDelta for Currency; using LPFeeLibrary for uint24; using CurrencyReserves for Currency; diff --git a/test/libraries/Position.t.sol b/test/libraries/Position.t.sol index 35a634669..0bb1cfff1 100644 --- a/test/libraries/Position.t.sol +++ b/test/libraries/Position.t.sol @@ -6,14 +6,14 @@ import {Position} from "../../src/libraries/Position.sol"; import {SafeCast} from "../../src/libraries/SafeCast.sol"; contract PositionTest is Test { - using Position for mapping(bytes32 => Position.Info); + using Position for mapping(bytes32 => Position.State); - mapping(bytes32 => Position.Info) internal positions; + mapping(bytes32 => Position.State) internal positions; function test_fuzz_get(address owner, int24 tickLower, int24 tickUpper, bytes32 salt) public view { bytes32 positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt)); - Position.Info storage expectedPosition = positions[positionKey]; - Position.Info storage position = positions.get(owner, tickLower, tickUpper, salt); + Position.State storage expectedPosition = positions[positionKey]; + Position.State storage position = positions.get(owner, tickLower, tickUpper, salt); bytes32 expectedPositionSlot; bytes32 positionSlot; assembly ("memory-safe") { @@ -25,11 +25,11 @@ contract PositionTest is Test { function test_fuzz_update( int128 liquidityDelta, - Position.Info memory pos, + Position.State memory pos, uint256 newFeeGrowthInside0X128, uint256 newFeeGrowthInside1X128 ) public { - Position.Info storage position = positions[0]; + Position.State storage position = positions[0]; position.liquidity = pos.liquidity; position.feeGrowthInside0LastX128 = pos.feeGrowthInside0LastX128; position.feeGrowthInside1LastX128 = pos.feeGrowthInside1LastX128; From 6aea4e018f17f8a2499c788cac547a06d6f0cb2b Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Fri, 30 Aug 2024 12:59:35 -0400 Subject: [PATCH 2/2] pr comments --- src/libraries/Pool.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/Pool.sol b/src/libraries/Pool.sol index 522efc1d2..af85824a7 100644 --- a/src/libraries/Pool.sol +++ b/src/libraries/Pool.sol @@ -237,9 +237,9 @@ library Pool { } } - // Tracks the state of a pool throughout a swap, and bubbles these values up at the end of the swap + // Tracks the state of a pool throughout a swap, and returns these values at the end of the swap struct SwapResult { - // the final sqrt(price) + // the current sqrt(price) uint160 sqrtPriceX96; // the tick associated with the current price int24 tick;