Skip to content

Commit

Permalink
Fix Bailsec Issue_16
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Oct 14, 2024
1 parent 65124c9 commit d182321
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions contracts/MaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract MaticX is
using StringsUpgradeable for string;

bytes32 public constant BOT = keccak256("BOT");
uint256 private constant MAX_FEE_PERCENT = 20;
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;

Expand Down Expand Up @@ -477,12 +478,15 @@ contract MaticX is
/// ------------------------------ Setters ---------------------------------

/// @notice Sets a fee percent.
/// @param _feePercent - Fee percent (10 = 10%)
/// @param _feePercent - Fee percent (1 = 1%)
// slither-disable-next-line reentrancy-eth
function setFeePercent(
uint8 _feePercent
) external override nonReentrant onlyRole(DEFAULT_ADMIN_ROLE) {
require(_feePercent <= 100, "Fee percent must not exceed 100");
require(
_feePercent <= MAX_FEE_PERCENT,
"Fee percent must not exceed 20"
);

uint256[] memory validatorIds = validatorRegistry.getValidators();
uint256 validatorIdCount = validatorIds.length;
Expand Down
10 changes: 6 additions & 4 deletions test/MaticX.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("MaticX", function () {
const stakeAmount = ethers.utils.parseUnits("100", 18);
const tripleStakeAmount = stakeAmount.mul(3);
const version = "2";
const feePercent = 10;
const feePercent = 20;

async function deployFixture(callMaticXInitializeV2 = true) {
await reset(providerUrl, envVars.FORKING_BLOCK_NUMBER);
Expand Down Expand Up @@ -2444,7 +2444,9 @@ describe("MaticX", function () {
const { maticX, stakerA, defaultAdminRole } =
await loadFixture(deployFixture);

const promise = maticX.connect(stakerA).setFeePercent(100);
const promise = maticX
.connect(stakerA)
.setFeePercent(feePercent);
await expect(promise).to.be.revertedWith(
`AccessControl: account ${stakerA.address.toLowerCase()} is missing role ${defaultAdminRole}`
);
Expand All @@ -2453,9 +2455,9 @@ describe("MaticX", function () {
it("Should revert with the right error if passing a too high fee percent", async function () {
const { maticX, manager } = await loadFixture(deployFixture);

const promise = maticX.connect(manager).setFeePercent(101);
const promise = maticX.connect(manager).setFeePercent(21);
await expect(promise).to.be.revertedWith(
"Fee percent must not exceed 100"
"Fee percent must not exceed 20"
);
});
});
Expand Down

0 comments on commit d182321

Please sign in to comment.