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 d62c4c8
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with empty hook.snap
@@ -1 +1 @@
309389
262425
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with native token.snap
@@ -1 +1 @@
184232
139000
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity.snap
@@ -1 +1 @@
189549
144317
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 1 token.snap
@@ -1 +1 @@
125296
100189
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 2 tokens.snap
@@ -1 +1 @@
172155
127115
2 changes: 1 addition & 1 deletion .forge-snapshots/initialize.snap
@@ -1 +1 @@
51816
51331
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
@@ -1 +1 @@
22909
22790
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with empty hook.snap
@@ -1 +1 @@
96164
54920
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with native token.snap
@@ -1 +1 @@
192350
147106
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity.snap
@@ -1 +1 @@
193814
148570
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap with native.snap
@@ -1 +1 @@
176897
131601
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap.snap
@@ -1 +1 @@
190773
145477
@@ -1 +1 @@
112356
71060
2 changes: 1 addition & 1 deletion .forge-snapshots/swap against liquidity.snap
@@ -1 +1 @@
100359
59063
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn 6909 for input.snap
@@ -1 +1 @@
120473
79177
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn native 6909 for input.snap
@@ -1 +1 @@
116428
75132
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint native output as 6909.snap
@@ -1 +1 @@
182756
137460
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint output as 6909.snap
@@ -1 +1 @@
199565
154269
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with dynamic fee.snap
@@ -1 +1 @@
133664
88368
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
@@ -1 +1 @@
100337
59041
2 changes: 1 addition & 1 deletion .forge-snapshots/update dynamic fee in before swap.snap
@@ -1 +1 @@
184666
138542
3 changes: 2 additions & 1 deletion foundry.toml
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
20 changes: 20 additions & 0 deletions src/Lock.sol
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >0.8.25;

/// @notice This is a temporary library that allows us to use transient storage (tstore/tload)
/// TODO: This library can be deleted when we have the transient keyword support in solidity.
abstract contract Lock {
bool transient private unlocked;

function unlock() internal virtual {
unlocked = true;
}

function lock() internal virtual {
unlocked = false;
}

function isUnlocked() public view virtual returns (bool) {
return unlocked;
}
}
25 changes: 12 additions & 13 deletions src/PoolManager.sol
Expand Up @@ -18,17 +18,17 @@ 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 {Lock} from "./Lock.sol";
import {NonZeroDeltaCount} from "./libraries/NonZeroDeltaCount.sol";
import {PoolGetters} from "./libraries/PoolGetters.sol";

/// @notice Holds the state for all pools
contract PoolManager is IPoolManager, ProtocolFees, NoDelegateCall, ERC6909Claims {
contract PoolManager is IPoolManager, ProtocolFees, Lock, NoDelegateCall, ERC6909Claims {
using PoolIdLibrary for PoolKey;
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;
Expand All @@ -41,8 +41,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 +74,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 +83,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(IPoolManager, Lock) returns (bool) {
return super.isUnlocked();
}

/// @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 +125,15 @@ 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();
unlock();

// 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();
lock();
}

function _accountDelta(Currency currency, int128 delta) internal {
Expand Down
33 changes: 0 additions & 33 deletions src/libraries/Lock.sol

This file was deleted.

12 changes: 6 additions & 6 deletions src/libraries/Pool.sol
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
@@ -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
4 changes: 2 additions & 2 deletions test/Lock.t.sol
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {Lock} from "../src/libraries/Lock.sol";
import {Lock} from "../src/Lock.sol";

contract LockTest is Test {
contract LockTest is Test, Lock {
function test_lock() public {
assertFalse(Lock.isUnlocked());

Expand Down

0 comments on commit d62c4c8

Please sign in to comment.