Skip to content

Commit fca2512

Browse files
committed
feat: make decimals configurable
1 parent 15b7a92 commit fca2512

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
A simple ERC20 token utilizing [OpenZeppelin libraries](https://github.com/OpenZeppelin/openzeppelin-contracts).
44

55
- [Burnable](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol)
6-
- [Ownable](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol), uncapped Minting
7-
- otherwise, [generic ERC20](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol) functionality
6+
- [Ownable Mint](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol), uncapped Minting
7+
- Configurable decimals
8+
- Otherwise, [generic ERC20](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol) functionality
89

910
## Usage
1011

src/SimpleERC20.sol

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
77

88
/// @notice A contract deployed to Host chain that allows tokens to enter the rollup.
99
contract SimpleERC20 is ERC20Burnable, Ownable {
10-
constructor(address initialOwner, string memory name, string memory symbol)
10+
uint8 public immutable _decimals;
11+
12+
constructor(address initialOwner, string memory name, string memory symbol, uint8 _dec)
1113
Ownable(initialOwner)
1214
ERC20(name, symbol)
13-
{}
15+
{
16+
_decimals = _dec;
17+
}
1418

1519
function mint(address to, uint256 amount) external onlyOwner returns (bool) {
1620
_mint(to, amount);
1721
return true;
1822
}
23+
24+
function decimals() public view override returns (uint8) {
25+
return _decimals;
26+
}
1927
}

test/SimpleERC20.t.sol

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ contract CounterTest is Test {
88
SimpleERC20 public test;
99

1010
function setUp() public {
11-
test = new SimpleERC20(address(this), "Test Token", "TEST");
11+
test = new SimpleERC20(address(this), "Test Token", "TEST", 8);
12+
}
13+
14+
function testMetadata() public view {
15+
assertEq(test.name(), "Test Token");
16+
assertEq(test.symbol(), "TEST");
17+
assertEq(test.decimals(), 8);
1218
}
1319

1420
function testMint() public {

0 commit comments

Comments
 (0)