-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Add a governor extension that implements a proposal guardian #5303
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
Merged
Amxx
merged 32 commits into
OpenZeppelin:master
from
Amxx:feature/governor/security_council
Jan 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6330d4c
Add a governor extension that implements a security council
Amxx 578543d
add tests
arr00 fb6e8b7
rename `GovernorSecurityCouncil` to `GovernorProposalGuardian`
arr00 d613cc8
update `GovernorProposalGuardian`
arr00 25eeb02
remove `.only`
arr00 8379051
Merge branch 'master' into feature/governor/security_council
arr00 5ba4596
use `getProposalId` instead of `hashProposal`
arr00 954b03c
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 e56c8b2
Apply suggestions from code review
arr00 db18886
Add proposal guardian to docs
arr00 f751ec6
use `_validateCancel` instead of overriding `cancel`
arr00 d6f0032
fix test, move error to interface
arr00 5ffeab0
consistent cancellation errors
arr00 9d378ac
fix tests
arr00 13f18c5
remove `.only`
arr00 409e406
move caller into params
arr00 85c8c15
simplify
arr00 7a7674b
Update GovernorProposalGuardian.test.js
Amxx ce162a6
move internal function
arr00 f83d972
update docs
arr00 37147e7
Merge pull request #10 from arr00/refactor/cancel-validate-cancel
Amxx 91fbe24
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 5f71ccf
fix lint and edit comments
arr00 855f819
Update GovernorProposalGuardian.test.js
Amxx 6a2030f
Apply suggestions from code review
Amxx 5621fa4
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 54ad414
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 af352f5
lint and fix tests
arr00 643e114
add test
arr00 b7a1a32
lint
arr00 0927af4
fix test
arr00 276185d
add changeset
arr00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
contracts/governance/extensions/GovernorSecurityCouncil.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.20; | ||
|
|
||
| import {Governor} from "../Governor.sol"; | ||
|
|
||
| /** | ||
| * @dev Extension of {Governor} for adds a security council that can cancel proposals at any stage of their lifecycle. | ||
| * | ||
| * Note: if the council is not configure, then proposers take over the | ||
| */ | ||
| abstract contract GovernorSecurityCouncil is Governor { | ||
| address private _council; | ||
|
|
||
| event CouncilSet(address oldCouncil, address newCouncil); | ||
|
|
||
| /** | ||
| * @dev Override {IGovernor-cancel} that implements the extended cancellation logic. | ||
| * * council can cancel any proposal at any point in the lifecycle. | ||
| * * if no council is set, proposer can cancel their proposals at any point in the lifecycle. | ||
| * * if the council is set, proposer keep their ability to cancel during the pending stage (default behavior). | ||
| */ | ||
| function cancel( | ||
| address[] memory targets, | ||
| uint256[] memory values, | ||
| bytes[] memory calldatas, | ||
| bytes32 descriptionHash | ||
| ) public virtual override returns (uint256) { | ||
| address caller = _msgSender(); | ||
| address authority = council(); | ||
|
|
||
| if (authority == address(0)) { | ||
| // if there is no council | ||
| // ... only the proposer can cancel | ||
| // ... no restriction on when the proposer can cancel | ||
| uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash); | ||
| address proposer = proposalProposer(proposalId); | ||
| if (caller != proposer) revert GovernorOnlyProposer(caller); | ||
| return _cancel(targets, values, calldatas, descriptionHash); | ||
| } else if (authority == caller) { | ||
| // if there is a council, and the caller is the council | ||
| // ... just cancel | ||
| return _cancel(targets, values, calldatas, descriptionHash); | ||
| } else { | ||
| // if there is a council, and the caller is not the council | ||
| // ... apply default behavior | ||
| return super.cancel(targets, values, calldatas, descriptionHash); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @dev Getter that returns the address of the council | ||
| */ | ||
| function council() public view virtual returns (address) { | ||
| return _council; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Update the council's address. This operation can only be performed through a governance proposal. | ||
| * | ||
| * Emits a {CouncilSet} event. | ||
| */ | ||
| function setCouncil(address newCouncil) public virtual onlyGovernance { | ||
| _setCouncil(newCouncil); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Internal setter for the council. | ||
| * | ||
| * Emits a {CouncilSet} event. | ||
| */ | ||
| function _setCouncil(address newCouncil) internal virtual { | ||
| emit CouncilSet(_council, newCouncil); | ||
| _council = newCouncil; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.