Skip to content

Commit

Permalink
optimization: uniform the swap fee boundry check rule (exclude to inc…
Browse files Browse the repository at this point in the history
…lude)
  • Loading branch information
chefburger committed Apr 3, 2024
1 parent 09d4460 commit 5276fae
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
109021
108896
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37221
37096
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36477
36480
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 @@
37427
37430
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
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 @@ -326,7 +326,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));
}
}
6 changes: 3 additions & 3 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 @@ -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

0 comments on commit 5276fae

Please sign in to comment.