GovernorBasicHarness.sol 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.2;
  3. import "../../contracts/governance/Governor.sol";
  4. import "../../contracts/governance/extensions/GovernorCountingSimple.sol";
  5. import "../../contracts/governance/extensions/GovernorVotes.sol";
  6. import "../../contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
  7. import "../../contracts/governance/extensions/GovernorTimelockCompound.sol";
  8. /*
  9. Wizard options:
  10. ERC20Votes
  11. TimelockCompound
  12. */
  13. contract GovernorBasicHarness is Governor, GovernorCountingSimple, GovernorVotes, GovernorVotesQuorumFraction, GovernorTimelockCompound {
  14. constructor(ERC20Votes _token, ICompoundTimelock _timelock, string memory name, uint256 quorumFraction)
  15. Governor(name)
  16. GovernorVotes(_token)
  17. GovernorVotesQuorumFraction(quorumFraction)
  18. GovernorTimelockCompound(_timelock)
  19. {}
  20. function isExecuted(uint256 proposalId) public view returns (bool) {
  21. return _proposals[proposalId].executed;
  22. }
  23. function isCanceled(uint256 proposalId) public view returns (bool) {
  24. return _proposals[proposalId].canceled;
  25. }
  26. uint256 _votingDelay;
  27. function votingDelay() public view override virtual returns (uint256) { // HARNESS: pure -> view
  28. return _votingDelay;
  29. }
  30. uint256 _votingPeriod;
  31. function votingPeriod() public view override virtual returns (uint256) { // HARNESS: pure -> view
  32. return _votingPeriod;
  33. }
  34. function snapshot(uint256 proposalId) public view returns (uint64) {
  35. return _proposals[proposalId].voteStart._deadline;
  36. }
  37. mapping(uint256 => uint256) public ghost_sum_vote_power_by_id;
  38. function _castVote(
  39. uint256 proposalId,
  40. address account,
  41. uint8 support,
  42. string memory reason
  43. ) internal override virtual returns (uint256) {
  44. uint256 deltaWeight = super._castVote(proposalId, account, support, reason); //HARNESS
  45. ghost_sum_vote_power_by_id[proposalId] += deltaWeight;
  46. return deltaWeight;
  47. }
  48. function callPropose(address[] memory targets,
  49. uint256[] memory values,
  50. bytes[] memory calldatas) public virtual returns (uint256) {
  51. return super.propose(targets, values, calldatas, "");
  52. }
  53. // Harness of castVoteWithReason to be able to impose requirement on the proposal ID.
  54. uint256 public _pId_Harness;
  55. function castVoteWithReason(uint256 proposalId, uint8 support, string calldata reason)
  56. public
  57. override(IGovernor, Governor)
  58. returns (uint256) {
  59. require(proposalId == _pId_Harness);
  60. return super.castVoteWithReason(proposalId, support, reason);
  61. }
  62. // The following functions are overrides required by Solidity.
  63. function quorum(uint256 blockNumber)
  64. public
  65. view
  66. override(IGovernor, GovernorVotesQuorumFraction)
  67. returns (uint256)
  68. {
  69. return super.quorum(blockNumber);
  70. }
  71. function getVotes(address account, uint256 blockNumber)
  72. public
  73. view
  74. override(IGovernor, GovernorVotes)
  75. returns (uint256)
  76. {
  77. return super.getVotes(account, blockNumber);
  78. }
  79. function state(uint256 proposalId)
  80. public
  81. view
  82. override(Governor, GovernorTimelockCompound)
  83. returns (ProposalState)
  84. {
  85. return super.state(proposalId);
  86. }
  87. function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
  88. public
  89. override(Governor, IGovernor)
  90. returns (uint256)
  91. {
  92. return super.propose(targets, values, calldatas, description);
  93. }
  94. function _execute(uint256 proposalId, address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
  95. internal
  96. override(Governor, GovernorTimelockCompound)
  97. {
  98. super._execute(proposalId, targets, values, calldatas, descriptionHash);
  99. }
  100. function _cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
  101. internal
  102. override(Governor, GovernorTimelockCompound)
  103. returns (uint256)
  104. {
  105. return super._cancel(targets, values, calldatas, descriptionHash);
  106. }
  107. function _executor()
  108. internal
  109. view
  110. override(Governor, GovernorTimelockCompound)
  111. returns (address)
  112. {
  113. return super._executor();
  114. }
  115. function supportsInterface(bytes4 interfaceId)
  116. public
  117. view
  118. override(Governor, GovernorTimelockCompound)
  119. returns (bool)
  120. {
  121. return super.supportsInterface(interfaceId);
  122. }
  123. }