diff --git a/packages/core/solidity/CHANGELOG.md b/packages/core/solidity/CHANGELOG.md index 696074ed9..5534f0a6b 100644 --- a/packages/core/solidity/CHANGELOG.md +++ b/packages/core/solidity/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Add `account` contract types for ERC-4337. ([#486](https://github.com/OpenZeppelin/contracts-wizard/pull/486)) +- Remove redundant overrides in Governor. ([#522](https://github.com/OpenZeppelin/contracts-wizard/pull/522)) - **Potentially breaking changes**: - Update pragma versions to 0.8.27. ([#486](https://github.com/OpenZeppelin/contracts-wizard/pull/486)) diff --git a/packages/core/solidity/src/governor.test.ts.md b/packages/core/solidity/src/governor.test.ts.md index 71f02b7c5..d3f9d9ffa 100644 --- a/packages/core/solidity/src/governor.test.ts.md +++ b/packages/core/solidity/src/governor.test.ts.md @@ -27,6 +27,10 @@ Generated by [AVA](https://avajs.dev). GovernorVotesQuorumFraction(4)␊ GovernorTimelockControl(_timelock)␊ {}␊ + ␊ + function proposalThreshold() public pure override returns (uint256) {␊ + return 1e18;␊ + }␊ ␊ function votingDelay() public pure override returns (uint256) {␊ return 50400; // 1 week␊ @@ -35,21 +39,8 @@ Generated by [AVA](https://avajs.dev). function votingPeriod() public pure override returns (uint256) {␊ return 50400; // 1 week␊ }␊ - ␊ - function proposalThreshold() public pure override returns (uint256) {␊ - return 1e18;␊ - }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -136,15 +127,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -219,6 +201,10 @@ Generated by [AVA](https://avajs.dev). GovernorVotes(_token)␊ GovernorTimelockControl(_timelock)␊ {}␊ + ␊ + function proposalThreshold() public pure override returns (uint256) {␊ + return 1e6;␊ + }␊ ␊ function votingDelay() public pure override returns (uint256) {␊ return 50400; // 1 week␊ @@ -231,10 +217,6 @@ Generated by [AVA](https://avajs.dev). function quorum(uint256 blockNumber) public pure override returns (uint256) {␊ return 1e6;␊ }␊ - ␊ - function proposalThreshold() public pure override returns (uint256) {␊ - return 1e6;␊ - }␊ ␊ // The following functions are overrides required by Solidity.␊ ␊ @@ -311,6 +293,10 @@ Generated by [AVA](https://avajs.dev). GovernorVotes(_token)␊ GovernorTimelockControl(_timelock)␊ {}␊ + ␊ + function proposalThreshold() public pure override returns (uint256) {␊ + return 1;␊ + }␊ ␊ function votingDelay() public pure override returns (uint256) {␊ return 50400; // 1 week␊ @@ -323,10 +309,6 @@ Generated by [AVA](https://avajs.dev). function quorum(uint256 blockNumber) public pure override returns (uint256) {␊ return 1;␊ }␊ - ␊ - function proposalThreshold() public pure override returns (uint256) {␊ - return 1;␊ - }␊ ␊ // The following functions are overrides required by Solidity.␊ ␊ @@ -409,33 +391,6 @@ Generated by [AVA](https://avajs.dev). {}␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function votingDelay()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingDelay();␊ - }␊ - ␊ - function votingPeriod()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingPeriod();␊ - }␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -532,15 +487,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -635,15 +581,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -730,15 +667,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -813,6 +741,10 @@ Generated by [AVA](https://avajs.dev). GovernorVotes(_token)␊ GovernorTimelockControl(_timelock)␊ {}␊ + ␊ + function proposalThreshold() public pure override returns (uint256) {␊ + return 1;␊ + }␊ ␊ function votingDelay() public pure override returns (uint256) {␊ return 50400; // 1 week␊ @@ -825,10 +757,6 @@ Generated by [AVA](https://avajs.dev). function quorum(uint256 blockNumber) public pure override returns (uint256) {␊ return 5;␊ }␊ - ␊ - function proposalThreshold() public pure override returns (uint256) {␊ - return 1;␊ - }␊ ␊ // The following functions are overrides required by Solidity.␊ ␊ @@ -911,33 +839,6 @@ Generated by [AVA](https://avajs.dev). {}␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function votingDelay()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingDelay();␊ - }␊ - ␊ - function votingPeriod()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingPeriod();␊ - }␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1033,15 +934,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1132,15 +1024,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1227,15 +1110,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1322,15 +1196,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1411,33 +1276,6 @@ Generated by [AVA](https://avajs.dev). {}␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function votingDelay()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingDelay();␊ - }␊ - ␊ - function votingPeriod()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingPeriod();␊ - }␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1533,15 +1371,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1622,33 +1451,6 @@ Generated by [AVA](https://avajs.dev). {}␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function votingDelay()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingDelay();␊ - }␊ - ␊ - function votingPeriod()␊ - public␊ - view␊ - override(Governor, GovernorSettings)␊ - returns (uint256)␊ - {␊ - return super.votingPeriod();␊ - }␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1744,15 +1546,6 @@ Generated by [AVA](https://avajs.dev). }␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(Governor, GovernorVotesQuorumFraction)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ @@ -1858,15 +1651,6 @@ Generated by [AVA](https://avajs.dev). {}␊ ␊ // The following functions are overrides required by Solidity.␊ - ␊ - function quorum(uint256 blockNumber)␊ - public␊ - view␊ - override(GovernorUpgradeable, GovernorVotesQuorumFractionUpgradeable)␊ - returns (uint256)␊ - {␊ - return super.quorum(blockNumber);␊ - }␊ ␊ function state(uint256 proposalId)␊ public␊ diff --git a/packages/core/solidity/src/governor.test.ts.snap b/packages/core/solidity/src/governor.test.ts.snap index 57f78976a..1e58b118d 100644 Binary files a/packages/core/solidity/src/governor.test.ts.snap and b/packages/core/solidity/src/governor.test.ts.snap differ diff --git a/packages/core/solidity/src/governor.ts b/packages/core/solidity/src/governor.ts index 2ffaa90e1..a8d64f010 100644 --- a/packages/core/solidity/src/governor.ts +++ b/packages/core/solidity/src/governor.ts @@ -1,7 +1,7 @@ import { supportsInterface } from './common-functions'; import type { CommonOptions } from './common-options'; import { withCommonDefaults, defaults as commonDefaults } from './common-options'; -import type { Contract } from './contract'; +import type { Contract, ImportContract } from './contract'; import { ContractBuilder } from './contract'; import { OptionsError } from './error'; import { setAccessControl } from './set-access-control'; @@ -105,15 +105,13 @@ export function buildGovernor(opts: GovernorOptions): Contract { return c; } +const Governor: ImportContract = { + name: 'Governor', + path: '@openzeppelin/contracts/governance/Governor.sol', +}; + function addBase(c: ContractBuilder, { name }: GovernorOptions) { - const Governor = { - name: 'Governor', - path: '@openzeppelin/contracts/governance/Governor.sol', - }; c.addParent(Governor, [name]); - c.addOverride(Governor, functions.votingDelay); - c.addOverride(Governor, functions.votingPeriod); - c.addOverride(Governor, functions.quorum); c.addOverride(Governor, functions.state); c.addOverride(Governor, functions.propose); c.addOverride(Governor, functions.proposalNeedsQueuing); @@ -221,6 +219,7 @@ function setVotingParameters(c: ContractBuilder, opts: Required } else { c.setFunctionBody([`return ${delayBlocks.value}; // ${delayBlocks.note}`], functions.votingDelay); } + c.addOverride(Governor, functions.votingDelay); const periodBlocks = getVotingPeriod(opts); if ('lit' in periodBlocks) { @@ -228,6 +227,7 @@ function setVotingParameters(c: ContractBuilder, opts: Required } else { c.setFunctionBody([`return ${periodBlocks.value}; // ${periodBlocks.note}`], functions.votingPeriod); } + c.addOverride(Governor, functions.votingPeriod); } function setProposalThreshold(c: ContractBuilder, opts: Required) { @@ -308,6 +308,7 @@ function addQuorum(c: ContractBuilder, opts: Required) { : `return ${opts.quorumAbsolute}e${opts.decimals};`; c.setFunctionBody([returnStatement], functions.quorum, 'pure'); + c.addOverride(Governor, functions.quorum); } }