IGovernor.sol 15 KB

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