From dce9957f9b74c104ff90e5f075474cabe27baeeb Mon Sep 17 00:00:00 2001 From: Sergey <2901744+evercoinx@users.noreply.github.com.> Date: Sun, 13 Oct 2024 15:55:57 +0300 Subject: [PATCH] Fix Bailsec Issue_13 --- contracts/MaticX.sol | 6 +++--- contracts/interfaces/IMaticX.sol | 2 +- test/MaticX.spec.ts | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/contracts/MaticX.sol b/contracts/MaticX.sol index bd85a69a..dce8ab6c 100644 --- a/contracts/MaticX.sol +++ b/contracts/MaticX.sol @@ -222,8 +222,7 @@ contract MaticX is uint256 leftAmountToWithdraw = amountToWithdraw; uint256 validatorIdCount = validatorIds.length; uint256 totalIterations = validatorIdCount; - uint256 requestEpoch = stakeManager.epoch() + - stakeManager.withdrawalDelay(); + uint256 requestEpoch = stakeManager.epoch(); while (leftAmountToWithdraw > 0 && totalIterations > 0) { uint256 validatorId = validatorIds[currentIdx]; @@ -314,7 +313,8 @@ contract MaticX is WithdrawalRequest memory userRequest = userRequests[_idx]; require( - stakeManager.epoch() >= userRequest.requestEpoch, + stakeManager.epoch() >= + userRequest.requestEpoch + stakeManager.withdrawalDelay(), "Not able to claim yet" ); diff --git a/contracts/interfaces/IMaticX.sol b/contracts/interfaces/IMaticX.sol index c1afc0f2..870c0fb9 100644 --- a/contracts/interfaces/IMaticX.sol +++ b/contracts/interfaces/IMaticX.sol @@ -13,7 +13,7 @@ interface IMaticX is IERC20Upgradeable { struct WithdrawalRequest { // Validator's incremental nonce uint256 validatorNonce; - // Request epoch number + // Request epoch uint256 requestEpoch; // Address of the validator share address validatorAddress; diff --git a/test/MaticX.spec.ts b/test/MaticX.spec.ts index 3ef0494b..55fc6c45 100644 --- a/test/MaticX.spec.ts +++ b/test/MaticX.spec.ts @@ -1559,11 +1559,12 @@ describe("MaticX", function () { const withdrawalIndex = 0; const withdrawalRequests = await maticX.getUserWithdrawalRequests(stakerA.address); - const [, withdrawalEpoch] = withdrawalRequests[withdrawalIndex]; + const [, requestEpoch] = withdrawalRequests[withdrawalIndex]; + const withdrawalDelay = await stakeManager.withdrawalDelay(); await stakeManager .connect(stakeManagerGovernance) - .setCurrentEpoch(withdrawalEpoch.sub(1)); + .setCurrentEpoch(requestEpoch.add(withdrawalDelay).sub(1)); const promise = maticX .connect(stakerA) @@ -1633,11 +1634,12 @@ describe("MaticX", function () { const withdrawalIndex = 0; const withdrawalRequests = await maticX.getUserWithdrawalRequests(stakerA.address); - const [, withdrawalEpoch] = withdrawalRequests[withdrawalIndex]; + const [, requestEpoch] = withdrawalRequests[withdrawalIndex]; + const withdrawalDelay = await stakeManager.withdrawalDelay(); await stakeManager .connect(stakeManagerGovernance) - .setCurrentEpoch(withdrawalEpoch); + .setCurrentEpoch(requestEpoch.add(withdrawalDelay)); const promise = maticX .connect(stakerA) @@ -1664,11 +1666,12 @@ describe("MaticX", function () { const withdrawalIndex = 0; const withdrawalRequests = await maticX.getUserWithdrawalRequests(stakerA.address); - const [, withdrawalEpoch] = withdrawalRequests[withdrawalIndex]; + const [, requestEpoch] = withdrawalRequests[withdrawalIndex]; + const withdrawalDelay = await stakeManager.withdrawalDelay(); await stakeManager .connect(stakeManagerGovernance) - .setCurrentEpoch(withdrawalEpoch); + .setCurrentEpoch(requestEpoch.add(withdrawalDelay)); const promise = maticX .connect(stakerA) @@ -1700,11 +1703,12 @@ describe("MaticX", function () { const withdrawalIndex = 0; const withdrawalRequests = await maticX.getUserWithdrawalRequests(stakerA.address); - const [, withdrawalEpoch] = withdrawalRequests[withdrawalIndex]; + const [, requestEpoch] = withdrawalRequests[withdrawalIndex]; + const withdrawalDelay = await stakeManager.withdrawalDelay(); await stakeManager .connect(stakeManagerGovernance) - .setCurrentEpoch(withdrawalEpoch); + .setCurrentEpoch(requestEpoch.add(withdrawalDelay)); const promise = maticX .connect(stakerA) @@ -1743,12 +1747,13 @@ describe("MaticX", function () { const withdrawalIndex = 0; const initialWithdrawalRequests = await maticX.getUserWithdrawalRequests(stakerA.address); - const [, withdrawalEpoch] = + const [, requestEpoch] = initialWithdrawalRequests[withdrawalIndex]; + const withdrawalDelay = await stakeManager.withdrawalDelay(); await stakeManager .connect(stakeManagerGovernance) - .setCurrentEpoch(withdrawalEpoch); + .setCurrentEpoch(requestEpoch.add(withdrawalDelay)); await maticX.connect(stakerA).claimWithdrawal(withdrawalIndex);