-
Notifications
You must be signed in to change notification settings - Fork 45
Migrate ERC20 contracts to Open Zeppelin 5 #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,11 @@ | |
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >=0.8.19 <=0.8.27; | ||
|
|
||
| import {ERC20Permit, ERC20} from "openzeppelin-contracts-4/token/ERC20/extensions/ERC20Permit.sol"; | ||
| import {ERC20Burnable} from "openzeppelin-contracts-4/token/ERC20/extensions/ERC20Burnable.sol"; | ||
| import {ERC20Capped} from "openzeppelin-contracts-4/token/ERC20/extensions/ERC20Capped.sol"; | ||
| import {AccessControl, IAccessControl} from "openzeppelin-contracts-4/access/AccessControl.sol"; | ||
| import {MintingAccessControl} from "../../../access/MintingAccessControl.sol"; | ||
| import {ERC20Permit, ERC20} from "openzeppelin-contracts-5/token/ERC20/extensions/ERC20Permit.sol"; | ||
| import {ERC20Burnable} from "openzeppelin-contracts-5/token/ERC20/extensions/ERC20Burnable.sol"; | ||
| import {ERC20Capped} from "openzeppelin-contracts-5/token/ERC20/extensions/ERC20Capped.sol"; | ||
| import {AccessControl, IAccessControl} from "openzeppelin-contracts-5/access/AccessControl.sol"; | ||
| import {MintingAccessControl} from "../../utils/MintingAccessControl.sol"; | ||
| import {IImmutableERC20Errors} from "./IImmutableERC20Errors.sol"; | ||
|
|
||
| /** | ||
|
|
@@ -66,10 +66,8 @@ contract ImmutableERC20MinterBurnerPermit is ERC20Capped, ERC20Burnable, ERC20Pe | |
| super.renounceRole(role, account); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking doc nit from the OZ5 migration: the NatSpec for this |
||
| } | ||
|
|
||
| /** | ||
| * @dev Delegate to Open Zeppelin's ERC20Capped contract. | ||
| */ | ||
| function _mint(address account, uint256 amount) internal override(ERC20, ERC20Capped) { | ||
| ERC20Capped._mint(account, amount); | ||
| } | ||
| /// @inheritdoc ERC20 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: |
||
| function _update(address from, address to, uint256 value) internal virtual override (ERC20Capped, ERC20) { | ||
| ERC20Capped._update(from, to, value); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright Immutable Pty Ltd 2018 - 2026 | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
| pragma solidity >=0.8.19 <=0.8.27; | ||
|
|
||
| import {IAccessControlEnumerable} from "openzeppelin-contracts-4/access/IAccessControlEnumerable.sol"; | ||
|
|
||
| interface IMintingAccessControlOz4 is IAccessControlEnumerable { | ||
| /** | ||
| * @notice Role to mint tokens | ||
| */ | ||
| function MINTER_ROLE() external returns (bytes32); | ||
|
|
||
| /** | ||
| * @notice Allows admin grant `user` `MINTER` role | ||
| * @param user The address to grant the `MINTER` role to | ||
| */ | ||
| function grantMinterRole(address user) external; | ||
|
|
||
| /** | ||
| * @notice Allows admin to revoke `MINTER_ROLE` role from `user` | ||
| * @param user The address to revoke the `MINTER` role from | ||
| */ | ||
| function revokeMinterRole(address user) external; | ||
|
|
||
| /** | ||
| * @notice Returns the addresses which have DEFAULT_ADMIN_ROLE | ||
| */ | ||
| function getAdmins() external view returns (address[] memory); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright Immutable Pty Ltd 2018 - 2026 | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
| pragma solidity >=0.8.19 <=0.8.27; | ||
|
|
||
| import {AccessControlEnumerable} from "openzeppelin-contracts-4/access/AccessControlEnumerable.sol"; | ||
|
|
||
| abstract contract MintingAccessControlOz4 is AccessControlEnumerable { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
| /// @notice Role to mint tokens | ||
| // forge-lint: disable-next-line(unsafe-typecast) | ||
| bytes32 public constant MINTER_ROLE = bytes32("MINTER_ROLE"); | ||
|
|
||
| /** | ||
| * @notice Allows admin grant `user` `MINTER` role | ||
| * @param user The address to grant the `MINTER` role to | ||
| */ | ||
| function grantMinterRole(address user) public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
| grantRole(MINTER_ROLE, user); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Allows admin to revoke `MINTER_ROLE` role from `user` | ||
| * @param user The address to revoke the `MINTER` role from | ||
| */ | ||
| function revokeMinterRole(address user) public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
| revokeRole(MINTER_ROLE, user); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Returns the addresses which have DEFAULT_ADMIN_ROLE | ||
| */ | ||
| function getAdmins() public view returns (address[] memory) { | ||
| uint256 adminCount = getRoleMemberCount(DEFAULT_ADMIN_ROLE); | ||
| address[] memory admins = new address[](adminCount); | ||
| for (uint256 i; i < adminCount; i++) { | ||
| admins[i] = getRoleMember(DEFAULT_ADMIN_ROLE, i); | ||
| } | ||
| return admins; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that these presets are on OZ5: the audit / threat-model status table in
contracts/token/erc20/README.md(which references the earlier OZ4 commitsb7adf0d7/aa6c1d4) is stale for this contract. That README is not part of this PR -- consider updating it to record the OZ5 migration, or to note the migrated code is not yet audited against OZ5.