From f6b043f2b1da97d5e715815fa5a019f90fa8d080 Mon Sep 17 00:00:00 2001 From: Samuil Borisov <88675952+SamBorisov@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:03:04 +0200 Subject: [PATCH] 285 governance consistent logic (#85) * update Governance * update AccessControl to Whitelisting * fix forge and HH tests --- README.md | 4 +- .../modules/MacroFactor/MacroFactor.sol | 2 +- .../APRCalculator/modules/Price/Price.sol | 7 +- contracts/HydraChain/HydraChain.sol | 12 +- contracts/HydraChain/IHydraChain.sol | 3 +- .../modules/Inspector/Inspector.sol | 24 +- .../ValidatorManager/ValidatorManager.sol | 8 +- .../IWhitelisting.sol} | 10 +- .../Whitelisting.sol} | 39 +- contracts/HydraDelegation/Delegation.sol | 2 +- contracts/HydraStaking/Staking.sol | 2 +- contracts/HydraVault/HydraVault.sol | 8 +- contracts/common/Governed/Governed.sol | 18 + contracts/common/Withdrawal/Withdrawal.sol | 2 +- docs/APRCalculator/APRCalculator.md | 17 - .../modules/MacroFactor/MacroFactor.md | 17 - docs/APRCalculator/modules/Price/Price.md | 17 - docs/APRCalculator/modules/RSI/RSIndex.md | 17 - docs/HydraChain/HydraChain.md | 251 +++++++---- docs/HydraChain/IHydraChain.md | 130 ++++++ .../modules/AccessControl/AccessControl.md | 312 ------------- .../HydraChain/modules/Inspector/Inspector.md | 241 ++++++---- .../ValidatorManager/ValidatorManager.md | 219 +++++++--- .../IWhitelisting.md} | 10 +- .../modules/Whitelisting/Whitelisting.md | 411 ++++++++++++++++++ docs/HydraVault/HydraVault.md | 164 ++++++- docs/common/Withdrawal/Withdrawal.md | 16 + .../access/Ownable2StepUpgradeable.md | 140 ------ test/APRCalculator/APRCalculator.test.ts | 8 +- test/APRCalculator/MacroFactor.test.ts | 8 +- test/APRCalculator/Price.test.ts | 12 +- test/HydraChain/HydraChain.test.ts | 16 +- test/HydraChain/Inspector.test.ts | 34 +- test/HydraChain/ValidatorManager.test.ts | 4 +- ...ssControl.test.ts => Whitelisting.test.ts} | 30 +- test/HydraDelegation/HydraDelegation.test.ts | 11 +- test/HydraStaking/HydraStaking.test.ts | 6 +- test/common/Withdrawal.test.ts | 7 +- test/constants.ts | 1 + test/forge/InitializedContracts.sol | 7 +- 40 files changed, 1334 insertions(+), 913 deletions(-) rename contracts/HydraChain/modules/{AccessControl/IAccessControl.sol => Whitelisting/IWhitelisting.sol} (77%) rename contracts/HydraChain/modules/{AccessControl/AccessControl.sol => Whitelisting/Whitelisting.sol} (60%) delete mode 100644 docs/HydraChain/modules/AccessControl/AccessControl.md rename docs/HydraChain/modules/{AccessControl/IAccessControl.md => Whitelisting/IWhitelisting.md} (82%) create mode 100644 docs/HydraChain/modules/Whitelisting/Whitelisting.md delete mode 100644 docs/elin/contracts-upgradeable/access/Ownable2StepUpgradeable.md rename test/HydraChain/{AccessControl.test.ts => Whitelisting.test.ts} (86%) diff --git a/README.md b/README.md index f719d73e..2c250c9b 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,11 @@ There are a several different contracts with different roles in the suite, as su │ GenesisProxy — "the genesis proxy contract" │ Faucet — "faucet for the test-net" │ HydraChain/ — "commit epochs, keeps validators data" -├─ AccessControl - "whitelisting users (could disable)" ├─ DaoIncentive - "distribute rewards for DAOs" ├─ Inspector - "handles validator bans" ├─ ValidatorManager - "keeps validator information" ├─ ValidatorsData - "real-time data for validators voting power" +├─ Whitelisting - "whitelisting users (could disable)" │ HydraDelegation/ - "handle delegations and commissions" ├─ DelegationPoolLib - "lib for the pool of the staker to delegators" ├─ LiquidDelegation - "handles giving liquidity tokens on delegate" @@ -89,11 +89,11 @@ Boneh–Lynn–Shacham (BLS) signature scheme on Barreto-Naehrig 254 bit curve ( Contract for committing epochs and keeping validators' data, handling validators' access -- Access control: Used for whitelisting addresses (whitelisted addresses can register) this feature can also be disabled so anyone can register and set a node - Dao Incentive: Distributes rewards that are kept for DAOs in the network, later those rewards are sent to the vault and could be sent to a specific contract if the governance agrees that is it helping the network! - Inspector: Handles validator bans, initiating a ban after certain inactivity of blocks and permanent ban applying penalty and giving reward (if non-governance wallet) ban the user! - Validator Manager: Handles validator information like status, keeping registered information and more. - Validators Data: Keep real-time data for validator voting power. +- Whitelisting: Used for whitelisting addresses (whitelisted addresses can register) this feature can also be disabled so anyone can register and set a node #### HydraStaking: diff --git a/contracts/APRCalculator/modules/MacroFactor/MacroFactor.sol b/contracts/APRCalculator/modules/MacroFactor/MacroFactor.sol index 42838637..73f262b7 100644 --- a/contracts/APRCalculator/modules/MacroFactor/MacroFactor.sol +++ b/contracts/APRCalculator/modules/MacroFactor/MacroFactor.sol @@ -33,7 +33,7 @@ abstract contract MacroFactor is IMacroFactor, Price { /** * @inheritdoc IMacroFactor */ - function changeDefaultMacroFactor(uint256 _macroFactor) external onlyRole(MANAGER_ROLE) { + function changeDefaultMacroFactor(uint256 _macroFactor) external onlyGovernance { if (_macroFactor < MIN_MACRO_FACTOR || _macroFactor > MAX_MACRO_FACTOR) { revert InvalidMacroFactor(); } diff --git a/contracts/APRCalculator/modules/Price/Price.sol b/contracts/APRCalculator/modules/Price/Price.sol index 97abfdc2..051b4ae2 100644 --- a/contracts/APRCalculator/modules/Price/Price.sol +++ b/contracts/APRCalculator/modules/Price/Price.sol @@ -11,7 +11,6 @@ import {IPrice} from "./IPrice.sol"; abstract contract Price is IPrice, Initializable, System, Governed, HydraChainConnector, PriceOracleConnector { uint256 public constant DENOMINATOR = 10000; - bytes32 public constant MANAGER_ROLE = keccak256("manager_role"); bool public disabledBonusesUpdates; uint256 public latestDailyPrice; @@ -31,8 +30,6 @@ abstract contract Price is IPrice, Initializable, System, Governed, HydraChainCo __HydraChainConnector_init(_hydraChainAddr); __PriceOracleConnector_init(_priceOracleAddr); __Price_init_unchained(_prices); - - _grantRole(MANAGER_ROLE, _governance); } // solhint-disable-next-line func-name-mixedcase @@ -63,7 +60,7 @@ abstract contract Price is IPrice, Initializable, System, Governed, HydraChainCo /** * @inheritdoc IPrice */ - function guardBonuses() external onlyRole(MANAGER_ROLE) { + function guardBonuses() external onlyGovernance { if (disabledBonusesUpdates) { revert GuardAlreadyEnabled(); } @@ -75,7 +72,7 @@ abstract contract Price is IPrice, Initializable, System, Governed, HydraChainCo /** * @inheritdoc IPrice */ - function disableGuard() external onlyRole(MANAGER_ROLE) { + function disableGuard() external onlyGovernance { if (!disabledBonusesUpdates) { revert GuardAlreadyDisabled(); } diff --git a/contracts/HydraChain/HydraChain.sol b/contracts/HydraChain/HydraChain.sol index cfe82cda..10f5de4b 100644 --- a/contracts/HydraChain/HydraChain.sol +++ b/contracts/HydraChain/HydraChain.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.17; import {ArraysUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ArraysUpgradeable.sol"; -import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; import {IBLS} from "../BLS/IBLS.sol"; import {HydraStakingConnector} from "../HydraStaking/HydraStakingConnector.sol"; @@ -14,15 +13,7 @@ import {Uptime} from "./modules/ValidatorManager/IValidatorManager.sol"; import {IHydraChain} from "./IHydraChain.sol"; import {Epoch} from "./IHydraChain.sol"; -contract HydraChain is - IHydraChain, - Ownable2StepUpgradeable, - HydraStakingConnector, - ValidatorManager, - Inspector, - DaoIncentive, - ValidatorsData -{ +contract HydraChain is IHydraChain, HydraStakingConnector, ValidatorManager, Inspector, DaoIncentive, ValidatorsData { using ArraysUpgradeable for uint256[]; uint256 public currentEpochId; @@ -49,7 +40,6 @@ contract HydraChain is address daoIncentiveVaultAddr, IBLS newBls ) external initializer onlySystemCall { - __Ownable2Step_init(); __HydraStakingConnector_init(hydraStakingAddr); __DaoIncentive_init(aprCalculatorAddr, rewardWalletAddr, daoIncentiveVaultAddr); __ValidatorManager_init(newValidators, newBls, hydraDelegationAddr, governance); diff --git a/contracts/HydraChain/IHydraChain.sol b/contracts/HydraChain/IHydraChain.sol index 845d01ab..73eb63e8 100644 --- a/contracts/HydraChain/IHydraChain.sol +++ b/contracts/HydraChain/IHydraChain.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.17; import {IInspector} from "./modules/Inspector/IInspector.sol"; import {IDaoIncentive} from "./modules/DaoIncentive/IDaoIncentive.sol"; import {IValidatorsData} from "./modules/ValidatorsData/IValidatorsData.sol"; +import {IWhitelisting} from "./modules/Whitelisting/IWhitelisting.sol"; import {IValidatorManager, ValidatorStatus} from "./modules/ValidatorManager/IValidatorManager.sol"; import {Uptime} from "./modules/ValidatorManager/IValidatorManager.sol"; @@ -13,7 +14,7 @@ struct Epoch { bytes32 epochRoot; } -interface IHydraChain is IInspector, IValidatorManager, IDaoIncentive, IValidatorsData { +interface IHydraChain is IInspector, IValidatorManager, IDaoIncentive, IValidatorsData, IWhitelisting { event NewEpoch(uint256 indexed id, uint256 indexed startBlock, uint256 indexed endBlock, bytes32 epochRoot); error CommitEpochFailed(string reason); diff --git a/contracts/HydraChain/modules/Inspector/Inspector.sol b/contracts/HydraChain/modules/Inspector/Inspector.sol index 831359df..aa13ec16 100644 --- a/contracts/HydraChain/modules/Inspector/Inspector.sol +++ b/contracts/HydraChain/modules/Inspector/Inspector.sol @@ -7,7 +7,7 @@ import {ValidatorManager, ValidatorStatus} from "../ValidatorManager/ValidatorMa import {IInspector} from "./IInspector.sol"; abstract contract Inspector is IInspector, ValidatorManager { - /// @notice The penalty that will be taken and burned from the bad valiator's staked amount + /// @notice The penalty that will be taken and burned from the bad validator's staked amount uint256 public validatorPenalty; /// @notice The reward for the person who reports a validator that have to be banned uint256 public reporterReward; @@ -86,7 +86,7 @@ abstract contract Inspector is IInspector, ValidatorManager { bansInitiated[validator] = 0; } - if (owner() == msg.sender) { + if (_isGovernance(msg.sender)) { hydraDelegationContract.lockCommissionReward(validator); } @@ -96,28 +96,28 @@ abstract contract Inspector is IInspector, ValidatorManager { /** * @inheritdoc IInspector */ - function setValidatorPenalty(uint256 newPenalty) external onlyOwner { + function setValidatorPenalty(uint256 newPenalty) external onlyGovernance { validatorPenalty = newPenalty; } /** * @inheritdoc IInspector */ - function setReporterReward(uint256 newReward) external onlyOwner { + function setReporterReward(uint256 newReward) external onlyGovernance { reporterReward = newReward; } /** * @inheritdoc IInspector */ - function setInitiateBanThreshold(uint256 newThreshold) external onlyOwner { + function setInitiateBanThreshold(uint256 newThreshold) external onlyGovernance { initiateBanThreshold = newThreshold; } /** * @inheritdoc IInspector */ - function setBanThreshold(uint256 newThreshold) external onlyOwner { + function setBanThreshold(uint256 newThreshold) external onlyGovernance { banThreshold = newThreshold; } @@ -139,7 +139,7 @@ abstract contract Inspector is IInspector, ValidatorManager { } // check if the owner (governance) is calling - if (msg.sender == owner()) { + if (_isGovernance(msg.sender)) { return true; } @@ -153,7 +153,7 @@ abstract contract Inspector is IInspector, ValidatorManager { /** * @notice Returns if a ban process can be initiated for a given validator - * @dev funtion is overriden in the hydra chain contract + * @dev This function is overridden in the hydra chain contract * @param account The address of the validator * @return Returns true if the validator is subject to initiate ban */ @@ -168,13 +168,13 @@ abstract contract Inspector is IInspector, ValidatorManager { function _ban(address validator) private { if (validators[validator].status == ValidatorStatus.Active) { PenalizedStakeDistribution[] memory rewards; - if (msg.sender != owner()) { + if (_isGovernance(msg.sender)) { + rewards = new PenalizedStakeDistribution[](1); + rewards[0] = PenalizedStakeDistribution({account: address(0), amount: validatorPenalty}); + } else { rewards = new PenalizedStakeDistribution[](2); rewards[0] = PenalizedStakeDistribution({account: msg.sender, amount: reporterReward}); rewards[1] = PenalizedStakeDistribution({account: address(0), amount: validatorPenalty}); - } else { - rewards = new PenalizedStakeDistribution[](1); - rewards[0] = PenalizedStakeDistribution({account: address(0), amount: validatorPenalty}); } hydraStakingContract.penalizeStaker(validator, rewards); diff --git a/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol b/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol index 1b737bae..0eb92f77 100644 --- a/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol +++ b/contracts/HydraChain/modules/ValidatorManager/ValidatorManager.sol @@ -8,14 +8,14 @@ import {Unauthorized} from "../../../common/Errors.sol"; import {HydraStakingConnector} from "../../../HydraStaking/HydraStakingConnector.sol"; import {HydraDelegationConnector} from "../../../HydraDelegation/HydraDelegationConnector.sol"; import {IBLS} from "../../../BLS/IBLS.sol"; -import {AccessControl} from "../AccessControl/AccessControl.sol"; +import {Whitelisting} from "../Whitelisting/Whitelisting.sol"; import {IValidatorManager, Validator, ValidatorInit, ValidatorStatus} from "./IValidatorManager.sol"; abstract contract ValidatorManager is IValidatorManager, System, Initializable, - AccessControl, + Whitelisting, HydraStakingConnector, HydraDelegationConnector { @@ -51,7 +51,7 @@ abstract contract ValidatorManager is address _hydraDelegationAddr, address _governance ) internal onlyInitializing { - __AccessControl_init(_governance); + __Whitelisting_init(_governance); __HydraDelegationConnector_init(_hydraDelegationAddr); __ValidatorManager_init_unchained(_newValidators, _newBls); } @@ -125,7 +125,7 @@ abstract contract ValidatorManager is /** * @inheritdoc IValidatorManager */ - function updateExponent(uint256 newValue) external onlyOwner { + function updateExponent(uint256 newValue) external onlyGovernance { if (newValue < 5000 || newValue > 10000) { revert InvalidPowerExponent(); // must be 0.5 <= Exponent <= 1 } diff --git a/contracts/HydraChain/modules/AccessControl/IAccessControl.sol b/contracts/HydraChain/modules/Whitelisting/IWhitelisting.sol similarity index 77% rename from contracts/HydraChain/modules/AccessControl/IAccessControl.sol rename to contracts/HydraChain/modules/Whitelisting/IWhitelisting.sol index c8df3056..fcf978a8 100644 --- a/contracts/HydraChain/modules/AccessControl/IAccessControl.sol +++ b/contracts/HydraChain/modules/Whitelisting/IWhitelisting.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -interface IAccessControl { +interface IWhitelisting { event AddedToWhitelist(address indexed validator); event RemovedFromWhitelist(address indexed validator); @@ -24,13 +24,13 @@ interface IAccessControl { /** * @notice Adds addresses that are allowed to register as validators. - * @param whitelistAddreses Array of address to whitelist + * @param whitelistAddresses Array of address to whitelist */ - function addToWhitelist(address[] calldata whitelistAddreses) external; + function addToWhitelist(address[] calldata whitelistAddresses) external; /** * @notice Deletes addresses that are allowed to register as validators. - * @param whitelistAddreses Array of address to remove from whitelist + * @param whitelistAddresses Array of address to remove from whitelist */ - function removeFromWhitelist(address[] calldata whitelistAddreses) external; + function removeFromWhitelist(address[] calldata whitelistAddresses) external; } diff --git a/contracts/HydraChain/modules/AccessControl/AccessControl.sol b/contracts/HydraChain/modules/Whitelisting/Whitelisting.sol similarity index 60% rename from contracts/HydraChain/modules/AccessControl/AccessControl.sol rename to contracts/HydraChain/modules/Whitelisting/Whitelisting.sol index 7b11ff2a..adc3ad48 100644 --- a/contracts/HydraChain/modules/AccessControl/AccessControl.sol +++ b/contracts/HydraChain/modules/Whitelisting/Whitelisting.sol @@ -1,24 +1,23 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; +import {Governed} from "../../../common/Governed/Governed.sol"; +import {IWhitelisting} from "./IWhitelisting.sol"; -import {IAccessControl} from "./IAccessControl.sol"; - -abstract contract AccessControl is IAccessControl, Ownable2StepUpgradeable { +abstract contract Whitelisting is IWhitelisting, Governed { mapping(address => bool) public isWhitelisted; bool public isWhitelistingEnabled; // _______________ Initializer _______________ // solhint-disable-next-line func-name-mixedcase - function __AccessControl_init(address _governance) internal onlyInitializing { - __AccessControl_init_unchained(_governance); + function __Whitelisting_init(address _governance) internal onlyInitializing { + __Governed_init(_governance); + __Whitelisting_init_unchained(); } // solhint-disable-next-line func-name-mixedcase - function __AccessControl_init_unchained(address _governance) internal onlyInitializing { - _transferOwnership(_governance); + function __Whitelisting_init_unchained() internal onlyInitializing { isWhitelistingEnabled = true; } @@ -35,36 +34,36 @@ abstract contract AccessControl is IAccessControl, Ownable2StepUpgradeable { // _______________ External functions _______________ /** - * @inheritdoc IAccessControl + * @inheritdoc IWhitelisting */ - function enableWhitelisting() external onlyOwner { + function enableWhitelisting() external onlyGovernance { if (isWhitelistingEnabled) revert WhitelistingAlreadyEnabled(); isWhitelistingEnabled = true; } /** - * @inheritdoc IAccessControl + * @inheritdoc IWhitelisting */ - function disableWhitelisting() external onlyOwner { + function disableWhitelisting() external onlyGovernance { if (!isWhitelistingEnabled) revert WhitelistingAlreadyDisabled(); isWhitelistingEnabled = false; } /** - * @inheritdoc IAccessControl + * @inheritdoc IWhitelisting */ - function addToWhitelist(address[] calldata whitelistAddreses) external onlyOwner { - for (uint256 i = 0; i < whitelistAddreses.length; i++) { - _addToWhitelist(whitelistAddreses[i]); + function addToWhitelist(address[] calldata whitelistAddresses) external onlyGovernance { + for (uint256 i = 0; i < whitelistAddresses.length; i++) { + _addToWhitelist(whitelistAddresses[i]); } } /** - * @inheritdoc IAccessControl + * @inheritdoc IWhitelisting */ - function removeFromWhitelist(address[] calldata whitelistAddreses) external onlyOwner { - for (uint256 i = 0; i < whitelistAddreses.length; i++) { - _removeFromWhitelist(whitelistAddreses[i]); + function removeFromWhitelist(address[] calldata whitelistAddresses) external onlyGovernance { + for (uint256 i = 0; i < whitelistAddresses.length; i++) { + _removeFromWhitelist(whitelistAddresses[i]); } } diff --git a/contracts/HydraDelegation/Delegation.sol b/contracts/HydraDelegation/Delegation.sol index 7997ae59..1541391b 100644 --- a/contracts/HydraDelegation/Delegation.sol +++ b/contracts/HydraDelegation/Delegation.sol @@ -75,7 +75,7 @@ contract Delegation is /** * @inheritdoc IDelegation */ - function changeMinDelegation(uint256 newMinDelegation) external onlyRole(DEFAULT_ADMIN_ROLE) { + function changeMinDelegation(uint256 newMinDelegation) external onlyGovernance { _changeMinDelegation(newMinDelegation); } diff --git a/contracts/HydraStaking/Staking.sol b/contracts/HydraStaking/Staking.sol index 058ba26a..2abcd672 100644 --- a/contracts/HydraStaking/Staking.sol +++ b/contracts/HydraStaking/Staking.sol @@ -76,7 +76,7 @@ contract Staking is IStaking, Governed, Withdrawal, HydraChainConnector, APRCalc /** * @inheritdoc IStaking */ - function changeMinStake(uint256 newMinStake) external onlyRole(DEFAULT_ADMIN_ROLE) { + function changeMinStake(uint256 newMinStake) external onlyGovernance { _changeMinStake(newMinStake); } diff --git a/contracts/HydraVault/HydraVault.sol b/contracts/HydraVault/HydraVault.sol index a12429d6..3ef6f520 100644 --- a/contracts/HydraVault/HydraVault.sol +++ b/contracts/HydraVault/HydraVault.sol @@ -2,18 +2,18 @@ pragma solidity 0.8.17; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {System} from "../common/System/System.sol"; +import {Governed} from "../common/Governed/Governed.sol"; -contract HydraVault is Initializable, System, OwnableUpgradeable { +contract HydraVault is Initializable, System, Governed { event FeeReceived(address indexed from, uint256 amount); event FeesRelocated(bool success, bytes data); // _______________ Initializer _______________ function initialize(address governance) public initializer onlySystemCall { - _transferOwnership(governance); + __Governed_init(governance); } // _______________ External functions _______________ @@ -23,7 +23,7 @@ contract HydraVault is Initializable, System, OwnableUpgradeable { * @param contractAddress The address of the contract that will be called * @param callData The encoded function with its signature and parameters, if any */ - function relocateFees(address contractAddress, bytes memory callData) external onlyOwner { + function relocateFees(address contractAddress, bytes memory callData) external onlyGovernance { (bool success, bytes memory data) = contractAddress.call{value: address(this).balance}(callData); emit FeesRelocated(success, data); diff --git a/contracts/common/Governed/Governed.sol b/contracts/common/Governed/Governed.sol index 486572c4..89eeba41 100644 --- a/contracts/common/Governed/Governed.sol +++ b/contracts/common/Governed/Governed.sol @@ -3,6 +3,8 @@ pragma solidity 0.8.17; import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; +import {Unauthorized} from "../Errors.sol"; + abstract contract Governed is AccessControlUpgradeable { // solhint-disable-next-line func-name-mixedcase function __Governed_init(address governance) internal onlyInitializing { @@ -15,6 +17,22 @@ abstract contract Governed is AccessControlUpgradeable { _grantRole(DEFAULT_ADMIN_ROLE, governance); } + // _______________ Modifiers _______________ + + modifier onlyGovernance() { + if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) { + revert Unauthorized("GOVERNANCE_ONLY"); + } + + _; + } + + // _______________ Internal functions _______________ + + function _isGovernance(address account) internal view returns (bool) { + return hasRole(DEFAULT_ADMIN_ROLE, account); + } + // slither-disable-next-line unused-state,naming-convention uint256[50] private __gap; } diff --git a/contracts/common/Withdrawal/Withdrawal.sol b/contracts/common/Withdrawal/Withdrawal.sol index 3bd59849..52636c7f 100644 --- a/contracts/common/Withdrawal/Withdrawal.sol +++ b/contracts/common/Withdrawal/Withdrawal.sol @@ -44,7 +44,7 @@ abstract contract Withdrawal is IWithdrawal, ReentrancyGuardUpgradeable, Governe /** * @inheritdoc IWithdrawal */ - function changeWithdrawalWaitPeriod(uint256 newWaitPeriod) external onlyRole(DEFAULT_ADMIN_ROLE) { + function changeWithdrawalWaitPeriod(uint256 newWaitPeriod) external onlyGovernance { _changeWithdrawalWaitPeriod(newWaitPeriod); } diff --git a/docs/APRCalculator/APRCalculator.md b/docs/APRCalculator/APRCalculator.md index 2de530e4..346185db 100644 --- a/docs/APRCalculator/APRCalculator.md +++ b/docs/APRCalculator/APRCalculator.md @@ -78,23 +78,6 @@ function FAST_SMA() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### MANAGER_ROLE - -```solidity -function MANAGER_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - ### MAX_MACRO_FACTOR ```solidity diff --git a/docs/APRCalculator/modules/MacroFactor/MacroFactor.md b/docs/APRCalculator/modules/MacroFactor/MacroFactor.md index 5972ad37..47d45e42 100644 --- a/docs/APRCalculator/modules/MacroFactor/MacroFactor.md +++ b/docs/APRCalculator/modules/MacroFactor/MacroFactor.md @@ -61,23 +61,6 @@ function FAST_SMA() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### MANAGER_ROLE - -```solidity -function MANAGER_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - ### MAX_MACRO_FACTOR ```solidity diff --git a/docs/APRCalculator/modules/Price/Price.md b/docs/APRCalculator/modules/Price/Price.md index 2ad186eb..f8f7d8e7 100644 --- a/docs/APRCalculator/modules/Price/Price.md +++ b/docs/APRCalculator/modules/Price/Price.md @@ -44,23 +44,6 @@ function DENOMINATOR() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### MANAGER_ROLE - -```solidity -function MANAGER_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - ### NATIVE_TOKEN_CONTRACT ```solidity diff --git a/docs/APRCalculator/modules/RSI/RSIndex.md b/docs/APRCalculator/modules/RSI/RSIndex.md index 96021b1e..7308c5a3 100644 --- a/docs/APRCalculator/modules/RSI/RSIndex.md +++ b/docs/APRCalculator/modules/RSI/RSIndex.md @@ -44,23 +44,6 @@ function DENOMINATOR() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### MANAGER_ROLE - -```solidity -function MANAGER_ROLE() external view returns (bytes32) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bytes32 | undefined | - ### MAX_RSI_BONUS ```solidity diff --git a/docs/HydraChain/HydraChain.md b/docs/HydraChain/HydraChain.md index f158bcab..704d0e21 100644 --- a/docs/HydraChain/HydraChain.md +++ b/docs/HydraChain/HydraChain.md @@ -10,6 +10,23 @@ ## Methods +### DEFAULT_ADMIN_ROLE + +```solidity +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### DOMAIN ```solidity @@ -146,17 +163,6 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### activateValidator ```solidity @@ -193,7 +199,7 @@ function activeValidatorsCount() external view returns (uint256) ### addToWhitelist ```solidity -function addToWhitelist(address[] whitelistAddreses) external nonpayable +function addToWhitelist(address[] whitelistAddresses) external nonpayable ``` Adds addresses that are allowed to register as validators. @@ -204,7 +210,7 @@ Adds addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to whitelist | +| whitelistAddresses | address[] | Array of address to whitelist | ### aprCalculatorContract @@ -532,6 +538,28 @@ Look up an epoch by block number. Searches in O(log n) time. |---|---|---| | _0 | Epoch | Epoch Returns epoch if found, or else, the last epoch | +### getRoleAdmin + +```solidity +function getRoleAdmin(bytes32 role) external view returns (bytes32) +``` + + + +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### getTotalVotingPower ```solidity @@ -617,6 +645,46 @@ Gets all validators. Returns already unactive validators as well. |---|---|---| | _0 | address[] | Returns array of addresses | +### grantRole + +```solidity +function grantRole(bytes32 role, address account) external nonpayable +``` + + + +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### hasRole + +```solidity +function hasRole(bytes32 role, address account) external view returns (bool) +``` + + + +*Returns `true` if `account` has been granted `role`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + ### hydraDelegationContract ```solidity @@ -737,7 +805,7 @@ function isSubjectToInitiateBan(address validator) external view returns (bool) Returns if a ban process can be initiated for a given validator -*funtion is overriden in the hydra chain contract* +*This function is overridden in the hydra chain contract* #### Parameters @@ -873,40 +941,6 @@ last rewards distribution timestamp |---|---|---| | _0 | uint256 | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### powerExponent ```solidity @@ -944,7 +978,7 @@ Validates BLS signature with the provided pubkey and registers validators into t ### removeFromWhitelist ```solidity -function removeFromWhitelist(address[] whitelistAddreses) external nonpayable +function removeFromWhitelist(address[] whitelistAddresses) external nonpayable ``` Deletes addresses that are allowed to register as validators. @@ -955,18 +989,24 @@ Deletes addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to remove from whitelist | +| whitelistAddresses | address[] | Array of address to remove from whitelist | -### renounceOwnership +### renounceRole ```solidity -function renounceOwnership() external nonpayable +function renounceRole(bytes32 role, address account) external nonpayable ``` -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | ### reporterReward @@ -985,6 +1025,23 @@ The reward for the person who reports a validator that have to be banned |---|---|---| | _0 | uint256 | undefined | +### revokeRole + +```solidity +function revokeRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + ### rewardWalletContract ```solidity @@ -1066,6 +1123,28 @@ Set the penalty amount for the banned validators |---|---|---| | newPenalty | uint256 | Amount of the penalty | +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*See {IERC165-supportsInterface}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + ### syncValidatorsData ```solidity @@ -1132,22 +1211,6 @@ function totalVotingPower() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - ### updateExponent ```solidity @@ -1170,7 +1233,7 @@ Sets new Voting Power Exponent Numerator. function validatorPenalty() external view returns (uint256) ``` -The penalty that will be taken and burned from the bad valiator's staked amount +The penalty that will be taken and burned from the bad validator's staked amount @@ -1359,10 +1422,26 @@ event NewValidator(address indexed validator, uint256[4] blsKey) | validator `indexed` | address | undefined | | blsKey | uint256[4] | undefined | -### OwnershipTransferStarted +### PowerExponentUpdated + +```solidity +event PowerExponentUpdated(uint256 newPowerExponent) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newPowerExponent | uint256 | undefined | + +### RemovedFromWhitelist ```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) +event RemovedFromWhitelist(address indexed validator) ``` @@ -1373,13 +1452,12 @@ event OwnershipTransferStarted(address indexed previousOwner, address indexed ne | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| validator `indexed` | address | undefined | -### OwnershipTransferred +### RoleAdminChanged ```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) ``` @@ -1390,13 +1468,14 @@ event OwnershipTransferred(address indexed previousOwner, address indexed newOwn | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | -### PowerExponentUpdated +### RoleGranted ```solidity -event PowerExponentUpdated(uint256 newPowerExponent) +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -1407,12 +1486,14 @@ event PowerExponentUpdated(uint256 newPowerExponent) | Name | Type | Description | |---|---|---| -| newPowerExponent | uint256 | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | -### RemovedFromWhitelist +### RoleRevoked ```solidity -event RemovedFromWhitelist(address indexed validator) +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -1423,7 +1504,9 @@ event RemovedFromWhitelist(address indexed validator) | Name | Type | Description | |---|---|---| -| validator `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | ### ValidatorBanned diff --git a/docs/HydraChain/IHydraChain.md b/docs/HydraChain/IHydraChain.md index a1475a4a..c55dbde4 100644 --- a/docs/HydraChain/IHydraChain.md +++ b/docs/HydraChain/IHydraChain.md @@ -26,6 +26,22 @@ Activates validator. |---|---|---| | account | address | Address of the validator | +### addToWhitelist + +```solidity +function addToWhitelist(address[] whitelistAddresses) external nonpayable +``` + +Adds addresses that are allowed to register as validators. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| whitelistAddresses | address[] | Array of address to whitelist | + ### banIsInitiated ```solidity @@ -110,6 +126,17 @@ Deactivates validator. |---|---|---| | account | address | Address of the validator | +### disableWhitelisting + +```solidity +function disableWhitelisting() external nonpayable +``` + +Disables the whitelisting feature. + +*Only callable by the contract owner.* + + ### distributeDAOIncentive ```solidity @@ -121,6 +148,17 @@ Distribute vault funds *Only callable by the system* +### enableWhitelisting + +```solidity +function enableWhitelisting() external nonpayable +``` + +Enables the whitelisting feature. + +*Only callable by the contract owner.* + + ### getActiveValidatorsCount ```solidity @@ -383,6 +421,22 @@ Validates BLS signature with the provided pubkey and registers validators into t | signature | uint256[2] | Signature to validate message against | | pubkey | uint256[4] | BLS public key of validator | +### removeFromWhitelist + +```solidity +function removeFromWhitelist(address[] whitelistAddresses) external nonpayable +``` + +Deletes addresses that are allowed to register as validators. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| whitelistAddresses | address[] | Array of address to remove from whitelist | + ### setBanThreshold ```solidity @@ -516,6 +570,22 @@ Sets new Voting Power Exponent Numerator. ## Events +### AddedToWhitelist + +```solidity +event AddedToWhitelist(address indexed validator) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validator `indexed` | address | undefined | + ### NewEpoch ```solidity @@ -568,6 +638,22 @@ event PowerExponentUpdated(uint256 newPowerExponent) |---|---|---| | newPowerExponent | uint256 | undefined | +### RemovedFromWhitelist + +```solidity +event RemovedFromWhitelist(address indexed validator) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validator `indexed` | address | undefined | + ### ValidatorBanned ```solidity @@ -701,6 +787,17 @@ error MaxValidatorsReached() +### MustBeWhitelisted + +```solidity +error MustBeWhitelisted() +``` + + + + + + ### NoBanInitiated ```solidity @@ -745,4 +842,37 @@ error NoVaultFundsToClaim() +### PreviouslyWhitelisted + +```solidity +error PreviouslyWhitelisted() +``` + + + + + + +### WhitelistingAlreadyDisabled + +```solidity +error WhitelistingAlreadyDisabled() +``` + + + + + + +### WhitelistingAlreadyEnabled + +```solidity +error WhitelistingAlreadyEnabled() +``` + + + + + + diff --git a/docs/HydraChain/modules/AccessControl/AccessControl.md b/docs/HydraChain/modules/AccessControl/AccessControl.md deleted file mode 100644 index 3d871f9d..00000000 --- a/docs/HydraChain/modules/AccessControl/AccessControl.md +++ /dev/null @@ -1,312 +0,0 @@ -# AccessControl - - - - - - - - - -## Methods - -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - -### addToWhitelist - -```solidity -function addToWhitelist(address[] whitelistAddreses) external nonpayable -``` - -Adds addresses that are allowed to register as validators. - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| whitelistAddreses | address[] | Array of address to whitelist | - -### disableWhitelisting - -```solidity -function disableWhitelisting() external nonpayable -``` - -Disables the whitelisting feature. - -*Only callable by the contract owner.* - - -### enableWhitelisting - -```solidity -function enableWhitelisting() external nonpayable -``` - -Enables the whitelisting feature. - -*Only callable by the contract owner.* - - -### isWhitelisted - -```solidity -function isWhitelisted(address) external view returns (bool) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### isWhitelistingEnabled - -```solidity -function isWhitelistingEnabled() external view returns (bool) -``` - - - - - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | bool | undefined | - -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### removeFromWhitelist - -```solidity -function removeFromWhitelist(address[] whitelistAddreses) external nonpayable -``` - -Deletes addresses that are allowed to register as validators. - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| whitelistAddreses | address[] | Array of address to remove from whitelist | - -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - - - -## Events - -### AddedToWhitelist - -```solidity -event AddedToWhitelist(address indexed validator) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| validator `indexed` | address | undefined | - -### Initialized - -```solidity -event Initialized(uint8 version) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| version | uint8 | undefined | - -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### RemovedFromWhitelist - -```solidity -event RemovedFromWhitelist(address indexed validator) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| validator `indexed` | address | undefined | - - - -## Errors - -### MustBeWhitelisted - -```solidity -error MustBeWhitelisted() -``` - - - - - - -### PreviouslyWhitelisted - -```solidity -error PreviouslyWhitelisted() -``` - - - - - - -### WhitelistingAlreadyDisabled - -```solidity -error WhitelistingAlreadyDisabled() -``` - - - - - - -### WhitelistingAlreadyEnabled - -```solidity -error WhitelistingAlreadyEnabled() -``` - - - - - - - diff --git a/docs/HydraChain/modules/Inspector/Inspector.md b/docs/HydraChain/modules/Inspector/Inspector.md index 1f0a02d1..be58fd19 100644 --- a/docs/HydraChain/modules/Inspector/Inspector.md +++ b/docs/HydraChain/modules/Inspector/Inspector.md @@ -10,6 +10,23 @@ ## Methods +### DEFAULT_ADMIN_ROLE + +```solidity +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### DOMAIN ```solidity @@ -146,17 +163,6 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### activateValidator ```solidity @@ -193,7 +199,7 @@ function activeValidatorsCount() external view returns (uint256) ### addToWhitelist ```solidity -function addToWhitelist(address[] whitelistAddreses) external nonpayable +function addToWhitelist(address[] whitelistAddresses) external nonpayable ``` Adds addresses that are allowed to register as validators. @@ -204,7 +210,7 @@ Adds addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to whitelist | +| whitelistAddresses | address[] | Array of address to whitelist | ### banIsInitiated @@ -355,6 +361,28 @@ Gets the number of current validators |---|---|---| | _0 | uint256 | Returns the count as uint256 | +### getRoleAdmin + +```solidity +function getRoleAdmin(bytes32 role) external view returns (bytes32) +``` + + + +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### getValidators ```solidity @@ -372,6 +400,46 @@ Gets all validators. Returns already unactive validators as well. |---|---|---| | _0 | address[] | Returns array of addresses | +### grantRole + +```solidity +function grantRole(bytes32 role, address account) external nonpayable +``` + + + +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### hasRole + +```solidity +function hasRole(bytes32 role, address account) external view returns (bool) +``` + + + +*Returns `true` if `account` has been granted `role`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + ### hydraDelegationContract ```solidity @@ -469,7 +537,7 @@ function isSubjectToInitiateBan(address account) external nonpayable returns (bo Returns if a ban process can be initiated for a given validator -*funtion is overriden in the hydra chain contract* +*This function is overridden in the hydra chain contract* #### Parameters @@ -588,40 +656,6 @@ function isWhitelistingEnabled() external view returns (bool) |---|---|---| | _0 | bool | undefined | -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - ### powerExponent ```solidity @@ -659,7 +693,7 @@ Validates BLS signature with the provided pubkey and registers validators into t ### removeFromWhitelist ```solidity -function removeFromWhitelist(address[] whitelistAddreses) external nonpayable +function removeFromWhitelist(address[] whitelistAddresses) external nonpayable ``` Deletes addresses that are allowed to register as validators. @@ -670,18 +704,24 @@ Deletes addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to remove from whitelist | +| whitelistAddresses | address[] | Array of address to remove from whitelist | -### renounceOwnership +### renounceRole ```solidity -function renounceOwnership() external nonpayable +function renounceRole(bytes32 role, address account) external nonpayable ``` -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* + +#### Parameters +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | ### reporterReward @@ -700,6 +740,23 @@ The reward for the person who reports a validator that have to be banned |---|---|---| | _0 | uint256 | undefined | +### revokeRole + +```solidity +function revokeRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + ### setBanThreshold ```solidity @@ -764,32 +821,38 @@ Set the penalty amount for the banned validators |---|---|---| | newPenalty | uint256 | Amount of the penalty | -### terminateBanProcedure +### supportsInterface ```solidity -function terminateBanProcedure() external nonpayable +function supportsInterface(bytes4 interfaceId) external view returns (bool) ``` -Method used to terminate the ban procedure +*See {IERC165-supportsInterface}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | -### transferOwnership +### terminateBanProcedure ```solidity -function transferOwnership(address newOwner) external nonpayable +function terminateBanProcedure() external nonpayable ``` +Method used to terminate the ban procedure -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | ### updateExponent @@ -813,7 +876,7 @@ Sets new Voting Power Exponent Numerator. function validatorPenalty() external view returns (uint256) ``` -The penalty that will be taken and burned from the bad valiator's staked amount +The penalty that will be taken and burned from the bad validator's staked amount @@ -944,10 +1007,26 @@ event NewValidator(address indexed validator, uint256[4] blsKey) | validator `indexed` | address | undefined | | blsKey | uint256[4] | undefined | -### OwnershipTransferStarted +### PowerExponentUpdated + +```solidity +event PowerExponentUpdated(uint256 newPowerExponent) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| newPowerExponent | uint256 | undefined | + +### RemovedFromWhitelist ```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) +event RemovedFromWhitelist(address indexed validator) ``` @@ -958,13 +1037,12 @@ event OwnershipTransferStarted(address indexed previousOwner, address indexed ne | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| validator `indexed` | address | undefined | -### OwnershipTransferred +### RoleAdminChanged ```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) ``` @@ -975,13 +1053,14 @@ event OwnershipTransferred(address indexed previousOwner, address indexed newOwn | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | -### PowerExponentUpdated +### RoleGranted ```solidity -event PowerExponentUpdated(uint256 newPowerExponent) +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -992,12 +1071,14 @@ event PowerExponentUpdated(uint256 newPowerExponent) | Name | Type | Description | |---|---|---| -| newPowerExponent | uint256 | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | -### RemovedFromWhitelist +### RoleRevoked ```solidity -event RemovedFromWhitelist(address indexed validator) +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -1008,7 +1089,9 @@ event RemovedFromWhitelist(address indexed validator) | Name | Type | Description | |---|---|---| -| validator `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | ### ValidatorBanned diff --git a/docs/HydraChain/modules/ValidatorManager/ValidatorManager.md b/docs/HydraChain/modules/ValidatorManager/ValidatorManager.md index 82da1460..a3598891 100644 --- a/docs/HydraChain/modules/ValidatorManager/ValidatorManager.md +++ b/docs/HydraChain/modules/ValidatorManager/ValidatorManager.md @@ -10,6 +10,23 @@ ## Methods +### DEFAULT_ADMIN_ROLE + +```solidity +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### DOMAIN ```solidity @@ -146,17 +163,6 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - ### activateValidator ```solidity @@ -193,7 +199,7 @@ function activeValidatorsCount() external view returns (uint256) ### addToWhitelist ```solidity -function addToWhitelist(address[] whitelistAddreses) external nonpayable +function addToWhitelist(address[] whitelistAddresses) external nonpayable ``` Adds addresses that are allowed to register as validators. @@ -204,7 +210,7 @@ Adds addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to whitelist | +| whitelistAddresses | address[] | Array of address to whitelist | ### bls @@ -278,6 +284,28 @@ Gets the number of current validators |---|---|---| | _0 | uint256 | Returns the count as uint256 | +### getRoleAdmin + +```solidity +function getRoleAdmin(bytes32 role) external view returns (bytes32) +``` + + + +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### getValidators ```solidity @@ -295,6 +323,46 @@ Gets all validators. Returns already unactive validators as well. |---|---|---| | _0 | address[] | Returns array of addresses | +### grantRole + +```solidity +function grantRole(bytes32 role, address account) external nonpayable +``` + + + +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### hasRole + +```solidity +function hasRole(bytes32 role, address account) external view returns (bool) +``` + + + +*Returns `true` if `account` has been granted `role`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + ### hydraDelegationContract ```solidity @@ -434,116 +502,111 @@ function isWhitelistingEnabled() external view returns (bool) |---|---|---| | _0 | bool | undefined | -### owner +### powerExponent ```solidity -function owner() external view returns (address) +function powerExponent() external view returns (uint256) ``` +`powerExponent` represents the numerator of the Voting Power Exponent, where the denominator is 10,000. The Voting Power Exponent is a fractional value between 0.5 and 1, used to exponentially decrease the voting power of a validator. This mechanism encourages better decentralization of the network. -*Returns the address of the current owner.* #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| _0 | uint256 | undefined | -### pendingOwner +### register ```solidity -function pendingOwner() external view returns (address) +function register(uint256[2] signature, uint256[4] pubkey) external nonpayable ``` +Validates BLS signature with the provided pubkey and registers validators into the set. +*Validator must be whitelisted.* -*Returns the address of the pending owner.* - - -#### Returns +#### Parameters | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| signature | uint256[2] | Signature to validate message against | +| pubkey | uint256[4] | BLS public key of validator | -### powerExponent +### removeFromWhitelist ```solidity -function powerExponent() external view returns (uint256) +function removeFromWhitelist(address[] whitelistAddresses) external nonpayable ``` -`powerExponent` represents the numerator of the Voting Power Exponent, where the denominator is 10,000. The Voting Power Exponent is a fractional value between 0.5 and 1, used to exponentially decrease the voting power of a validator. This mechanism encourages better decentralization of the network. - +Deletes addresses that are allowed to register as validators. -#### Returns +#### Parameters | Name | Type | Description | |---|---|---| -| _0 | uint256 | undefined | +| whitelistAddresses | address[] | Array of address to remove from whitelist | -### register +### renounceRole ```solidity -function register(uint256[2] signature, uint256[4] pubkey) external nonpayable +function renounceRole(bytes32 role, address account) external nonpayable ``` -Validates BLS signature with the provided pubkey and registers validators into the set. -*Validator must be whitelisted.* + +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* #### Parameters | Name | Type | Description | |---|---|---| -| signature | uint256[2] | Signature to validate message against | -| pubkey | uint256[4] | BLS public key of validator | +| role | bytes32 | undefined | +| account | address | undefined | -### removeFromWhitelist +### revokeRole ```solidity -function removeFromWhitelist(address[] whitelistAddreses) external nonpayable +function revokeRole(bytes32 role, address account) external nonpayable ``` -Deletes addresses that are allowed to register as validators. +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* #### Parameters | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to remove from whitelist | +| role | bytes32 | undefined | +| account | address | undefined | -### renounceOwnership +### supportsInterface ```solidity -function renounceOwnership() external nonpayable +function supportsInterface(bytes4 interfaceId) external view returns (bool) ``` -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - +*See {IERC165-supportsInterface}.* +#### Parameters -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | -#### Parameters +#### Returns | Name | Type | Description | |---|---|---| -| newOwner | address | undefined | +| _0 | bool | undefined | ### updateExponent @@ -681,10 +744,10 @@ event NewValidator(address indexed validator, uint256[4] blsKey) | validator `indexed` | address | undefined | | blsKey | uint256[4] | undefined | -### OwnershipTransferStarted +### PowerExponentUpdated ```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) +event PowerExponentUpdated(uint256 newPowerExponent) ``` @@ -695,13 +758,12 @@ event OwnershipTransferStarted(address indexed previousOwner, address indexed ne | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| newPowerExponent | uint256 | undefined | -### OwnershipTransferred +### RemovedFromWhitelist ```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +event RemovedFromWhitelist(address indexed validator) ``` @@ -712,13 +774,12 @@ event OwnershipTransferred(address indexed previousOwner, address indexed newOwn | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| validator `indexed` | address | undefined | -### PowerExponentUpdated +### RoleAdminChanged ```solidity -event PowerExponentUpdated(uint256 newPowerExponent) +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) ``` @@ -729,12 +790,14 @@ event PowerExponentUpdated(uint256 newPowerExponent) | Name | Type | Description | |---|---|---| -| newPowerExponent | uint256 | undefined | +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | -### RemovedFromWhitelist +### RoleGranted ```solidity -event RemovedFromWhitelist(address indexed validator) +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -745,7 +808,27 @@ event RemovedFromWhitelist(address indexed validator) | Name | Type | Description | |---|---|---| -| validator `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + +### RoleRevoked + +```solidity +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | diff --git a/docs/HydraChain/modules/AccessControl/IAccessControl.md b/docs/HydraChain/modules/Whitelisting/IWhitelisting.md similarity index 82% rename from docs/HydraChain/modules/AccessControl/IAccessControl.md rename to docs/HydraChain/modules/Whitelisting/IWhitelisting.md index 2acab876..135bef97 100644 --- a/docs/HydraChain/modules/AccessControl/IAccessControl.md +++ b/docs/HydraChain/modules/Whitelisting/IWhitelisting.md @@ -1,4 +1,4 @@ -# IAccessControl +# IWhitelisting @@ -13,7 +13,7 @@ ### addToWhitelist ```solidity -function addToWhitelist(address[] whitelistAddreses) external nonpayable +function addToWhitelist(address[] whitelistAddresses) external nonpayable ``` Adds addresses that are allowed to register as validators. @@ -24,7 +24,7 @@ Adds addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to whitelist | +| whitelistAddresses | address[] | Array of address to whitelist | ### disableWhitelisting @@ -51,7 +51,7 @@ Enables the whitelisting feature. ### removeFromWhitelist ```solidity -function removeFromWhitelist(address[] whitelistAddreses) external nonpayable +function removeFromWhitelist(address[] whitelistAddresses) external nonpayable ``` Deletes addresses that are allowed to register as validators. @@ -62,7 +62,7 @@ Deletes addresses that are allowed to register as validators. | Name | Type | Description | |---|---|---| -| whitelistAddreses | address[] | Array of address to remove from whitelist | +| whitelistAddresses | address[] | Array of address to remove from whitelist | diff --git a/docs/HydraChain/modules/Whitelisting/Whitelisting.md b/docs/HydraChain/modules/Whitelisting/Whitelisting.md new file mode 100644 index 00000000..a2c219a8 --- /dev/null +++ b/docs/HydraChain/modules/Whitelisting/Whitelisting.md @@ -0,0 +1,411 @@ +# Whitelisting + + + + + + + + + +## Methods + +### DEFAULT_ADMIN_ROLE + +```solidity +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + +### addToWhitelist + +```solidity +function addToWhitelist(address[] whitelistAddresses) external nonpayable +``` + +Adds addresses that are allowed to register as validators. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| whitelistAddresses | address[] | Array of address to whitelist | + +### disableWhitelisting + +```solidity +function disableWhitelisting() external nonpayable +``` + +Disables the whitelisting feature. + +*Only callable by the contract owner.* + + +### enableWhitelisting + +```solidity +function enableWhitelisting() external nonpayable +``` + +Enables the whitelisting feature. + +*Only callable by the contract owner.* + + +### getRoleAdmin + +```solidity +function getRoleAdmin(bytes32 role) external view returns (bytes32) +``` + + + +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + +### grantRole + +```solidity +function grantRole(bytes32 role, address account) external nonpayable +``` + + + +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### hasRole + +```solidity +function hasRole(bytes32 role, address account) external view returns (bool) +``` + + + +*Returns `true` if `account` has been granted `role`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### isWhitelisted + +```solidity +function isWhitelisted(address) external view returns (bool) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### isWhitelistingEnabled + +```solidity +function isWhitelistingEnabled() external view returns (bool) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### removeFromWhitelist + +```solidity +function removeFromWhitelist(address[] whitelistAddresses) external nonpayable +``` + +Deletes addresses that are allowed to register as validators. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| whitelistAddresses | address[] | Array of address to remove from whitelist | + +### renounceRole + +```solidity +function renounceRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### revokeRole + +```solidity +function revokeRole(bytes32 role, address account) external nonpayable +``` + + + +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*See {IERC165-supportsInterface}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + + + +## Events + +### AddedToWhitelist + +```solidity +event AddedToWhitelist(address indexed validator) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validator `indexed` | address | undefined | + +### Initialized + +```solidity +event Initialized(uint8 version) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| version | uint8 | undefined | + +### RemovedFromWhitelist + +```solidity +event RemovedFromWhitelist(address indexed validator) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| validator `indexed` | address | undefined | + +### RoleAdminChanged + +```solidity +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | + +### RoleGranted + +```solidity +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + +### RoleRevoked + +```solidity +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + + + +## Errors + +### MustBeWhitelisted + +```solidity +error MustBeWhitelisted() +``` + + + + + + +### PreviouslyWhitelisted + +```solidity +error PreviouslyWhitelisted() +``` + + + + + + +### Unauthorized + +```solidity +error Unauthorized(string only) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| only | string | undefined | + +### WhitelistingAlreadyDisabled + +```solidity +error WhitelistingAlreadyDisabled() +``` + + + + + + +### WhitelistingAlreadyEnabled + +```solidity +error WhitelistingAlreadyEnabled() +``` + + + + + + + diff --git a/docs/HydraVault/HydraVault.md b/docs/HydraVault/HydraVault.md index 8bdb1ef1..702b04de 100644 --- a/docs/HydraVault/HydraVault.md +++ b/docs/HydraVault/HydraVault.md @@ -10,6 +10,23 @@ ## Methods +### DEFAULT_ADMIN_ROLE + +```solidity +function DEFAULT_ADMIN_ROLE() external view returns (bytes32) +``` + + + + + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | + ### NATIVE_TOKEN_CONTRACT ```solidity @@ -112,38 +129,83 @@ function VALIDATOR_PKCHECK_PRECOMPILE_GAS() external view returns (uint256) |---|---|---| | _0 | uint256 | undefined | -### initialize +### getRoleAdmin ```solidity -function initialize(address governance) external nonpayable +function getRoleAdmin(bytes32 role) external view returns (bytes32) ``` +*Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes32 | undefined | +### grantRole + +```solidity +function grantRole(bytes32 role, address account) external nonpayable +``` + + + +*Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleGranted} event.* #### Parameters | Name | Type | Description | |---|---|---| -| governance | address | undefined | +| role | bytes32 | undefined | +| account | address | undefined | -### owner +### hasRole ```solidity -function owner() external view returns (address) +function hasRole(bytes32 role, address account) external view returns (bool) ``` -*Returns the address of the current owner.* +*Returns `true` if `account` has been granted `role`.* +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | #### Returns | Name | Type | Description | |---|---|---| -| _0 | address | undefined | +| _0 | bool | undefined | + +### initialize + +```solidity +function initialize(address governance) external nonpayable +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| governance | address | undefined | ### relocateFees @@ -162,32 +224,61 @@ Generic method that will be used to transfer the generated fees to another contr | contractAddress | address | The address of the contract that will be called | | callData | bytes | The encoded function with its signature and parameters, if any | -### renounceOwnership +### renounceRole ```solidity -function renounceOwnership() external nonpayable +function renounceRole(bytes32 role, address account) external nonpayable ``` -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* +*Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. May emit a {RoleRevoked} event.* +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role | bytes32 | undefined | +| account | address | undefined | -### transferOwnership +### revokeRole ```solidity -function transferOwnership(address newOwner) external nonpayable +function revokeRole(bytes32 role, address account) external nonpayable ``` -*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.* +*Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. May emit a {RoleRevoked} event.* #### Parameters | Name | Type | Description | |---|---|---| -| newOwner | address | undefined | +| role | bytes32 | undefined | +| account | address | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*See {IERC165-supportsInterface}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | @@ -243,10 +334,46 @@ event Initialized(uint8 version) |---|---|---| | version | uint8 | undefined | -### OwnershipTransferred +### RoleAdminChanged + +```solidity +event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| previousAdminRole `indexed` | bytes32 | undefined | +| newAdminRole `indexed` | bytes32 | undefined | + +### RoleGranted + +```solidity +event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | + +### RoleRevoked ```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender) ``` @@ -257,8 +384,9 @@ event OwnershipTransferred(address indexed previousOwner, address indexed newOwn | Name | Type | Description | |---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | +| role `indexed` | bytes32 | undefined | +| account `indexed` | address | undefined | +| sender `indexed` | address | undefined | diff --git a/docs/common/Withdrawal/Withdrawal.md b/docs/common/Withdrawal/Withdrawal.md index f269966d..92ee82e2 100644 --- a/docs/common/Withdrawal/Withdrawal.md +++ b/docs/common/Withdrawal/Withdrawal.md @@ -373,6 +373,22 @@ error NoWithdrawalAvailable() +### Unauthorized + +```solidity +error Unauthorized(string only) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| only | string | undefined | + ### WithdrawalFailed ```solidity diff --git a/docs/elin/contracts-upgradeable/access/Ownable2StepUpgradeable.md b/docs/elin/contracts-upgradeable/access/Ownable2StepUpgradeable.md deleted file mode 100644 index 904aaea7..00000000 --- a/docs/elin/contracts-upgradeable/access/Ownable2StepUpgradeable.md +++ /dev/null @@ -1,140 +0,0 @@ -# Ownable2StepUpgradeable - - - - - - - -*Contract module which provides access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership} and {acceptOwnership}. This module is used through inheritance. It will make available all functions from parent (Ownable).* - -## Methods - -### acceptOwnership - -```solidity -function acceptOwnership() external nonpayable -``` - - - -*The new owner accepts the ownership transfer.* - - -### owner - -```solidity -function owner() external view returns (address) -``` - - - -*Returns the address of the current owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### pendingOwner - -```solidity -function pendingOwner() external view returns (address) -``` - - - -*Returns the address of the pending owner.* - - -#### Returns - -| Name | Type | Description | -|---|---|---| -| _0 | address | undefined | - -### renounceOwnership - -```solidity -function renounceOwnership() external nonpayable -``` - - - -*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.* - - -### transferOwnership - -```solidity -function transferOwnership(address newOwner) external nonpayable -``` - - - -*Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.* - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| newOwner | address | undefined | - - - -## Events - -### Initialized - -```solidity -event Initialized(uint8 version) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| version | uint8 | undefined | - -### OwnershipTransferStarted - -```solidity -event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - -### OwnershipTransferred - -```solidity -event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) -``` - - - - - -#### Parameters - -| Name | Type | Description | -|---|---|---| -| previousOwner `indexed` | address | undefined | -| newOwner `indexed` | address | undefined | - - - diff --git a/test/APRCalculator/APRCalculator.test.ts b/test/APRCalculator/APRCalculator.test.ts index e27e4ebf..3b5cfda9 100644 --- a/test/APRCalculator/APRCalculator.test.ts +++ b/test/APRCalculator/APRCalculator.test.ts @@ -28,6 +28,8 @@ export function RunAPRCalculatorTests(): void { expect(aprCalculator.deployTransaction.from).to.equal(this.signers.admin.address); expect(await aprCalculator.DENOMINATOR()).to.be.equal(DENOMINATOR); expect(await aprCalculator.BASE_APR()).to.equal(BASE_APR); + expect(await aprCalculator.hasRole(await aprCalculator.DEFAULT_ADMIN_ROLE(), this.signers.governance.address)) + .to.be.false; // RSIndex expect(await aprCalculator.MAX_RSI_BONUS()).to.be.equal(MAX_RSI_BONUS); @@ -71,11 +73,9 @@ export function RunAPRCalculatorTests(): void { const { aprCalculator, hydraChain, priceOracle } = await loadFixture( this.fixtures.initializedHydraChainStateFixture ); - const managerRole = await aprCalculator.MANAGER_ROLE(); - const adminRole = await aprCalculator.DEFAULT_ADMIN_ROLE(); - expect(await aprCalculator.hasRole(managerRole, this.signers.governance.address)).to.be.true; - expect(await aprCalculator.hasRole(adminRole, this.signers.governance.address)).to.be.true; + expect(await aprCalculator.hasRole(await aprCalculator.DEFAULT_ADMIN_ROLE(), this.signers.governance.address)) + .to.be.true; // Macro Factor expect(await aprCalculator.defaultMacroFactor()).to.equal(INITIAL_DEFAULT_MACRO_FACTOR); diff --git a/test/APRCalculator/MacroFactor.test.ts b/test/APRCalculator/MacroFactor.test.ts index 66f7b167..12770521 100644 --- a/test/APRCalculator/MacroFactor.test.ts +++ b/test/APRCalculator/MacroFactor.test.ts @@ -129,11 +129,9 @@ export function RunMacroFactorTests(): void { it("should revert if not called by governance", async function () { const { aprCalculator } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - const managerRole = await aprCalculator.MANAGER_ROLE(); - - await expect(aprCalculator.changeDefaultMacroFactor(10)).to.be.revertedWith( - ERRORS.accessControl(this.signers.accounts[0].address.toLocaleLowerCase(), managerRole) - ); + await expect(aprCalculator.changeDefaultMacroFactor(10)) + .to.be.revertedWithCustomError(aprCalculator, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should revert if new default macro factor is not between min and max macro factor", async function () { diff --git a/test/APRCalculator/Price.test.ts b/test/APRCalculator/Price.test.ts index a86db165..df75c714 100644 --- a/test/APRCalculator/Price.test.ts +++ b/test/APRCalculator/Price.test.ts @@ -67,9 +67,9 @@ export function RunPriceTests(): void { it("should revert guardBonuses if not called by governance", async function () { const { aprCalculator } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - await expect(aprCalculator.connect(this.signers.system).guardBonuses()).to.be.revertedWith( - ERRORS.accessControl(this.signers.system.address, await aprCalculator.MANAGER_ROLE()) - ); + await expect(aprCalculator.connect(this.signers.system).guardBonuses()) + .to.be.revertedWithCustomError(aprCalculator, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should revert guardBonuses if already guarded", async function () { @@ -94,9 +94,9 @@ export function RunPriceTests(): void { it("should revert guard disable if not called by governance", async function () { const { aprCalculator } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - await expect(aprCalculator.connect(this.signers.accounts[4]).disableGuard()).to.be.revertedWith( - ERRORS.accessControl(this.signers.accounts[4].address, await aprCalculator.MANAGER_ROLE()) - ); + await expect(aprCalculator.connect(this.signers.accounts[4]).disableGuard()) + .to.be.revertedWithCustomError(aprCalculator, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should revert guard disable if not guarded", async function () { diff --git a/test/HydraChain/HydraChain.test.ts b/test/HydraChain/HydraChain.test.ts index 4266e00b..0de32828 100644 --- a/test/HydraChain/HydraChain.test.ts +++ b/test/HydraChain/HydraChain.test.ts @@ -5,7 +5,7 @@ import * as hre from "hardhat"; import { ERRORS, INITIAL_COMMISSION, MAX_ACTIVE_VALIDATORS } from "../constants"; import { RunInspectorTests } from "./Inspector.test"; -import { RunAccessControlTests } from "./AccessControl.test"; +import { RunWhitelistingTests } from "./Whitelisting.test"; import { RunValidatorManagerTests } from "./ValidatorManager.test"; import { RunDaoIncentiveTests } from "./DaoIncentive.test"; import { RunValidatorsDataTests } from "./ValidatrosData.test"; @@ -17,10 +17,13 @@ export function RunHydraChainTests(): void { const { hydraChain } = await loadFixture(this.fixtures.presetHydraChainStateFixture); expect(hydraChain.deployTransaction.from).to.equal(this.signers.admin.address); - expect(await hydraChain.owner()).to.equal(hre.ethers.constants.AddressZero); expect(await hydraChain.currentEpochId()).to.equal(0); + expect( + await hydraChain.hasRole(await hydraChain.DEFAULT_ADMIN_ROLE(), this.signers.governance.address), + "hasRole" + ).to.be.false; - // AccessControl + // Whitelisting expect(await hydraChain.isWhitelistingEnabled()).to.be.false; // DaoIncentive @@ -112,12 +115,11 @@ export function RunHydraChainTests(): void { const validator = await hydraChain.getValidator(adminAddress); expect(await hydraChain.currentEpochId(), "currentEpochId").to.equal(1); - expect(await hydraChain.owner(), "owner").to.equal(this.signers.governance.address); expect( await hydraDelegation.hasRole(await hydraDelegation.DEFAULT_ADMIN_ROLE(), this.signers.governance.address) ).to.be.true; - // AccessControl + // Whitelisting expect(await hydraChain.isWhitelistingEnabled()).to.be.true; // DaoIncentive @@ -281,8 +283,8 @@ export function RunHydraChainTests(): void { }); }); - describe("Access Control", function () { - RunAccessControlTests(); + describe("Whitelisting", function () { + RunWhitelistingTests(); }); describe("Dao Incentive", function () { RunDaoIncentiveTests(); diff --git a/test/HydraChain/Inspector.test.ts b/test/HydraChain/Inspector.test.ts index 553ddb3b..08d9cde9 100644 --- a/test/HydraChain/Inspector.test.ts +++ b/test/HydraChain/Inspector.test.ts @@ -10,11 +10,11 @@ import { LiquidityToken__factory } from "../../typechain-types"; export function RunInspectorTests(): void { describe("setValidatorPenalty", function () { - it("should revert not owner when try to set validator penalty", async function () { + it("should revert when not governance try to set validator penalty", async function () { const { hydraChain } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); - await expect(hydraChain.connect(this.signers.validators[0]).setValidatorPenalty(0)).to.be.revertedWith( - ERRORS.ownable - ); + await expect(hydraChain.connect(this.signers.validators[0]).setValidatorPenalty(0)) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should set new validator penalty", async function () { @@ -27,12 +27,12 @@ export function RunInspectorTests(): void { }); describe("setReporterReward", function () { - it("should revert not owner when try to set reporter reward", async function () { + it("should revert when not governance try to set reporter reward", async function () { const { hydraChain } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); - await expect(hydraChain.connect(this.signers.validators[0]).setReporterReward(0)).to.be.revertedWith( - ERRORS.ownable - ); + await expect(hydraChain.connect(this.signers.validators[0]).setReporterReward(0)) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should set new reporter reward", async function () { @@ -45,12 +45,12 @@ export function RunInspectorTests(): void { }); describe("setInitiateBanThreshold", function () { - it("should revert not owner when try to set initiate ban threshold", async function () { + it("should revert when not governance try to set initiate ban threshold", async function () { const { hydraChain } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); - await expect(hydraChain.connect(this.signers.validators[0]).setBanThreshold(0)).to.be.revertedWith( - ERRORS.ownable - ); + await expect(hydraChain.connect(this.signers.validators[0]).setBanThreshold(0)) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should set new initiate ban threshold", async function () { @@ -63,12 +63,12 @@ export function RunInspectorTests(): void { }); describe("setBanThreshold", function () { - it("should revert not owner when try to set ban finish threshold", async function () { + it("should revert when not governance try to set ban finish threshold", async function () { const { hydraChain } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); - await expect(hydraChain.connect(this.signers.validators[0]).setBanThreshold(0)).to.be.revertedWith( - ERRORS.ownable - ); + await expect(hydraChain.connect(this.signers.validators[0]).setBanThreshold(0)) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should set new ban finish threshold", async function () { @@ -490,7 +490,7 @@ export function RunInspectorTests(): void { expect(await hydraStaking.pendingWithdrawals(await hydraChain.signer.getAddress())).to.eq(reporterReward); }); - it("should ban the validator even if threshold is not met, if called from the contract owner (governance)", async function () { + it("should ban the validator even if threshold is not met, if called from the governance", async function () { const { systemHydraChain, hydraStaking } = await loadFixture(this.fixtures.stakedValidatorsStateFixture); // commit a couple of epochs in order to have a timestamp diff --git a/test/HydraChain/ValidatorManager.test.ts b/test/HydraChain/ValidatorManager.test.ts index b4a20077..bd61c4d4 100644 --- a/test/HydraChain/ValidatorManager.test.ts +++ b/test/HydraChain/ValidatorManager.test.ts @@ -279,7 +279,9 @@ export function RunValidatorManagerTests(): void { it("should revert trying to update the Exponent if we are no-govern address", async function () { const { hydraChain } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - await expect(hydraChain.updateExponent(6000)).to.be.revertedWith("Ownable: caller is not the owner"); + await expect(hydraChain.updateExponent(6000)) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should revert trying to update the Exponent invalid small value", async function () { diff --git a/test/HydraChain/AccessControl.test.ts b/test/HydraChain/Whitelisting.test.ts similarity index 86% rename from test/HydraChain/AccessControl.test.ts rename to test/HydraChain/Whitelisting.test.ts index dd3c8e35..a359aec8 100644 --- a/test/HydraChain/AccessControl.test.ts +++ b/test/HydraChain/Whitelisting.test.ts @@ -5,20 +5,24 @@ import { expect } from "chai"; import * as mcl from "../../ts/mcl"; import { CHAIN_ID, DOMAIN, ERRORS } from "../constants"; -export function RunAccessControlTests(): void { +export function RunWhitelistingTests(): void { describe("Whitelist", function () { - it("should be modified only by the owner", async function () { + it("should be modified only by the governance", async function () { const { hydraChain } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); await expect( hydraChain.connect(this.signers.validators[0]).addToWhitelist([this.signers.validators[0].address]), "addToWhitelist" - ).to.be.revertedWith(ERRORS.ownable); + ) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); await expect( hydraChain.connect(this.signers.validators[0]).removeFromWhitelist([this.signers.validators[0].address]), "removeFromWhitelist" - ).to.be.revertedWith(ERRORS.ownable); + ) + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should be able to add to whitelist", async function () { @@ -89,22 +93,20 @@ export function RunAccessControlTests(): void { }); describe("Enable and Disable Whitelisting", function () { - it("enable should be modified only by the owner", async function () { + it("enable should be modified only by the governance", async function () { const { hydraChain } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - await expect( - hydraChain.connect(this.signers.validators[0]).enableWhitelisting(), - "enableWhitelisting" - ).to.be.revertedWith(ERRORS.ownable); + await expect(hydraChain.connect(this.signers.validators[0]).enableWhitelisting(), "enableWhitelisting") + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); - it("disable should be modified only by the owner", async function () { + it("disable should be modified only by the governance", async function () { const { hydraChain } = await loadFixture(this.fixtures.initializedHydraChainStateFixture); - await expect( - hydraChain.connect(this.signers.validators[0]).disableWhitelisting(), - "disableWhitelisting" - ).to.be.revertedWith(ERRORS.ownable); + await expect(hydraChain.connect(this.signers.validators[0]).disableWhitelisting(), "disableWhitelisting") + .to.be.revertedWithCustomError(hydraChain, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should not be able to enable whitelisting if it is already enabled", async function () { diff --git a/test/HydraDelegation/HydraDelegation.test.ts b/test/HydraDelegation/HydraDelegation.test.ts index 5b0a533a..a7c5ad78 100644 --- a/test/HydraDelegation/HydraDelegation.test.ts +++ b/test/HydraDelegation/HydraDelegation.test.ts @@ -254,15 +254,12 @@ export function RunHydraDelegationTests(): void { }); describe("Change minDelegate", function () { - it("should revert if non-default_admin_role address try to change MinDelegation", async function () { + it("should revert if non-governance address try to change MinDelegation", async function () { const { hydraDelegation } = await loadFixture(this.fixtures.delegatedFixture); - // eslint-disable-next-line no-unused-vars - const adminRole = await hydraDelegation.DEFAULT_ADMIN_ROLE(); - - await expect( - hydraDelegation.connect(this.signers.validators[0]).changeMinDelegation(this.minDelegation.mul(2)) - ).to.be.revertedWith(ERRORS.accessControl(this.signers.validators[0].address.toLocaleLowerCase(), adminRole)); + await expect(hydraDelegation.connect(this.signers.validators[0]).changeMinDelegation(this.minDelegation.mul(2))) + .to.be.revertedWithCustomError(hydraDelegation, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); expect(await hydraDelegation.minDelegation()).to.be.equal(this.minDelegation); }); diff --git a/test/HydraStaking/HydraStaking.test.ts b/test/HydraStaking/HydraStaking.test.ts index 5616c3d8..48e885e3 100644 --- a/test/HydraStaking/HydraStaking.test.ts +++ b/test/HydraStaking/HydraStaking.test.ts @@ -235,9 +235,9 @@ export function RunHydraStakingTests(): void { it("should revert if non-Govern address try to change min stake", async function () { const { hydraStaking } = await loadFixture(this.fixtures.registeredValidatorsStateFixture); - await expect(hydraStaking.connect(this.signers.validators[0]).changeMinStake(this.minStake)).to.be.revertedWith( - ERRORS.accessControl(this.signers.validators[0].address, await hydraStaking.DEFAULT_ADMIN_ROLE()) - ); + await expect(hydraStaking.connect(this.signers.validators[0]).changeMinStake(this.minStake)) + .to.be.revertedWithCustomError(hydraStaking, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should revert if minStake is too low", async function () { diff --git a/test/common/Withdrawal.test.ts b/test/common/Withdrawal.test.ts index e608cbff..bda48d07 100644 --- a/test/common/Withdrawal.test.ts +++ b/test/common/Withdrawal.test.ts @@ -73,11 +73,10 @@ export function RunWithdrawalTests(): void { it("should fail to update withdraw time if not governance", async function () { const { hydraStaking } = await loadFixture(this.fixtures.withdrawableFixture); - const adminRole = await hydraStaking.DEFAULT_ADMIN_ROLE(); - await expect( - hydraStaking.connect(this.signers.validators[0]).changeWithdrawalWaitPeriod(WEEK * 2) - ).to.be.revertedWith(ERRORS.accessControl(this.signers.validators[0].address, adminRole)); + await expect(hydraStaking.connect(this.signers.validators[0]).changeWithdrawalWaitPeriod(WEEK * 2)) + .to.be.revertedWithCustomError(hydraStaking, ERRORS.unauthorized.name) + .withArgs(ERRORS.unauthorized.governanceArg); }); it("should fail update withdraw time if we pass 0", async function () { diff --git a/test/constants.ts b/test/constants.ts index 7d186430..0bb5d49a 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -53,6 +53,7 @@ export const ERRORS = { onlyHydraDelegationArg: "ONLY_HYDRA_DELEGATION", inactiveStakerArg: "INACTIVE_STAKER", priceOracleArg: "ONLY_PRICE_ORACLE", + governanceArg: "GOVERNANCE_ONLY", }, inactiveValidator: "INACTIVE_VALIDATOR", invalidValidator: "INVALID_VALIDATOR", diff --git a/test/forge/InitializedContracts.sol b/test/forge/InitializedContracts.sol index cd99d6ca..13023266 100644 --- a/test/forge/InitializedContracts.sol +++ b/test/forge/InitializedContracts.sol @@ -227,7 +227,8 @@ contract TestInitlizedContracts is InitializedContracts { // HydraChain function test_getGovernanceFromHydraChain() public view { - assert(hydraChain.owner() == governance); + bytes32 role = hydraChain.DEFAULT_ADMIN_ROLE(); + assert(hydraChain.hasRole(role, governance) == true); } function test_getStakingFromHydraChain() public view { @@ -300,8 +301,8 @@ contract TestInitlizedContracts is InitializedContracts { // HydraDelegation function test_getGovernanceFromHydraDelegation() public view { - bytes32 role = hydraStaking.DEFAULT_ADMIN_ROLE(); - assert(hydraStaking.hasRole(role, governance) == true); + bytes32 role = hydraDelegation.DEFAULT_ADMIN_ROLE(); + assert(hydraDelegation.hasRole(role, governance) == true); } function test_getInitalCommissionFromHydraDelegation() public view {