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

ERC 20 Fixed Supply No Burn Preset #188

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions contracts/token/erc20/ImmutableERC20.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// Copyright (c) Immutable Pty Ltd 2018 - 2024
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ImmutableERC20 is ERC20 {
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {}

/**
* @notice ERC 20 contract that wraps Open Zeppelin's ERC 20 contract.
*/
abstract contract ImmutableERC20 is ERC20 {
/**
* @dev Delegate to Open Zeppelin's contract.
* @param _name Name of the token.
* @param _symbol Token symbol.
*/
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {}
}
20 changes: 20 additions & 0 deletions contracts/token/erc20/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ERC 20 Tokens

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. |
| ImmutableERC20FixedSupplyNoBurn | ERC 20 contract with a fixed supply defined at deployment. |



# Status

Contract threat models and audits:

| Description | Date |Version Audited | Link to Report |
|---------------------------|------------------|-----------------|----------------|
| Not audited and no threat model | - | - | - |

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Immutable Pty Ltd 2018 - 2024
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";


/**
* @notice ERC 20 contract that mints a fixed total supply of tokens when the contract
* is deployed.
* @dev This contract has the concept of an owner, called _hubOwner in the constructor.
* This account has no rights to execute any administrative actions within the contract,
* with the exception of transferOwnership. 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 ImmutableERC20FixedSupplyNoBurn is Ownable, ERC20 {
error RenounceOwnershipNotAllowed();


/**
* @dev Mints `_totalSupply` number of token and transfers them to `_owner`.
*
* @param _name Name of the token.
* @param _symbol Token symbol.
* @param _totalSupply Supply of the token.
* @param _treasurer Initial owner of entire supply of all tokens.
* @param _hubOwner The account associated with Immutable Hub.
*/
constructor(string memory _name, string memory _symbol, uint256 _totalSupply, address _treasurer, address _hubOwner) ERC20(_name, _symbol) {
_mint(_treasurer, _totalSupply);
_transferOwnership(_hubOwner);
}

/**
* @notice Prevent calls to renounce ownership.
*/
function renounceOwnership() public pure override {
revert RenounceOwnershipNotAllowed();
}
}
2 changes: 2 additions & 0 deletions contracts/trading/seaport/zones/ImmutableSignedZone.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Immutable Pty Ltd 2018 - 2023
// SPDX-License-Identifier: Apache-2
// solhint-disable compiler-version
// slither-disable-start missing-inheritance
pragma solidity ^0.8.17;

import {ZoneParameters, Schema, ReceivedItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
Expand Down Expand Up @@ -513,3 +514,4 @@ contract ImmutableSignedZone is
return interfaceId == type(ZoneInterface).interfaceId || super.supportsInterface(interfaceId);
}
}
// slither-disable-end missing-inheritance
51 changes: 51 additions & 0 deletions test/token/erc20/preset/ImmutableERC20FixedSupplyNoBurn.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "forge-std/Test.sol";

import {ImmutableERC20FixedSupplyNoBurn} from "contracts/token/erc20/preset/ImmutableERC20FixedSupplyNoBurn.sol";


contract ImmutableERC20FixedSupplyNoBurnTest is Test {

ImmutableERC20FixedSupplyNoBurn public erc20;

address public treasurer;
address public hubOwner;
string name;
string symbol;
uint256 supply;

function setUp() public virtual {
hubOwner = makeAddr("hubOwner");
treasurer = makeAddr("treasurer");
name = "HappyToken";
symbol = "HPY";
supply = 1000000;

erc20 = new ImmutableERC20FixedSupplyNoBurn(name, symbol, supply, treasurer, hubOwner);
}

function testInit() public {
assertEq(erc20.name(), name, "name");
assertEq(erc20.symbol(), symbol, "symbol");
assertEq(erc20.totalSupply(), supply, "supply");
assertEq(erc20.balanceOf(treasurer), supply, "initial treasurer balance");
assertEq(erc20.balanceOf(hubOwner), 0, "initial hub owner balance");
assertEq(erc20.owner(), hubOwner, "Hub owner");
}

function testChangeOwner() public {
address newOwner = makeAddr("newOwner");
vm.prank(hubOwner);
erc20.transferOwnership(newOwner);
assertEq(erc20.owner(), newOwner, "new owner");
}

function testRenounceOwnerBlocked() public {
vm.prank(hubOwner);
vm.expectRevert(abi.encodeWithSelector(ImmutableERC20FixedSupplyNoBurn.RenounceOwnershipNotAllowed.selector));
erc20.renounceOwnership();
}

}
14 changes: 14 additions & 0 deletions test/token/erc20/preset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Test Plan for Immutable ERC20 Preset contracts

## ImmutableERC20FixedSupplyNoBurn.sol
This section defines tests for contracts/erc20/preset/ImmutableERC20FixedSupplyNoBurn.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/ImmutableERC20FixedSupplyNoBurn.t.sol.

| Test name |Description | Happy Case | Implemented |
|---------------------------------| --------------------------------------------------|------------|-------------|
| testInit | Check constructor. | Yes | Yes |
| testChangeOwner | Check change ownership. | Yes | Yes |
| testRenounceOwnershipBlocked | Ensure renounceOwnership reverts. | No | Yes |
Loading