Skip to content

Commit

Permalink
Merge branch 'main' into isomorphic-slot0
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed May 16, 2024
2 parents 584e4c1 + 7d97026 commit aa3872b
Show file tree
Hide file tree
Showing 73 changed files with 1,345 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/SwapMath_oneForZero_exactInPartial.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3038
3016
2 changes: 1 addition & 1 deletion .forge-snapshots/SwapMath_oneForZero_exactOutPartial.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3278
3256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151192
153643
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity CA fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
329534
331825
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
284169
286600
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141325
143853
Original file line number Diff line number Diff line change
@@ -1 +1 @@
299696
302147
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 1 token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
108696
107894
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 2 tokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149234
148384
2 changes: 1 addition & 1 deletion .forge-snapshots/erc20 collect protocol fees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57354
57275
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getFeeGrowthGlobals.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1344
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getFeeGrowthInside.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
446
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getLiquidity.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
446
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getPositionInfo.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1606
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getPositionLiquidity.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
446
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getSlot0.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
446
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getTickBitmap.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
446
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getTickFeeGrowthOutside.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1344
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getTickInfo.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1606
1 change: 1 addition & 0 deletions .forge-snapshots/extsload getTickLiquidity.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
446
Original file line number Diff line number Diff line change
@@ -1 +1 @@
594
572
Original file line number Diff line number Diff line change
@@ -1 +1 @@
878
856
1 change: 1 addition & 0 deletions .forge-snapshots/getReserves.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1198
2 changes: 1 addition & 1 deletion .forge-snapshots/initialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61953
61910
2 changes: 1 addition & 1 deletion .forge-snapshots/native collect protocol fees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
59587
59520
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23521
21967
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity CA fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185045
187291
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121063
123469
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117838
120256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
104932
1 change: 1 addition & 0 deletions .forge-snapshots/simple addLiquidity.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
167750
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
98529
1 change: 1 addition & 0 deletions .forge-snapshots/simple removeLiquidity.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
90895
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap with native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117124
117047
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132363
132208
2 changes: 1 addition & 1 deletion .forge-snapshots/swap CA custom curve + swap noop.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135694
134601
2 changes: 1 addition & 1 deletion .forge-snapshots/swap CA fee on unspecified.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
184630
183536
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113577
112672
2 changes: 1 addition & 1 deletion .forge-snapshots/swap against liquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124998
124015
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn 6909 for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136994
136056
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn native 6909 for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126100
125196
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint native output as 6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148172
147245
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint output as 6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
164987
164062
Original file line number Diff line number Diff line change
@@ -1 +1 @@
224263
222579
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with dynamic fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149254
148263
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125010
124027
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with lp fee and protocol fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181553
180495
2 changes: 1 addition & 1 deletion .forge-snapshots/update dynamic fee in before swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
159796
158738
7 changes: 6 additions & 1 deletion src/Extsload.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {IExtsload} from "./interfaces/IExtsload.sol";
/// @notice Enables public storage access for efficient state retrieval by external contracts.
/// https://eips.ethereum.org/EIPS/eip-2330#rationale
abstract contract Extsload is IExtsload {
/// @inheritdoc IExtsload
function extsload(bytes32 slot) external view returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
value := sload(slot)
}
}

/// @inheritdoc IExtsload
function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes memory) {
bytes memory value = new bytes(32 * nSlots);

Expand All @@ -26,8 +28,11 @@ abstract contract Extsload is IExtsload {
return value;
}

/// @dev since the function is external and enters a new call context and exits right after execution, Solidity's memory management convention can be disregarded and a direct slice of memory can be returned
/// @inheritdoc IExtsload
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory) {
// since the function is external and enters a new call context and exits right
// after execution, Solidity's memory management convention can be disregarded
// and a direct slice of memory can be returned
assembly ("memory-safe") {
// abi offset for dynamic array
mstore(0, 0x20)
Expand Down
38 changes: 38 additions & 0 deletions src/Exttload.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import {IExttload} from "./interfaces/IExttload.sol";

/// @notice Enables public transient storage access for efficient state retrieval by external contracts.
/// https://eips.ethereum.org/EIPS/eip-2330#rationale
abstract contract Exttload is IExttload {
/// @inheritdoc IExttload
function exttload(bytes32 slot) external view returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}

/// @inheritdoc IExttload
function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory) {
// since the function is external and enters a new call context and exits right
// after execution, Solidity's memory management convention can be disregarded
// and a direct slice of memory can be returned
assembly ("memory-safe") {
// abi offset for dynamic array
mstore(0, 0x20)
mstore(0x20, slots.length)
let end := add(0x40, shl(5, slots.length))
let memptr := 0x40
let calldataptr := slots.offset
for {} 1 {} {
mstore(memptr, tload(calldataload(calldataptr)))
memptr := add(memptr, 0x20)
calldataptr := add(calldataptr, 0x20)
if iszero(lt(memptr, end)) { break }
}
return(0, end)
}
}
}
77 changes: 4 additions & 73 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {NonZeroDeltaCount} from "./libraries/NonZeroDeltaCount.sol";
import {PoolGetters} from "./libraries/PoolGetters.sol";
import {Reserves} from "./libraries/Reserves.sol";
import {Extsload} from "./Extsload.sol";
import {Exttload} from "./Exttload.sol";

