IGovernor.sol 10 KB

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