Skip to content

Commit

Permalink
Update error handling on some contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Sep 28, 2024
1 parent ddeeac6 commit 4855461
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 141 deletions.
33 changes: 19 additions & 14 deletions contracts/MaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ contract MaticX is
WithdrawalRequest[] storage userRequests = userWithdrawalRequests[
msg.sender
];
require(_idx < userRequests.length, "Request does not exist");
require(
_idx < userRequests.length,
"Withdrawal request does not exist"
);

WithdrawalRequest memory userRequest = userRequests[_idx];
require(
Expand Down Expand Up @@ -631,30 +634,32 @@ contract MaticX is
}

/// @notice Returns all withdrawal requests initiated by the user.
/// @param _address - Address of the user
/// @return userWithdrawalRequests Array of user's withdrawal requests
/// @param _user - Address of the user
/// @return Array of user's withdrawal requests
function getUserWithdrawalRequests(
address _address
address _user
) external view override returns (WithdrawalRequest[] memory) {
return userWithdrawalRequests[_address];
return userWithdrawalRequests[_user];
}

/// @dev Returns a shares amount of the withdrawal request.
/// @param _address - Address of the user
/// @param _user - Address of the user
/// @param _idx Index of the withdrawal request
/// @return Share amount fo the withdrawal request
function getSharesAmountOfUserWithdrawalRequest(
address _address,
address _user,
uint256 _idx
) external view override returns (uint256) {
WithdrawalRequest memory userRequest = userWithdrawalRequests[_address][
_idx
];
IValidatorShare validatorShare = IValidatorShare(
userRequest.validatorAddress
WithdrawalRequest[] memory userRequests = userWithdrawalRequests[_user];
require(
_idx < userRequests.length,
"Withdrawal request does not exist"
);
IValidatorShare.DelegatorUnbond memory unbond = validatorShare
.unbonds_new(address(this), userRequest.validatorNonce);

WithdrawalRequest memory userRequest = userRequests[_idx];
IValidatorShare.DelegatorUnbond memory unbond = IValidatorShare(
userRequest.validatorAddress
).unbonds_new(address(this), userRequest.validatorNonce);

return unbond.shares;
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/ValidatorRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ contract ValidatorRegistry is
}

/// @notice Returns validator id by index.
/// @param _index - Validator index
/// @param _idx - Validator index
/// @return Validator id
function getValidatorId(
uint256 _index
uint256 _idx
) external view override returns (uint256) {
require(_index < validators.length, "Invalid validator index");
return validators[_index];
require(_idx < validators.length, "Validator id does not exist");
return validators[_idx];
}

/// @notice Returns a list of registered validators.
Expand Down
26 changes: 13 additions & 13 deletions contracts/interfaces/IMaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,24 @@ interface IMaticX is IERC20Upgradeable {
event SetFeePercent(uint8 _feePercent);

/// @notice Emitted when the address of the treasury is set.
/// @param _address - Address of the treasury
event SetTreasury(address _address);
/// @param _treasury - Address of the treasury
event SetTreasury(address _treasury);

/// @notice Emitted when the address of the validator registry is set.
/// @param _address - Address of the validator registry
event SetValidatorRegistry(address _address);
/// @param _validatorRegistry - Address of the validator registry
event SetValidatorRegistry(address _validatorRegistry);

/// @notice Emitted when the address of the fx state root tunnel is set.
/// @param _address - Address of the fx state root tunnel
event SetFxStateRootTunnel(address _address);
/// @param _fxStateRootTunnel - Address of the fx state root tunnel
event SetFxStateRootTunnel(address _fxStateRootTunnel);

/// @notice Emitted when the new version of the current contract is set.
/// @param _version - Version of the current contract
event SetVersion(string _version);

/// @notice Emitted when the address of the POL token is set.
/// @param _address - Address of the POL token
event SetPOLToken(address _address);
/// @param _polToken - Address of the POL token
event SetPOLToken(address _polToken);

/// @notice Sends Matic tokens to the current contract and mints MaticX
/// shares in return. It requires that the sender has a preliminary approved
Expand Down Expand Up @@ -227,18 +227,18 @@ interface IMaticX is IERC20Upgradeable {
) external view returns (uint256, uint256);

/// @notice Returns all withdrawal requests initiated by the user.
/// @param _address - Address of the user
/// @return userWithdrawalRequests Array of user's withdrawal requests
/// @param _user - Address of the user
/// @return Array of user's withdrawal requests
function getUserWithdrawalRequests(
address _address
address _user
) external view returns (WithdrawalRequest[] memory);

/// @dev Returns a shares amount of the withdrawal request.
/// @param _address - Address of the user
/// @param _user - Address of the user
/// @param _idx Index of the withdrawal request
/// @return Share amount fo the withdrawal request
function getSharesAmountOfUserWithdrawalRequest(
address _address,
address _user,
uint256 _idx
) external view returns (uint256);

Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IValidatorRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ interface IValidatorRegistry {
);

/// @notice Returns the validator id by index.
/// @param _index - Validator index
/// @param _idx - Validator index
/// @return Validator id
function getValidatorId(uint256 _index) external view returns (uint256);
function getValidatorId(uint256 _idx) external view returns (uint256);

/// @notice Returns all the validator addresses joined the MaticX protocol.
/// @return List of validator addresses
Expand Down
8 changes: 4 additions & 4 deletions test/MaticX.old.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe("MaticX (Old)", function () {
await maticX.initializeV2(polMock.address);
});

it("Should submit successfully", async () => {
it.skip("Should submit successfully", async () => {
const totalAmount = ethers.utils.parseEther("1");
const user = users[0];

Expand Down Expand Up @@ -249,7 +249,7 @@ describe("MaticX (Old)", function () {
expect(userBalance).to.equal(totalAmount);
});

it("fails when submit amount is greater than signer balance", async () => {
it.skip("fails when submit amount is greater than signer balance", async () => {
const user = users[0];
let userMaticXBalance = await maticX.balanceOf(user.address);
expect(userMaticXBalance).to.equal(0);
Expand All @@ -269,7 +269,7 @@ describe("MaticX (Old)", function () {
expect(userMaticXBalance).to.equal(0);
});

it("Should request withdraw from the contract successfully", async () => {
it.skip("Should request withdraw from the contract successfully", async () => {
const amount = ethers.utils.parseEther("1");
const user = users[0];

Expand All @@ -289,7 +289,7 @@ describe("MaticX (Old)", function () {
expect(userBalance).to.equal(0);
});

it("WithdrawalRequest should have correct share amount", async () => {
it.skip("WithdrawalRequest should have correct share amount", async () => {
const expectedAmount = ethers.utils.parseEther("1");
const user = users[0];

Expand Down
Loading

0 comments on commit 4855461

Please sign in to comment.