GovernorWithParamsMock.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {Governor} from "../../governance/Governor.sol";
  4. import {GovernorCountingSimple} from "../../governance/extensions/GovernorCountingSimple.sol";
  5. import {GovernorVotes} from "../../governance/extensions/GovernorVotes.sol";
  6. abstract contract GovernorWithParamsMock is GovernorVotes, GovernorCountingSimple {
  7. event CountParams(uint256 uintParam, string strParam);
  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. }