-
Notifications
You must be signed in to change notification settings - Fork 38
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
[gms-1627] erc20 improvements #204
Changes from 1 commit
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,7 +2,7 @@ | |
// SPDX-License-Identifier: Apache 2.0 | ||
pragma solidity 0.8.19; | ||
|
||
import {AccessControlEnumerable} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; | ||
import {AccessControlEnumerable, AccessControl, IAccessControl} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; | ||
Check warning on line 5 in contracts/access/MintingAccessControl.sol GitHub Actions / Run solhint
|
||
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. If importing AccessControl and IAccessControl is important, please add a Solhint exclusion to remove the warning messages |
||
|
||
abstract contract MintingAccessControl is AccessControlEnumerable { | ||
/// @notice Role to mint tokens | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ | |
This directory contains ERC 20 token contracts that game studios could choose to use | ||
directly or extend. | ||
|
||
| Contract | Description | | ||
|---------------------------------|-----------------------------------------------| | ||
| ImmutableERC20 | Provides basic ERC 20 capability. Designed to be extended. | | ||
| Contract | Description | | ||
|--------------------------------------- |-----------------------------------------------| | ||
| preset/ImmutableERC20MinterBurnerPermit| Provides basic ERC 20 Permit, Capped token supply and burn capability. Designed to be extended. | | ||
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. Is this still correct, "Designed to be extended" ? Do we envisage game studios will deploy this as is? |
||
| preset/ImmutableERC20FixedSupplyNoBurn | ERC 20 contract with a fixed supply defined at deployment. | | ||
|
||
## ImmutableERC20MinterBurnerPermit | ||
|
||
This contract contains Permit methods, allowing the token owner to give a third party operator a `Permit` which is a signed message that can be used by the third party to give approval to themselves to operate on the tokens owned by the original owner. Users of permit should take care of the signed messages, as anyone who has access to this signed message can use it to gain access to the tokens. Read more on the EIP here: [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612). | ||
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. Permit is more complex (and safer) than what is described here. 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. How about: This contract contains Permit methods, allowing the token owner to give a third party operator a |
||
# Status | ||
|
||
Contract threat models and audits: | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Immutable Pty Ltd 2018 - 2024 | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
import {ERC20Permit, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; | ||
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | ||
import {ERC20Capped} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol"; | ||
import {MintingAccessControl, AccessControl, IAccessControl} from "../../../access/MintingAccessControl.sol"; | ||
import {IImmutableERC20Errors} from "./Errors.sol"; | ||
|
||
/** | ||
* @notice ERC 20 contract that wraps Open Zeppelin's ERC 20 contract. | ||
* This contract has the concept of an owner, called _owner in the constructor. | ||
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. This needs to be updated. The contract no longer has the concept of an "owner" |
||
* This account has no rights to execute any administrative actions within the contract, | ||
* with the exception of transferOwnership and role grants/revokes. This account is accessed via the owner() | ||
* function. The Immutable Hub uses this function to help associate the ERC 20 contract | ||
* with a specific Immutable Hub account. | ||
*/ | ||
contract ImmutableERC20MinterBurnerPermit is ERC20Capped, ERC20Burnable, ERC20Permit, MintingAccessControl { | ||
/// @notice Role to mint tokens | ||
bytes32 public constant HUB_OWNER_ROLE = bytes32("HUB_OWNER_ROLE"); | ||
|
||
/** | ||
* @dev Delegate to Open Zeppelin's contract. | ||
* @param _name Name of the token. | ||
* @param _symbol Token symbol. | ||
* @param _hubOwner The account that owns the contract and is associated with Immutable Hub. | ||
* @param minterRole The account that has the MINTER_ROLE. | ||
* @param _maxTokenSupply The maximum supply of the token. | ||
* @param _admin The account that has the DEFAULT_ADMIN_ROLE. | ||
*/ | ||
constructor(string memory _name, string memory _symbol, address _hubOwner, address minterRole, uint256 _maxTokenSupply, address _admin) ERC20(_name, _symbol) ERC20Permit(_name) ERC20Capped(_maxTokenSupply) { | ||
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. I would order the parameters: That is, order all of the admin roles together and all of the token stuff together. |
||
_grantRole(DEFAULT_ADMIN_ROLE, _admin); | ||
_grantRole(HUB_OWNER_ROLE, _hubOwner); | ||
_grantRole(MINTER_ROLE, minterRole); | ||
} | ||
|
||
|
||
/** | ||
* @dev Mints `amount` number of token and transfers them to the `to` address. | ||
* @param to the address to mint the tokens to. | ||
* @param amount The amount of tokens to mint. | ||
*/ | ||
function mint(address to, uint256 amount) external onlyRole(MINTER_ROLE) { | ||
_mint(to, amount); | ||
} | ||
|
||
|
||
/** | ||
* @dev Renounces the role `role` from the calling account. Prevents the last hub owner and admin from | ||
* renouncing their role. | ||
* @param role The role to renounce. | ||
* @param account The account to renounce the role from. | ||
*/ | ||
function renounceRole(bytes32 role, address account) public override(AccessControl, IAccessControl) { | ||
if (getRoleMemberCount(role) == 1 && (role == HUB_OWNER_ROLE || role == DEFAULT_ADMIN_ROLE)) { | ||
revert IImmutableERC20Errors.RenounceOwnershipNotAllowed(); | ||
} | ||
super.renounceRole(role, account); | ||
} | ||
|
||
|
||
/** | ||
* @dev Delegate to Open Zeppelin's ERC20Capped contract. | ||
*/ | ||
function _mint(address account, uint256 amount) internal override(ERC20, ERC20Capped) { | ||
ERC20Capped._mint(account, amount); | ||
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. MinterBurnerPermit but it is also Capped. |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,12 @@ All of the tests defined in the table below are in test/erc20/preset/ImmutableER | |
| testRenounceOwnershipBlocked | Ensure renounceOwnership reverts. | No | Yes | | ||
|
||
|
||
## ImmutableERC20.sol | ||
This section defines tests for contracts/erc20/preset/ImmutableERC20.sol. Note | ||
## ImmutableERC20MinterBurnerPermit.sol | ||
This section defines tests for contracts/erc20/preset/ImmutableERC20MinterBurnerPermit.sol. Note | ||
that this contract extends Open Zeppelin's ERC 20 contract which is extensively tested here: | ||
https://github.com/OpenZeppelin/openzeppelin-contracts/tree/release-v4.9/test/token/ERC20 . | ||
|
||
All of the tests defined in the table below are in test/erc20/preset/ImmutableERC20.t.sol. | ||
All of the tests defined in the table below are in test/erc20/preset/ImmutableERC20MinterBurnerPermit.t.sol. | ||
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. also need tests for: I would also have one test for each piece of OZ functionality you have brought in. This is just to make sure that the capability is there (the file was included correctly) and it at a high level works. testBurn |
||
|
||
| Test name |Description | Happy Case | Implemented | | ||
|---------------------------------| --------------------------------------------------|------------|-------------| | ||
|
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.
ImmutableERC20 should be ImmutableERC20MinterBurnerPermit