-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWBCHToken.sol
190 lines (140 loc) · 4.94 KB
/
WBCHToken.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
pragma solidity ^0.4.24;
contract MathLib
{
function add(uint256 x, uint256 y) pure internal returns (uint256 z)
{
assert((z = x + y) >= x);
}
function sub(uint256 x, uint256 y) pure internal returns (uint256 z)
{
assert((z = x - y) <= x);
}
function mul(uint256 x, uint256 y) pure internal returns (uint256 z)
{
assert((z = x * y) >= x);
}
function div(uint256 x, uint256 y) pure internal returns (uint256 z)
{
z = x / y;
}
function min(uint256 x, uint256 y) pure internal returns (uint256 z)
{
return x <= y ? x : y;
}
function max(uint256 x, uint256 y) pure internal returns (uint256 z)
{
return x >= y ? x : y;
}
}
contract ERC20
{
function totalSupply() public constant returns (uint supply);
function balanceOf(address who) public constant returns (uint value);
function allowance(address owner, address spender) public constant returns (uint _allowance);
function transfer(address to, uint value) public returns (bool ok);
function transferFrom(address from, address to, uint value) public returns (bool ok);
function approve(address spender, uint value) public returns (bool ok);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
contract TokenBase is ERC20, MathLib
{
uint256 _supply;
mapping (address => uint256) _balances;
mapping (address => mapping (address => uint256)) _approvals;
constructor(uint256 supply) public
{
_balances[msg.sender] = supply;
_supply = supply;
}
function totalSupply() public constant returns (uint256)
{
return _supply;
}
function balanceOf(address src) public constant returns (uint256)
{
return _balances[src];
}
function allowance(address src, address guy) public constant returns (uint256)
{
return _approvals[src][guy];
}
function transfer(address dst, uint wad) public returns (bool)
{
assert(_balances[msg.sender] >= wad);
_balances[msg.sender] = sub(_balances[msg.sender], wad);
_balances[dst] = add(_balances[dst], wad);
emit Transfer(msg.sender, dst, wad);
return true;
}
function transferFrom(address src, address dst, uint wad) public returns (bool)
{
assert(_balances[src] >= wad);
assert(_approvals[src][msg.sender] >= wad);
_approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
_balances[src] = sub(_balances[src], wad);
_balances[dst] = add(_balances[dst], wad);
emit Transfer(src, dst, wad);
return true;
}
function approve(address guy, uint256 wad) public returns (bool)
{
_approvals[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
}
interface GatewayVote
{
function burnForGateway(address from, string receiver, uint64 wad) external;
}
contract WBCHToken is TokenBase(0)
{
uint8 public decimals = 8;
address private Gateway;
string public name = "Wrapped BCH (BCH-MALLOW-ETH for standard)";
string public symbol = "WBCH";
event Mint(address receiver, uint64 wad);
event Burn(address from, string receiver, uint64 wad);
event GatewayChangedTo(address newer);
constructor(address gateway) public
{
Gateway = gateway;
emit GatewayChangedTo(Gateway);
}
function transfer(address dst, uint wad) public returns (bool)
{
return super.transfer(dst, wad);
}
function transferFrom(address src, address dst, uint wad) public returns (bool)
{
return super.transferFrom(src, dst, wad);
}
function approve(address guy, uint wad) public returns (bool)
{
return super.approve(guy, wad);
}
function mint(address receiver, uint64 wad) external returns (bool)
{
require(msg.sender == Gateway);
_balances[receiver] = add(_balances[receiver], wad);
_supply = add(_supply, wad);
emit Mint(receiver, wad);
return true;
}
function changeGatewayAddr(address newer) external returns (bool)
{
require(msg.sender == Gateway);
Gateway = newer;
emit GatewayChangedTo(Gateway);
return true;
}
function burn(uint64 wad, string receiver) external
{
assert(_balances[msg.sender] >= wad);
_balances[msg.sender] = sub(_balances[msg.sender], wad);
_supply = sub(_supply, wad);
emit Burn(msg.sender, receiver, wad);
GatewayVote(Gateway).burnForGateway(msg.sender, receiver, wad);
}
}