IGovernor.sol 7.2 KB

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