-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHuraToken.sol
62 lines (53 loc) · 1.77 KB
/
HuraToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract HuraToken is ERC20, Ownable {
uint256 public maxSupply;
address public moderator;
uint256 public moderatorMaxSupply;
uint256 public moderatorSupply;
constructor() ERC20("Hura Token", "HRA") {
moderator = msg.sender;
maxSupply = 9 * (10 ** 29); // 900B
moderatorMaxSupply = 50 * (10 ** 24); // 50M
moderatorSupply = 0;
_mint(msg.sender, 9 * (10 ** 27)); // 9B
}
function mint(address to, uint256 amount) external onlyModerator {
require(maxSupply >= totalSupply() + amount, "Exceed maxSupply");
require(
moderatorMaxSupply >= moderatorSupply + amount,
"Exceed moderatorMaxSupply"
);
_mint(to, amount);
moderatorSupply += amount;
}
function burn(address from, uint256 amount) external onlyModerator {
_burn(from, amount);
if (moderatorSupply < amount) {
moderatorSupply = 0;
} else {
moderatorSupply -= amount;
}
}
modifier onlyModerator() {
require(
msg.sender == moderator,
"Only the moderator can call this function"
);
_;
}
function changeModerator(address newModerator) external onlyOwner {
require(newModerator != address(0), "moderator cannot be zero address");
moderator = newModerator;
}
function changeModeratorMaxSupply(
uint256 newModeratorMaxSupply
) external onlyOwner {
moderatorMaxSupply = newModeratorMaxSupply;
}
function resetModeratorSupply() external onlyOwner {
moderatorSupply = 0;
}
}