IGovernor.sol 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.9.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. abstract contract 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 operate on a proposal.
  61. */
  62. error GovernorInsufficientProposerVotes(address proposer, uint256 votes, uint256 threshold);
  63. /**
  64. * @dev The vote type used is not valid for the corresponding counting module.
  65. */
  66. error GovernorInvalidVoteType();
  67. /**
  68. * @dev The provided signature is not valid for the expected `voter`.
  69. * If the `voter` is a contract, the signature is not valid using {IERC1271-isValidSignature}.
  70. */
  71. error GovernorInvalidSignature(address voter);
  72. /**
  73. * @dev Emitted when a proposal is created.
  74. */
  75. event ProposalCreated(
  76. uint256 proposalId,
  77. address proposer,
  78. address[] targets,
  79. uint256[] values,
  80. string[] signatures,
  81. bytes[] calldatas,
  82. uint256 voteStart,
  83. uint256 voteEnd,
  84. string description
  85. );
  86. /**
  87. * @dev Emitted when a proposal is canceled.
  88. */
  89. event ProposalCanceled(uint256 proposalId);
  90. /**
  91. * @dev Emitted when a proposal is executed.
  92. */
  93. event ProposalExecuted(uint256 proposalId);
  94. /**
  95. * @dev Emitted when a vote is cast without params.
  96. *
  97. * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
  98. */
  99. event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
  100. /**
  101. * @dev Emitted when a vote is cast with params.
  102. *
  103. * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
  104. * `params` are additional encoded parameters. Their interpepretation also depends on the voting module used.
  105. */
  106. event VoteCastWithParams(
  107. address indexed voter,
  108. uint256 proposalId,
  109. uint8 support,
  110. uint256 weight,
  111. string reason,
  112. bytes params
  113. );
  114. /**
  115. * @notice module:core
  116. * @dev Name of the governor instance (used in building the ERC712 domain separator).
  117. */
  118. function name() public view virtual returns (string memory);
  119. /**
  120. * @notice module:core
  121. * @dev Version of the governor instance (used in building the ERC712 domain separator). Default: "1"
  122. */
  123. function version() public view virtual returns (string memory);
  124. /**
  125. * @notice module:core
  126. * @dev See {IERC6372}
  127. */
  128. function clock() public view virtual returns (uint48);
  129. /**
  130. * @notice module:core
  131. * @dev See EIP-6372.
  132. */
  133. // solhint-disable-next-line func-name-mixedcase
  134. function CLOCK_MODE() public view virtual returns (string memory);
  135. /**
  136. * @notice module:voting
  137. * @dev A description of the possible `support` values for {castVote} and the way these votes are counted, meant to
  138. * be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of
  139. * key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`.
  140. *
  141. * There are 2 standard keys: `support` and `quorum`.
  142. *
  143. * - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`.
  144. * - `quorum=bravo` means that only For votes are counted towards quorum.
  145. * - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum.
  146. *
  147. * If a counting module makes use of encoded `params`, it should include this under a `params` key with a unique
  148. * name that describes the behavior. For example:
  149. *
  150. * - `params=fractional` might refer to a scheme where votes are divided fractionally between for/against/abstain.
  151. * - `params=erc721` might refer to a scheme where specific NFTs are delegated to vote.
  152. *
  153. * NOTE: The string can be decoded by the standard
  154. * https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`]
  155. * JavaScript class.
  156. */
  157. // solhint-disable-next-line func-name-mixedcase
  158. function COUNTING_MODE() public view virtual returns (string memory);
  159. /**
  160. * @notice module:core
  161. * @dev Hashing function used to (re)build the proposal id from the proposal details..
  162. */
  163. function hashProposal(
  164. address[] memory targets,
  165. uint256[] memory values,
  166. bytes[] memory calldatas,
  167. bytes32 descriptionHash
  168. ) public pure virtual returns (uint256);
  169. /**
  170. * @notice module:core
  171. * @dev Current state of a proposal, following Compound's convention
  172. */
  173. function state(uint256 proposalId) public view virtual returns (ProposalState);
  174. /**
  175. * @notice module:core
  176. * @dev Timepoint used to retrieve user's votes and quorum. If using block number (as per Compound's Comp), the
  177. * snapshot is performed at the end of this block. Hence, voting for this proposal starts at the beginning of the
  178. * following block.
  179. */
  180. function proposalSnapshot(uint256 proposalId) public view virtual returns (uint256);
  181. /**
  182. * @notice module:core
  183. * @dev Timepoint at which votes close. If using block number, votes close at the end of this block, so it is
  184. * possible to cast a vote during this block.
  185. */
  186. function proposalDeadline(uint256 proposalId) public view virtual returns (uint256);
  187. /**
  188. * @notice module:core
  189. * @dev The account that created a proposal.
  190. */
  191. function proposalProposer(uint256 proposalId) public view virtual returns (address);
  192. /**
  193. * @notice module:user-config
  194. * @dev Delay, between the proposal is created and the vote starts. The unit this duration is expressed in depends
  195. * on the clock (see EIP-6372) this contract uses.
  196. *
  197. * This can be increased to leave time for users to buy voting power, or delegate it, before the voting of a
  198. * proposal starts.
  199. *
  200. * NOTE: While this interface returns a uint256, timepoints are stored as uint48 following the ERC-6372 clock type.
  201. * Consequently this value must fit in a uint48 (when added to the current clock). See {IERC6372-clock}.
  202. */
  203. function votingDelay() public view virtual returns (uint256);
  204. /**
  205. * @notice module:user-config
  206. * @dev Delay between the vote start and vote end. The unit this duration is expressed in depends on the clock
  207. * (see EIP-6372) this contract uses.
  208. *
  209. * NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
  210. * duration compared to the voting delay.
  211. *
  212. * NOTE: This value is stored when the proposal is submitted so that possible changes to the value do not affect
  213. * proposals that have already been submitted. The type used to save it is a uint32. Consequently, while this
  214. * interface returns a uint256, the value it returns should fit in a uint32.
  215. */
  216. function votingPeriod() public view virtual returns (uint256);
  217. /**
  218. * @notice module:user-config
  219. * @dev Minimum number of cast voted required for a proposal to be successful.
  220. *
  221. * NOTE: The `timepoint` parameter corresponds to the snapshot used for counting vote. This allows to scale the
  222. * quorum depending on values such as the totalSupply of a token at this timepoint (see {ERC20Votes}).
  223. */
  224. function quorum(uint256 timepoint) public view virtual returns (uint256);
  225. /**
  226. * @notice module:reputation
  227. * @dev Voting power of an `account` at a specific `timepoint`.
  228. *
  229. * Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
  230. * multiple), {ERC20Votes} tokens.
  231. */
  232. function getVotes(address account, uint256 timepoint) public view virtual returns (uint256);
  233. /**
  234. * @notice module:reputation
  235. * @dev Voting power of an `account` at a specific `timepoint` given additional encoded parameters.
  236. */
  237. function getVotesWithParams(
  238. address account,
  239. uint256 timepoint,
  240. bytes memory params
  241. ) public view virtual returns (uint256);
  242. /**
  243. * @notice module:voting
  244. * @dev Returns whether `account` has cast a vote on `proposalId`.
  245. */
  246. function hasVoted(uint256 proposalId, address account) public view virtual returns (bool);
  247. /**
  248. * @dev Create a new proposal. Vote start after a delay specified by {IGovernor-votingDelay} and lasts for a
  249. * duration specified by {IGovernor-votingPeriod}.
  250. *
  251. * Emits a {ProposalCreated} event.
  252. */
  253. function propose(
  254. address[] memory targets,
  255. uint256[] memory values,
  256. bytes[] memory calldatas,
  257. string memory description
  258. ) public virtual returns (uint256 proposalId);
  259. /**
  260. * @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
  261. * deadline to be reached.
  262. *
  263. * Emits a {ProposalExecuted} event.
  264. *
  265. * Note: some module can modify the requirements for execution, for example by adding an additional timelock.
  266. */
  267. function execute(
  268. address[] memory targets,
  269. uint256[] memory values,
  270. bytes[] memory calldatas,
  271. bytes32 descriptionHash
  272. ) public payable virtual returns (uint256 proposalId);
  273. /**
  274. * @dev Cancel a proposal. A proposal is cancellable by the proposer, but only while it is Pending state, i.e.
  275. * before the vote starts.
  276. *
  277. * Emits a {ProposalCanceled} event.
  278. */
  279. function cancel(
  280. address[] memory targets,
  281. uint256[] memory values,
  282. bytes[] memory calldatas,
  283. bytes32 descriptionHash
  284. ) public virtual returns (uint256 proposalId);
  285. /**
  286. * @dev Cast a vote
  287. *
  288. * Emits a {VoteCast} event.
  289. */
  290. function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256 balance);
  291. /**
  292. * @dev Cast a vote with a reason
  293. *
  294. * Emits a {VoteCast} event.
  295. */
  296. function castVoteWithReason(
  297. uint256 proposalId,
  298. uint8 support,
  299. string calldata reason
  300. ) public virtual returns (uint256 balance);
  301. /**
  302. * @dev Cast a vote with a reason and additional encoded parameters
  303. *
  304. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  305. */
  306. function castVoteWithReasonAndParams(
  307. uint256 proposalId,
  308. uint8 support,
  309. string calldata reason,
  310. bytes memory params
  311. ) public virtual returns (uint256 balance);
  312. /**
  313. * @dev Cast a vote using the voter's signature, including ERC-1271 signature support.
  314. *
  315. * Emits a {VoteCast} event.
  316. */
  317. function castVoteBySig(
  318. uint256 proposalId,
  319. uint8 support,
  320. address voter,
  321. bytes memory signature
  322. ) public virtual returns (uint256 balance);
  323. /**
  324. * @dev Cast a vote with a reason and additional encoded parameters using the voter's signature,
  325. * including ERC-1271 signature support.
  326. *
  327. * Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
  328. */
  329. function castVoteWithReasonAndParamsBySig(
  330. uint256 proposalId,
  331. uint8 support,
  332. address voter,
  333. string calldata reason,
  334. bytes memory params,
  335. bytes memory signature
  336. ) public virtual returns (uint256 balance);
  337. }