Skip to content

Commit

Permalink
Merge branch 'main' into optimization/BalanceDelta
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed May 30, 2024
2 parents 615c996 + 2099560 commit 4dd78da
Show file tree
Hide file tree
Showing 64 changed files with 156 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181588
180685
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185653
184784
Original file line number Diff line number Diff line change
@@ -1 +1 @@
137576
137347
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
331429
331202
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
193689
192796
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138220
136931
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32575
32533
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148243
146635
Original file line number Diff line number Diff line change
@@ -1 +1 @@
296172
294227
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131429
130141
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120460
119261
Original file line number Diff line number Diff line change
@@ -1 +1 @@
977463
975902
Original file line number Diff line number Diff line change
@@ -1 +1 @@
339653
338092
Original file line number Diff line number Diff line change
@@ -1 +1 @@
343130
341673
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146073
144616
Original file line number Diff line number Diff line change
@@ -1 +1 @@
180414
179041
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186397
185024
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138837
137479
Original file line number Diff line number Diff line change
@@ -1 +1 @@
309646
308185
Original file line number Diff line number Diff line change
@@ -1 +1 @@
362836
360013
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178004
175181
Original file line number Diff line number Diff line change
@@ -1 +1 @@
248032
245159
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170799
168435
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114635
112267
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124115
121284
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141394
138632
Original file line number Diff line number Diff line change
@@ -1 +1 @@
174910
172143
Original file line number Diff line number Diff line change
@@ -1 +1 @@
161272
158546
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79336
76575
Original file line number Diff line number Diff line change
@@ -1 +1 @@
153550
150789
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
96143
93467
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79339
76578
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32291
32316
2 changes: 1 addition & 1 deletion .forge-snapshots/ExtsloadTest#extsloadInBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11374
11394
Original file line number Diff line number Diff line change
@@ -1 +1 @@
525
520
Original file line number Diff line number Diff line change
@@ -1 +1 @@
653
648
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2239
2234
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3029
3019
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1981
1976
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3029
3019
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2229
2224
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3182
3177
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1971
1966
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3182
3177
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1151
1159
2 changes: 1 addition & 1 deletion .forge-snapshots/TickTest#update.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134819
134827
Original file line number Diff line number Diff line change
@@ -1 +1 @@
81647
81469
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121653
121465
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45235
45057
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45234
45056
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#testLock_NoOp.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33260
33072
6 changes: 3 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[profile.default]
src = 'src'
out = 'foundry-out'
solc_version = '0.8.24'
solc_version = '0.8.26'
optimizer_runs = 800
via_ir = false
ffi = true
fs_permissions = [
{ access = "read-write", path = ".forge-snapshots/" },
{ access = "read", path = "./foundry-out" },
{ access = "read", path = "./script/config"},
{ access = "read", path = "./script/config" },
]
evm_version = 'cancun'

Expand All @@ -21,7 +21,7 @@ runs = 1000
runs = 10000

[profile.ci.invariant]
runs = 1000 # The number of calls to make in the invariant tests
runs = 1000 # The number of calls to make in the invariant tests
call_override = false # Override calls
fail_on_revert = false # Fail the test if the contract reverts

