Skip to content

Commit 8198205

Browse files
qiweiiifrangio
andauthored
Fix doc MyGovernor example doesn't compile (#4282)
Co-authored-by: Francisco Giordano <[email protected]>
1 parent a6e2671 commit 8198205

File tree

9 files changed

+196
-208
lines changed

9 files changed

+196
-208
lines changed

.github/workflows/checks.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ concurrency:
1212
group: checks-${{ github.ref }}
1313
cancel-in-progress: true
1414

15+
env:
16+
NODE_OPTIONS: --max_old_space_size=5120
17+
1518
jobs:
1619
lint:
1720
runs-on: ubuntu-latest
@@ -25,7 +28,6 @@ jobs:
2528
runs-on: ubuntu-latest
2629
env:
2730
FORCE_COLOR: 1
28-
NODE_OPTIONS: --max_old_space_size=4096
2931
GAS: true
3032
steps:
3133
- uses: actions/checkout@v3
@@ -56,8 +58,6 @@ jobs:
5658
run: bash scripts/upgradeable/transpile.sh
5759
- name: Run tests
5860
run: npm run test
59-
env:
60-
NODE_OPTIONS: --max_old_space_size=4096
6161
- name: Check linearisation of the inheritance graph
6262
run: npm run test:inheritance
6363
- name: Check storage layout
@@ -85,8 +85,6 @@ jobs:
8585
- name: Set up environment
8686
uses: ./.github/actions/setup
8787
- run: npm run coverage
88-
env:
89-
NODE_OPTIONS: --max_old_space_size=4096
9088
- uses: codecov/codecov-action@v3
9189
with:
9290
token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.2;
3+
4+
import "../../../governance/Governor.sol";
5+
import "../../../governance/compatibility/GovernorCompatibilityBravo.sol";
6+
import "../../../governance/extensions/GovernorVotes.sol";
7+
import "../../../governance/extensions/GovernorVotesQuorumFraction.sol";
8+
import "../../../governance/extensions/GovernorTimelockControl.sol";
9+
10+
contract MyGovernor is
11+
Governor,
12+
GovernorCompatibilityBravo,
13+
GovernorVotes,
14+
GovernorVotesQuorumFraction,
15+
GovernorTimelockControl
16+
{
17+
constructor(
18+
IVotes _token,
19+
TimelockController _timelock
20+
) Governor("MyGovernor") GovernorVotes(_token) GovernorVotesQuorumFraction(4) GovernorTimelockControl(_timelock) {}
21+
22+
function votingDelay() public pure override returns (uint256) {
23+
return 7200; // 1 day
24+
}
25+
26+
function votingPeriod() public pure override returns (uint256) {
27+
return 50400; // 1 week
28+
}
29+
30+
function proposalThreshold() public pure override returns (uint256) {
31+
return 0;
32+
}
33+
34+
// The functions below are overrides required by Solidity.
35+
36+
function state(
37+
uint256 proposalId
38+
) public view override(Governor, IGovernor, GovernorTimelockControl) returns (ProposalState) {
39+
return super.state(proposalId);
40+
}
41+
42+
function propose(
43+
address[] memory targets,
44+
uint256[] memory values,
45+
bytes[] memory calldatas,
46+
string memory description
47+
) public override(Governor, GovernorCompatibilityBravo, IGovernor) returns (uint256) {
48+
return super.propose(targets, values, calldatas, description);
49+
}
50+
51+
function cancel(
52+
address[] memory targets,
53+
uint256[] memory values,
54+
bytes[] memory calldatas,
55+
bytes32 descriptionHash
56+
) public override(Governor, GovernorCompatibilityBravo, IGovernor) returns (uint256) {
57+
return super.cancel(targets, values, calldatas, descriptionHash);
58+
}
59+
60+
function _execute(
61+
uint256 proposalId,
62+
address[] memory targets,
63+
uint256[] memory values,
64+
bytes[] memory calldatas,
65+
bytes32 descriptionHash
66+
) internal override(Governor, GovernorTimelockControl) {
67+
super._execute(proposalId, targets, values, calldatas, descriptionHash);
68+
}
69+
70+
function _cancel(
71+
address[] memory targets,
72+
uint256[] memory values,
73+
bytes[] memory calldatas,
74+
bytes32 descriptionHash
75+
) internal override(Governor, GovernorTimelockControl) returns (uint256) {
76+
return super._cancel(targets, values, calldatas, descriptionHash);
77+
}
78+
79+
function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
80+
return super._executor();
81+
}
82+
83+
function supportsInterface(
84+
bytes4 interfaceId
85+
) public view override(Governor, IERC165, GovernorTimelockControl) returns (bool) {
86+
return super.supportsInterface(interfaceId);
87+
}
88+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.2;
3+
4+
import "../../../token/ERC20/ERC20.sol";
5+
import "../../../token/ERC20/extensions/ERC20Permit.sol";
6+
import "../../../token/ERC20/extensions/ERC20Votes.sol";
7+
8+
contract MyToken is ERC20, ERC20Permit, ERC20Votes {
9+
constructor() ERC20("MyToken", "MTK") ERC20Permit("MyToken") {}
10+
11+
// The functions below are overrides required by Solidity.
12+
13+
function _afterTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Votes) {
14+
super._afterTokenTransfer(from, to, amount);
15+
}
16+
17+
function _mint(address to, uint256 amount) internal override(ERC20, ERC20Votes) {
18+
super._mint(to, amount);
19+
}
20+
21+
function _burn(address account, uint256 amount) internal override(ERC20, ERC20Votes) {
22+
super._burn(account, amount);
23+
}
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.2;
3+
4+
import "../../../token/ERC20/ERC20.sol";
5+
import "../../../token/ERC20/extensions/ERC20Permit.sol";
6+
import "../../../token/ERC20/extensions/ERC20Votes.sol";
7+
8+
contract MyTokenTimestampBased is ERC20, ERC20Permit, ERC20Votes {
9+
constructor() ERC20("MyTokenTimestampBased", "MTK") ERC20Permit("MyTokenTimestampBased") {}
10+
11+
// Overrides IERC6372 functions to make the token & governor timestamp-based
12+
13+
function clock() public view override returns (uint48) {
14+
return uint48(block.timestamp);
15+
}
16+
17+
// solhint-disable-next-line func-name-mixedcase
18+
function CLOCK_MODE() public pure override returns (string memory) {
19+
return "mode=timestamp";
20+
}
21+
22+
// The functions below are overrides required by Solidity.
23+
24+
function _afterTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Votes) {
25+
super._afterTokenTransfer(from, to, amount);
26+
}
27+
28+
function _mint(address to, uint256 amount) internal override(ERC20, ERC20Votes) {
29+
super._mint(to, amount);
30+
}
31+
32+
function _burn(address account, uint256 amount) internal override(ERC20, ERC20Votes) {
33+
super._burn(account, amount);
34+
}
35+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.2;
3+
4+
import "../../../token/ERC20/ERC20.sol";
5+
import "../../../token/ERC20/extensions/ERC20Permit.sol";
6+
import "../../../token/ERC20/extensions/ERC20Votes.sol";
7+
import "../../../token/ERC20/extensions/ERC20Wrapper.sol";
8+
9+
contract MyTokenWrapped is ERC20, ERC20Permit, ERC20Votes, ERC20Wrapper {
10+
constructor(
11+
IERC20 wrappedToken
12+
) ERC20("MyTokenWrapped", "MTK") ERC20Permit("MyTokenWrapped") ERC20Wrapper(wrappedToken) {}
13+
14+
// The functions below are overrides required by Solidity.
15+
16+
function decimals() public pure override(ERC20, ERC20Wrapper) returns (uint8) {
17+
return 18;
18+
}
19+
20+
function _afterTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Votes) {
21+
super._afterTokenTransfer(from, to, amount);
22+
}
23+
24+
function _mint(address to, uint256 amount) internal override(ERC20, ERC20Votes) {
25+
super._mint(to, amount);
26+
}
27+
28+
function _burn(address account, uint256 amount) internal override(ERC20, ERC20Votes) {
29+
super._burn(account, amount);
30+
}
31+
}

contracts/mocks/wizard/MyGovernor3.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "../../governance/extensions/GovernorVotes.sol";
77
import "../../governance/extensions/GovernorVotesQuorumFraction.sol";
88
import "../../governance/extensions/GovernorTimelockControl.sol";
99

10-
contract MyGovernor is
10+
contract MyGovernor3 is
1111
Governor,
1212
GovernorTimelockControl,
1313
GovernorCompatibilityBravo,

0 commit comments

Comments
 (0)