GovernorHarness.sol 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. function initialized(uint256 proposalId) public view returns (bool){
  10. if (_proposals[proposalId].voteStart._deadline != 0 && _proposals[proposalId].voteEnd._deadline != 0) {
  11. return true;
  12. }
  13. return false;
  14. }
  15. mapping(uint256 => uint256) _quorum;
  16. function quorum(uint256 blockNumber) public view override virtual returns (uint256) {
  17. return _quorum[blockNumber];
  18. }
  19. mapping (address => mapping (uint256 => uint256)) _getVotes;
  20. function getVotes(address account, uint256 blockNumber) public view override virtual returns (uint256) {
  21. return _getVotes[account][blockNumber];
  22. }
  23. mapping (uint256 => bool) __quoromReached;
  24. function _quorumReached(uint256 proposalId) public view override virtual returns (bool) {
  25. return __quoromReached[proposalId];
  26. }
  27. mapping (uint256 => bool) __voteSucceeded;
  28. function _voteSucceeded(uint256 proposalId) public view override virtual returns (bool) {
  29. return __voteSucceeded[proposalId];
  30. }
  31. //string _COUNTING_MODE;
  32. function COUNTING_MODE() public pure override virtual returns (string memory) {
  33. return "dummy";
  34. }
  35. mapping(uint256 => mapping(address => bool)) _hasVoted;
  36. function hasVoted(uint256 proposalId, address account) public view override virtual returns (bool) {
  37. return _hasVoted[proposalId][account];
  38. }
  39. uint256 _votingDelay;
  40. function votingDelay() public view override virtual returns (uint256) {
  41. return _votingDelay;
  42. }
  43. uint256 _votingPeriod;
  44. function votingPeriod() public view override virtual returns (uint256) {
  45. return _votingPeriod;
  46. }
  47. constructor(string memory name) Governor(name) {}
  48. // _countVots == Sum of castVote
  49. //
  50. // RHS:
  51. // 1) use counter_vote_power as a counter
  52. // 2) use counter_vote_power as a temp var for a ghost
  53. //
  54. // LHS:
  55. // mapping of count
  56. // countMap
  57. mapping(uint256 => uint256) counted_weight;
  58. // uint decision;
  59. // uint numberOfOptions;
  60. function _countVote(
  61. uint256 proposalId,
  62. address account,
  63. uint8 support,
  64. uint256 weight
  65. ) internal override virtual {
  66. counted_weight[proposalId] += weight;
  67. }
  68. mapping(uint256 => uint256) public counter_vote_power_by_id;
  69. mapping(uint256 => uint256) public ghost_vote_power_by_id;
  70. function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) {
  71. address voter = _msgSender();
  72. // 2)
  73. ghost_vote_power_by_id[proposalId] = _castVote(proposalId, voter, support, "");
  74. // 1)
  75. counter_vote_power_by_id[proposalId] += ghost_vote_power_by_id[proposalId];
  76. // return _castVote(proposalId, voter, support, "");
  77. return ghost_vote_power_by_id[proposalId];
  78. }
  79. function castVoteWithReason(
  80. uint256 proposalId,
  81. uint8 support,
  82. string calldata reason
  83. ) public virtual override returns (uint256) {
  84. address voter = _msgSender();
  85. // 2)
  86. ghost_vote_power_by_id[proposalId] = _castVote(proposalId, voter, support, reason);
  87. // 1)
  88. counter_vote_power_by_id[proposalId] += ghost_vote_power_by_id[proposalId];
  89. return ghost_vote_power_by_id[proposalId];
  90. }
  91. function castVoteBySig(
  92. uint256 proposalId,
  93. uint8 support,
  94. uint8 v,
  95. bytes32 r,
  96. bytes32 s
  97. ) public virtual override returns (uint256) {
  98. address voter = ECDSA.recover(
  99. _hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support))),
  100. v,
  101. r,
  102. s
  103. );
  104. // 2)
  105. ghost_vote_power_by_id[proposalId] = _castVote(proposalId, voter, support, "");
  106. // 1)
  107. counter_vote_power_by_id[proposalId] += ghost_vote_power_by_id[proposalId];
  108. return ghost_vote_power_by_id[proposalId];
  109. }
  110. }