-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElonDoge.sol
164 lines (125 loc) · 4.82 KB
/
ElonDoge.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
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import './IERC20.sol';
import "./Ownable.sol";
import "./Pausable.sol";
contract ElonDoge is IERC20, Ownable, Pausable {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping (address => uint256) internal _balances;
mapping (address => mapping (address => uint256)) internal _allowed;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor (
string memory _name,
string memory _symbol,
uint8 _decimals,
uint256 _totalSupply
) {
symbol = _symbol;
name = _name;
decimals = _decimals;
totalSupply = _totalSupply;
_balances[msg.sender] = _totalSupply;
}
function transfer(
address _to,
uint256 _value
) external override whenNotPaused returns (bool) {
require(_to != address(0), 'ERC20: to address is not valid');
require(_value <= _balances[msg.sender], 'ERC20: insufficient balance');
_balances[msg.sender] = _balances[msg.sender] - _value;
_balances[_to] = _balances[_to] + _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(
address _owner
) external override view returns (uint256 balance) {
return _balances[_owner];
}
function approve(
address _spender,
uint256 _value
) external override whenNotPaused returns (bool) {
_allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(
address _from,
address _to,
uint256 _value
) external override whenNotPaused returns (bool) {
require(_from != address(0), 'ERC20: from address is not valid');
require(_to != address(0), 'ERC20: to address is not valid');
require(_value <= _balances[_from], 'ERC20: insufficient balance');
require(_value <= _allowed[_from][msg.sender], 'ERC20: transfer from value not allowed');
_allowed[_from][msg.sender] = _allowed[_from][msg.sender] - _value;
_balances[_from] = _balances[_from] - _value;
_balances[_to] = _balances[_to] + _value;
emit Transfer(_from, _to, _value);
return true;
}
function allowance(
address _owner,
address _spender
) external override view whenNotPaused returns (uint256) {
return _allowed[_owner][_spender];
}
function increaseApproval(
address _spender,
uint256 _addedValue
) external whenNotPaused returns (bool) {
_allowed[msg.sender][_spender] = _allowed[msg.sender][_spender] + _addedValue;
emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(
address _spender,
uint256 _subtractedValue
) external whenNotPaused returns (bool) {
uint256 oldValue = _allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
_allowed[msg.sender][_spender] = 0;
} else {
_allowed[msg.sender][_spender] = oldValue - _subtractedValue;
}
emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]);
return true;
}
function mintTo(
address _to,
uint256 _amount
) external whenNotPaused onlyOwner returns (bool) {
require(_to != address(0), 'ERC20: to address is not valid');
_balances[_to] = _balances[_to] + _amount;
totalSupply = totalSupply + _amount;
emit Transfer(address(0), _to, _amount);
return true;
}
function burn(
uint256 _amount
) external whenNotPaused returns (bool) {
require(_balances[msg.sender] >= _amount, 'ERC20: insufficient balance');
_balances[msg.sender] = _balances[msg.sender] - _amount;
totalSupply = totalSupply - _amount;
emit Transfer(msg.sender, address(0), _amount);
return true;
}
function burnFrom(
address _from,
uint256 _amount
) external whenNotPaused returns (bool) {
require(_from != address(0), 'ERC20: from address is not valid');
require(_balances[_from] >= _amount, 'ERC20: insufficient balance');
require(_amount <= _allowed[_from][msg.sender], 'ERC20: burn from value not allowed');
_allowed[_from][msg.sender] = _allowed[_from][msg.sender] - _amount;
_balances[_from] = _balances[_from] - _amount;
totalSupply = totalSupply - _amount;
emit Transfer(_from, address(0), _amount);
return true;
}
}