Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add solc binaries and transient storage lock library #395

Merged
merged 13 commits into from
Nov 14, 2023
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
FOUNDRY_FUZZ_SEED=0x4444

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
FOUNDRY_SOLC="./bin/solc-static-linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
FOUNDRY_SOLC="./bin/solc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to solc-mac for clarity

fi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
197447
172021
2 changes: 1 addition & 1 deletion .forge-snapshots/cached dynamic fee, no hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
184082
158656
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 @@
95906
76947
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 @@
153271
134745
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 @@
25011
25033
2 changes: 1 addition & 1 deletion .forge-snapshots/gas overhead of no-op lock.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58439
14918
2 changes: 1 addition & 1 deletion .forge-snapshots/initialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38079
38101
2 changes: 1 addition & 1 deletion .forge-snapshots/mint with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
307014
264055
2 changes: 1 addition & 1 deletion .forge-snapshots/mint with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
275044
232085
2 changes: 1 addition & 1 deletion .forge-snapshots/mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
293680
250721
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 @@
36677
36699
2 changes: 1 addition & 1 deletion .forge-snapshots/poolManager bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24366
24630
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151298
129248
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124939
106413
2 changes: 1 addition & 1 deletion .forge-snapshots/swap against liquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
109627
91101
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn claim for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126356
107809
1 change: 0 additions & 1 deletion .forge-snapshots/swap mint 1155 as output.snap

This file was deleted.

2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint output as claim.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
166380
147831
1 change: 0 additions & 1 deletion .forge-snapshots/swap with 1155 as input.snap

This file was deleted.

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 @@
196682
171256
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
109605
91079
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 @@
203277
177851
309 changes: 160 additions & 149 deletions .gas-snapshot

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ All contributions must follow the below standards. Maintainers will close out PR

## Setup

Run `source .env` to set FOUNDRY_SOLC to the correct solc binary.

`forge build` to get contract artifacts and dependencies for forge

## Tests
Expand Down
Binary file added bin/solc
Binary file not shown.
Binary file added bin/solc-static-linux
Binary file not shown.
6 changes: 5 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ optimizer_runs = 800
via_ir = false
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}, { access = "read", path = "./out"}]
evm_version = 'paris'
cancun = true

[profile.default.fuzz]
runs = 100
Expand All @@ -13,4 +13,8 @@ seed = "0x4444"
[profile.ci.fuzz]
runs = 1000

[profile.ci]
fuzz_runs = 100000
solc = "./bin/solc-static-linux"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait so does the other one only work on mac? thats awk for people who run non-mac locally

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there are different binaries for diff machines :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we made .env set the solc binary environment variable depending on os?
something like

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
        FOUNDRY_SOLC = ...
elif [[ "$OSTYPE" == "darwin"* ]]; then
        FOUNDRY_SOLC = ...
else
        # Unknown.
fi

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows users have questions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if youre a windows user can you echo $OSTYPE so we know what to put? I think its "win32" but not sure


# See more config options https://github.com/foundry-rs/foundry/tree/master/config
34 changes: 19 additions & 15 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {Position} from "./libraries/Position.sol";
import {FeeLibrary} from "./libraries/FeeLibrary.sol";
import {Currency, CurrencyLibrary} from "./types/Currency.sol";
import {PoolKey} from "./types/PoolKey.sol";
import {LockDataLibrary} from "./libraries/LockDataLibrary.sol";
import {NoDelegateCall} from "./NoDelegateCall.sol";
import {Owned} from "./Owned.sol";
import {IHooks} from "./interfaces/IHooks.sol";
Expand All @@ -20,6 +19,7 @@ import {Fees} from "./Fees.sol";
import {Claims} from "./Claims.sol";
import {PoolId, PoolIdLibrary} from "./types/PoolId.sol";
import {BalanceDelta} from "./types/BalanceDelta.sol";
import {Lockers} from "./libraries/Lockers.sol";

