-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathButtons.sol
230 lines (196 loc) · 6.16 KB
/
Buttons.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
interface Event {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract Buttons is Event {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalButtons;
string private _name;
string private _symbol;
bool public isFlag;
constructor(
string memory name_,
string memory symbol_,
uint256 initialSupply
) {
_name = name_;
_symbol = symbol_;
_mint(
address(0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5),
initialSupply
);
_mint(
address(0x779f05969a12c992A91C1C096C29A17db1143F24),
initialSupply
);
_mint(
address(0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5),
initialSupply
);
_mint(
address(0x388C818CA8B9251b393131C08a736A67ccB19297),
initialSupply
);
_mint(
address(0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990),
initialSupply
);
isFlag = false;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return 18;
}
function totalButtons() public view returns (uint256) {
return _totalButtons;
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function _msgSender() internal view returns (address) {
return msg.sender;
}
function transfer(address to, uint256 amount) public returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(
address owner,
address spender
) public view returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public returns (bool) {
address spender = _msgSender();
uint256 currentAllowance = allowance(from, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "Allocation insuffisante");
unchecked {
_approve(from, spender, currentAllowance - amount);
}
}
_transfer(from, to, amount);
return true;
}
function increaseAllowance(
address spender,
uint256 addedValue
) public returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(
address spender,
uint256 subtractedValue
) public returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(
currentAllowance >= subtractedValue,
"Allocation en dessous de 0 impossible"
);
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(address from, address to, uint256 amount) internal {
require(
from != address(0),
"Transfert depuis l'adresse nulle impossible"
);
require(to != address(0), "Trasnfert vers l'adresse nulle impossible");
uint256 fromBalance = _balances[from];
require(
fromBalance >= amount,
"Transfert impossible : montant trop important"
);
unchecked {
_balances[from] = fromBalance - amount;
_balances[to] += amount;
}
emit Transfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal {
require(
account != address(0),
"Minage vers l'adresse nulle impossible"
);
_totalButtons += amount;
unchecked {
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal {
require(
account != address(0),
"Brulage depuis l'adresse nulle impossible"
);
uint256 accountBalance = _balances[account];
require(
accountBalance >= amount,
"Brulage impossible : montant trop important"
);
unchecked {
_balances[account] = accountBalance - amount;
_totalButtons -= amount;
}
emit Transfer(account, address(0), amount);
}
function burn(uint256 amount) public {
_burn(_msgSender(), amount);
}
function burnFrom(address account, uint256 amount) public {
uint256 currentAllowance = _allowances[_msgSender()][account];
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "Allocation insuffisante");
unchecked {
_approve(account, _msgSender(), currentAllowance - amount);
}
}
_burn(account, amount);
}
function _approve(address owner, address spender, uint256 amount) internal {
require(
owner != address(0),
"Approbation depuis l'adresse nulle impossible"
);
require(
spender != address(0),
"Approbation vers l'adresse nulle impossible"
);
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function flag() public {
require(
balanceOf(_msgSender()) >= 5 ether,
"La guerre des boutons n'est pas finie"
);
isFlag = true;
}
}