// 4
// 44
Expand Down Expand Up @@ -74,7 +75,8 @@ import {Extsload} from "./Extsload.sol";
// 44444 444
// 444
/// @notice Holds the state for all pools
contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claims, Extsload {

contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claims, Extsload, Exttload {
using PoolIdLibrary for PoolKey;
using SafeCast for *;
using Pool for *;
Expand All @@ -92,60 +94,14 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim
/// @inheritdoc IPoolManager
int24 public constant MIN_TICK_SPACING = TickMath.MIN_TICK_SPACING;

mapping(PoolId id => Pool.State) public pools;
mapping(PoolId id => Pool.State) internal pools;

constructor(uint256 controllerGasLimit) ProtocolFees(controllerGasLimit) {}

function _getPool(PoolId id) internal view override returns (Pool.State storage) {
return pools[id];
}

/// @inheritdoc IPoolManager
function getSlot0(PoolId id)
external
view
override
returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)
{
Slot0 slot0 = pools[id].slot0;

return (slot0.sqrtPriceX96(), slot0.tick(), slot0.protocolFee(), slot0.lpFee());
}

/// @inheritdoc IPoolManager
function getLiquidity(PoolId id) external view override returns (uint128 liquidity) {
return pools[id].liquidity;
}

/// @inheritdoc IPoolManager
function getLiquidity(PoolId id, address _owner, int24 tickLower, int24 tickUpper, bytes32 salt)
external
view
override
returns (uint128 liquidity)
{
return pools[id].positions.get(_owner, tickLower, tickUpper, salt).liquidity;
}

function getPosition(PoolId id, address _owner, int24 tickLower, int24 tickUpper, bytes32 salt)
external
view
override
returns (Position.Info memory position)
{
return pools[id].positions.get(_owner, tickLower, tickUpper, salt);
}

/// @inheritdoc IPoolManager
function currencyDelta(address caller, Currency currency) external view returns (int256) {
return currency.getDelta(caller);
}

/// @inheritdoc IPoolManager
function isUnlocked() external view override returns (bool) {
return Lock.isUnlocked();
}

/// @notice This will revert if the contract is locked
modifier onlyWhenUnlocked() {
if (!Lock.isUnlocked()) revert ManagerLocked();
Expand Down Expand Up @@ -373,29 +329,4 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim
PoolId id = key.toId();
pools[id].setLPFee(newDynamicLPFee);
}

function getNonzeroDeltaCount() external view returns (uint256 _nonzeroDeltaCount) {
return NonZeroDeltaCount.read();
}

function getPoolTickInfo(PoolId id, int24 tick) external view returns (Pool.TickInfo memory) {
return pools[id].getPoolTickInfo(tick);
}

function getPoolBitmapInfo(PoolId id, int16 word) external view returns (uint256 tickBitmap) {
return pools[id].getPoolBitmapInfo(word);
}

/// @notice Temporary view function. Replaceable by transient EXTSLOAD.
function getReserves(Currency currency) external view returns (uint256 balance) {
return currency.getReserves();
}

function getFeeGrowthGlobals(PoolId id)
external
view
returns (uint256 feeGrowthGlobal0x128, uint256 feeGrowthGlobal1x128)
{
return pools[id].getFeeGrowthGlobals();
}
}
Loading

0 comments on commit aa3872b

Please sign in to comment.