|
@@ -17,7 +17,7 @@ import "./IGovernor.sol";
|
|
|
/**
|
|
|
* @dev Core of the governance system, designed to be extended though various modules.
|
|
|
*
|
|
|
- * This contract is abstract and requires several function to be implemented in various modules:
|
|
|
+ * This contract is abstract and requires several functions to be implemented in various modules:
|
|
|
*
|
|
|
* - A counting module must implement {quorum}, {_quorumReached}, {_voteSucceeded} and {_countVote}
|
|
|
* - A voting module must implement {_getVotes}
|
|
@@ -27,7 +27,6 @@ import "./IGovernor.sol";
|
|
|
*/
|
|
|
abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receiver, IERC1155Receiver {
|
|
|
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
|
|
|
- using SafeCast for uint256;
|
|
|
|
|
|
bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support)");
|
|
|
bytes32 public constant EXTENDED_BALLOT_TYPEHASH =
|
|
@@ -90,25 +89,34 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
|
|
|
* @dev Function to receive ETH that will be handled by the governor (disabled if executor is a third party contract)
|
|
|
*/
|
|
|
receive() external payable virtual {
|
|
|
- require(_executor() == address(this));
|
|
|
+ require(_executor() == address(this), "Governor: must send to executor");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @dev See {IERC165-supportsInterface}.
|
|
|
*/
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
|
|
|
- // In addition to the current interfaceId, also support previous version of the interfaceId that did not
|
|
|
- // include the castVoteWithReasonAndParams() function as standard
|
|
|
+ bytes4 governorCancelId = this.cancel.selector ^ this.proposalProposer.selector;
|
|
|
+
|
|
|
+ bytes4 governorParamsId = this.castVoteWithReasonAndParams.selector ^
|
|
|
+ this.castVoteWithReasonAndParamsBySig.selector ^
|
|
|
+ this.getVotesWithParams.selector;
|
|
|
+
|
|
|
+ // The original interface id in v4.3.
|
|
|
+ bytes4 governor43Id = type(IGovernor).interfaceId ^
|
|
|
+ type(IERC6372).interfaceId ^
|
|
|
+ governorCancelId ^
|
|
|
+ governorParamsId;
|
|
|
+
|
|
|
+ // An updated interface id in v4.6, with params added.
|
|
|
+ bytes4 governor46Id = type(IGovernor).interfaceId ^ type(IERC6372).interfaceId ^ governorCancelId;
|
|
|
+
|
|
|
+ // For the updated interface id in v4.9, we use governorCancelId directly.
|
|
|
+
|
|
|
return
|
|
|
- interfaceId ==
|
|
|
- (type(IGovernor).interfaceId ^
|
|
|
- type(IERC6372).interfaceId ^
|
|
|
- this.cancel.selector ^
|
|
|
- this.castVoteWithReasonAndParams.selector ^
|
|
|
- this.castVoteWithReasonAndParamsBySig.selector ^
|
|
|
- this.getVotesWithParams.selector) ||
|
|
|
- // Previous interface for backwards compatibility
|
|
|
- interfaceId == (type(IGovernor).interfaceId ^ type(IERC6372).interfaceId ^ this.cancel.selector) ||
|
|
|
+ interfaceId == governor43Id ||
|
|
|
+ interfaceId == governor46Id ||
|
|
|
+ interfaceId == governorCancelId ||
|
|
|
interfaceId == type(IERC1155Receiver).interfaceId ||
|
|
|
super.supportsInterface(interfaceId);
|
|
|
}
|
|
@@ -210,9 +218,9 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @dev Address of the proposer
|
|
|
+ * @dev Returns the account that created a given proposal.
|
|
|
*/
|
|
|
- function _proposalProposer(uint256 proposalId) internal view virtual returns (address) {
|
|
|
+ function proposalProposer(uint256 proposalId) public view virtual override returns (address) {
|
|
|
return _proposals[proposalId].proposer;
|
|
|
}
|
|
|
|
|
@@ -283,8 +291,8 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
|
|
|
|
|
|
_proposals[proposalId] = ProposalCore({
|
|
|
proposer: proposer,
|
|
|
- voteStart: snapshot.toUint64(),
|
|
|
- voteEnd: deadline.toUint64(),
|
|
|
+ voteStart: SafeCast.toUint64(snapshot),
|
|
|
+ voteEnd: SafeCast.toUint64(deadline),
|
|
|
executed: false,
|
|
|
canceled: false,
|
|
|
__gap_unused0: 0,
|
|
@@ -317,9 +325,9 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
|
|
|
) public payable virtual override returns (uint256) {
|
|
|
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
|
|
|
|
|
|
- ProposalState status = state(proposalId);
|
|
|
+ ProposalState currentState = state(proposalId);
|
|
|
require(
|
|
|
- status == ProposalState.Succeeded || status == ProposalState.Queued,
|
|
|
+ currentState == ProposalState.Succeeded || currentState == ProposalState.Queued,
|
|
|
"Governor: proposal not successful"
|
|
|
);
|
|
|
_proposals[proposalId].executed = true;
|
|
@@ -415,10 +423,12 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
|
|
|
) internal virtual returns (uint256) {
|
|
|
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
|
|
|
|
|
|
- ProposalState status = state(proposalId);
|
|
|
+ ProposalState currentState = state(proposalId);
|
|
|
|
|
|
require(
|
|
|
- status != ProposalState.Canceled && status != ProposalState.Expired && status != ProposalState.Executed,
|
|
|
+ currentState != ProposalState.Canceled &&
|
|
|
+ currentState != ProposalState.Expired &&
|
|
|
+ currentState != ProposalState.Executed,
|
|
|
"Governor: proposal not active"
|
|
|
);
|
|
|
_proposals[proposalId].canceled = true;
|