Governor_v1.sol
Inherits: ERC165Upgradeable, IGovernor_v1, AccessControlUpgradeable
Author: Inverter Network
This contract manages various administrative functions that can be executed only by specified multisig addresses. It supports upgrades to {IInverterBeacon_v1} contracts through role-based permissions, enabling a timelocked upgrade process and emergency procedures.
Inherits from {ERC165Upgradeable} for interface detection, {AccessControlUpgradeable} for role-based access control, and implements the {IGovernor_v1} interface for governance functionalities, i.e. setting the fee manager, setting the timelock, upgrading the beacons and exposing the emergency shutdown.
State Variables
COMMUNITY_MULTISIG_ROLE
Role of the community multisig.
bytes32 public constant COMMUNITY_MULTISIG_ROLE = "0x01";
TEAM_MULTISIG_ROLE
Role of the team multisig.
bytes32 public constant TEAM_MULTISIG_ROLE = "0x02";
feeManager
{FeeManager_v1} contract.
IFeeManager_v1 private feeManager;
moduleFactory
{ModuleFactory_v1} contract.
IModuleFactory_v1 private moduleFactory;
linkedBeacons
Array of {IInverterBeacon_v1}s that are linked to this {Governor_v1}, populated via moduleFactoryInitCallback
.
IInverterBeacon_v1[] private linkedBeacons;
timelockPeriod
Length of each timelock.
uint public timelockPeriod;
beaconTimelock
Struct to store timelock information for each {IInverterBeacon_v1}.
mapping(address beacon => IGovernor_v1.Timelock timelock) private beaconTimelock;
__gap
Storage gap for future upgrades.
uint[50] private __gap;
Functions
supportsInterface
See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(AccessControlUpgradeable, ERC165Upgradeable)
returns (bool);
onlyLinkedModuleFactory
Modifier to guarantee function is only callable by the linked {ModuleFactory_v1}.
modifier onlyLinkedModuleFactory();
linkedBeaconsEmpty
Modifier to guarantee linked {IInverterBeacon_v1}s are not empty.
modifier linkedBeaconsEmpty();
validAddress
Modifier to guarantee the given address is valid.
modifier validAddress(address adr);
validTimelockPeriod
Modifier to guarantee the given timelock period is valid.
modifier validTimelockPeriod(uint amt);
accessibleBeacon
Modifier to guarantee the given {IInverterBeacon_v1} is accessible.
modifier accessibleBeacon(address target);
onlyCommunityOrTeamMultisig
Modifier to guarantee only the community or team multisig can call the function.
modifier onlyCommunityOrTeamMultisig();
upgradeProcessAlreadyStarted
Modifier to check if the upgrade process for the given {IInverterBeacon_v1} is already started.
modifier upgradeProcessAlreadyStarted(address beacon);
timelockPeriodExceeded
Modifier to check if the timelock period for the given {IInverterBeacon_v1} is exceeded.
modifier timelockPeriodExceeded(address beacon);
constructor
constructor();
init
The module's initializer function.
function init(
address _communityMultisig,
address _teamMultisig,
uint _timelockPeriod,
address _feeManager,
address _moduleFactory
)
external
initializer
validAddress(_communityMultisig)
validAddress(_teamMultisig)
validTimelockPeriod(_timelockPeriod);
Parameters
_communityMultisig
address
The address of the community multisig.
_teamMultisig
address
The address of the team multisig.
moduleFactoryInitCallback
Callback function that is called by {ModuleFactory_v1} during initialization.
function moduleFactoryInitCallback(
IInverterBeacon_v1[] calldata registeredBeacons
) external onlyLinkedModuleFactory linkedBeaconsEmpty;
Parameters
getBeaconTimelock
Returns the current timelock of a {IInverterBeacon_v1} address.
function getBeaconTimelock(address beacon)
external
view
returns (Timelock memory);
Parameters
Returns
getLinkedBeacons
Returns the list of currently linked {IInverterBeacon_v1}s.
function getLinkedBeacons()
external
view
returns (IInverterBeacon_v1[] memory);
Returns
<none>
IInverterBeacon_v1[]
LinkedBeacons The array of {IInverterBeacon_v1}s that are currently linked to the {Governor_v1}.
getFeeManager
Returns the {FeeManager_v1} address.
function getFeeManager() external view returns (address);
Returns
setFeeManager
Sets the address of the {FeeManager_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setFeeManager(address newFeeManager)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
getModuleFactory
Returns the {ModuleFactory_v1} address.
function getModuleFactory() external view returns (address);
Returns
setModuleFactory
Sets the address of the {ModuleFactory_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setModuleFactory(address newModuleFactory)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
setFeeManagerMaxFee
Sets the maximum fee percentage that can be assigned in the linked {FeeManager_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setFeeManagerMaxFee(uint maxFee)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
maxFee
uint256
The max Fee in relation to the BPS.
setFeeManagerDefaultProtocolTreasury
Sets the default protocol treasury address in the linked {FeeManager_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setFeeManagerDefaultProtocolTreasury(address _defaultProtocolTreasury)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
_defaultProtocolTreasury
address
The address of the default protocol treasury.
setFeeManagerWorkflowTreasuries
Sets the protocol treasury address for a specific workflow in the linked {FeeManager_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setFeeManagerWorkflowTreasuries(address workflow, address treasury)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
workflow
address
The address of the workflow.
treasury
address
The address of the protocol treasury for that specific workflow.
setFeeManagerDefaultCollateralFee
Sets the default collateral fee of the protocol in the linked {FeeManager_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setFeeManagerDefaultCollateralFee(uint _defaultCollateralFee)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
_defaultCollateralFee
uint256
The default collateral fee of the protocol in relation to the BPS.
setFeeManagerDefaultIssuanceFee
Sets the default issuance fee of the protocol in the linked {FeeManager_v1}.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setFeeManagerDefaultIssuanceFee(uint _defaultIssuanceFee)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
_defaultIssuanceFee
uint256
The default issuance fee of the protocol in relation to the BPS.
setFeeManagerCollateralWorkflowFee
Sets the collateral fee for a specific workflow module function in the linked {FeeManager_v1}.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function setFeeManagerCollateralWorkflowFee(
address workflow,
address module,
bytes4 functionSelector,
bool set,
uint fee
) external onlyCommunityOrTeamMultisig;
Parameters
workflow
address
The address of the workflow that contains the module function.
module
address
The address of the module that contains the function.
functionSelector
bytes4
The function selector of the target function.
set
bool
Boolean that determines if the fee is actually used or not.
fee
uint256
The collateral fee in relation to the BPS.
setFeeManagerIssuanceWorkflowFee
Sets the issuance fee for a specific workflow module function in the linked {FeeManager_v1}.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function setFeeManagerIssuanceWorkflowFee(
address workflow,
address module,
bytes4 functionSelector,
bool set,
uint fee
) external onlyCommunityOrTeamMultisig;
Parameters
workflow
address
The address of the workflow that contains the module function.
module
address
The address of the module that contains the function.
functionSelector
bytes4
The function selector of the target function.
set
bool
Boolean that determines if the fee is actually used or not.
fee
uint256
The issuance fee in relation to the BPS.
registerMetadataInModuleFactory
Registers a {IInverterBeacon_v1} with the provided metadata
in the target {ModuleFactory_v1}.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function registerMetadataInModuleFactory(
IModule_v1.Metadata memory metadata,
IInverterBeacon_v1 beacon
) external onlyCommunityOrTeamMultisig accessibleBeacon(address(beacon));
Parameters
metadata
IModule_v1.Metadata
The metadata that will be registered.
upgradeBeaconWithTimelock
Starts the upgrade process of a {IInverterBeacon_v1} by creating a timelock period after which the {IInverterBeacon_v1} can be upgraded via triggerUpgradeBeaconWithTimelock()
.
This function will override previous timelocks even if they are active.
function upgradeBeaconWithTimelock(
address beacon,
address newImplementation,
uint newMinorVersion,
uint newPatchVersion
)
external
onlyCommunityOrTeamMultisig
accessibleBeacon(beacon)
validAddress(newImplementation);
Parameters
triggerUpgradeBeaconWithTimelock
Upgrades a {IInverterBeacon_v1} with the data provided by the active timelock.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function triggerUpgradeBeaconWithTimelock(address beacon)
external
onlyCommunityOrTeamMultisig
accessibleBeacon(beacon)
upgradeProcessAlreadyStarted(beacon)
timelockPeriodExceeded(beacon);
Parameters
cancelUpgrade
Cancels an upgrade of {IInverterBeacon_v1} by setting the active timelock to inactive.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function cancelUpgrade(address beacon)
external
onlyCommunityOrTeamMultisig
upgradeProcessAlreadyStarted(beacon);
Parameters
setTimelockPeriod
Sets the timelock period of a {IInverterBeacon_v1} upgrade process.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function setTimelockPeriod(uint newTimelockPeriod)
external
onlyRole(COMMUNITY_MULTISIG_ROLE);
Parameters
newTimelockPeriod
uint256
initiateBeaconShutdown
Initiates the shutdown of a {IInverterBeacon_v1}.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function initiateBeaconShutdown(address beacon)
external
onlyCommunityOrTeamMultisig
accessibleBeacon(beacon);
Parameters
initiateBeaconShutdownForAllLinkedBeacons
Initiates the shutdown of all linked {IInverterBeacon_v1}s.
Can only be accessed by either the COMMUNITY_MULTISIG_ROLE
or the TEAM_MULTISIG_ROLE
.
function initiateBeaconShutdownForAllLinkedBeacons()
external
onlyCommunityOrTeamMultisig;
forceUpgradeBeaconAndRestartImplementation
This function forces the upgrade of a beacon and restarts the implementation afterwards.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function forceUpgradeBeaconAndRestartImplementation(
address beacon,
address newImplementation,
uint newMinorVersion,
uint newPatchVersion
)
external
onlyRole(COMMUNITY_MULTISIG_ROLE)
accessibleBeacon(beacon)
validAddress(newImplementation);
Parameters
restartBeaconImplementation
Restarts the {IInverterBeacon_v1} implementation.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
.
function restartBeaconImplementation(address beacon)
external
onlyRole(COMMUNITY_MULTISIG_ROLE)
accessibleBeacon(beacon);
Parameters
acceptOwnership
Accepts the ownership over the target address.
Can only be accessed by the COMMUNITY_MULTISIG_ROLE
or TEAM_MULTISIG_ROLE
.
function acceptOwnership(address adr) external onlyCommunityOrTeamMultisig;
Parameters
adr
address
The address of target that wants to hand over the ownership.
_setFeeManager
sets the internal {FeeManager_v1} address.
function _setFeeManager(address newFeeManager)
internal
validAddress(newFeeManager);
Parameters
_setTimelockPeriod
sets the internal timelock period.
function _setTimelockPeriod(uint newTimelockPeriod)
internal
validTimelockPeriod(newTimelockPeriod);
Parameters
newTimelockPeriod
uint256
the new timelock period.
_setModuleFactory
sets the internal {ModuleFactory_v1} address.
function _setModuleFactory(address newModuleFactory)
internal
validAddress(newModuleFactory);
Parameters
_isBeaconAccessible
Internal function that checks if target address is a {IInverterBeacon_v1} and this contract has the ownership of it.
function _isBeaconAccessible(address target) internal returns (bool);
Last updated