<details>
<summary>POC</summary>
1. Add this test to `RebateFiHookTest.t.sol` test file.
Note that the `currentSellFee` variable is used on a sale transaction due to faulty contract logic.
```javascript
function test_PoC_SellFee_99Percent() public {
uint24 extremeFee = 990000;
rebateHook.ChangeFee(true, extremeFee, false, 0);
uint24 currentBuyFee;
uint24 currentSellFee;
(currentBuyFee, currentSellFee) = rebateHook.getFeeConfig();
assertEq(currentBuyFee, extremeFee, "Buy fee was not set to 99%");
uint256 ethAmount = 50 ether;
uint256 reFiAmount = 50 ether;
vm.deal(address(this), ethAmount);
uint160 sqrtPriceLower = TickMath.getSqrtPriceAtTick(-60);
uint160 sqrtPriceUpper = TickMath.getSqrtPriceAtTick(60);
uint128 liquidityETH = LiquidityAmounts.getLiquidityForAmount0(
SQRT_PRICE_1_1_s,
sqrtPriceUpper,
ethAmount
);
uint128 liquidityReFi = LiquidityAmounts.getLiquidityForAmount1(
sqrtPriceLower,
SQRT_PRICE_1_1_s,
reFiAmount
);
uint128 liquidity = liquidityETH < liquidityReFi ? liquidityETH : liquidityReFi;
modifyLiquidityRouter.modifyLiquidity{value: ethAmount}(
key,
ModifyLiquidityParams({
tickLower: -60,
tickUpper: 60,
liquidityDelta: int256(uint256(liquidity)),
salt: bytes32(0)
}),
ZERO_BYTES
);
reFiToken.approve(address(modifyLiquidityRouter), type(uint256).max);
vm.deal(address(this), ethAmount);
modifyLiquidityRouter.modifyLiquidity{value: ethAmount}(
key,
ModifyLiquidityParams({
tickLower: -60,
tickUpper: 60,
liquidityDelta: int256(uint256(liquidity)),
salt: bytes32(0)
}),
ZERO_BYTES
);
uint256 sellAmount = 1 ether;
vm.startPrank(user1);
reFiToken.mint(user1, sellAmount);
reFiToken.approve(address(swapRouter), type(uint256).max);
uint256 initialEth = user1.balance;
SwapParams memory params = SwapParams({
zeroForOne: false,
amountSpecified: -int256(sellAmount),
sqrtPriceLimitX96: TickMath.MAX_SQRT_PRICE - 1
});
PoolSwapTest.TestSettings memory testSettings =
PoolSwapTest.TestSettings(false, false);
swapRouter.swap(key, params, testSettings, ZERO_BYTES);
vm.stopPrank();
uint256 finalEth = user1.balance;
uint256 receivedEth = finalEth - initialEth;
console.log("ETH received after selling 1 ReFi (99% fee):", receivedEth);
uint256 expectedEth = 1e16;
assertLe(receivedEth, 0.02 ether, "Expected output < 2% (tolerance)");
assertGe(receivedEth, expectedEth * 98 / 100, "Expected output >= 0.98% (tolerance)");
}
```
</details>
1.Modify the `ChangeFee` function To apply a maximum fee limit .
```diff
+ uint24 public constant MAX_FEE = 10000; // for example
/// @notice Updates the buy and/or sell fee percentages
/// @param _isBuyFee Whether to update the buy fee
/// @param _buyFee New buy fee value (if _isBuyFee is true)
/// @param _isSellFee Whether to update the sell fee
/// @param _sellFee New sell fee value (if _isSellFee is true)
/// @dev Only callable by owner
function ChangeFee(
bool _isBuyFee,
uint24 _buyFee,
bool _isSellFee,
uint24 _sellFee
) external onlyOwner {
- if(_isBuyFee) buyFee = _buyFee;
+ if(_isBuyFee) {
+ require(_buyFee <= MAX_FEE, "Buy fee exceeds max limit (1%)");
+ buyFee = _buyFee;
+ }
- if(_isSellFee) sellFee = _sellFee;
+ if(_isSellFee) {
+ require(_sellFee <= MAX_FEE, "Sell fee exceeds max limit (1%)");
+ sellFee = _sellFee;
+ }
}
```