-
Notifications
You must be signed in to change notification settings - Fork 76
/
token.sol
138 lines (104 loc) · 4.33 KB
/
token.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/// token.sol -- ERC20 implementation with minting and burning
// Copyright (C) 2015, 2016, 2017 DappHub, LLC
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.4.23 <0.7.0;
import "ds-math/math.sol";
import "ds-auth/auth.sol";
contract DSToken is DSMath, DSAuth {
bool public stopped;
uint256 public totalSupply;
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
string public symbol;
uint8 public decimals = 18; // standard token precision. override to customize
string public name = ""; // Optional token name
constructor(string memory symbol_) public {
symbol = symbol_;
}
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
event Mint(address indexed guy, uint wad);
event Burn(address indexed guy, uint wad);
event Stop();
event Start();
modifier stoppable {
require(!stopped, "ds-stop-is-stopped");
_;
}
function approve(address guy) external returns (bool) {
return approve(guy, uint(-1));
}
function approve(address guy, uint wad) public stoppable returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
function transfer(address dst, uint wad) external returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint wad)
public
stoppable
returns (bool)
{
if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
require(allowance[src][msg.sender] >= wad, "ds-token-insufficient-approval");
allowance[src][msg.sender] = sub(allowance[src][msg.sender], wad);
}
require(balanceOf[src] >= wad, "ds-token-insufficient-balance");
balanceOf[src] = sub(balanceOf[src], wad);
balanceOf[dst] = add(balanceOf[dst], wad);
emit Transfer(src, dst, wad);
return true;
}
function push(address dst, uint wad) external {
transferFrom(msg.sender, dst, wad);
}
function pull(address src, uint wad) external {
transferFrom(src, msg.sender, wad);
}
function move(address src, address dst, uint wad) external {
transferFrom(src, dst, wad);
}
function mint(uint wad) external {
mint(msg.sender, wad);
}
function burn(uint wad) external {
burn(msg.sender, wad);
}
function mint(address guy, uint wad) public auth stoppable {
balanceOf[guy] = add(balanceOf[guy], wad);
totalSupply = add(totalSupply, wad);
emit Mint(guy, wad);
}
function burn(address guy, uint wad) public auth stoppable {
if (guy != msg.sender && allowance[guy][msg.sender] != uint(-1)) {
require(allowance[guy][msg.sender] >= wad, "ds-token-insufficient-approval");
allowance[guy][msg.sender] = sub(allowance[guy][msg.sender], wad);
}
require(balanceOf[guy] >= wad, "ds-token-insufficient-balance");
balanceOf[guy] = sub(balanceOf[guy], wad);
totalSupply = sub(totalSupply, wad);
emit Burn(guy, wad);
}
function stop() public auth {
stopped = true;
emit Stop();
}
function start() public auth {
stopped = false;
emit Start();
}
function setName(string memory name_) public auth {
name = name_;
}
}