IGovernor.sol 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.5.0) (governance/IGovernor.sol)
  3. pragma solidity ^0.8.0;
  4. import "../utils/introspection/ERC165.sol";
  5. /**
  6. * @dev Interface of the {Governor} core.
  7. *
  8. * _Available since v4.3._
  9. */
  10. abstract contract IGovernor is IERC165 {
  11. enum ProposalState {
  12. Pending,
  13. Active,
  14. Canceled,
  15. Defeated,
  16. Succeeded,
  17. Queued,
  18. Expired,
  19. Executed
  20. }
  21. /**
  22. * @dev Emitted when a proposal is created.
  23. */
  24. event ProposalCreated(
  25. uint256 proposalId,
  26. address proposer,
  27. address[] targets,
  28. uint256[] values,
  29. string[] signatures,
  30. bytes[] calldatas,
  31. uint256 startBlock,
  32. uint256 endBlock,
  33. string description
  34. );
  35. /**
  36. * @dev Emitted when a proposal is canceled.
  37. */
  38. event ProposalCanceled(uint256 proposalId);
  39. /**
  40. * @dev Emitted when a proposal is executed.
  41. */
  42. event ProposalExecuted(uint256 proposalId);
  43. /**
  44. * @dev Emitted when a vote is cast.
  45. *
  46. * Note: `support` values should be seen as buckets. There interpretation depends on the voting module used.
  47. */
  48. event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
  49. /**
  50. * @notice module:core
  51. * @dev Name of the governor instance (used in building the ERC712 domain separator).
  52. */
  53. function name() public view virtual returns (string memory);
  54. /**
  55. * @notice module:core
  56. * @dev Version of the governor instance (used in building the ERC712 domain separator). Default: "1"
  57. */
  58. function version() public view virtual returns (string memory);
  59. /**
  60. * @notice module:voting
  61. * @dev A description of the possible `support` values for {castVote} and the way these votes are counted, meant to
  62. * be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of
  63. * key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`.
  64. *
  65. * There are 2 standard keys: `support` and `quorum`.
  66. *
  67. * - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`.
  68. * - `quorum=bravo` means that only For votes are counted towards quorum.
  69. * - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum.
  70. *
  71. * NOTE: The string can be decoded by the standard
  72. * https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`]
  73. * JavaScript class.
  74. */
  75. // solhint-disable-next-line func-name-mixedcase
  76. function COUNTING_MODE() public pure virtual returns (string memory);
  77. /**
  78. * @notice module:core
  79. * @dev Hashing function used to (re)build the proposal id from the proposal details..
  80. */
  81. function hashProposal(
  82. address[] calldata targets,
  83. uint256[] calldata values,
  84. bytes[] calldata calldatas,
  85. bytes32 descriptionHash
  86. ) public pure virtual returns (uint256);
  87. /**
  88. * @notice module:core
  89. * @dev Current state of a proposal, following Compound's convention
  90. */
  91. function state(uint256 proposalId) public view virtual returns (ProposalState);
  92. /**
  93. * @notice module:core
  94. * @dev Block number used to retrieve user's votes and quorum. As per Compound's Comp and OpenZeppelin's
  95. * ERC20Votes, the snapshot is performed at the end of this block. Hence, voting for this proposal starts at the
  96. * beginning of the following block.
  97. */
  98. function proposalSnapshot(uint256 proposalId) public view virtual returns (uint256);
  99. /**
  100. * @notice module:core
  101. * @dev Block number at which votes close. Votes close at the end of this block, so it is possible to cast a vote
  102. * during this block.
  103. */
  104. function proposalDeadline(uint256 proposalId) public view virtual returns (uint256);
  105. /**
  106. * @notice module:user-config
  107. * @dev Delay, in number of block, between the proposal is created and the vote starts. This can be increassed to
  108. * leave time for users to buy voting power, of delegate it, before the voting of a proposal starts.
  109. */
  110. function votingDelay() public view virtual returns (uint256);
  111. /**
  112. * @notice module:user-config
  113. * @dev Delay, in number of blocks, between the vote start and vote ends.
  114. *
  115. * NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
  116. * duration compared to the voting delay.
  117. */
  118. function votingPeriod() public view virtual returns (uint256);
  119. /**
  120. * @notice module:user-config
  121. * @dev Minimum number of cast voted required for a proposal to be successful.
  122. *
  123. * Note: The `blockNumber` parameter corresponds to the snaphot used for counting vote. This allows to scale the
  124. * quroum depending on values such as the totalSupply of a token at this block (see {ERC20Votes}).
  125. */
  126. function quorum(uint256 blockNumber) public view virtual returns (uint256);
  127. /**
  128. * @notice module:reputation
  129. * @dev Voting power of an `account` at a specific `blockNumber`.
  130. *
  131. * Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
  132. * multiple), {ERC20Votes} tokens.
  133. */
  134. function getVotes(address account, uint256 blockNumber) public view virtual returns (uint256);
  135. /**
  136. * @notice module:voting
  137. * @dev Returns weither `account` has cast a vote on `proposalId`.
  138. */
  139. function hasVoted(uint256 proposalId, address account) public view virtual returns (bool);
  140. /**
  141. * @dev Create a new proposal. Vote start {IGovernor-votingDelay} blocks after the proposal is created and ends
  142. * {IGovernor-votingPeriod} blocks after the voting starts.
  143. *
  144. * Emits a {ProposalCreated} event.
  145. */
  146. function propose(
  147. address[] memory targets,
  148. uint256[] memory values,
  149. bytes[] memory calldatas,
  150. string memory description
  151. ) public virtual returns (uint256 proposalId);
  152. /**
  153. * @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
  154. * deadline to be reached.
  155. *
  156. * Emits a {ProposalExecuted} event.
  157. *
  158. * Note: some module can modify the requirements for execution, for example by adding an additional timelock.
  159. */
  160. function execute(
  161. address[] memory targets,
  162. uint256[] memory values,
  163. bytes[] memory calldatas,
  164. bytes32 descriptionHash
  165. ) public payable virtual returns (uint256 proposalId);
  166. /**
  167. * @dev Cast a vote
  168. *
  169. * Emits a {VoteCast} event.
  170. */
  171. function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256 balance);
  172. /**
  173. * @dev Cast a vote with a reason
  174. *
  175. * Emits a {VoteCast} event.
  176. */
  177. function castVoteWithReason(
  178. uint256 proposalId,
  179. uint8 support,
  180. string calldata reason
  181. ) public virtual returns (uint256 balance);
  182. /**
  183. * @dev Cast a vote using the user cryptographic signature.
  184. *
  185. * Emits a {VoteCast} event.
  186. */
  187. function castVoteBySig(
  188. uint256 proposalId,
  189. uint8 support,
  190. uint8 v,
  191. bytes32 r,
  192. bytes32 s
  193. ) public virtual returns (uint256 balance);
  194. }