Governor.sol 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.9.0) (governance/Governor.sol)
  3. pragma solidity ^0.8.19;
  4. import "../token/ERC721/IERC721Receiver.sol";
  5. import "../token/ERC1155/IERC1155Receiver.sol";
  6. import "../utils/cryptography/ECDSA.sol";
  7. import "../utils/cryptography/EIP712.sol";
  8. import "../utils/introspection/ERC165.sol";
  9. import "../utils/math/SafeCast.sol";
  10. import "../utils/structs/DoubleEndedQueue.sol";
  11. import "../utils/Address.sol";
  12. import "../utils/Context.sol";
  13. import "./IGovernor.sol";
  14. /**
  15. * @dev Core of the governance system, designed to be extended though various modules.
  16. *
  17. * This contract is abstract and requires several functions to be implemented in various modules:
  18. *
  19. * - A counting module must implement {quorum}, {_quorumReached}, {_voteSucceeded} and {_countVote}
  20. * - A voting module must implement {_getVotes}
  21. * - Additionally, {votingPeriod} must also be implemented
  22. *
  23. * _Available since v4.3._
  24. */
  25. abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receiver, IERC1155Receiver {
  26. using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
  27. bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support)");
  28. bytes32 public constant EXTENDED_BALLOT_TYPEHASH =
  29. keccak256("ExtendedBallot(uint256 proposalId,uint8 support,string reason,bytes params)");
  30. // solhint-disable var-name-mixedcase
  31. struct ProposalCore {
  32. // --- start retyped from Timers.BlockNumber at offset 0x00 ---
  33. uint64 voteStart;
  34. address proposer;
  35. bytes4 __gap_unused0;
  36. // --- start retyped from Timers.BlockNumber at offset 0x20 ---
  37. uint64 voteEnd;
  38. bytes24 __gap_unused1;
  39. // --- Remaining fields starting at offset 0x40 ---------------
  40. bool executed;
  41. bool canceled;
  42. }
  43. // solhint-enable var-name-mixedcase
  44. string private _name;
  45. /// @custom:oz-retyped-from mapping(uint256 => Governor.ProposalCore)
  46. mapping(uint256 => ProposalCore) private _proposals;
  47. // This queue keeps track of the governor operating on itself. Calls to functions protected by the
  48. // {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},
  49. // consumed by the {onlyGovernance} modifier and eventually reset in {_afterExecute}. This ensures that the
  50. // execution of {onlyGovernance} protected calls can only be achieved through successful proposals.
  51. DoubleEndedQueue.Bytes32Deque private _governanceCall;
  52. /**
  53. * @dev Restricts a function so it can only be executed through governance proposals. For example, governance
  54. * parameter setters in {GovernorSettings} are protected using this modifier.
  55. *
  56. * The governance executing address may be different from the Governor's own address, for example it could be a
  57. * timelock. This can be customized by modules by overriding {_executor}. The executor is only able to invoke these
  58. * functions during the execution of the governor's {execute} function, and not under any other circumstances. Thus,
  59. * for example, additional timelock proposers are not able to change governance parameters without going through the
  60. * governance protocol (since v4.6).
  61. */
  62. modifier onlyGovernance() {
  63. if (_msgSender() != _executor()) {
  64. revert GovernorOnlyGovernance();
  65. }
  66. if (_executor() != address(this)) {
  67. bytes32 msgDataHash = keccak256(_msgData());
  68. // loop until popping the expected operation - throw if deque is empty (operation not authorized)
  69. while (_governanceCall.popFront() != msgDataHash) {}
  70. }
  71. _;
  72. }
  73. /**
  74. * @dev Sets the value for {name} and {version}
  75. */
  76. constructor(string memory name_) EIP712(name_, version()) {
  77. _name = name_;
  78. }
  79. /**
  80. * @dev Function to receive ETH that will be handled by the governor (disabled if executor is a third party contract)
  81. */
  82. receive() external payable virtual {
  83. if (_executor() != address(this)) {
  84. revert GovernorDepositDisabled(address(this));
  85. }
  86. }
  87. /**
  88. * @dev See {IERC165-supportsInterface}.
  89. */
  90. function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
  91. bytes4 governorCancelId = this.cancel.selector ^ this.proposalProposer.selector;
  92. bytes4 governorParamsId = this.castVoteWithReasonAndParams.selector ^
  93. this.castVoteWithReasonAndParamsBySig.selector ^
  94. this.getVotesWithParams.selector;
  95. // The original interface id in v4.3.
  96. bytes4 governor43Id = type(IGovernor).interfaceId ^
  97. type(IERC6372).interfaceId ^
  98. governorCancelId ^
  99. governorParamsId;
  100. // An updated interface id in v4.6, with params added.
  101. bytes4 governor46Id = type(IGovernor).interfaceId ^ type(IERC6372).interfaceId ^ governorCancelId;
  102. // For the updated interface id in v4.9, we use governorCancelId directly.
  103. return
  104. interfaceId == governor43Id ||
  105. interfaceId == governor46Id ||
  106. interfaceId == governorCancelId ||
  107. interfaceId == type(IERC1155Receiver).interfaceId ||
  108. super.supportsInterface(interfaceId);
  109. }
  110. /**
  111. * @dev See {IGovernor-name}.
  112. */
  113. function name() public view virtual override returns (string memory) {
  114. return _name;
  115. }
  116. /**
  117. * @dev See {IGovernor-version}.
  118. */
  119. function version() public view virtual override returns (string memory) {
  120. return "1";
  121. }
  122. /**
  123. * @dev See {IGovernor-hashProposal}.
  124. *
  125. * The proposal id is produced by hashing the ABI encoded `targets` array, the `values` array, the `calldatas` array
  126. * and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id
  127. * can be produced from the proposal data which is part of the {ProposalCreated} event. It can even be computed in
  128. * advance, before the proposal is submitted.
  129. *
  130. * Note that the chainId and the governor address are not part of the proposal id computation. Consequently, the
  131. * same proposal (with same operation and same description) will have the same id if submitted on multiple governors
  132. * across multiple networks. This also means that in order to execute the same operation twice (on the same
  133. * governor) the proposer will have to change the description in order to avoid proposal id conflicts.
  134. */
  135. function hashProposal(
  136. address[] memory targets,
  137. uint256[] memory values,
  138. bytes[] memory calldatas,
  139. bytes32 descriptionHash
  140. ) public pure virtual override returns (uint256) {
  141. return uint256(keccak256(abi.encode(targets, values, calldatas, descriptionHash)));
  142. }
  143. /**
  144. * @dev See {IGovernor-state}.
  145. */
  146. function state(uint256 proposalId) public view virtual override returns (ProposalState) {
  147. ProposalCore storage proposal = _proposals[proposalId];
  148. if (proposal.executed) {
  149. return ProposalState.Executed;
  150. }
  151. if (proposal.canceled) {
  152. return ProposalState.Canceled;
  153. }
  154. uint256 snapshot = proposalSnapshot(proposalId);
  155. if (snapshot == 0) {
  156. revert GovernorNonexistentProposal(proposalId);
  157. }
  158. uint256 currentTimepoint = clock();
  159. if (snapshot >= currentTimepoint) {
  160. return ProposalState.Pending;
  161. }
  162. uint256 deadline = proposalDeadline(proposalId);
  163. if (deadline >= currentTimepoint) {
  164. return ProposalState.Active;
  165. }
  166. if (_quorumReached(proposalId) && _voteSucceeded(proposalId)) {
  167. return ProposalState.Succeeded;
  168. } else {
  169. return ProposalState.Defeated;
  170. }
  171. }
  172. /**
  173. * @dev Part of the Governor Bravo's interface: _"The number of votes required in order for a voter to become a proposer"_.
  174. */
  175. function proposalThreshold() public view virtual returns (uint256) {
  176. return 0;
  177. }
  178. /**
  179. * @dev See {IGovernor-proposalSnapshot}.
  180. */
  181. function proposalSnapshot(uint256 proposalId) public view virtual override returns (uint256) {
  182. return _proposals[proposalId].voteStart;
  183. }
  184. /**
  185. * @dev See {IGovernor-proposalDeadline}.
  186. */
  187. function proposalDeadline(uint256 proposalId) public view virtual override returns (uint256) {
  188. return _proposals[proposalId].voteEnd;
  189. }
  190. /**
  191. * @dev Returns the account that created a given proposal.
  192. */
  193. function proposalProposer(uint256 proposalId) public view virtual override returns (address) {
  194. return _proposals[proposalId].proposer;
  195. }
  196. /**
  197. * @dev Amount of votes already cast passes the threshold limit.
  198. */
  199. function _quorumReached(uint256 proposalId) internal view virtual returns (bool);
  200. /**
  201. * @dev Is the proposal successful or not.
  202. */
  203. function _voteSucceeded(uint256 proposalId) internal view virtual returns (bool);
  204. /**
  205. * @dev Get the voting weight of `account` at a specific `timepoint`, for a vote as described by `params`.
  206. */
  207. function _getVotes(address account, uint256 timepoint, bytes memory params) internal view virtual returns (uint256);
  208. /**
  209. * @dev Register a vote for `proposalId` by `account` with a given `support`, voting `weight` and voting `params`.
  210. *
  211. * Note: Support is generic and can represent various things depending on the voting system used.
  212. */
  213. function _countVote(
  214. uint256 proposalId,
  215. address account,
  216. uint8 support,
  217. uint256 weight,
  218. bytes memory params
  219. ) internal virtual;
  220. /**
  221. * @dev Default additional encoded parameters used by castVote methods that don't include them
  222. *
  223. * Note: Should be overridden by specific implementations to use an appropriate value, the
  224. * meaning of the additional params, in the context of that implementation
  225. */
  226. function _defaultParams() internal view virtual returns (bytes memory) {
  227. return "";
  228. }
  229. /**
  230. * @dev See {IGovernor-propose}.
  231. */
  232. function propose(
  233. address[] memory targets,
  234. uint256[] memory values,
  235. bytes[] memory calldatas,
  236. string memory description
  237. ) public virtual override returns (uint256) {
  238. address proposer = _msgSender();
  239. uint256 currentTimepoint = clock();
  240. // Avoid stack too deep
  241. {
  242. uint256 proposerVotes = getVotes(proposer, currentTimepoint - 1);
  243. uint256 votesThreshold = proposalThreshold();
  244. if (proposerVotes < votesThreshold) {
  245. revert GovernorProposerInvalidTreshold(proposer, proposerVotes, votesThreshold);
  246. }
  247. }
  248. uint256 proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));
  249. if (targets.length != values.length || targets.length != calldatas.length || targets.length == 0) {
  250. revert GovernorInvalidProposalLength(targets.length, calldatas.length, values.length);
  251. }
  252. if (_proposals[proposalId].voteStart != 0) {
  253. revert GovernorIncorrectState(proposalId, state(proposalId), bytes32(0));
  254. }
  255. uint256 snapshot = currentTimepoint + votingDelay();
  256. uint256 deadline = snapshot + votingPeriod();
  257. _proposals[proposalId] = ProposalCore({
  258. proposer: proposer,
  259. voteStart: SafeCast.toUint64(snapshot),
  260. voteEnd: SafeCast.toUint64(deadline),
  261. executed: false,
  262. canceled: false,
  263. __gap_unused0: 0,
  264. __gap_unused1: 0
  265. });
  266. emit ProposalCreated(
  267. proposalId,
  268. proposer,
  269. targets,
  270. values,
  271. new string[](targets.length),
  272. calldatas,
  273. snapshot,
  274. deadline,
  275. description
  276. );
  277. return proposalId;
  278. }
  279. /**
  280. * @dev See {IGovernor-execute}.
  281. */
  282. function execute(
  283. address[] memory targets,
  284. uint256[] memory values,
  285. bytes[] memory calldatas,
  286. bytes32 descriptionHash
  287. ) public payable virtual override returns (uint256) {
  288. uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
  289. ProposalState currentState = state(proposalId);
  290. if (currentState != ProposalState.Succeeded && currentState != ProposalState.Queued) {
  291. revert GovernorIncorrectState(
  292. proposalId,
  293. currentState,
  294. _encodeState(ProposalState.Succeeded) | _encodeState(ProposalState.Queued)
  295. );
  296. }
  297. _proposals[proposalId].executed = true;
  298. emit ProposalExecuted(proposalId);
  299. _beforeExecute(proposalId, targets, values, calldatas, descriptionHash);
  300. _execute(proposalId, targets, values, calldatas, descriptionHash);
  301. _afterExecute(proposalId, targets, values, calldatas, descriptionHash);
  302. return proposalId;
  303. }
  304. /**
  305. * @dev See {IGovernor-cancel}.
  306. */
  307. function cancel(
  308. address[] memory targets,
  309. uint256[] memory values,
  310. bytes[] memory calldatas,
  311. bytes32 descriptionHash
  312. ) public virtual override returns (uint256) {
  313. uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
  314. ProposalState currentState = state(proposalId);
  315. if (currentState != ProposalState.Pending) {
  316. revert GovernorIncorrectState(proposalId, currentState, _encodeState(ProposalState.Pending));
  317. }
  318. if (_msgSender() != proposalProposer(proposalId)) {
  319. revert GovernorOnlyProposer(_msgSender());
  320. }
  321. return _cancel(targets, values, calldatas, descriptionHash);
  322. }
  323. /**
  324. * @dev Internal execution mechanism. Can be overridden to implement different execution mechanism
  325. */
  326. function _execute(
  327. uint256 /* proposalId */,
  328. address[] memory targets,
  329. uint256[] memory values,
  330. bytes[] memory calldatas,
  331. bytes32 /*descriptionHash*/
  332. ) internal virtual {
  333. for (uint256 i = 0; i < targets.length; ++i) {
  334. (bool success, bytes memory returndata) = targets[i].call{value: values[i]}(calldatas[i]);
  335. Address.verifyCallResult(success, returndata, _customGovernorRevert);
  336. }
  337. }
  338. /**
  339. * @dev Hook before execution is triggered.
  340. */
  341. function _beforeExecute(
  342. uint256 /* proposalId */,
  343. address[] memory targets,
  344. uint256[] memory /* values */,
  345. bytes[] memory calldatas,
  346. bytes32 /*descriptionHash*/
  347. ) internal virtual {
  348. if (_executor() != address(this)) {
  349. for (uint256 i = 0; i < targets.length; ++i) {
  350. if (targets[i] == address(this)) {
  351. _governanceCall.pushBack(keccak256(calldatas[i]));
  352. }
  353. }
  354. }
  355. }
  356. /**
  357. * @dev Hook after execution is triggered.
  358. */
  359. function _afterExecute(
  360. uint256 /* proposalId */,
  361. address[] memory /* targets */,
  362. uint256[] memory /* values */,
  363. bytes[] memory /* calldatas */,
  364. bytes32 /*descriptionHash*/
  365. ) internal virtual {
  366. if (_executor() != address(this)) {
  367. if (!_governanceCall.empty()) {
  368. _governanceCall.clear();
  369. }
  370. }
  371. }
  372. /**
  373. * @dev Internal cancel mechanism: locks up the proposal timer, preventing it from being re-submitted. Marks it as
  374. * canceled to allow distinguishing it from executed proposals.
  375. *
  376. * Emits a {IGovernor-ProposalCanceled} event.
  377. */
  378. function _cancel(
  379. address[] memory targets,
  380. uint256[] memory values,
  381. bytes[] memory calldatas,
  382. bytes32 descriptionHash
  383. ) internal virtual returns (uint256) {
  384. uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
  385. ProposalState currentState = state(proposalId);
  386. if (
  387. currentState == ProposalState.Canceled ||
  388. currentState == ProposalState.Expired ||
  389. currentState == ProposalState.Executed
  390. ) {
  391. uint256 maxProposalState = uint256(type(ProposalState).max); // All proposal states
  392. bytes32 mask = bytes32(uint256(2 ** maxProposalState - 1)); // 0x...1111
  393. bytes32 forbiddenStates = _encodeState(ProposalState.Canceled) |
  394. _encodeState(ProposalState.Expired) |
  395. _encodeState(ProposalState.Executed);
  396. revert GovernorIncorrectState(proposalId, currentState, mask ^ forbiddenStates);
  397. }
  398. _proposals[proposalId].canceled = true;
  399. emit ProposalCanceled(proposalId);
  400. return proposalId;
  401. }
  402. /**
  403. * @dev See {IGovernor-getVotes}.
  404. */
  405. function getVotes(address account, uint256 timepoint) public view virtual override returns (uint256) {
  406. return _getVotes(account, timepoint, _defaultParams());
  407. }
  408. /**
  409. * @dev See {IGovernor-getVotesWithParams}.
  410. */
  411. function getVotesWithParams(
  412. address account,
  413. uint256 timepoint,
  414. bytes memory params
  415. ) public view virtual override returns (uint256) {
  416. return _getVotes(account, timepoint, params);
  417. }
  418. /**
  419. * @dev See {IGovernor-castVote}.
  420. */
  421. function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) {
  422. address voter = _msgSender();
  423. return _castVote(proposalId, voter, support, "");
  424. }
  425. /**
  426. * @dev See {IGovernor-castVoteWithReason}.
  427. */
  428. function castVoteWithReason(
  429. uint256 proposalId,
  430. uint8 support,
  431. string calldata reason
  432. ) public virtual override returns (uint256) {
  433. address voter = _msgSender();
  434. return _castVote(proposalId, voter, support, reason);
  435. }
  436. /**
  437. * @dev See {IGovernor-castVoteWithReasonAndParams}.
  438. */
  439. function castVoteWithReasonAndParams(
  440. uint256 proposalId,
  441. uint8 support,
  442. string calldata reason,
  443. bytes memory params
  444. ) public virtual override returns (uint256) {
  445. address voter = _msgSender();
  446. return _castVote(proposalId, voter, support, reason, params);
  447. }
  448. /**
  449. * @dev See {IGovernor-castVoteBySig}.
  450. */
  451. function castVoteBySig(
  452. uint256 proposalId,
  453. uint8 support,
  454. uint8 v,
  455. bytes32 r,
  456. bytes32 s
  457. ) public virtual override returns (uint256) {
  458. address voter = ECDSA.recover(
  459. _hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support))),
  460. v,
  461. r,
  462. s
  463. );
  464. return _castVote(proposalId, voter, support, "");
  465. }
  466. /**
  467. * @dev See {IGovernor-castVoteWithReasonAndParamsBySig}.
  468. */
  469. function castVoteWithReasonAndParamsBySig(
  470. uint256 proposalId,
  471. uint8 support,
  472. string calldata reason,
  473. bytes memory params,
  474. uint8 v,
  475. bytes32 r,
  476. bytes32 s
  477. ) public virtual override returns (uint256) {
  478. address voter = ECDSA.recover(
  479. _hashTypedDataV4(
  480. keccak256(
  481. abi.encode(
  482. EXTENDED_BALLOT_TYPEHASH,
  483. proposalId,
  484. support,
  485. keccak256(bytes(reason)),
  486. keccak256(params)
  487. )
  488. )
  489. ),
  490. v,
  491. r,
  492. s
  493. );
  494. return _castVote(proposalId, voter, support, reason, params);
  495. }
  496. /**
  497. * @dev Internal vote casting mechanism: Check that the vote is pending, that it has not been cast yet, retrieve
  498. * voting weight using {IGovernor-getVotes} and call the {_countVote} internal function. Uses the _defaultParams().
  499. *
  500. * Emits a {IGovernor-VoteCast} event.
  501. */
  502. function _castVote(
  503. uint256 proposalId,
  504. address account,
  505. uint8 support,
  506. string memory reason
  507. ) internal virtual returns (uint256) {
  508. return _castVote(proposalId, account, support, reason, _defaultParams());
  509. }
  510. /**
  511. * @dev Internal vote casting mechanism: Check that the vote is pending, that it has not been cast yet, retrieve
  512. * voting weight using {IGovernor-getVotes} and call the {_countVote} internal function.
  513. *
  514. * Emits a {IGovernor-VoteCast} event.
  515. */
  516. function _castVote(
  517. uint256 proposalId,
  518. address account,
  519. uint8 support,
  520. string memory reason,
  521. bytes memory params
  522. ) internal virtual returns (uint256) {
  523. ProposalCore storage proposal = _proposals[proposalId];
  524. ProposalState currentState = state(proposalId);
  525. if (currentState != ProposalState.Active) {
  526. revert GovernorIncorrectState(proposalId, currentState, _encodeState(ProposalState.Active));
  527. }
  528. uint256 weight = _getVotes(account, proposal.voteStart, params);
  529. _countVote(proposalId, account, support, weight, params);
  530. if (params.length == 0) {
  531. emit VoteCast(account, proposalId, support, weight, reason);
  532. } else {
  533. emit VoteCastWithParams(account, proposalId, support, weight, reason, params);
  534. }
  535. return weight;
  536. }
  537. /**
  538. * @dev Relays a transaction or function call to an arbitrary target. In cases where the governance executor
  539. * is some contract other than the governor itself, like when using a timelock, this function can be invoked
  540. * in a governance proposal to recover tokens or Ether that was sent to the governor contract by mistake.
  541. * Note that if the executor is simply the governor itself, use of `relay` is redundant.
  542. */
  543. function relay(address target, uint256 value, bytes calldata data) external payable virtual onlyGovernance {
  544. (bool success, bytes memory returndata) = target.call{value: value}(data);
  545. Address.verifyCallResult(success, returndata, _customGovernorRevert);
  546. }
  547. /**
  548. * @dev Address through which the governor executes action. Will be overloaded by module that execute actions
  549. * through another contract such as a timelock.
  550. */
  551. function _executor() internal view virtual returns (address) {
  552. return address(this);
  553. }
  554. /**
  555. * @dev See {IERC721Receiver-onERC721Received}.
  556. */
  557. function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
  558. return this.onERC721Received.selector;
  559. }
  560. /**
  561. * @dev See {IERC1155Receiver-onERC1155Received}.
  562. */
  563. function onERC1155Received(
  564. address,
  565. address,
  566. uint256,
  567. uint256,
  568. bytes memory
  569. ) public virtual override returns (bytes4) {
  570. return this.onERC1155Received.selector;
  571. }
  572. /**
  573. * @dev See {IERC1155Receiver-onERC1155BatchReceived}.
  574. */
  575. function onERC1155BatchReceived(
  576. address,
  577. address,
  578. uint256[] memory,
  579. uint256[] memory,
  580. bytes memory
  581. ) public virtual override returns (bytes4) {
  582. return this.onERC1155BatchReceived.selector;
  583. }
  584. /**
  585. * @dev Encodes a `ProposalState` into a `bytes32` representation where each bit enabled corresponds to
  586. * the underlying position in the `ProposalState` enum. For example:
  587. *
  588. * 0x000...10000
  589. * ^^^^^^------ ...
  590. * ^----- Succeeded
  591. * ^---- Defeated
  592. * ^--- Canceled
  593. * ^-- Active
  594. * ^- Pending
  595. */
  596. function _encodeState(ProposalState proposalState) internal pure returns (bytes32) {
  597. return bytes32(1 << uint8(proposalState));
  598. }
  599. /**
  600. * @dev Default revert function for failed executed functions without any other bubbled up reason.
  601. */
  602. function _customGovernorRevert() internal pure {
  603. revert GovernorFailedCall();
  604. }
  605. }