GovernorHarness.sol 4.9 KB

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