GovernorWithParamsMock.sol 1.6 KB

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