IGovernor.sol 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.0.0) (governance/IGovernor.sol)
  3. pragma solidity ^0.8.20;
  4. import {IERC165} from "../interfaces/IERC165.sol";
  5. import {IERC6372} from "../interfaces/IERC6372.sol";
  6. /**
  7. * @dev Interface of the {Governor} core.
  8. */
  9. interface IGovernor is IERC165, IERC6372 {
  10. enum ProposalState {
  11. Pending,
  12. Active,
  13. Canceled,
  14. Defeated,
  15. Succeeded,
  16. Queued,
  17. Expired,
  18. Executed
  19. }
  20. /**
  21. * @dev Empty proposal or a mismatch between the parameters length for a proposal call.
  22. */
  23. error GovernorInvalidProposalLength(uint256 targets, uint256 calldatas, uint256 values);
  24. /**
  25. * @dev The vote was already cast.
  26. */
  27. error GovernorAlreadyCastVote(address voter);
  28. /**
  29. * @dev Token deposits are disabled in this contract.
  30. */
  31. error GovernorDisabledDeposit();
  32. /**
  33. * @dev The `account` is not a proposer.
  34. */
  35. error GovernorOnlyProposer(address account);
  36. /**
  37. * @dev The `account` is not the governance executor.
  38. */
  39. error GovernorOnlyExecutor(address account);
  40. /**
  41. * @dev The `proposalId` doesn't exist.
  42. */
  43. error GovernorNonexistentProposal(uint256 proposalId);
  44. /**
  45. * @dev The current state of a proposal is not the required for performing an operation.
  46. * The `expectedStates` is a bitmap with the bits enabled for each ProposalState enum position
  47. * counting from right to left.
  48. *
  49. * NOTE: If `expectedState` is `bytes32(0)`, the proposal is expected to not be in any state (i.e. not exist).
  50. * This is the case when a proposal that is expected to be unset is already initiated (the proposal is duplicated).
  51. *
  52. * See {Governor-_encodeStateBitmap}.
  53. */
  54. error GovernorUnexpectedProposalState(uint256 proposalId, ProposalState current, bytes32 expectedStates);
  55. /**
  56. * @dev The voting period set is not a valid period.
  57. */
  58. error GovernorInvalidVotingPeriod(uint256 votingPeriod);
  59. /**
  60. * @dev The `proposer` does not have the required votes to create a proposal.
  61. */
  62. error GovernorInsufficientProposerVotes(address proposer, uint256 votes, uint256 threshold);
  63. /**
  64. * @dev The `proposer` is not allowed to create a proposal.
  65. */
  66. error GovernorRestrictedProposer(address proposer);
  67. /**
  68. * @dev The vote type used is not valid for the corresponding counting module.
  69. */
  70. error GovernorInvalidVoteType();
  71. /**
  72. * @dev Queue operation is not implemented for this governor. Execute should be called directly.
  73. */
  74. error GovernorQueueNotImplemented();
  75. /**
  76. * @dev The proposal hasn't been queued yet.
  77. */
  78. error GovernorNotQueuedProposal(uint256 proposalId);
  79. /**
  80. * @dev The proposal has already been queued.
  81. */
  82. error GovernorAlreadyQueuedProposal(uint256 proposalId);
  83. /**
  84. * @dev The provided signature is not valid for the expected `voter`.
  85. * If the `voter` is a contract, the signature is not valid using {IERC1271-isValidSignature}.
  86. */
  87. error GovernorInvalidSignature(address voter);
  88. /**
  89. * @dev Emitted when a proposal is created.
  90. */
  91. event ProposalCreated(
  92. uint256 proposalId,
  93. address proposer,
  94. address[] targets,
  95. uint256[] values,
  96. string[] signatures,
  97. bytes[] calldatas,
  98. uint256 voteStart,
  99. uint256 voteEnd,
  100. string description
  101. );
  102. /**
  103. * @dev Emitted when a proposal is queued.
  104. */
  105. event ProposalQueued(uint256 proposalId, uint256 etaSeconds);
  106. /**
  107. * @dev Emitted when a proposal is executed.
  108. */
  109. event ProposalExecuted(uint256 proposalId);
  110. /**
  111. * @dev Emitted when a proposal is canceled.
  112. */
  113. event ProposalCanceled(uint256 proposalId);
  114. /**
  115. * @dev Emitted when a vote is cast without params.
  116. *
  117. * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
  118. */
  119. event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
  120. /**
  121. * @dev Emitted when a vote is cast with params.
  122. *
  123. * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
  124. * `params` are additional encoded parameters. Their interpepretation also depends on the voting module used.
  125. */
  126. event VoteCastWithParams(
  127. address indexed voter,
  128. uint256 proposalId,
  129. uint8 support,
  130. uint256 weight,
  131. string reason,
  132. bytes params
  133. );
  134. /**
  135. * @notice module:core
  136. * @dev Name of the governor instance (used in building the EIP-712 domain separator).
  137. */
  138. function name() external view returns (string memory);
  139. /**
  140. * @notice module:core
  141. * @dev Version of the governor instance (used in building the EIP-712 domain separator). Default: "1"
  142. */
  143. function version() external view returns (string memory);
  144. /**
  145. * @notice module:voting
  146. * @dev A description of the possible `support` values for {castVote} and the way these votes are counted, meant to
  147. * be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of
  148. * key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`.
  149. *
  150. * There are 2 standard keys: `support` and `quorum`.
  151. *
  152. * - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`.
  153. * - `quorum=bravo` means that only For votes are counted towards quorum.
  154. * - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum.
  155. *
  156. * If a counting module makes use of encoded `params`, it should include this under a `params` key with a unique
  157. * name that describes the behavior. For example:
  158. *
  159. * - `params=fractional` might refer to a scheme where votes are divided fractionally between for/against/abstain.
  160. * - `params=erc721` might refer to a scheme where specific NFTs are delegated to vote.
  161. *
  162. * NOTE: The string can be decoded by the standard
  163. * https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`]
  164. * JavaScript class.
  165. */
  166. // solhint-disable-next-line func-name-mixedcase
  167. function COUNTING_MODE() external view returns (string memory);
  168. /**
  169. * @notice module:core
  170. * @dev Hashing function used to (re)build the proposal id from the proposal details..
  171. */
  172. function hashProposal(
  173. address[] memory targets,
  174. uint256[] memory values,
  175. bytes[] memory calldatas,
  176. bytes32 descriptionHash
  177. ) external pure returns (uint256);
  178. /**
  179. * @notice module:core
  180. * @dev Current state of a proposal, following Compound's convention
  181. */
  182. function state(uint256 proposalId) external view returns (ProposalState);
  183. /**
  184. * @notice module:core
  185. * @dev The number of votes required in order for a voter to become a proposer.
  186. */
  187. function proposalThreshold() external view returns (uint256);
  188. /**
  189. * @notice module:core
  190. * @dev Timepoint used to retrieve user's votes and quorum. If using block number (as per Compound's Comp), the
  191. * snapshot is performed at the end of this block. Hence, voting for this proposal starts at the beginning of the
  192. * following block.
  193. */
  194. function proposalSnapshot(uint256 proposalId) external view returns (uint256);
  195. /**
  196. * @notice module:core
  197. * @dev Timepoint at which votes close. If using block number, votes close at the end of this block, so it is
  198. * possible to cast a vote during this block.
  199. */
  200. function proposalDeadline(uint256 proposalId) external view returns (uint256);
  201. /**
  202. * @notice module:core
  203. * @dev The account that created a proposal.
  204. */
  205. function proposalProposer(uint256 proposalId) external view returns (address);
  206. /**
  207. * @notice module:core
  208. * @dev The time when a queued proposal becomes executable ("ETA"). Unlike {proposalSnapshot} and
  209. * {proposalDeadline}, this doesn't use the governor clock, and instead relies on the executor's clock which may be
  210. * different. In most cases this will be a timestamp.
  211. */
  212. function proposalEta(uint256 proposalId) external view returns (uint256);
  213. /**
  214. * @notice module:core
  215. * @dev Whether a proposal needs to be queued before execution.
  216. */
  217. function proposalNeedsQueuing(uint256 proposalId) external view returns (bool);
  218. /**
  219. * @notice module:user-config
  220. * @dev Delay, between the proposal is created and the vote starts. The unit this duration is expressed in depends
  221. * on the clock (see ERC-6372) this contract uses.
  222. *
  223. * This can be increased to leave time for users to buy voting power, or delegate it, before the voting of a
  224. * proposal starts.
  225. *
  226. * NOTE: While this interface returns a uint256, timepoints are stored as uint48 following the ERC-6372 clock type.
  227. * Consequently this value must fit in a uint48 (when added to the current clock). See {IERC6372-clock}.
  228. */
  229. function votingDelay() external view returns (uint256);
  230. /**
  231. * @notice module:user-config
  232. * @dev Delay between the vote start and vote end. The unit this duration is expressed in depends on the clock
  233. * (see ERC-6372) this contract uses.
  234. *
  235. * NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
  236. * duration compared to the voting delay.
  237. *
  238. * NOTE: This value is stored when the proposal is submitted so that possible changes to the value do not affect
  239. * proposals that have already been submitted. The type used to save it is a uint32. Consequently, while this
  240. * interface returns a uint256, the value it returns should fit in a uint32.
  241. */
  242. function votingPeriod() external view returns (uint256);
  243. /**
  244. * @notice module:user-config
  245. * @dev Minimum number of cast voted required for a proposal to be successful.
  246. *
  247. * NOTE: The `timepoint` parameter corresponds to the snapshot used for counting vote. This allows to scale the
  248. * quorum depending on values such as the totalSupply of a token at this timepoint (see {ERC20Votes}).
  249. */
  250. function quorum(uint256 timepoint) external view returns (uint256);
  251. /**
  252. * @notice module:reputation
  253. * @dev Voting power of an `account` at a specific `timepoint`.
  254. *
  255. * Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
  256. * multiple), {ERC20Votes} tokens.
  257. */
  258. function getVotes(address account, uint256 timepoint) external view returns (uint256);
  259. /**
  260. * @notice module:reputation
  261. * @dev Voting power of an `account` at a specific `timepoint` given additional encoded parameters.
  262. */
  263. function getVotesWithParams(
  264. address account,
  265. uint256 timepoint,
  266. bytes memory params
  267. ) external view returns (uint256);
  268. /**
  269. * @notice module:voting
  270. * @dev Returns whether `account` has cast a vote on `proposalId`.
  271. */
  272. function hasVoted(uint256 proposalId, address account) external view returns (bool);
  273. /**
  274. * @dev Create a new proposal. Vote start after a delay specified by {IGovernor-votingDelay} and lasts for a
  275. * duration specified by {IGovernor-votingPeriod}.
  276. *
  277. * Emits a {ProposalCreated} event.
  278. */
  279. function propose(
  280. address[] memory targets,
  281. uint256[] memory values,
  282. bytes[] memory calldatas,
  283. string memory description
  284. ) external returns (uint256 proposalId);
  285. /**
  286. * @dev Queue a proposal. Some governors require this step to be performed before execution can happen. If queuing
  287. * is not necessary, this function may revert.
  288. * Queuing a proposal requires the quorum to be reached, the vote to be successful, and the deadline to be reached.
  289. *
  290. * Emits a {ProposalQueued} event.
  291. */
  292. function queue(
  293. address[] memory targets,
  294. uint256[] memory values,
  295. bytes[] memory calldatas,
  296. bytes32 descriptionHash
  297. ) external returns (uint256 proposalId);
  298. /**
  299. * @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
  300. * deadline to be reached. Depending on the governor it might also be required that the proposal was queued and
  301. * that some delay passed.
  302. *
  303. * Emits a {ProposalExecuted} event.
  304. *
  305. * NOTE: Some modules can modify the requirements for execution, for example by adding an additional timelock.
  306. */
  307. function execute(
  308. address[] memory targets,
  309. uint256[] memory values,
  310. bytes[] memory calldatas,
  311. bytes32 descriptionHash
  312. ) external payable returns (uint256 proposalId);
  313. /**
  314. * @dev Cancel a proposal. A proposal is cancellable by the proposer, but only while it is Pending state, i.e.
  315. * before the vote starts.
  316. *
  317. * Emits a {ProposalCanceled} event.
  318. */
  319. function cancel(
  320. address[] memory targets,
  321. uint256[] memory values,
  322. bytes[] memory calldatas,
  323. bytes32 descriptionHash
  324. ) external returns (uint256 proposalId);
  325. /**
  326. * @dev Cast a vote
  327. *
  328. * Emits a {VoteCast} event.
  329. */
  330. function castVote(uint256 proposalId, uint8 support) external returns (uint256 balance);
  331. /**
  332. * @dev Cast a vote with a reason
  333. *
  334. * Emits a {VoteCast} event.
  335. */
  336. function castVoteWithReason(
  337. uint256 proposalId,
  338. uint8 support,
  339. string calldata reason
  340. ) external returns (uint256 balance);
  341. /**
  342. * @dev Cast a vote with a reason and additional encoded parameters
  343. *
  344. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  345. */
  346. function castVoteWithReasonAndParams(
  347. uint256 proposalId,
  348. uint8 support,
  349. string calldata reason,
  350. bytes memory params
  351. ) external returns (uint256 balance);
  352. /**
  353. * @dev Cast a vote using the voter's signature, including ERC-1271 signature support.
  354. *
  355. * Emits a {VoteCast} event.
  356. */
  357. function castVoteBySig(
  358. uint256 proposalId,
  359. uint8 support,
  360. address voter,
  361. bytes memory signature
  362. ) external returns (uint256 balance);
  363. /**
  364. * @dev Cast a vote with a reason and additional encoded parameters using the voter's signature,
  365. * including ERC-1271 signature support.
  366. *
  367. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  368. */
  369. function castVoteWithReasonAndParamsBySig(
  370. uint256 proposalId,
  371. uint8 support,
  372. address voter,
  373. string calldata reason,
  374. bytes memory params,
  375. bytes memory signature
  376. ) external returns (uint256 balance);
  377. }