IGovernor.sol 16 KB

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