-
Notifications
You must be signed in to change notification settings - Fork 64
/
StableToken_v2.sol
70 lines (55 loc) · 1.66 KB
/
StableToken_v2.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
pragma solidity ^0.5.0;
import "zos-lib/contracts/Initializable.sol";
/**
* StableToken contract version v2
*/
contract StableToken is Initializable {
string public name;
string public symbol;
uint8 public decimals;
address public owner;
uint public totalSupply;
mapping(address => uint) public balances;
//Introduced in version v2
address public minter;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
modifier onlyMinter() {
require(msg.sender == minter);
_;
}
function initialize(
address _owner,
string memory _name,
string memory _symbol,
uint8 _decimals
)
public initializer
{
owner = _owner;
name = _name;
symbol = _symbol;
decimals = _decimals;
uint tokensToMint = 1000000 * (10 ** uint(decimals));
totalSupply += tokensToMint;
balances[owner] += tokensToMint;
}
//Fixed integer overflow issue in v2
function transfer(address _to, uint _amount) public returns (bool) {
require(balances[msg.sender] >= _amount);
balances[msg.sender] -= _amount;
balances[_to] += _amount;
emit Transfer(msg.sender, _to, _amount);
return true;
}
function initializeMinter(address _minter) public {
require(minter == address(0));
minter = _minter;
}
function mint(uint _newTokens) public onlyMinter {
uint tempTotalSupply = totalSupply + _newTokens;
require(tempTotalSupply >= totalSupply);
totalSupply += _newTokens;
balances[minter] += _newTokens;
}
//Rest of the code
}