From 0a191551c6689fcc983655a3b274291ef1ac1017 Mon Sep 17 00:00:00 2001 From: blockgroot <170620375+blockgroot@users.noreply.github.com> Date: Thu, 11 Jul 2024 05:29:26 +0000 Subject: [PATCH] feat: revert when swap fee is too high --- contracts/L2/ETHxPoolV1.sol | 3 +++ test/L2/ETHxPoolV1.t.sol | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/contracts/L2/ETHxPoolV1.sol b/contracts/L2/ETHxPoolV1.sol index 4391d12..43741a5 100644 --- a/contracts/L2/ETHxPoolV1.sol +++ b/contracts/L2/ETHxPoolV1.sol @@ -53,6 +53,8 @@ contract ETHxPoolV1 is AccessControlUpgradeable, ReentrancyGuardUpgradeable { error InvalidAmount(); /// @dev Thrown when input is invalid basis fee error InvalidBps(); + /// @dev Thrown when input fee is too high + error HighFees(); /// @dev Thrown when transfer is failed error TransferFailed(); @@ -161,6 +163,7 @@ contract ETHxPoolV1 is AccessControlUpgradeable, ReentrancyGuardUpgradeable { /// @param _feeBps The fee basis points function setFeeBps(uint256 _feeBps) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_feeBps > 10_000) revert InvalidBps(); + if (_feeBps > 1000) revert HighFees(); feeBps = _feeBps; diff --git a/test/L2/ETHxPoolV1.t.sol b/test/L2/ETHxPoolV1.t.sol index 9e4e24c..799ffd1 100644 --- a/test/L2/ETHxPoolV1.t.sol +++ b/test/L2/ETHxPoolV1.t.sol @@ -64,6 +64,13 @@ contract ETHxPoolV1Test is Test { eTHxPoolV1.setFeeBps(feeBps); } + function testSetFeeHighFees(uint256 feeBps) public { + vm.assume(feeBps > 1000 && feeBps <= 10_000); + vm.prank(admin); + vm.expectRevert(abi.encodeWithSelector(ETHxPoolV1.HighFees.selector)); + eTHxPoolV1.setFeeBps(feeBps); + } + function testSetFeeAdminRequired() public { address nonAdmin = vm.addr(0x102); vm.prank(nonAdmin);