IGovernor.sol 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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:core
  139. * @dev The account that created a proposal.
  140. */
  141. function proposalProposer(uint256 proposalId) public view virtual returns (address);
  142. /**
  143. * @notice module:user-config
  144. * @dev Delay, between the proposal is created and the vote starts. The unit this duration is expressed in depends
  145. * on the clock (see EIP-6372) this contract uses.
  146. *
  147. * This can be increased to leave time for users to buy voting power, or delegate it, before the voting of a
  148. * proposal starts.
  149. */
  150. function votingDelay() public view virtual returns (uint256);
  151. /**
  152. * @notice module:user-config
  153. * @dev Delay between the vote start and vote end. The unit this duration is expressed in depends on the clock
  154. * (see EIP-6372) this contract uses.
  155. *
  156. * NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
  157. * duration compared to the voting delay.
  158. */
  159. function votingPeriod() public view virtual returns (uint256);
  160. /**
  161. * @notice module:user-config
  162. * @dev Minimum number of cast voted required for a proposal to be successful.
  163. *
  164. * NOTE: The `timepoint` parameter corresponds to the snapshot used for counting vote. This allows to scale the
  165. * quorum depending on values such as the totalSupply of a token at this timepoint (see {ERC20Votes}).
  166. */
  167. function quorum(uint256 timepoint) public view virtual returns (uint256);
  168. /**
  169. * @notice module:reputation
  170. * @dev Voting power of an `account` at a specific `timepoint`.
  171. *
  172. * Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
  173. * multiple), {ERC20Votes} tokens.
  174. */
  175. function getVotes(address account, uint256 timepoint) public view virtual returns (uint256);
  176. /**
  177. * @notice module:reputation
  178. * @dev Voting power of an `account` at a specific `timepoint` given additional encoded parameters.
  179. */
  180. function getVotesWithParams(
  181. address account,
  182. uint256 timepoint,
  183. bytes memory params
  184. ) public view virtual returns (uint256);
  185. /**
  186. * @notice module:voting
  187. * @dev Returns whether `account` has cast a vote on `proposalId`.
  188. */
  189. function hasVoted(uint256 proposalId, address account) public view virtual returns (bool);
  190. /**
  191. * @dev Create a new proposal. Vote start after a delay specified by {IGovernor-votingDelay} and lasts for a
  192. * duration specified by {IGovernor-votingPeriod}.
  193. *
  194. * Emits a {ProposalCreated} event.
  195. */
  196. function propose(
  197. address[] memory targets,
  198. uint256[] memory values,
  199. bytes[] memory calldatas,
  200. string memory description
  201. ) public virtual returns (uint256 proposalId);
  202. /**
  203. * @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
  204. * deadline to be reached.
  205. *
  206. * Emits a {ProposalExecuted} event.
  207. *
  208. * Note: some module can modify the requirements for execution, for example by adding an additional timelock.
  209. */
  210. function execute(
  211. address[] memory targets,
  212. uint256[] memory values,
  213. bytes[] memory calldatas,
  214. bytes32 descriptionHash
  215. ) public payable virtual returns (uint256 proposalId);
  216. /**
  217. * @dev Cancel a proposal. A proposal is cancellable by the proposer, but only while it is Pending state, i.e.
  218. * before the vote starts.
  219. *
  220. * Emits a {ProposalCanceled} event.
  221. */
  222. function cancel(
  223. address[] memory targets,
  224. uint256[] memory values,
  225. bytes[] memory calldatas,
  226. bytes32 descriptionHash
  227. ) public virtual returns (uint256 proposalId);
  228. /**
  229. * @dev Cast a vote
  230. *
  231. * Emits a {VoteCast} event.
  232. */
  233. function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256 balance);
  234. /**
  235. * @dev Cast a vote with a reason
  236. *
  237. * Emits a {VoteCast} event.
  238. */
  239. function castVoteWithReason(
  240. uint256 proposalId,
  241. uint8 support,
  242. string calldata reason
  243. ) public virtual returns (uint256 balance);
  244. /**
  245. * @dev Cast a vote with a reason and additional encoded parameters
  246. *
  247. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  248. */
  249. function castVoteWithReasonAndParams(
  250. uint256 proposalId,
  251. uint8 support,
  252. string calldata reason,
  253. bytes memory params
  254. ) public virtual returns (uint256 balance);
  255. /**
  256. * @dev Cast a vote using the user's cryptographic signature.
  257. *
  258. * Emits a {VoteCast} event.
  259. */
  260. function castVoteBySig(
  261. uint256 proposalId,
  262. uint8 support,
  263. uint8 v,
  264. bytes32 r,
  265. bytes32 s
  266. ) public virtual returns (uint256 balance);
  267. /**
  268. * @dev Cast a vote with a reason and additional encoded parameters using the user's cryptographic signature.
  269. *
  270. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  271. */
  272. function castVoteWithReasonAndParamsBySig(
  273. uint256 proposalId,
  274. uint8 support,
  275. string calldata reason,
  276. bytes memory params,
  277. uint8 v,
  278. bytes32 r,
  279. bytes32 s
  280. ) public virtual returns (uint256 balance);
  281. }