Skip to content

Commit

Permalink
Refactor MaticX contract
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Sep 14, 2024
1 parent 2f3cb8a commit f065e7a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
14 changes: 7 additions & 7 deletions contracts/MaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract MaticX is
uint256 private reentrancyGuardStatus;

/**
* @dev Enables guard from reentrancy calls.
* @dev Enables guard from reentrant calls.
*/
modifier nonReentrant() {
require(
Expand All @@ -77,12 +77,9 @@ contract MaticX is
address _manager,
address _treasury
) external initializer {
__AccessControl_init();
__Pausable_init();
__ERC20_init("Liquid Staking Matic", "MaticX");

require(_manager != address(0), "Zero manager address");
_setupRole(DEFAULT_ADMIN_ROLE, _manager);
AccessControlUpgradeable.__AccessControl_init();
PausableUpgradeable.__Pausable_init();
ERC20Upgradeable.__ERC20_init("Liquid Staking Matic", "MaticX");

require(
_validatorRegistry != address(0),
Expand All @@ -96,6 +93,9 @@ contract MaticX is
require(_maticToken != address(0), "Zero matic token address");
maticToken = _maticToken;

require(_manager != address(0), "Zero manager address");
_setupRole(DEFAULT_ADMIN_ROLE, _manager);

require(_treasury != address(0), "Zero treasury address");
treasury = _treasury;

Expand Down
15 changes: 15 additions & 0 deletions contracts/mocks/ExtendedMaticXMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.7;

import { MaticX } from "../MaticX.sol";

contract ExtendedMaticXMock is MaticX {
uint256 public value;

event ValueSet(uint256 value);

function setValue(uint256 value_) external {
value = value_;
emit ValueSet(value_);
}
}
45 changes: 45 additions & 0 deletions test/MaticX.forking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,51 @@ describe("MaticX (Forking)", function () {
});
});

describe("Upgrade the contract", function () {
describe("Checks", function () {
it("Should return a new address of the implementation if extended", async function () {
const { maticX } = await loadFixture(deployFixture);

const initialImplementationAddress =
await upgrades.erc1967.getImplementationAddress(
maticX.address
);

const ExtendedMaticXMock =
await ethers.getContractFactory("ExtendedMaticXMock");
await upgrades.upgradeProxy(maticX, ExtendedMaticXMock);

const currentImplementationAddress: string =
await upgrades.erc1967.getImplementationAddress(
maticX.address
);
expect(initialImplementationAddress).not.to.equal(
currentImplementationAddress
);
});

it("Should return the same address of the implementation if not extended", async function () {
const { maticX } = await loadFixture(deployFixture);

const initialImplementationAddress: string =
await upgrades.erc1967.getImplementationAddress(
maticX.address
);

const MaticX = await ethers.getContractFactory("MaticX");
await upgrades.upgradeProxy(maticX, MaticX);

const currentImplementationAddress: string =
await upgrades.erc1967.getImplementationAddress(
maticX.address
);
expect(currentImplementationAddress).to.equal(
initialImplementationAddress
);
});
});
});

describe("Fallback", function () {
describe("Negative", function () {
it("Should revert if calling a non existing method", async function () {
Expand Down

0 comments on commit f065e7a

Please sign in to comment.