Expand Down
7 changes: 3 additions & 4 deletions src/libraries/LPFeeLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ library LPFeeLibrary {
error FeeTooLarge();

/// @dev the flag and mask
uint24 public constant FEE_MASK = 0x7FFFFF;
uint24 public constant OVERRIDE_MASK = 0xBFFFFF;

// the top bit of the fee in a PoolKey is used to signal if a Pool's LP fee is dynamic
// a dynamic fee pool must have exactly same value for fee field
uint24 public constant DYNAMIC_FEE_FLAG = 0x800000;

// the second bit of the fee returned by beforeSwap is used to signal if the stored LP fee should be overridden in this swap
Expand All @@ -29,7 +28,7 @@ library LPFeeLibrary {
uint24 public constant TEN_PERCENT_FEE = 100_000;

function isDynamicLPFee(uint24 self) internal pure returns (bool) {
return self & DYNAMIC_FEE_FLAG != 0;
return self == DYNAMIC_FEE_FLAG;
}

function validate(uint24 self, uint24 maxFee) internal pure {
Expand All @@ -40,7 +39,7 @@ library LPFeeLibrary {
function getInitialLPFee(uint24 self) internal pure returns (uint24 lpFee) {
// the initial fee for a dynamic fee pool is 0
if (self.isDynamicLPFee()) return 0;
lpFee = self & FEE_MASK;
lpFee = self;
}

/// @notice returns true if the fee has the override flag set (top bit of the uint24)
Expand Down
1 change: 0 additions & 1 deletion src/pool-bin/BinPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ contract BinPoolManager is IBinPoolManager, ProtocolFees, Extsload {
msg.sender, key, swapForY, 0, amountOut
);
} else {
// clear the top 4 bits since they may be flagged
lpFee = key.fee.getInitialLPFee();
}
lpFee.validate(LPFeeLibrary.TEN_PERCENT_FEE);
Expand Down
2 changes: 1 addition & 1 deletion src/types/BalanceDelta.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.24;

import {SafeCast} from "../libraries/SafeCast.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/types/PoolKey.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct PoolKey {
IHooks hooks;
/// @notice The pool manager of the pool
IPoolManager poolManager;
/// @notice The pool lp fee, capped at 1_000_000. The upper 4 bits determine if the hook sets any fees.
/// @notice The pool lp fee, capped at 1_000_000. If the pool has a dynamic fee then it must be exactly equal to 0x800000
uint24 fee;
/// @notice Hooks callback and pool specific parameters, i.e. tickSpacing for CL, binStep for bin
bytes32 parameters;
Expand Down
2 changes: 1 addition & 1 deletion test/VaultToken.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;
pragma solidity ^0.8.24;

import {Test} from "forge-std/Test.sol";
import {VaultToken} from "../src/VaultToken.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/BalanceDelta.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ contract TestBalanceDelta is Test {
else assertFalse(isEqual);
}

function test_fuzz_neq(int128 a, int128 b, int128 c, int128 d) public pure {
function test_fuzz_neq(int128 a, int128 b, int128 c, int128 d) public {
bool isNotEqual = (toBalanceDelta(a, b) != toBalanceDelta(c, d));
if (a != c || b != d) assertTrue(isNotEqual);
else assertFalse(isNotEqual);
Expand Down
22 changes: 17 additions & 5 deletions test/libraries/LPFeeLibrary.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ contract LPFeeLibraryTest is Test {
assertEq(LPFeeLibrary.isDynamicLPFee(0x100000), false);

// 1111 1111 1111 1111 1111 1111
assertEq(LPFeeLibrary.isDynamicLPFee(0xFFFFFF), true);
assertEq(LPFeeLibrary.isDynamicLPFee(0xFFFFFF), false);

// 0111 1111 1111 1111 1111 1111
assertEq(LPFeeLibrary.isDynamicLPFee(0x7FFFFF), false);
}

function testIsDynamicLPFeeFuzz(uint24 fee) public {
if (fee != 0x800000) {
assertEq(LPFeeLibrary.isDynamicLPFee(fee), false);
} else {
assertEq(LPFeeLibrary.isDynamicLPFee(fee), true);
}
}

function testGetInitialLPFee() public {
// static
assertEq(LPFeeLibrary.getInitialLPFee(0x000001), 0x000001);
Expand All @@ -36,12 +44,16 @@ contract LPFeeLibraryTest is Test {
assertEq(LPFeeLibrary.getInitialLPFee(0x001004), 0x001004);
assertEq(LPFeeLibrary.getInitialLPFee(0x111020), 0x111020);
assertEq(LPFeeLibrary.getInitialLPFee(0x511020), 0x511020);

assertEq(LPFeeLibrary.getInitialLPFee(0xF00F05), 0xF00F05);
assertEq(LPFeeLibrary.getInitialLPFee(0x800310), 0x800310);
assertEq(LPFeeLibrary.getInitialLPFee(0x901020), 0x901020);
assertEq(LPFeeLibrary.getInitialLPFee(0x800001), 0x800001);
assertEq(LPFeeLibrary.getInitialLPFee(0x800010), 0x800010);
assertEq(LPFeeLibrary.getInitialLPFee(0x800100), 0x800100);
assertEq(LPFeeLibrary.getInitialLPFee(0x801000), 0x801000);
assertEq(LPFeeLibrary.getInitialLPFee(0x810000), 0x810000);
// dynamic
assertEq(LPFeeLibrary.getInitialLPFee(0xF00F05), 0);
assertEq(LPFeeLibrary.getInitialLPFee(0x800310), 0);
assertEq(LPFeeLibrary.getInitialLPFee(0x800000), 0);
assertEq(LPFeeLibrary.getInitialLPFee(0x901020), 0);
}

function testFuzzValidate(uint24 self, uint24 maxFee) public {
Expand Down
Loading

0 comments on commit 4dd78da

Please sign in to comment.