Skip to content

Commit

Permalink
Using a fork of the transpiler that supports transient storage
Browse files Browse the repository at this point in the history
Compiler can be found here: ethereum/solidity#14957
Commit: Amxx/solidity@f2c760e
  • Loading branch information
Amxx committed Mar 29, 2024
1 parent 1dda6f5 commit e8e408e
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 207 deletions.
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 @@
309389
262287
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 @@
184232
138862
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
189549
144179
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 @@
125296
100096
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 @@
172155
126977
2 changes: 1 addition & 1 deletion .forge-snapshots/initialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51816
51331
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22909
22632
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 @@
96164
54782
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 @@
192350
146968
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
193814
148432
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 @@
176897
131463
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
190773
145339
Original file line number Diff line number Diff line change
@@ -1 +1 @@
112356
70922
2 changes: 1 addition & 1 deletion .forge-snapshots/swap against liquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
100359
58925
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 @@
120473
79039
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 @@
116428
74994
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 @@
182756
137322
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 @@
199565
154131
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 @@
133664
88230
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
100337
58903
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 @@
184666
138404
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ optimizer_runs = 800
via_ir = false
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}, { access = "read", path = "./out"}]
solc = "0.8.24"
#solc = "0.8.24"
solc = "/home/amxx/Work/Repos/solidity/build/solc/solc"
evm_version = "cancun"

[profile.default.fuzz]
Expand Down
35 changes: 18 additions & 17 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {ProtocolFees} from "./ProtocolFees.sol";
import {ERC6909Claims} from "./ERC6909Claims.sol";
import {PoolId, PoolIdLibrary} from "./types/PoolId.sol";
import {BalanceDelta, BalanceDeltaLibrary} from "./types/BalanceDelta.sol";
import {Lock} from "./libraries/Lock.sol";
import {NonZeroDeltaCount} from "./libraries/NonZeroDeltaCount.sol";
import {PoolGetters} from "./libraries/PoolGetters.sol";

/// @notice Holds the state for all pools
Expand All @@ -28,11 +26,14 @@ 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.Info);
using CurrencyLibrary for Currency;
using SwapFeeLibrary for uint24;
using PoolGetters for Pool.State;

bool transient private unlocked;
uint256 transient private nonZeroDeltaCount;

/// @inheritdoc IPoolManager
int24 public constant MAX_TICK_SPACING = TickMath.MAX_TICK_SPACING;

Expand All @@ -41,8 +42,7 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim

/// @dev Represents the currencies due/owed to each caller.
/// Must all net to zero when manager gets locked again
/// TODO this needs to be transient
mapping(address caller => mapping(Currency currency => int256 currencyDelta)) public currencyDelta;
mapping(address caller => mapping(Currency currency => int256 currencyDelta)) transient public currencyDelta;

/// @inheritdoc IPoolManager
mapping(Currency currency => uint256) public override reservesOf;
Expand Down Expand Up @@ -75,7 +75,7 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim
override
returns (uint128 liquidity)
{
return pools[id].positions.get(_owner, tickLower, tickUpper).liquidity;
return Position.get(pools[id].positions, _owner, tickLower, tickUpper).liquidity;
}

function getPosition(PoolId id, address _owner, int24 tickLower, int24 tickUpper)
Expand All @@ -84,16 +84,16 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim
override
returns (Position.Info memory position)
{
return pools[id].positions.get(_owner, tickLower, tickUpper);
return Position.get(pools[id].positions, _owner, tickLower, tickUpper);
}

