GovernorWithParamsMock.sol 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../governance/extensions/GovernorCountingSimple.sol";
  4. import "../governance/extensions/GovernorVotes.sol";
  5. contract GovernorWithParamsMock is GovernorVotes, GovernorCountingSimple {
  6. event CountParams(uint256 uintParam, string strParam);
  7. constructor(string memory name_, IVotes token_) Governor(name_) GovernorVotes(token_) {}
  8. function quorum(uint256) public pure override returns (uint256) {
  9. return 0;
  10. }
  11. function votingDelay() public pure override returns (uint256) {
  12. return 4;
  13. }
  14. function votingPeriod() public pure override returns (uint256) {
  15. return 16;
  16. }
  17. function _getVotes(
  18. address account,
  19. uint256 blockNumber,
  20. bytes memory params
  21. ) internal view override(Governor, GovernorVotes) returns (uint256) {
  22. uint256 reduction = 0;
  23. // If the user provides parameters, we reduce the voting weight by the amount of the integer param
  24. if (params.length > 0) {
  25. (reduction, ) = abi.decode(params, (uint256, string));
  26. }
  27. // reverts on overflow
  28. return super._getVotes(account, blockNumber, params) - reduction;
  29. }
  30. function _countVote(
  31. uint256 proposalId,
  32. address account,
  33. uint8 support,
  34. uint256 weight,
  35. bytes memory params
  36. ) internal override(Governor, GovernorCountingSimple) {
  37. if (params.length > 0) {
  38. (uint256 _uintParam, string memory _strParam) = abi.decode(params, (uint256, string));
  39. emit CountParams(_uintParam, _strParam);
  40. }
  41. return super._countVote(proposalId, account, support, weight, params);
  42. }
  43. function cancel(
  44. address[] memory targets,
  45. uint256[] memory values,
  46. bytes[] memory calldatas,
  47. bytes32 salt
  48. ) public returns (uint256 proposalId) {
  49. return _cancel(targets, values, calldatas, salt);
  50. }
  51. }