/
ERC20Token.sol
101 lines (83 loc) · 3.74 KB
/
ERC20Token.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
/*
* Copyright 2018 Eligma Ltd.
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.4.21;
import "./Interfaces/tokenRecipientInterface.sol";
import "./Interfaces/ERC20TokenInterface.sol";
import "./Utils/Owned.sol";
import "./Utils/SafeMath.sol";
import "./Utils/Lockable.sol";
contract ERC20Token is ERC20TokenInterface, SafeMath, Owned, Lockable {
string public standard;
string public name;
string public symbol;
uint8 public decimals;
address public mintingContractAddress;
uint256 supply = 0;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowances;
event Mint(address indexed _to, uint256 _value);
event Burn(address indexed _from, uint _value);
function totalSupply() constant public returns (uint256) {
return supply;
}
function balanceOf(address _owner) constant public returns (uint256 balance) {
return balances[_owner];
}
function transfer(address _to, uint256 _value) lockAffected public returns (bool success) {
require(_to != 0x0 && _to != address(this));
balances[msg.sender] = safeSub(balanceOf(msg.sender), _value);
balances[_to] = safeAdd(balanceOf(_to), _value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) lockAffected public returns (bool success) {
allowances[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) lockAffected public returns (bool success) {
tokenRecipientInterface spender = tokenRecipientInterface(_spender);
approve(_spender, _value);
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) lockAffected public returns (bool success) {
require(_to != 0x0 && _to != address(this));
balances[_from] = safeSub(balanceOf(_from), _value);
balances[_to] = safeAdd(balanceOf(_to), _value);
allowances[_from][msg.sender] = safeSub(allowances[_from][msg.sender], _value);
emit Transfer(_from, _to, _value);
return true;
}
function allowance(address _owner, address _spender) constant public returns (uint256 remaining) {
return allowances[_owner][_spender];
}
function mint(address _to, uint256 _amount) public {
require(msg.sender == mintingContractAddress);
supply = safeAdd(supply, _amount);
balances[_to] = safeAdd(balances[_to], _amount);
emit Mint(_to, _amount);
emit Transfer(0x0, _to, _amount);
}
function burn(uint _amount) public {
balances[msg.sender] = safeSub(balanceOf(msg.sender), _amount);
supply = safeSub(supply, _amount);
emit Burn(msg.sender, _amount);
emit Transfer(msg.sender, 0x0, _amount);
}
function salvageTokensFromContract(address _tokenAddress, address _to, uint _amount) onlyOwner public {
ERC20TokenInterface(_tokenAddress).transfer(_to, _amount);
}
function killContract() public onlyOwner {
selfdestruct(owner);
}
}