Skip to content

Commit

Permalink
Fix Bailsec Issue_13
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Oct 13, 2024
1 parent b762adc commit dce9957
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions contracts/MaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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"
);

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IMaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 15 additions & 10 deletions test/MaticX.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit dce9957

Please sign in to comment.