/// @notice Holds the state for all pools
contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {
Expand All @@ -29,7 +29,6 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {
using Hooks for IHooks;
using Position for mapping(bytes32 => Position.Info);
using CurrencyLibrary for Currency;
using LockDataLibrary for IPoolManager.LockData;
using FeeLibrary for uint24;

/// @inheritdoc IPoolManager
Expand All @@ -38,9 +37,6 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {
/// @inheritdoc IPoolManager
int24 public constant override MIN_TICK_SPACING = 1;

/// @inheritdoc IPoolManager
IPoolManager.LockData public override lockData;

/// @dev Represents the currencies due/owed to each locker.
/// Must all net to zero when the last lock is released.
mapping(address locker => mapping(Currency currency => int256 currencyDelta)) public currencyDelta;
Expand Down Expand Up @@ -94,7 +90,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {

/// @inheritdoc IPoolManager
function getLock(uint256 i) external view override returns (address locker) {
return LockDataLibrary.getLock(i);
return Lockers.getLocker(i);
}

/// @inheritdoc IPoolManager
Expand Down Expand Up @@ -139,31 +135,31 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {

/// @inheritdoc IPoolManager
function lock(bytes calldata data) external override returns (bytes memory result) {
lockData.push(msg.sender);
Lockers.push(msg.sender);

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

if (lockData.length == 1) {
if (lockData.nonzeroDeltaCount != 0) revert CurrencyNotSettled();
delete lockData;
if (Lockers.length() == 1) {
if (Lockers.nonzeroDeltaCount() != 0) revert CurrencyNotSettled();
Lockers.clear();
} else {
lockData.pop();
Lockers.pop();
}
}

function _accountDelta(Currency currency, int128 delta) internal {
if (delta == 0) return;

address locker = lockData.getActiveLock();
address locker = Lockers.getCurrentLocker();
int256 current = currencyDelta[locker][currency];
int256 next = current + delta;

unchecked {
if (next == 0) {
lockData.nonzeroDeltaCount--;
Lockers.decrementNonzeroDeltaCount();
} else if (current == 0) {
lockData.nonzeroDeltaCount++;
Lockers.incrementNonzeroDeltaCount();
}
}

Expand All @@ -177,7 +173,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {
}

modifier onlyByLocker() {
address locker = lockData.getActiveLock();
address locker = Lockers.getCurrentLocker();
if (msg.sender != locker) revert LockedBy(locker);
_;
}
Expand Down Expand Up @@ -388,6 +384,14 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {
return value;
}

function getLockLength() external view returns (uint256 _length) {
return Lockers.length();
}

function getLockNonzeroDeltaCount() external view returns (uint256 _nonzeroDeltaCount) {
return Lockers.nonzeroDeltaCount();
}

/// @notice receive native tokens for native pools
receive() external payable {}
}
15 changes: 5 additions & 10 deletions src/interfaces/IPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,14 @@ interface IPoolManager is IFees, IClaims {
/// @notice Returns the reserves for a given ERC20 currency
function reservesOf(Currency currency) external view returns (uint256);

/// @notice Contains data about pool lockers.
struct LockData {
/// @notice The current number of active lockers
uint128 length;
/// @notice The total number of nonzero deltas over all active + completed lockers
uint128 nonzeroDeltaCount;
}

/// @notice Returns the locker in the ith position of the locker queue.
function getLock(uint256 i) external view returns (address locker);

/// @notice Returns lock data
function lockData() external view returns (uint128 length, uint128 nonzeroDeltaCount);
/// @notice Returns the length of the lockers array, which is the number of locks open on the PoolManager.
function getLockLength() external view returns (uint256 _length);

/// @notice Returns the number of nonzero deltas open on the PoolManager that must be zerod by the close of the initial lock.
function getLockNonzeroDeltaCount() external view returns (uint256 _nonzeroDeltaCount);

/// @notice Initialize the state for a given pool ID
function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData)
Expand Down
50 changes: 0 additions & 50 deletions src/libraries/LockDataLibrary.sol

This file was deleted.

Loading
Loading