Skip to content

Commit d1b3cf9

Browse files
authored
add erc20 with configurable decimals (#113)
1 parent 5816389 commit d1b3cf9

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/tradable/ElvToken.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
88
import "./cmn/Roles.sol";
99

1010
contract ElvToken is ERC20, ERC20Burnable, Pausable, AccessControlEnumerable {
11-
constructor(string memory name, string memory symbol, uint256 amount) ERC20(name, symbol) {
11+
12+
uint8 private tokenDecimal;
13+
constructor(string memory name, string memory symbol, uint8 decimal, uint256 amount) ERC20(name, symbol) {
1214
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
1315
_grantRole(ElvCmnRoles.PAUSER_ROLE, msg.sender);
16+
tokenDecimal = decimal;
1417
_mint(msg.sender, amount * 10 ** decimals());
1518
_grantRole(ElvCmnRoles.MINTER_ROLE, msg.sender);
1619
}
1720

21+
function decimals() public view virtual override returns (uint8) {
22+
return tokenDecimal;
23+
}
24+
1825
function pause() public onlyRole(ElvCmnRoles.PAUSER_ROLE) {
1926
_pause();
2027
}

test/elvToken/ElvToken.t.sol

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import {console} from "forge-std/console.sol";
5+
import {Test} from "forge-std/Test.sol";
6+
import "src/tradable/ElvToken.sol";
7+
8+
9+
contract ERC20PaymentsTest is Test {
10+
ElvToken internal token;
11+
address public deployer;
12+
13+
function setUp() public virtual {
14+
vm.prank(msg.sender, msg.sender);
15+
deployer = msg.sender;
16+
token = new ElvToken("ElvToken","ELV",6,20000);
17+
}
18+
19+
function testDecimals() public{
20+
assertEq(token.decimals(), 6);
21+
}
22+
23+
function testTokenMinted() public {
24+
assertEq(token.balanceOf(deployer), 20000 * 10 ** token.decimals());
25+
}
26+
}

test/payments/ERC20Payments.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract ERC20PaymentsTest is Test {
2929
carol = users[2];
3030
vm.label(carol, "Carol");
3131

32-
token = new ElvToken("ElvToken","ELV",20000000);
32+
token = new ElvToken("ElvToken","ELV",18, 20000000);
3333
erc20Payments = new ERC20Payments();
3434
}
3535

0 commit comments

Comments
 (0)