Skip to content
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

Merged
merged 2 commits into from
Apr 16, 2024
Merged

[gms-1627] erc20 improvements #204

merged 2 commits into from
Apr 16, 2024

Conversation

jasonzwli
Copy link
Contributor

No description provided.

@jasonzwli jasonzwli requested a review from a team as a code owner April 15, 2024 02:40
@jasonzwli jasonzwli requested a review from drinkcoffee April 15, 2024 03:00
@@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImmutableERC20 should be ImmutableERC20MinterBurnerPermit

| 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. |
Copy link
Contributor

Choose a reason for hiding this comment

The 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 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 take care when signing messages. If they inadvertantly sign a malicious permit, then the attacker could use use it to gain access to the user's tokens. Read more on the EIP here: EIP-2612.


/**
* @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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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"

* @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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would order the parameters:
_roleAdmin
_minterAdmin
_hubOwner
_name
_symbol
_maxTokenSupply

That is, order all of the admin roles together and all of the token stuff together.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need tests for:
testRenounceLastHubOwnerBlocked

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
testPermit

* @param _maxTokenSupply The maximum supply of the token.

*/
constructor(address _roleAdmin, address _minterAdmin, address _hubOwner, string memory _name, string memory _symbol, uint256 _maxTokenSupply) ERC20(_name, _symbol) ERC20Permit(_name) ERC20Capped(_maxTokenSupply) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to keep these constructor parameters similar across ERC20 contracts. Leading with common parameters string memory _name, string memory _symbol, address _hubOwner and then parameters that differ per ERC20.

}

function testPermit() public {
uint256 ownerPrivateKey = 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makeAddrAndKey() is a nice way to get the address and privatekey in a single line.

(address alice, uint256 key) = makeAddrAndKey("alice");

* @dev Delegate to Open Zeppelin's ERC20Capped contract.
*/
function _mint(address account, uint256 amount) internal override(ERC20, ERC20Capped) {
ERC20Capped._mint(account, amount);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MinterBurnerPermit but it is also Capped.

@jasonzwli jasonzwli enabled auto-merge (squash) April 16, 2024 01:35
@jasonzwli jasonzwli merged commit aa6c1d4 into main Apr 16, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants