GovernorHarness.sol 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import "../../contracts/governance/Governor.sol";
  2. contract GovernorHarness is Governor {
  3. function isExecuted(uint256 proposalId) public view returns (bool) {
  4. return _proposals[proposalId].executed;
  5. }
  6. function isCanceled(uint256 proposalId) public view returns (bool) {
  7. return _proposals[proposalId].canceled;
  8. }
  9. mapping(uint256 => uint256) _quorum;
  10. function quorum(uint256 blockNumber) public view override virtual returns (uint256) {
  11. return _quorum[blockNumber];
  12. }
  13. mapping (address => mapping (uint256 => uint256)) _getVotes;
  14. function getVotes(address account, uint256 blockNumber) public view override virtual returns (uint256) {
  15. return _getVotes[account][blockNumber];
  16. }
  17. mapping (uint256 => bool) __quoromReached;
  18. function _quorumReached(uint256 proposalId) public view override virtual returns (bool) {
  19. return __quoromReached[proposalId];
  20. }
  21. mapping (uint256 => bool) __voteSucceeded;
  22. function _voteSucceeded(uint256 proposalId) public view override virtual returns (bool) {
  23. return __voteSucceeded[proposalId];
  24. }
  25. //string _COUNTING_MODE;
  26. function COUNTING_MODE() public pure override virtual returns (string memory) {
  27. return "dummy";
  28. }
  29. mapping(uint256 => mapping(address => bool)) _hasVoted;
  30. function hasVoted(uint256 proposalId, address account) public view override virtual returns (bool) {
  31. return _hasVoted[proposalId][account];
  32. }
  33. uint256 _votingDelay;
  34. function votingDelay() public view override virtual returns (uint256) {
  35. return _votingDelay;
  36. }
  37. uint256 _votingPeriod;
  38. function votingPeriod() public view override virtual returns (uint256) {
  39. return _votingPeriod;
  40. }
  41. constructor(string memory name) Governor(name) {}
  42. // _countVots == Sum of castVote
  43. //
  44. // RHS:
  45. // 1) use counter_vote_power as a counter
  46. // 2) use counter_vote_power as a temp var for a ghost
  47. //
  48. // LHS:
  49. // mapping of count
  50. // countMap
  51. mapping(uint256 => mapping(address => uint256)) counted_weight_by_id;
  52. function _countVote(
  53. uint256 proposalId,
  54. address account,
  55. uint8 support,
  56. uint256 weight
  57. ) internal override virtual {
  58. counted_weight_by_id[proposalId][account] += weight;
  59. }
  60. mapping(uint256 => uint256) counter_vote_power_by_id;
  61. function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) {
  62. address voter = _msgSender();
  63. // 1)
  64. counter_vote_power_by_id[proposalId] += _castVote(proposalId, voter, support, "");
  65. return _castVote(proposalId, voter, support, "");
  66. // 2)
  67. // counter_vote_power_by_id[proposalId] = _castVote(proposalId, voter, support, "");
  68. // return counter_vote_power;
  69. }
  70. function castVoteWithReason(
  71. uint256 proposalId,
  72. uint8 support,
  73. string calldata reason
  74. ) public virtual override returns (uint256) {
  75. address voter = _msgSender();
  76. counter_vote_power_by_id[proposalId] += _castVote(proposalId, voter, support, reason);
  77. return _castVote(proposalId, voter, support, reason);
  78. }
  79. function castVoteBySig(
  80. uint256 proposalId,
  81. uint8 support,
  82. uint8 v,
  83. bytes32 r,
  84. bytes32 s
  85. ) public virtual override returns (uint256) {
  86. address voter = ECDSA.recover(
  87. _hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support))),
  88. v,
  89. r,
  90. s
  91. );
  92. counter_vote_power_by_id[proposalId] += _castVote(proposalId, voter, support, "");
  93. return _castVote(proposalId, voter, support, "");
  94. }
  95. }