function isUnlocked() external view override returns (bool) {
return Lock.isUnlocked();
function isUnlocked() public view override returns (bool) {
return unlocked;
}

/// @notice This will revert if the contract is locked
modifier onlyWhenUnlocked() {
if (!Lock.isUnlocked()) revert ManagerLocked();
if (!isUnlocked()) revert ManagerLocked();
_;
}

Expand Down Expand Up @@ -126,15 +126,16 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim

/// @inheritdoc IPoolManager
function unlock(bytes calldata data) external override returns (bytes memory result) {
if (Lock.isUnlocked()) revert AlreadyUnlocked();
if (isUnlocked()) revert AlreadyUnlocked();

Lock.unlock();
unlocked = true;

// the caller does everything in this callback, including paying what they owe via calls to settle
result = IUnlockCallback(msg.sender).unlockCallback(data);

if (NonZeroDeltaCount.read() != 0) revert CurrencyNotSettled();
Lock.lock();
if (nonZeroDeltaCount != 0) revert CurrencyNotSettled();

unlocked = false;
}

function _accountDelta(Currency currency, int128 delta) internal {
Expand All @@ -145,9 +146,9 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim

unchecked {
if (next == 0) {
NonZeroDeltaCount.decrement();
nonZeroDeltaCount -= 1;
} else if (current == 0) {
NonZeroDeltaCount.increment();
nonZeroDeltaCount += 1;
}
}

Expand Down Expand Up @@ -330,7 +331,7 @@ contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claim
}

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

function getPoolTickInfo(PoolId id, int24 tick) external view returns (Pool.TickInfo memory) {
Expand Down
33 changes: 0 additions & 33 deletions src/libraries/Lock.sol

This file was deleted.

39 changes: 0 additions & 39 deletions src/libraries/NonZeroDeltaCount.sol

This file was deleted.

12 changes: 6 additions & 6 deletions src/libraries/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {BalanceDelta, toBalanceDelta} from "../types/BalanceDelta.sol";

library Pool {
using SafeCast for *;
using TickBitmap for mapping(int16 => uint256);
using Position for mapping(bytes32 => Position.Info);
// using TickBitmap for mapping(int16 => uint256);
// using Position for mapping(bytes32 => Position.Info);
using Position for Position.Info;
using Pool for State;

Expand Down Expand Up @@ -180,17 +180,17 @@ library Pool {
}

if (state.flippedLower) {
self.tickBitmap.flipTick(params.tickLower, params.tickSpacing);
TickBitmap.flipTick(self.tickBitmap, params.tickLower, params.tickSpacing);
}
if (state.flippedUpper) {
self.tickBitmap.flipTick(params.tickUpper, params.tickSpacing);
TickBitmap.flipTick(self.tickBitmap, params.tickUpper, params.tickSpacing);
}
}

(state.feeGrowthInside0X128, state.feeGrowthInside1X128) =
getFeeGrowthInside(self, params.tickLower, params.tickUpper);

(feesOwed0, feesOwed1) = self.positions.get(params.owner, params.tickLower, params.tickUpper).update(
(feesOwed0, feesOwed1) = Position.get(self.positions, params.owner, params.tickLower, params.tickUpper).update(
params.liquidityDelta, state.feeGrowthInside0X128, state.feeGrowthInside1X128
);

Expand Down Expand Up @@ -343,7 +343,7 @@ library Pool {
step.sqrtPriceStartX96 = state.sqrtPriceX96;

(step.tickNext, step.initialized) =
self.tickBitmap.nextInitializedTickWithinOneWord(state.tick, params.tickSpacing, params.zeroForOne);
TickBitmap.nextInitializedTickWithinOneWord(self.tickBitmap, state.tick, params.tickSpacing, params.zeroForOne);

// ensure that we do not overshoot the min/max tick, as the tick bitmap is not aware of these bounds
if (step.tickNext < TickMath.MIN_TICK) {
Expand Down
1 change: 0 additions & 1 deletion src/test/MockERC6909Claims.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {ERC6909Claims} from "../ERC6909Claims.sol";
import {CurrencyLibrary, Currency} from "../types/Currency.sol";

Expand Down
19 changes: 0 additions & 19 deletions test/Lock.t.sol

This file was deleted.

0 comments on commit e8e408e

Please sign in to comment.