Skip to content

Commit

Permalink
Implement method to initialize V2 on ValidatorRegistry contract
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Sep 14, 2024
1 parent f065e7a commit 8ede8f7
Show file tree
Hide file tree
Showing 5 changed files with 624 additions and 22 deletions.
27 changes: 13 additions & 14 deletions contracts/ValidatorRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ contract ValidatorRegistry is
) external initializer {
AccessControlUpgradeable.__AccessControl_init();
PausableUpgradeable.__Pausable_init();
ReentrancyGuardUpgradeable.__ReentrancyGuard_init();

require(_stakeManager != address(0), "Zero stake manager address");
stakeManager = _stakeManager;
Expand All @@ -60,6 +59,19 @@ contract ValidatorRegistry is
_setupRole(DEFAULT_ADMIN_ROLE, _manager);
}

/**
* @dev Initializes version 2 of the current contract.
* @param _polToken - Address of the POL token
*/
function initializeV2(
address _polToken
) external reinitializer(2) onlyRole(DEFAULT_ADMIN_ROLE) {
ReentrancyGuardUpgradeable.__ReentrancyGuard_init();

require(_polToken != address(0), "Zero POL token address");
polToken = _polToken;
}

/// ----------------------------- API --------------------------------------

/// @notice Allows a validator that was already staked on the polygon stake manager
Expand Down Expand Up @@ -191,19 +203,6 @@ contract ValidatorRegistry is
emit SetVersion(_version);
}

/**
* @dev Sets the address of the POL token. Callable by the admin only.
* @param _address - Address of the POL token
*/
function setPOLToken(
address _address
) external override onlyRole(DEFAULT_ADMIN_ROLE) {
require(_address != address(0), "Zero POL token address");

polToken = _address;
emit SetPOLToken(_address);
}

/// @notice Allows to pause the contract.
function togglePause() external override onlyRole(DEFAULT_ADMIN_ROLE) {
paused() ? _unpause() : _pause();
Expand Down
4 changes: 0 additions & 4 deletions contracts/interfaces/IValidatorRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ interface IValidatorRegistry {

event SetVersion(string _version);

event SetPOLToken(address _address);

function addValidator(uint256 _validatorId) external;

function removeValidator(uint256 _validatorId) external;
Expand Down Expand Up @@ -55,6 +53,4 @@ interface IValidatorRegistry {
function getValidatorId(uint256 _index) external view returns (uint256);

function getValidators() external view returns (uint256[] memory);

function setPOLToken(address _address) external;
}
15 changes: 15 additions & 0 deletions contracts/mocks/ExtendedValidatorRegistryMock.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 { ValidatorRegistry } from "../ValidatorRegistry.sol";

contract ExtendedValidatorRegistryMock is ValidatorRegistry {
uint256 public value;

event ValueSet(uint256 value);

function setValue(uint256 value_) external {
value = value_;
emit ValueSet(value_);
}
}
8 changes: 4 additions & 4 deletions test/MaticX.forking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ describe("MaticX (Forking)", function () {
it("Should return the right paused status", async function () {
const { maticX } = await loadFixture(deployFixture);

const paused: boolean = await maticX.paused();
const paused = await maticX.paused();
expect(paused).to.be.false;
});

Expand Down Expand Up @@ -354,7 +354,7 @@ describe("MaticX (Forking)", function () {
await ethers.getContractFactory("ExtendedMaticXMock");
await upgrades.upgradeProxy(maticX, ExtendedMaticXMock);

const currentImplementationAddress: string =
const currentImplementationAddress =
await upgrades.erc1967.getImplementationAddress(
maticX.address
);
Expand All @@ -366,15 +366,15 @@ describe("MaticX (Forking)", function () {
it("Should return the same address of the implementation if not extended", async function () {
const { maticX } = await loadFixture(deployFixture);

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

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

const currentImplementationAddress: string =
const currentImplementationAddress =
await upgrades.erc1967.getImplementationAddress(
maticX.address
);
Expand Down
Loading

0 comments on commit 8ede8f7

Please sign in to comment.