Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

285 governance consistent logic #85

Merged
merged 9 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 2 additions & 5 deletions contracts/APRCalculator/modules/Price/Price.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
12 changes: 1 addition & 11 deletions contracts/HydraChain/HydraChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion contracts/HydraChain/IHydraChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions contracts/HydraChain/modules/Inspector/Inspector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,7 +86,7 @@ abstract contract Inspector is IInspector, ValidatorManager {
bansInitiated[validator] = 0;
}

if (owner() == msg.sender) {
if (_isGovernance(msg.sender)) {
hydraDelegationContract.lockCommissionReward(validator);
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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
*/
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -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]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/HydraDelegation/Delegation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/HydraStaking/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/HydraVault/HydraVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 _______________
Expand All @@ -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);
Expand Down
Loading
Loading