IGovernor.sol 13 KB

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