Skip to content

Commit

Permalink
Add ability for governor admin to configure and upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
toninorair committed Oct 23, 2024
1 parent 1cfaf25 commit 34d50be
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
43 changes: 42 additions & 1 deletion src/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { IPortal } from "../interfaces/IPortal.sol";

import { IGovernor } from "./interfaces/IGovernor.sol";

// TODO: add events

/**
* @title Base governor contract.
* @author M^0 Labs
Expand All @@ -19,8 +21,17 @@ contract Governor is IGovernor {
/// @inheritdoc IGovernor
address public immutable registrar;

constructor(address portal_) {
/// @inheritdoc IGovernor
address public governorAdmin;

modifier onlyGovernorAdmin() {
if (msg.sender != governorAdmin) revert UnauthorizedGovernorAdmin();
_;
}

constructor(address portal_, address governorAdmin_) {
if ((portal = portal_) == address(0)) revert ZeroPortal();
if ((governorAdmin = governorAdmin_) == address(0)) revert ZeroGovernorAdmin();

registrar = IPortal(portal_).registrar();
}
Expand All @@ -40,4 +51,34 @@ contract Governor is IGovernor {

upgrader_.delegatecall(abi.encodeWithSignature("execute()"));
}

/// @inheritdoc IGovernor
function configure(address configurator_) external onlyGovernorAdmin {
if (configurator_ == address(0)) revert ZeroConfigurator();

configurator_.delegatecall(abi.encodeWithSignature("execute()"));
}

/// @inheritdoc IGovernor
function upgrade(address upgrader_) external onlyGovernorAdmin {
if (upgrader_ == address(0)) revert ZeroUpgrader();

upgrader_.delegatecall(abi.encodeWithSignature("execute()"));
}

/// @inheritdoc IGovernor
function transferOwnership(address newGovernorAdmin_) external onlyGovernorAdmin {
if (newGovernorAdmin_ == address(0)) revert ZeroGovernorAdmin();

_transferOwnership(newGovernorAdmin_);
}

/// @inheritdoc IGovernor
function disableGovernorAdmin() external onlyGovernorAdmin {
_transferOwnership(address(0));
}

function _transferOwnership(address newGovernorAdmin_) internal {
governorAdmin = newGovernorAdmin_;
}
}
21 changes: 21 additions & 0 deletions src/governance/interfaces/IGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,36 @@ interface IGovernor {
/// @notice Emitted when the Portal address is 0x0.
error ZeroPortal();

/// @notice Emitted when the Governor admin address is 0x0.
error ZeroGovernorAdmin();

/// @notice Emitted when the caller is not the Governor admin.
error UnauthorizedGovernorAdmin();

/// @notice Executes the configuration approved by governance.
function configure() external;

/// @notice Executes the upgrade approved by governance.
function configure(address configurator) external;

/// @notice Executes the upgrade approved by governance.
function upgrade() external;

/// @notice Executes the upgrade approved by governance.
function upgrade(address upgrader) external;

/// @notice Address of the Portal being governed.
function portal() external view returns (address);

/// @notice Address of the Registrar where Configurator and Upgrader are stored.
function registrar() external view returns (address);

/// @notice Address of the Governor admin.
function governorAdmin() external view returns (address);

/// @notice Transfers the ownership of the Governor to a new Governor admin.
function transferOwnership(address newGovernorAdmin_) external;

/// @notice Disables the Governor admin functionality.
function disableGovernorAdmin() external;
}
2 changes: 1 addition & 1 deletion test/fork/Configure.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ contract Configure is ConfigureBase, Test {

config_[2] = optimismConfig_;

Governor governor_ = new Governor(address(hubPortal_));
Governor governor_ = new Governor(address(hubPortal_), address(this));
address configurator_ = address(new MainnetConfigurator(address(hubPortal_), address(wormholeTransceiver_)));

hubPortal_.transferOwnership(address(governor_));
Expand Down
2 changes: 1 addition & 1 deletion test/fork/Upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contract Upgrade is UpgradeBase, Test {
IManagerBase(hubPortal_).setTransceiver(address(wormholeTransceiver_));
INttManager(hubPortal_).setThreshold(1);

Governor governor_ = new Governor(address(hubPortal_));
Governor governor_ = new Governor(address(hubPortal_), address(this));
address upgrader_ = address(new MainnetUpgrader(address(hubPortal_), address(wormholeTransceiver_)));

hubPortal_.transferOwnership(address(governor_));
Expand Down

0 comments on commit 34d50be

Please sign in to comment.