Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor/currency-set…
Browse files Browse the repository at this point in the history
…tlement
  • Loading branch information
ChefMist committed May 30, 2024
2 parents f1b73a5 + 2099560 commit c8e1cb1
Show file tree
Hide file tree
Showing 62 changed files with 154 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181729
180826
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185616
184747
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 @@
331570
331343
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
193836
192943
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138357
137069
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32551
32545
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148415
146807
Original file line number Diff line number Diff line change
@@ -1 +1 @@
296310
294365
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131567
130278
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120501
119302
Original file line number Diff line number Diff line change
@@ -1 +1 @@
977635
976074
Original file line number Diff line number Diff line change
@@ -1 +1 @@
339825
338264
Original file line number Diff line number Diff line change
@@ -1 +1 @@
343302
341845
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146245
144788
Original file line number Diff line number Diff line change
@@ -1 +1 @@
180669
179296
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186652
185279
Original file line number Diff line number Diff line change
@@ -1 +1 @@
139032
137674
Original file line number Diff line number Diff line change
@@ -1 +1 @@
309785
308324
Original file line number Diff line number Diff line change
@@ -1 +1 @@
363044
360221
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178212
175389
Original file line number Diff line number Diff line change
@@ -1 +1 @@
248228
245355
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170800
168436
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114636
112268
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124318
121487
Original file line number Diff line number Diff line change
@@ -1 +1 @@
141559
138797
Original file line number Diff line number Diff line change
@@ -1 +1 @@
175051
172284
Original file line number Diff line number Diff line change
@@ -1 +1 @@
161437
158711
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79435
76674
Original file line number Diff line number Diff line change
@@ -1 +1 @@
153726
150965
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
96242
93566
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79438
76677
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29467
32328
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 @@
81624
81446
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 @@
45212
45034
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45211
45033
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/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
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
2 changes: 1 addition & 1 deletion test/pool-bin/BinHookReturnsFee.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract BinHookReturnsFeeTest is Test, BinTestHelper {
currency1: currency1,
hooks: dynamicReturnsFeesHook,
poolManager: poolManager,
fee: LPFeeLibrary.DYNAMIC_FEE_FLAG, // 3000 = 0.3%
fee: LPFeeLibrary.DYNAMIC_FEE_FLAG,
parameters: bytes32(uint256(dynamicReturnsFeesHook.getHooksRegistrationBitmap())).setBinStep(10)
});

Expand Down
Loading

0 comments on commit c8e1cb1

Please sign in to comment.