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

Optimization/weekly 0328 #9

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
109043
108918
Original file line number Diff line number Diff line change
@@ -1 +1 @@
92267
90480
Original file line number Diff line number Diff line change
@@ -1 +1 @@
67459
65672
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151014
149227
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68638
66851
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54221
52432
Original file line number Diff line number Diff line change
@@ -1 +1 @@
970211
968422
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121725
119936
Original file line number Diff line number Diff line change
@@ -1 +1 @@
339401
337612
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56462
54673
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93238
91450
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95223
93435
Original file line number Diff line number Diff line change
@@ -1 +1 @@
74667
72879
Original file line number Diff line number Diff line change
@@ -1 +1 @@
321109
319320
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41898
41503
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19774
19379
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37243
37118
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
39509
39114
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22897
22502
Original file line number Diff line number Diff line change
@@ -1 +1 @@
350592
348803
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61140
59351
Original file line number Diff line number Diff line change
@@ -1 +1 @@
243530
242396
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
84302
82513
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53609
52475
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36544
36547
Original file line number Diff line number Diff line change
@@ -1 +1 @@
43462
42329
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56609
54821
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104707
102919
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25044433
25042645
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36500
36021
Original file line number Diff line number Diff line change
@@ -1 +1 @@
103205
101418
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42150
41671
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36503
36024
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5496
5499
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19612
19217
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37494
37497
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29755
29360
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22061
21666
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#Vault.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7033
7180
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122519
120730
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158811
156938
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46974
45186
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46973
45185
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#testLock_NoOp.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11627
11232
Original file line number Diff line number Diff line change
@@ -1 +1 @@
72506
71681
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34113
33288
2 changes: 1 addition & 1 deletion src/libraries/FeeLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library FeeLibrary {
}

function isStaticFeeTooLarge(uint24 self, uint24 maxFee) internal pure returns (bool) {
return self & STATIC_FEE_MASK >= maxFee;
return self & STATIC_FEE_MASK > maxFee;
}

