IGovernor.sol 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 casted.
  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.
  94. */
  95. function proposalSnapshot(uint256 proposalId) public view virtual returns (uint256);
  96. /**
  97. * @notice module:core
  98. * @dev timestamp at which votes close.
  99. */
  100. function proposalDeadline(uint256 proposalId) public view virtual returns (uint256);
  101. /**
  102. * @notice module:user-config
  103. * @dev delay, in number of block, between the proposal is created and the vote starts. This can be increassed to
  104. * leave time for users to buy voting power, of delegate it, before the voting of a proposal starts.
  105. */
  106. function votingDelay() public view virtual returns (uint256);
  107. /**
  108. * @notice module:user-config
  109. * @dev delay, in number of blocks, between the vote start and vote ends.
  110. *
  111. * Note: the {votingDelay} can delay the start of the vote. This must be considered when setting the voting
  112. * duration compared to the voting delay.
  113. */
  114. function votingPeriod() public view virtual returns (uint256);
  115. /**
  116. * @notice module:user-config
  117. * @dev Minimum number of casted voted requiered for a proposal to be successful.
  118. *
  119. * Note: The `blockNumber` parameter corresponds to the snaphot used for counting vote. This allows to scale the
  120. * quroum depending on values such as the totalSupply of a token at this block (see {ERC20Votes}).
  121. */
  122. function quorum(uint256 blockNumber) public view virtual returns (uint256);
  123. /**
  124. * @notice module:reputation
  125. * @dev Voting power of an `account` at a specific `blockNumber`.
  126. *
  127. * Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
  128. * multiple), {ERC20Votes} tokens.
  129. */
  130. function getVotes(address account, uint256 blockNumber) public view virtual returns (uint256);
  131. /**
  132. * @notice module:voting
  133. * @dev Returns weither `account` has casted a vote on `proposalId`.
  134. */
  135. function hasVoted(uint256 proposalId, address account) public view virtual returns (bool);
  136. /**
  137. * @dev Create a new proposal. Vote start {IGovernor-votingDelay} blocks after the proposal is created and ends
  138. * {IGovernor-votingPeriod} blocks after the voting starts.
  139. *
  140. * Emits a {ProposalCreated} event.
  141. */
  142. function propose(
  143. address[] memory targets,
  144. uint256[] memory values,
  145. bytes[] memory calldatas,
  146. string memory description
  147. ) public virtual returns (uint256 proposalId);
  148. /**
  149. * @dev Execute a successful proposal. This requiers the quorum to be reached, the vote to be successful, and the
  150. * deadline to be reached.
  151. *
  152. * Emits a {ProposalExecuted} event.
  153. *
  154. * Note: some module can modify the requierements for execution, for example by adding an additional timelock.
  155. */
  156. function execute(
  157. address[] memory targets,
  158. uint256[] memory values,
  159. bytes[] memory calldatas,
  160. bytes32 descriptionHash
  161. ) public payable virtual returns (uint256 proposalId);
  162. /**
  163. * @dev Cast a vote
  164. *
  165. * Emits a {VoteCast} event.
  166. */
  167. function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256 balance);
  168. /**
  169. * @dev Cast a with a reason
  170. *
  171. * Emits a {VoteCast} event.
  172. */
  173. function castVoteWithReason(
  174. uint256 proposalId,
  175. uint8 support,
  176. string calldata reason
  177. ) public virtual returns (uint256 balance);
  178. /**
  179. * @dev Cast a vote using the user cryptographic signature.
  180. *
  181. * Emits a {VoteCast} event.
  182. */
  183. function castVoteBySig(
  184. uint256 proposalId,
  185. uint8 support,
  186. uint8 v,
  187. bytes32 r,
  188. bytes32 s
  189. ) public virtual returns (uint256 balance);
  190. }