GovernorFullHarness.sol 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.2;
  3. import "../munged/governance/Governor.sol";
  4. import "../munged/governance/extensions/GovernorCountingSimple.sol";
  5. import "../munged/governance/extensions/GovernorPreventLateQuorum.sol";
  6. import "../munged/governance/extensions/GovernorTimelockControl.sol";
  7. import "../munged/governance/extensions/GovernorVotes.sol";
  8. import "../munged/governance/extensions/GovernorVotesQuorumFraction.sol";
  9. import "../munged/token/ERC20/extensions/ERC20Votes.sol";
  10. contract GovernorFullHarness is
  11. Governor,
  12. GovernorCountingSimple,
  13. GovernorTimelockControl,
  14. GovernorPreventLateQuorum,
  15. GovernorVotes,
  16. GovernorVotesQuorumFraction
  17. {
  18. using SafeCast for uint256;
  19. using Timers for Timers.BlockNumber;
  20. using Checkpoints for Checkpoints.History;
  21. constructor(
  22. IVotes _token,
  23. TimelockController _timelock,
  24. uint64 initialVoteExtension,
  25. uint256 quorumNumeratorValue
  26. )
  27. Governor("Harness")
  28. GovernorPreventLateQuorum(initialVoteExtension)
  29. GovernorTimelockControl(_timelock)
  30. GovernorVotes(_token)
  31. GovernorVotesQuorumFraction(quorumNumeratorValue)
  32. {}
  33. mapping(uint256 => uint256) public ghost_sum_vote_power_by_id;
  34. // variable added to check when _castVote is called
  35. uint256 public latestCastVoteCall;
  36. // Harness from Votes //
  37. function getPastTotalSupply(uint256 blockNumber) public view returns(uint256) {
  38. return token.getPastTotalSupply(blockNumber);
  39. }
  40. // Harness from GovernorVotesQuorumFraction //
  41. function getQuorumNumeratorLength() public view returns(uint256) {
  42. return _quorumNumeratorHistory._checkpoints.length;
  43. }
  44. function getQuorumNumeratorLatest() public view returns(uint256) {
  45. return _quorumNumeratorHistory.latest();
  46. }
  47. function getDeprecatedQuorumNumerator() public view returns(uint256) {
  48. return _quorumNumerator;
  49. }
  50. // Harness from GovernorPreventLateQuorum //
  51. function getVoteExtension() public view returns (uint64) {
  52. return _voteExtension;
  53. }
  54. function getExtendedDeadlineIsUnset(uint256 proposalId) public view returns (bool) {
  55. return _extendedDeadlines[proposalId].isUnset();
  56. }
  57. function getExtendedDeadlineIsStarted(uint256 proposalId) public view returns (bool) {
  58. return _extendedDeadlines[proposalId].isStarted();
  59. }
  60. function getExtendedDeadline(uint256 proposalId) public view returns (uint64) {
  61. return _extendedDeadlines[proposalId].getDeadline();
  62. }
  63. // Harness from GovernorCountingSimple //
  64. function getAgainstVotes(uint256 proposalId) public view returns (uint256) {
  65. ProposalVote storage proposalvote = _proposalVotes[proposalId];
  66. return proposalvote.againstVotes;
  67. }
  68. function getAbstainVotes(uint256 proposalId) public view returns (uint256) {
  69. ProposalVote storage proposalvote = _proposalVotes[proposalId];
  70. return proposalvote.abstainVotes;
  71. }
  72. function getForVotes(uint256 proposalId) public view returns (uint256) {
  73. ProposalVote storage proposalvote = _proposalVotes[proposalId];
  74. return proposalvote.forVotes;
  75. }
  76. function quorumReached(uint256 proposalId) public view returns (bool) {
  77. return _quorumReached(proposalId);
  78. }
  79. function voteSucceeded(uint256 proposalId) public view returns (bool) {
  80. return _voteSucceeded(proposalId);
  81. }
  82. // Harness from Governor //
  83. function getExecutor() public view returns (address) {
  84. return _executor();
  85. }
  86. function isExecuted(uint256 proposalId) public view returns (bool) {
  87. return _proposals[proposalId].executed;
  88. }
  89. function isCanceled(uint256 proposalId) public view returns (bool) {
  90. return _proposals[proposalId].canceled;
  91. }
  92. // The following functions are overrides required by Solidity added by Certora. //
  93. function proposalDeadline(uint256 proposalId)
  94. public
  95. view
  96. virtual
  97. override(Governor, GovernorPreventLateQuorum, IGovernor)
  98. returns (uint256)
  99. {
  100. return super.proposalDeadline(proposalId);
  101. }
  102. function _castVote(
  103. uint256 proposalId,
  104. address account,
  105. uint8 support,
  106. string memory reason,
  107. bytes memory params
  108. ) internal virtual override(Governor, GovernorPreventLateQuorum) returns (uint256) {
  109. // flag for when _castVote is called
  110. latestCastVoteCall = block.number;
  111. // added to run GovernorCountingSimple.spec
  112. uint256 deltaWeight = super._castVote(proposalId, account, support, reason, params);
  113. ghost_sum_vote_power_by_id[proposalId] += deltaWeight;
  114. return deltaWeight;
  115. }
  116. function lateQuorumVoteExtension() public view virtual override returns (uint64) {
  117. return super.lateQuorumVoteExtension();
  118. }
  119. function setLateQuorumVoteExtension(uint64 newVoteExtension) public virtual override onlyGovernance {
  120. super.setLateQuorumVoteExtension(newVoteExtension);
  121. }
  122. // The following functions are overrides required by Solidity added by OZ Wizard. //
  123. function votingDelay() public pure override returns (uint256) {
  124. return 1; // 1 block
  125. }
  126. function votingPeriod() public pure override returns (uint256) {
  127. return 45818; // 1 week
  128. }
  129. function quorum(uint256 blockNumber)
  130. public
  131. view
  132. override(IGovernor, GovernorVotesQuorumFraction)
  133. returns (uint256)
  134. {
  135. return super.quorum(blockNumber);
  136. }
  137. function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
  138. return super.state(proposalId);
  139. }
  140. function propose(
  141. address[] memory targets,
  142. uint256[] memory values,
  143. bytes[] memory calldatas,
  144. string memory description
  145. ) public override(Governor, IGovernor) returns (uint256) {
  146. return super.propose(targets, values, calldatas, description);
  147. }
  148. function _execute(
  149. uint256 proposalId,
  150. address[] memory targets,
  151. uint256[] memory values,
  152. bytes[] memory calldatas,
  153. bytes32 descriptionHash
  154. ) internal override(Governor, GovernorTimelockControl) {
  155. super._execute(proposalId, targets, values, calldatas, descriptionHash);
  156. }
  157. function _cancel(
  158. address[] memory targets,
  159. uint256[] memory values,
  160. bytes[] memory calldatas,
  161. bytes32 descriptionHash
  162. ) internal override(Governor, GovernorTimelockControl) returns (uint256) {
  163. return super._cancel(targets, values, calldatas, descriptionHash);
  164. }
  165. function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
  166. return super._executor();
  167. }
  168. function supportsInterface(bytes4 interfaceId)
  169. public
  170. view
  171. override(Governor, GovernorTimelockControl)
  172. returns (bool)
  173. {
  174. return super.supportsInterface(interfaceId);
  175. }
  176. }