GovernorHarness.sol 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/GovernorTimelockControl.sol";
  6. import "../munged/governance/extensions/GovernorVotes.sol";
  7. import "../munged/governance/extensions/GovernorVotesQuorumFraction.sol";
  8. import "../munged/token/ERC20/extensions/ERC20Votes.sol";
  9. contract GovernorHarness is
  10. Governor,
  11. GovernorCountingSimple,
  12. GovernorVotes,
  13. GovernorVotesQuorumFraction,
  14. GovernorTimelockControl
  15. {
  16. using SafeCast for uint256;
  17. using Timers for Timers.BlockNumber;
  18. constructor(
  19. IVotes _token,
  20. TimelockController _timelock,
  21. uint64 initialVoteExtension,
  22. uint256 quorumNumeratorValue
  23. )
  24. Governor("Harness")
  25. GovernorVotes(_token)
  26. GovernorVotesQuorumFraction(quorumNumeratorValue)
  27. GovernorTimelockControl(_timelock)
  28. {}
  29. mapping(uint256 => uint256) public ghost_sum_vote_power_by_id;
  30. // variable added to check when _castVote is called
  31. uint256 public latestCastVoteCall;
  32. // Harness from GovernorCountingSimple //
  33. function getAgainstVotes(uint256 proposalId) public view returns (uint256) {
  34. ProposalVote storage proposalvote = _proposalVotes[proposalId];
  35. return proposalvote.againstVotes;
  36. }
  37. function getAbstainVotes(uint256 proposalId) public view returns (uint256) {
  38. ProposalVote storage proposalvote = _proposalVotes[proposalId];
  39. return proposalvote.abstainVotes;
  40. }
  41. function getForVotes(uint256 proposalId) public view returns (uint256) {
  42. ProposalVote storage proposalvote = _proposalVotes[proposalId];
  43. return proposalvote.forVotes;
  44. }
  45. function quorumReached(uint256 proposalId) public view returns (bool) {
  46. return _quorumReached(proposalId);
  47. }
  48. function voteSucceeded(uint256 proposalId) public view returns (bool) {
  49. return _voteSucceeded(proposalId);
  50. }
  51. // Harness from Governor //
  52. function getExecutor() public view returns (address) {
  53. return _executor();
  54. }
  55. function isExecuted(uint256 proposalId) public view returns (bool) {
  56. return _proposals[proposalId].executed;
  57. }
  58. function isCanceled(uint256 proposalId) public view returns (bool) {
  59. return _proposals[proposalId].canceled;
  60. }
  61. // The following functions are overrides required by Solidity added by Certora. //
  62. function _castVote(
  63. uint256 proposalId,
  64. address account,
  65. uint8 support,
  66. string memory reason,
  67. bytes memory params
  68. ) internal virtual override returns (uint256) {
  69. // flag for when _castVote is called
  70. latestCastVoteCall = block.number;
  71. // added to run GovernorCountingSimple.spec
  72. uint256 deltaWeight = super._castVote(proposalId, account, support, reason, params);
  73. ghost_sum_vote_power_by_id[proposalId] += deltaWeight;
  74. return deltaWeight;
  75. }
  76. // The following functions are overrides required by Solidity added by OZ Wizard. //
  77. function votingDelay() public pure override returns (uint256) {
  78. return 1; // 1 block
  79. }
  80. function votingPeriod() public pure override returns (uint256) {
  81. return 45818; // 1 week
  82. }
  83. function quorum(uint256 blockNumber)
  84. public
  85. view
  86. override(IGovernor, GovernorVotesQuorumFraction)
  87. returns (uint256)
  88. {
  89. return super.quorum(blockNumber);
  90. }
  91. function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
  92. return super.state(proposalId);
  93. }
  94. function propose(
  95. address[] memory targets,
  96. uint256[] memory values,
  97. bytes[] memory calldatas,
  98. string memory description
  99. ) public override(Governor, IGovernor) returns (uint256) {
  100. return super.propose(targets, values, calldatas, description);
  101. }
  102. function _execute(
  103. uint256 proposalId,
  104. address[] memory targets,
  105. uint256[] memory values,
  106. bytes[] memory calldatas,
  107. bytes32 descriptionHash
  108. ) internal override(Governor, GovernorTimelockControl) {
  109. super._execute(proposalId, targets, values, calldatas, descriptionHash);
  110. }
  111. function _cancel(
  112. address[] memory targets,
  113. uint256[] memory values,
  114. bytes[] memory calldatas,
  115. bytes32 descriptionHash
  116. ) internal override(Governor, GovernorTimelockControl) returns (uint256) {
  117. return super._cancel(targets, values, calldatas, descriptionHash);
  118. }
  119. function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
  120. return super._executor();
  121. }
  122. function supportsInterface(bytes4 interfaceId)
  123. public
  124. view
  125. override(Governor, GovernorTimelockControl)
  126. returns (bool)
  127. {
  128. return super.supportsInterface(interfaceId);
  129. }
  130. }