-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1year.sol
325 lines (239 loc) · 9.25 KB
/
1year.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// ----------------------------------------------------------------------------
// 'ONEYEAR Token' contract
// Mineable ERC20 Token using Proof Of Work
//
// Symbol : ONEYEAR
// Name : ONEYEAR Token
// Total supply: 1000000
// Decimals : 0
//
// ----------------------------------------------------------------------------
pragma solidity ^0.5.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b > 0);
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
function ceil(uint256 a, uint256 m) internal pure returns (uint256) {
uint256 c = add(a,m);
uint256 d = sub(c,1);
return mul(div(d,m),m);
}
}
contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor(string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
function name() public view returns(string memory) {
return _name;
}
function symbol() public view returns(string memory) {
return _symbol;
}
function decimals() public view returns(uint8) {
return _decimals;
}
}
contract ONEYEAR is ERC20Detailed {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => uint256) private _blockStart;
mapping (address => mapping (address => uint256)) private _allowed;
string constant tokenName = "ONEYEAR";
string constant tokenSymbol = "ONEYEAR";
uint8 constant tokenDecimals = 0;
uint256 constant dayBlocks = 6000; // BLOCKS MINED PER DAY ON ETH BLOCKCHAIN
uint256 constant limitTime = 7;
uint256 _limitBlocks = dayBlocks*limitTime/100; // 1% BLOCKS PER LIMITTIME
uint256 _totalSupply = 1000000;
constructor() public payable ERC20Detailed(tokenName, tokenSymbol, tokenDecimals) {
_mint(msg.sender, _totalSupply);
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
function findOnePercent(uint256 value) public pure returns (uint256) {
uint256 roundValue = value.ceil(100);
uint256 onePercent = roundValue.mul(100).div(10000);
return onePercent;
}
function getBlocksDifference(address owner) public view returns (uint256) {
require(owner != address(0));
return block.number - _blockStart[owner];
}
function getLimitBlocksPercentual(address owner) public view returns (uint256) {
require(owner != address(0));
if (getBlocksDifference(owner)/_limitBlocks <= 0) {
return 1;
}
return getBlocksDifference(owner)/_limitBlocks;
}
function setNewStartBlock(address to, uint256 blockNumber, uint256 value) public view returns (uint256) {
require(value > 0);
require(to != address(0));
if(_blockStart[to] == 0) {
return blockNumber;
}
uint256 tempTokenAmount = getLimitBlocksPercentual(to)*_balances[to]/100 + value/100;
uint256 tempNewBlockStart = blockNumber - tempTokenAmount*_limitBlocks*100/(_balances[to]+value);
return tempNewBlockStart;
}
// ******************
// TRANSFER FUNCTIONS
// ******************
function transfer(address to, uint256 value) public returns (bool) {
require(value <= _balances[msg.sender]);
require(to != address(0));
uint256 tokensToBurn = 0;
uint256 tokensToTransfer = 0;
_balances[msg.sender] = _balances[msg.sender].sub(value);
if(_blockStart[msg.sender] == 0) { // OWNER ADDRESS SENDING TOKENS
tokensToBurn = findOnePercent(value);
tokensToTransfer = value.sub(tokensToBurn);
_blockStart[to] = block.number;
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokensToBurn);
} else {
tokensToBurn = findOnePercent(value)*getLimitBlocksPercentual(msg.sender);
tokensToTransfer = value.sub(tokensToBurn);
_blockStart[to] = setNewStartBlock (to, block.number, tokensToTransfer);
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokensToBurn);
}
emit Transfer(msg.sender, to, tokensToTransfer);
emit Transfer(msg.sender, address(0), tokensToBurn);
return true;
}
function transferFrom(address from, address to, uint256 value) public returns (bool) {
require(value <= _balances[from]);
require(value <= _allowed[from][msg.sender]);
require(to != address(0));
_balances[from] = _balances[from].sub(value);
uint256 tokensToBurn = 0;
uint256 tokensToTransfer = 0;
if(_blockStart[msg.sender] == 0) { // OWNER ADDRESS SENDING TOKENS
tokensToBurn = findOnePercent(value);
tokensToTransfer = value.sub(tokensToBurn);
_blockStart[to] = block.number;
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokensToBurn);
} else {
tokensToBurn = findOnePercent(value)*getLimitBlocksPercentual(msg.sender);
tokensToTransfer = value.sub(tokensToBurn);
_blockStart[to] = setNewStartBlock (to, block.number, tokensToTransfer);
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokensToBurn);
}
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
emit Transfer(from, to, tokensToTransfer);
emit Transfer(from, address(0), tokensToBurn);
return true;
}
function multiTransfer(address[] memory receivers, uint256[] memory amounts) public {
for (uint256 i = 0; i < receivers.length; i++) {
transfer(receivers[i], amounts[i]);
}
}
// ***************
// DEBUG FUNCTIONS
// ***************
function getStartBlock(address to) public view returns (uint256) {
return _blockStart[to];
}
function getLimitBlocks() public view returns (uint256) {
return _limitBlocks;
}
function getDayBlocks() public pure returns (uint256) {
return dayBlocks;
}
function getLimitTime() public pure returns (uint256) {
return limitTime;
}
// *******************+
// ALLOWANCE FUNCTIONS
// *******************
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = (_allowed[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = (_allowed[msg.sender][spender].sub(subtractedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
function approve(address spender, uint256 value) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// *************
// MINT FUNCTION
// *************
function _mint(address account, uint256 amount) internal {
require(amount != 0);
_balances[account] = _balances[account].add(amount);
_blockStart[account] = 0; // NO BLOCK NUMBER TO DISTRIBUTE FIRST TIME ONLY WITH 1% BURNING
emit Transfer(address(0), account, amount);
}
// **************
// BURN FUNCTIONS
// **************
function _burn(address account, uint256 amount) internal {
require(amount != 0);
require(amount <= _balances[account]);
_totalSupply = _totalSupply.sub(amount);
_balances[account] = _balances[account].sub(amount);
emit Transfer(account, address(0), amount);
}
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}
function burnFrom(address account, uint256 amount) external {
require(amount <= _allowed[account][msg.sender]);
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub(amount);
_burn(account, amount);
}
}