Skip to content

Commit

Permalink
feat: upgrade governance strategy
Browse files Browse the repository at this point in the history
- governance strategy plugin can be updated by successful proposal.
  • Loading branch information
gabririgo committed Jan 28, 2023
1 parent 42d3379 commit 939fecb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ interface IGovernanceEvents {
/// @param proposalId Number of the proposal.
event ProposalExecuted(uint256 proposalId);

/// @notice Emmited when the governance strategy is updated.
/// @param newStrategy Address of the new strategy contract.
event StrategyUpdated(address newStrategy);

/// @notice Emitted when voting thresholds get updated.
/// @dev Only governance can update thresholds.
/// @param proposalThreshold Number of votes required to add a proposal.
Expand Down
15 changes: 10 additions & 5 deletions contracts/governance/interfaces/governance/IGovernanceUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
pragma solidity >=0.8.0 <0.9.0;

interface IGovernanceUpgrade {
/// @notice Updates the governance implementation address.
/// @dev Only callable after successful voting.
/// @param newImplementation Address of the new governance implementation contract.
function upgradeImplementation(address newImplementation) external;

/// @notice Updates the proposal and quorum thresholds to the given values.
/// @dev Only callable by the governance contract itself.
/// @dev Thresholds can only be updated via a successful governance proposal.
/// @param newProposalThreshold The new value for the proposal threshold.
/// @param newQuorumThreshold The new value for the quorum threshold.
function updateThresholds(uint256 newProposalThreshold, uint256 newQuorumThreshold) external;

/// @notice Updates the governance strategy plugin.
/// @dev Only callable by the governance contract itself.
/// @param newStrategy Address of the new strategy contract.
function updateGovernanceStrategy(address newStrategy) external;

/// @notice Updates the governance implementation address.
/// @dev Only callable after successful voting.
/// @param newImplementation Address of the new governance implementation contract.
function upgradeImplementation(address newImplementation) external;
}
11 changes: 11 additions & 0 deletions contracts/governance/mixins/MixinUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pragma solidity >=0.8.0 <0.9.0;

import "../../utils/storageSlot/StorageSlot.sol";
import "../interfaces/IGovernanceStrategy.sol";
import "./MixinStorage.sol"; // storage inherits from interface which declares events

abstract contract MixinUpgrade is MixinStorage {
Expand Down Expand Up @@ -58,11 +59,21 @@ abstract contract MixinUpgrade is MixinStorage {
uint256 newProposalThreshold,
uint256 newQuorumThreshold
) external override onlyDelegatecall onlyGovernance {
IGovernanceStrategy(_governanceStrategy().value).assertValidThresholds(newProposalThreshold, newQuorumThreshold);
_governanceParameters().proposalThreshold = newProposalThreshold;
_governanceParameters().quorumThreshold = newQuorumThreshold;
emit ThresholdsUpdated(newProposalThreshold, newQuorumThreshold);
}

/// @inheritdoc IGovernanceUpgrade
function updateGovernanceStrategy(address newStrategy) external override onlyDelegatecall onlyGovernance {
address oldStrategy = _governanceStrategy().value;
assert(newStrategy != oldStrategy);
require(_isContract(newStrategy), "UPGRADE_NOT_CONTRACT_ERROR");
_governanceStrategy().value = newStrategy;
emit StrategyUpdated(newStrategy);
}

/// @dev Returns whether an address is a contract.
/// @return Bool target address has code.
function _isContract(address target) private view returns (bool) {
Expand Down

0 comments on commit 939fecb

Please sign in to comment.