-
Notifications
You must be signed in to change notification settings - Fork 36
/
bradesco_token_aberto.sol
243 lines (205 loc) · 7.34 KB
/
bradesco_token_aberto.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
SPDX-License-Identifier: CC-BY-4.0
(c) Desenvolvido por Jeff Prestes
This work is licensed under a Creative Commons Attribution 4.0 International License.
*/
pragma solidity 0.8.19;
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
/// @title Manages the contract owner
contract Owned {
address payable contractOwner;
modifier onlyOwner() {
require(msg.sender == contractOwner, "only owner can perform this operation");
_;
}
constructor() {
contractOwner = payable(msg.sender);
}
function whoIsTheOwner() public view returns(address) {
return contractOwner;
}
function changeOwner(address _newOwner) onlyOwner public returns (bool) {
require(_newOwner != address(0x0), "only valid address");
contractOwner = payable(_newOwner);
return true;
}
}
/// @title ERC-20 Token template
contract ExercicioToken is IERC20Metadata, Owned {
string private myName;
string private mySymbol;
uint256 private myTotalSupply;
uint8 private myDecimals;
mapping (address=>uint256) balances;
mapping (address=>mapping (address=>uint256)) ownerAllowances;
modifier hasEnoughBalance(address owner, uint amount) {
uint balance;
balance = balances[owner];
require (balance >= amount);
_;
}
modifier isAllowed(address spender, address tokenOwner, uint amount) {
require (amount <= ownerAllowances[tokenOwner][spender]);
_;
}
modifier tokenAmountValid(uint256 amount) {
require(amount > 0);
require(amount <= myTotalSupply);
_;
}
constructor() {
myName = "Exercicio Token";
mySymbol = "EXCT";
myDecimals = 2;
mint(msg.sender, (1000000000 * (10 ** myDecimals)));
}
function name() public view returns(string memory) {
return myName;
}
function symbol() public view returns(string memory) {
return mySymbol;
}
function totalSupply() public override view returns(uint256) {
return myTotalSupply;
}
function decimals() public override view returns (uint8) {
return myDecimals;
}
function balanceOf(address tokenOwner) public override view returns(uint256) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public override view returns(uint256) {
return ownerAllowances[tokenOwner][spender];
}
function transfer(address to, uint256 amount)
public
override
hasEnoughBalance(msg.sender, amount)
tokenAmountValid(amount)
returns (bool)
{
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint limit) public override returns(bool) {
require(spender != address(0), "ERC20: approve to the zero address");
ownerAllowances[msg.sender][spender] = limit;
emit Approval(msg.sender, spender, limit);
return true;
}
function transferFrom(address from, address to, uint256 amount) public override
hasEnoughBalance(from, amount) isAllowed(msg.sender, from, amount) tokenAmountValid(amount)
returns(bool) {
balances[from] = balances[from] - amount;
balances[to] += amount;
ownerAllowances[from][msg.sender] = amount;
emit Transfer(from, to, amount);
return true;
}
function mint(address account, uint256 amount) public returns (bool) {
require(account != address(0), "ERC20: mint to the zero address");
myTotalSupply = myTotalSupply + amount;
balances[account] = balances[account] + amount;
emit Transfer(address(0), account, amount);
return true;
}
function burn(address account, uint256 amount) public returns (bool) {
require(account != address(0), "ERC20: burn from address");
require(msg.sender == account || msg.sender == contractOwner, "you are not allowed to burn");
balances[account] = balances[account] - amount;
myTotalSupply = myTotalSupply - amount;
emit Transfer(account, address(0), amount);
return true;
}
}