IGovernor.sol 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.8.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 without params.
  45. *
  46. * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
  47. */
  48. event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
  49. /**
  50. * @dev Emitted when a vote is cast with params.
  51. *
  52. * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
  53. * `params` are additional encoded parameters. Their interpepretation also depends on the voting module used.
  54. */
  55. event VoteCastWithParams(
  56. address indexed voter,
  57. uint256 proposalId,
  58. uint8 support,
  59. uint256 weight,
  60. string reason,
  61. bytes params
  62. );
  63. /**
  64. * @notice module:core
  65. * @dev Name of the governor instance (used in building the ERC712 domain separator).
  66. */
  67. function name() public view virtual returns (string memory);
  68. /**
  69. * @notice module:core
  70. * @dev Version of the governor instance (used in building the ERC712 domain separator). Default: "1"
  71. */
  72. function version() public view virtual returns (string memory);
  73. /**
  74. * @notice module:voting
  75. * @dev A description of the possible `support` values for {castVote} and the way these votes are counted, meant to
  76. * be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of
  77. * key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`.
  78. *
  79. * There are 2 standard keys: `support` and `quorum`.
  80. *
  81. * - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`.
  82. * - `quorum=bravo` means that only For votes are counted towards quorum.
  83. * - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum.
  84. *
  85. * If a counting module makes use of encoded `params`, it should include this under a `params` key with a unique
  86. * name that describes the behavior. For example:
  87. *
  88. * - `params=fractional` might refer to a scheme where votes are divided fractionally between for/against/abstain.
  89. * - `params=erc721` might refer to a scheme where specific NFTs are delegated to vote.
  90. *
  91. * NOTE: The string can be decoded by the standard
  92. * https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`]
  93. * JavaScript class.
  94. */
  95. // solhint-disable-next-line func-name-mixedcase
  96. function COUNTING_MODE() public pure virtual returns (string memory);
  97. /**
  98. * @notice module:core
  99. * @dev Hashing function used to (re)build the proposal id from the proposal details..
  100. */
  101. function hashProposal(
  102. address[] memory targets,
  103. uint256[] memory values,
  104. bytes[] memory calldatas,
  105. bytes32 descriptionHash
  106. ) public pure virtual returns (uint256);
  107. /**
  108. * @notice module:core
  109. * @dev Current state of a proposal, following Compound's convention
  110. */
  111. function state(uint256 proposalId) public view virtual returns (ProposalState);
  112. /**
  113. * @notice module:core
  114. * @dev Block number used to retrieve user's votes and quorum. As per Compound's Comp and OpenZeppelin's
  115. * ERC20Votes, the snapshot is performed at the end of this block. Hence, voting for this proposal starts at the
  116. * beginning of the following block.
  117. */
  118. function proposalSnapshot(uint256 proposalId) public view virtual returns (uint256);
  119. /**
  120. * @notice module:core
  121. * @dev Block number at which votes close. Votes close at the end of this block, so it is possible to cast a vote
  122. * during this block.
  123. */
  124. function proposalDeadline(uint256 proposalId) public view virtual returns (uint256);
  125. /**
  126. * @notice module:user-config
  127. * @dev Delay, in number of block, between the proposal is created and the vote starts. This can be increased to
  128. * leave time for users to buy voting power, or delegate it, before the voting of a proposal starts.
  129. */
  130. function votingDelay() public view virtual returns (uint256);
  131. /**
  132. * @notice module:user-config
  133. * @dev Delay, in number of blocks, between the vote start and vote ends.
  134. *
  135. * NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
  136. * duration compared to the voting delay.
  137. */
  138. function votingPeriod() public view virtual returns (uint256);
  139. /**
  140. * @notice module:user-config
  141. * @dev Minimum number of cast voted required for a proposal to be successful.
  142. *
  143. * Note: The `blockNumber` parameter corresponds to the snapshot used for counting vote. This allows to scale the
  144. * quorum depending on values such as the totalSupply of a token at this block (see {ERC20Votes}).
  145. */
  146. function quorum(uint256 blockNumber) public view virtual returns (uint256);
  147. /**
  148. * @notice module:reputation
  149. * @dev Voting power of an `account` at a specific `blockNumber`.
  150. *
  151. * Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
  152. * multiple), {ERC20Votes} tokens.
  153. */
  154. function getVotes(address account, uint256 blockNumber) public view virtual returns (uint256);
  155. /**
  156. * @notice module:reputation
  157. * @dev Voting power of an `account` at a specific `blockNumber` given additional encoded parameters.
  158. */
  159. function getVotesWithParams(
  160. address account,
  161. uint256 blockNumber,
  162. bytes memory params
  163. ) public view virtual returns (uint256);
  164. /**
  165. * @notice module:voting
  166. * @dev Returns whether `account` has cast a vote on `proposalId`.
  167. */
  168. function hasVoted(uint256 proposalId, address account) public view virtual returns (bool);
  169. /**
  170. * @dev Create a new proposal. Vote start {IGovernor-votingDelay} blocks after the proposal is created and ends
  171. * {IGovernor-votingPeriod} blocks after the voting starts.
  172. *
  173. * Emits a {ProposalCreated} event.
  174. */
  175. function propose(
  176. address[] memory targets,
  177. uint256[] memory values,
  178. bytes[] memory calldatas,
  179. string memory description
  180. ) public virtual returns (uint256 proposalId);
  181. /**
  182. * @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
  183. * deadline to be reached.
  184. *
  185. * Emits a {ProposalExecuted} event.
  186. *
  187. * Note: some module can modify the requirements for execution, for example by adding an additional timelock.
  188. */
  189. function execute(
  190. address[] memory targets,
  191. uint256[] memory values,
  192. bytes[] memory calldatas,
  193. bytes32 descriptionHash
  194. ) public payable virtual returns (uint256 proposalId);
  195. /**
  196. * @dev Cancel a proposal. This is restricted to Pending proposal (before the vote starts) and is restricted to
  197. * the proposal's proposer.
  198. *
  199. * Emits a {ProposalCanceled} event.
  200. */
  201. function cancel(uint256 proposalId) public virtual;
  202. /**
  203. * @dev Cast a vote
  204. *
  205. * Emits a {VoteCast} event.
  206. */
  207. function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256 balance);
  208. /**
  209. * @dev Cast a vote with a reason
  210. *
  211. * Emits a {VoteCast} event.
  212. */
  213. function castVoteWithReason(
  214. uint256 proposalId,
  215. uint8 support,
  216. string calldata reason
  217. ) public virtual returns (uint256 balance);
  218. /**
  219. * @dev Cast a vote with a reason and additional encoded parameters
  220. *
  221. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  222. */
  223. function castVoteWithReasonAndParams(
  224. uint256 proposalId,
  225. uint8 support,
  226. string calldata reason,
  227. bytes memory params
  228. ) public virtual returns (uint256 balance);
  229. /**
  230. * @dev Cast a vote using the user's cryptographic signature.
  231. *
  232. * Emits a {VoteCast} event.
  233. */
  234. function castVoteBySig(
  235. uint256 proposalId,
  236. uint8 support,
  237. uint8 v,
  238. bytes32 r,
  239. bytes32 s
  240. ) public virtual returns (uint256 balance);
  241. /**
  242. * @dev Cast a vote with a reason and additional encoded parameters using the user's cryptographic signature.
  243. *
  244. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  245. */
  246. function castVoteWithReasonAndParamsBySig(
  247. uint256 proposalId,
  248. uint8 support,
  249. string calldata reason,
  250. bytes memory params,
  251. uint8 v,
  252. bytes32 r,
  253. bytes32 s
  254. ) public virtual returns (uint256 balance);
  255. }