/
HackerFederationHE3ERC20.sol
119 lines (106 loc) · 3.94 KB
/
HackerFederationHE3ERC20.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.6;
import "https://github.com/qq79324055/openzeppelin-contracts/blob/release-v3.0.0/contracts/token/ERC20/ERC20.sol";
contract HE3 is ERC20 {
// Current supply
uint256 public _currentSupply;
// Manager
address public _owner;
// Burn address
address public _burnAddress;
// Fee address
address public _feeAddress;
// Initial Address
address public _initialAddress;
// Initial amount
uint256 public _initialToken;
/**
* Constuctor func.
*
* Requirements:
*
* - `initialSupply`: total amount
* - `name`: token name
* - `symbol`: token symbol
*/
constructor(
uint256 initialSupply,
string memory name,
string memory symbol,
address initialAddress,
uint256 initialToken,
address feeAddress,
address burnAddress
) ERC20(name, symbol) public {
_owner = msg.sender;
_initialAddress = initialAddress;
_initialToken = initialToken;
_feeAddress = feeAddress;
_burnAddress = burnAddress;
_totalSupply = _totalSupply.add(initialSupply * 10 ** uint256(decimals()));
_balances[_initialAddress] = _balances[_initialAddress].add(_initialToken * 10 ** uint256(decimals()));
_currentSupply = _currentSupply.add(_initialToken * 10 ** uint256(decimals()));
emit Transfer(address(0), _initialAddress, _initialToken * 10 ** uint256(decimals()));
}
modifier onlyOwner() {
require(msg.sender == _owner, "This function is restricted to the owner");
_;
}
modifier notAddress0(address newAddress) {
require(newAddress != address(0), "Address should not be address(0)");
_;
}
// Update owner
function updateOwnerAddress(address newOwnerAddress) public onlyOwner notAddress0(newOwnerAddress) {
_owner = newOwnerAddress;
}
// Update burn address
function updateBurnAddress(address newBurnAddress) public onlyOwner notAddress0(newBurnAddress) {
_burnAddress = newBurnAddress;
}
// Update fee address
function updateFeeAddress(address newFeeAddress) public onlyOwner notAddress0(newFeeAddress) {
_feeAddress = newFeeAddress;
}
/**
* Mint token, only owner have permission
*
* Requirements:
*
* `userAddress`: to account address
* - `userToken`: reward amount
* - `feeToken`: fee amount
*/
function mint(address userAddress, uint256 userToken, uint256 feeToken) public onlyOwner{
require(userAddress != address(0), "ERC20: mint to the zero address");
uint256 mintTotal = userToken.add(feeToken);
_currentSupply = _currentSupply.add(mintTotal);
require(_currentSupply <= _totalSupply, "TotalMintBalance should be less than or equal totalSupply");
_balances[_feeAddress] = _balances[_feeAddress].add(feeToken);
emit Transfer(address(0), _feeAddress, feeToken);
// mint to user
_balances[userAddress] = _balances[userAddress].add(userToken);
emit Transfer(address(0), userAddress, userToken);
}
/**
* Only owner can burn token
*
* Requirements:
*
* - `_amount`: burn amount
*/
function burnFromOwner(uint256 amount) public onlyOwner {
_totalSupply = _totalSupply.sub(amount);
_balances[_burnAddress] = _balances[_burnAddress].add(amount);
emit Transfer(address(0), _burnAddress, amount);
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
if (recipient == _burnAddress) {
_totalSupply = _totalSupply.sub(amount);
_currentSupply = _currentSupply.sub(amount);
}
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
}