function getStaticFee(uint24 self) internal pure returns (uint24) {
Expand Down
11 changes: 8 additions & 3 deletions src/libraries/SettlementGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import {IVault} from "../interfaces/IVault.sol";
/// - 1: uint256 unsettledDeltasCount
/// - 2: mapping(address, mapping(Currency => int256)) currencyDelta
library SettlementGuard {
uint256 constant LOCKER_SLOT = uint256(keccak256("SETTLEMENT_LOCKER")) - 1;
uint256 constant UNSETTLED_DELTAS_COUNT = uint256(keccak256("SETTLEMENT_UNSETTLEMENTD_DELTAS_COUNT")) - 1;
uint256 constant CURRENCY_DELTA = uint256(keccak256("SETTLEMENT_CURRENCY_DELTA")) - 1;
// uint256 constant LOCKER_SLOT = uint256(keccak256("SETTLEMENT_LOCKER")) - 1;
uint256 constant LOCKER_SLOT = 0xedda7c051899c54dd66eaf5e13c031326ab4729812a579bed198ab93fd313d70;
Copy link
Collaborator

Choose a reason for hiding this comment

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

verified this on my end too 👍


// uint256 constant UNSETTLED_DELTAS_COUNT = uint256(keccak256("SETTLEMENT_UNSETTLEMENTD_DELTAS_COUNT")) - 1;
uint256 constant UNSETTLED_DELTAS_COUNT = 0xa88ffc6a483ae852b901fb1c3a0df606e2e4461b493434e6643ebdc3ffabd151;

// uint256 constant CURRENCY_DELTA = uint256(keccak256("SETTLEMENT_CURRENCY_DELTA")) - 1;
uint256 constant CURRENCY_DELTA = 0x6dc13502b9ba2a9e8e42c53a1856d632b29d5aab3bcb4a2476bfec06cbd9cf22;

function setLocker(address newLocker) internal {
address currentLocker = getLocker();
Expand Down
4 changes: 2 additions & 2 deletions src/pool-bin/BinPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload {
override
poolManagerMatch(address(key.poolManager))
{
/// @dev Accept up to FeeLibrary.TEN_PERCENT_FEE for fee. Add +1 as isStaticFeeTooLarge function checks >=
if (key.fee.isStaticFeeTooLarge(FeeLibrary.TEN_PERCENT_FEE + 1)) revert FeeTooLarge();
/// @dev Accept up to FeeLibrary.TEN_PERCENT_FEE for fee
if (key.fee.isStaticFeeTooLarge(FeeLibrary.TEN_PERCENT_FEE)) revert FeeTooLarge();

uint16 binStep = key.parameters.getBinStep();
if (binStep < MIN_BIN_STEP) revert BinStepTooSmall();
Expand Down
2 changes: 1 addition & 1 deletion src/pool-cl/CLPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {

function _fetchDynamicSwapFee(PoolKey memory key) internal view returns (uint24 dynamicSwapFee) {
dynamicSwapFee = ICLDynamicFeeManager(address(key.hooks)).getFee(msg.sender, key);
if (dynamicSwapFee >= FeeLibrary.ONE_HUNDRED_PERCENT_FEE) revert FeeTooLarge();
if (dynamicSwapFee > FeeLibrary.ONE_HUNDRED_PERCENT_FEE) revert FeeTooLarge();
}

function _checkPoolInitialized(PoolId id) internal view {
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/FeeLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ contract FeeLibraryTest is Test {
}

function testFuzzIsStaicFeeTooLarge(uint24 self, uint24 maxFee) public {
assertEq(FeeLibrary.getStaticFee(self) >= maxFee, FeeLibrary.isStaticFeeTooLarge(self, maxFee));
assertEq(FeeLibrary.getStaticFee(self) > maxFee, FeeLibrary.isStaticFeeTooLarge(self, maxFee));
}
}
8 changes: 4 additions & 4 deletions test/pool-cl/CLPoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ contract CLPoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot {
poolManager.initialize(key, TickMath.MIN_SQRT_RATIO, new bytes(0));
}

// 1000000 i.e. 100% overflow
// 1000000 i.e. 100% + 1 overflow
{
PoolKey memory key = PoolKey({
currency0: Currency.wrap(makeAddr("token0")),
currency1: Currency.wrap(makeAddr("token1")),
hooks: IHooks(address(0)),
poolManager: poolManager,
fee: uint24(1000000),
fee: uint24(1000001),
parameters: bytes32(uint256(0xa0000))
});

Expand Down Expand Up @@ -300,7 +300,7 @@ contract CLPoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot {
key.hooks = IHooks(address(0));
key.poolManager = poolManager;

if (key.fee & FeeLibrary.STATIC_FEE_MASK >= FeeLibrary.ONE_HUNDRED_PERCENT_FEE) {
if (key.fee & FeeLibrary.STATIC_FEE_MASK > FeeLibrary.ONE_HUNDRED_PERCENT_FEE) {
vm.expectRevert(abi.encodeWithSelector(IFees.FeeTooLarge.selector));
poolManager.initialize(key, sqrtPriceX96, ZERO_BYTES);
} else if (key.parameters.getTickSpacing() > poolManager.MAX_TICK_SPACING()) {
Expand Down Expand Up @@ -2339,7 +2339,7 @@ contract CLPoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot {
parameters: bytes32(uint256(10) << 16)
});

clFeeManagerHook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE);
clFeeManagerHook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1);

vm.expectRevert(IFees.FeeTooLarge.selector);
poolManager.updateDynamicSwapFee(key);
Expand Down
6 changes: 3 additions & 3 deletions test/pool-cl/libraries/CLPoolSwapFee.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ contract CLPoolSwapFeeTest is Deployers, TokenFixture, Test {

function testPoolInitializeFailsWithTooLargeFee() public {
// cl pool swap fee is capped at 1_000_000
hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE);
hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1);

vm.expectRevert(IFees.FeeTooLarge.selector);
poolManager.initialize(dynamicFeeKey, SQRT_RATIO_1_1, ZERO_BYTES);

{
vm.expectRevert(IFees.FeeTooLarge.selector);
staticFeeKey.fee = FeeLibrary.ONE_HUNDRED_PERCENT_FEE;
staticFeeKey.fee = FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1;
poolManager.initialize(staticFeeKey, SQRT_RATIO_1_1, ZERO_BYTES);
}
}
Expand All @@ -95,7 +95,7 @@ contract CLPoolSwapFeeTest is Deployers, TokenFixture, Test {
hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE / 2);
poolManager.initialize(dynamicFeeKey, SQRT_RATIO_1_1, ZERO_BYTES);

hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE);
hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1);
vm.expectRevert(IFees.FeeTooLarge.selector);
poolManager.updateDynamicSwapFee(dynamicFeeKey);
}
Expand Down
Loading