This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoonVestToken.sol
458 lines (412 loc) · 14.6 KB
/
MoonVestToken.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the BEP20 standard
*/
interface BEP20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract MoonVestToken is BEP20 {
/// @dev Token Details
string public constant name = "MoonVest.Network";
string public constant symbol = "MVN";
uint8 public constant decimals = 12;
mapping(address => uint256) private balances;
mapping(address => mapping(address => uint256)) private allowances;
uint256 private baseSupply = 1e24;
uint256 private _totalSupply = 1e24;
/// @dev Divisors/Multiplier used to calculate burn and fees
uint32 private baseBurnDivisor = 30;
uint32 private hodlerFeeDivisor = 50;
uint32 private externalFeeDivisor = 1000;
uint8 private whaleBurnMultiplier = 50;
/// @dev Admin and address where fees are sent
address private admin;
address private feeAddress;
mapping(address => bool) private excludedSenders;
mapping(address => bool) private excludedReceivers;
/// @dev freeTransfer() enabled
bool private allowFreeTransfer = false;
constructor() {
admin = msg.sender;
feeAddress = msg.sender;
balances[msg.sender] = _totalSupply;
excludedSenders[msg.sender] = true;
excludedReceivers[msg.sender] = true;
}
/**
* @dev Throws if called by any account other than the admin
*/
modifier onlyAdmin() {
require(msg.sender == admin, "MoonVestToken: caller is not Admin");
_;
}
/**
* @return Balance of given @param account
*/
function totalSupply() external view override returns (uint256) {
return _totalSupply;
}
/**
* @return Balance of given @param account
*/
function balanceOf(address account)
external
view
override
returns (uint256)
{
return (balances[account] * _totalSupply) / baseSupply;
}
/**
* @return Allowance given to @param spender by @param owner
*/
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return allowances[owner][spender];
}
/**
* @notice Approves @param spender to spend up to @param amount on behalf of caller
*/
function approve(address spender, uint256 amount)
external
override
returns (bool)
{
_approve(msg.sender, spender, amount);
return true;
}
/**
* @notice Increases the spending allowance granted to @param spender for caller by @param addedValue
*/
function increaseAllowance(address spender, uint256 addedValue)
external
returns (bool)
{
_approve(
msg.sender,
spender,
allowances[msg.sender][spender] + addedValue
);
return true;
}
/**
* @notice Decreases the spending allowance granted to @param spender for caller by @param subtractedValue
*/
function decreaseAllowance(address spender, uint256 subtractedValue)
external
returns (bool)
{
uint256 currentAllowance = allowances[msg.sender][spender];
_approve(msg.sender, spender, currentAllowance - subtractedValue);
return true;
}
/**
* @param _baseBurnDivisor divisor to calculate base burn rate. amount / divisor = baseBurnRate
*/
function setBaseBurnDivisor(uint8 _baseBurnDivisor) external onlyAdmin {
require(
_baseBurnDivisor > 19,
"MoonVestToken::setBaseBurnDivisor: baseBurnDivisor must be greater than 19"
); // 1/20 = 5% max base burn
baseBurnDivisor = _baseBurnDivisor;
}
/**
* @param _hodlerFeeDivisor divisor to calculate fees to Hodlers. amount / divisor = fees
*/
function setHodlerFeeDivisor(uint8 _hodlerFeeDivisor) external onlyAdmin {
require(
_hodlerFeeDivisor > 19,
"MoonVestToken::setFeeDivisor: hodlerFeeDivisor must be greater than 19"
); // 1/20 = 5% Max Fee
hodlerFeeDivisor = _hodlerFeeDivisor;
}
/**
* @param _externalFeeDivisor divisor to calculate fees to Hodlers. amount / divisor = fees
*/
function setExternalFeeDivisor(uint8 _externalFeeDivisor)
external
onlyAdmin
{
require(
_externalFeeDivisor > 19,
"MoonVestToken::setFeeDivisor: externalFeeDivisor must be greater than 19"
); // 1/20 = 5% Max Fee
externalFeeDivisor = _externalFeeDivisor;
}
/**
* @param _whaleBurnMultiplier Multiplier to calculate amount burned for large transfers
*/
function setWhaleBurnMultiplier(uint8 _whaleBurnMultiplier)
external
onlyAdmin
{
require(
_whaleBurnMultiplier < 30,
"MoonVestToken::setWhaleBurnMultiplier: _whaleBurnMultiplier must be less than 30"
);
whaleBurnMultiplier = _whaleBurnMultiplier;
}
/**
* @param _feeAddress address to collect fees
*/
function setFeeAddress(address _feeAddress) external onlyAdmin {
feeAddress = _feeAddress;
}
/**
* @param _senderToAdd address to exclude from paying fees when sending
*/
function addExcludedSender(address _senderToAdd) external onlyAdmin {
excludedSenders[_senderToAdd] = true;
}
/**
* @param _senderToRemove address to remove from fee exception when sending
*/
function removeExcludedSender(address _senderToRemove) external onlyAdmin {
excludedSenders[_senderToRemove] = false;
}
/**
* @param _receiverToAdd address to exclude from paying fees when receiving
*/
function addExcludedReceiver(address _receiverToAdd) external onlyAdmin {
excludedReceivers[_receiverToAdd] = true;
}
/**
* @param _receiverToRemove address to remove from fee exception when receiving
*/
function removeExcludedReceiver(address _receiverToRemove)
external
onlyAdmin
{
excludedReceivers[_receiverToRemove] = false;
}
/**
* @return bool wether @param sender is excluded from fees
*/
function isExcludedSender(address sender) external view returns (bool) {
return excludedSenders[sender];
}
/**
* @return bool wether @param receiver is excluded from fees
*/
function isExcludedReceiver(address receiver) external view returns (bool) {
return excludedReceivers[receiver];
}
/**
* @param _allowFreeTransfer Whether free transfers should be allowed to public
*/
function setAllowFreeTransfer(bool _allowFreeTransfer) external onlyAdmin {
allowFreeTransfer = _allowFreeTransfer;
}
/**
* @param _newAdmin address to become new Admin.
*/
function setAdmin(address _newAdmin) external onlyAdmin {
admin = _newAdmin;
}
/**
* @notice Transfer tokens
* @param recipient Address to recieve transferred tokens
* @param amount Amount to be sent. A portion of this will be burned and collected as fees
*/
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
// Bypass fees if sender or reciever is excluded
if (excludedSenders[msg.sender] || excludedReceivers[recipient]) {
_transfer(msg.sender, recipient, amount);
} else {
_transferWithFees(msg.sender, recipient, amount);
}
return true;
}
/**
* @notice Transfer tokens from approved allowance
* @param sender address sending tokens.
* @param recipient address to recieve transferred tokens.
* @param amount Amount to be sent. A portion of this will be burned.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_approve(sender, msg.sender, allowances[sender][msg.sender] - amount);
// Bypass fees if sender or reciever is excluded
if (
excludedSenders[sender] ||
excludedSenders[msg.sender] ||
excludedReceivers[recipient]
) {
_transfer(sender, recipient, amount);
} else {
_transferWithFees(sender, recipient, amount);
}
return true;
}
/**
* @notice Transfer without burn/fees. This is not the standard BEP20 transfer.
* @param recipient address to recieve transferred tokens.
* @param amount Amount to be sent.
*/
function freeTransfer(address recipient, uint256 amount) external {
require(
allowFreeTransfer,
"MoonVestToken::freeTransfer: freeTransfer is currently turned off"
);
_transfer(msg.sender, recipient, amount);
}
/**
* @notice Transfer without burn from approved allowance. This is not the standard BEP20 transferFrom.
* @param sender address sending tokens.
* @param recipient address to recieve transferred tokens.
* @param amount Amount to be sent.
*/
function freeTransferFrom(
address sender,
address recipient,
uint256 amount
) external {
require(
allowFreeTransfer,
"MoonVestToken::freeTransferFrom: freeTrasnfer is currently turned off"
);
_approve(sender, msg.sender, allowances[sender][msg.sender] - amount);
_transfer(sender, recipient, amount);
}
/**
* @notice Transfers tokens to multiple addresses.
* @param addresses Addresses to send tokens to.
* @param amounts Amounts of tokens to send.
*/
function multiTransfer(
address[] calldata addresses,
uint256[] calldata amounts
) external {
require(
allowFreeTransfer,
"MoonVestToken::freeTransferFrom: freeTrasnfer is currently turned off"
);
require(
addresses.length == amounts.length,
"MoonVestToken::multiTransfer: addresses and amounts count do not match"
);
for (uint256 i = 0; i < amounts.length; i++) {
_transfer(msg.sender, addresses[i], amounts[i]);
}
}
/**
* @notice Destroys @param amount tokens and reduces total supply.
*/
function burn(uint256 amount) external {
uint256 baseAccountBalance = balances[msg.sender];
require(
(baseAccountBalance * _totalSupply) / baseSupply >= amount,
"MoonVestToken::burn: burn amount exceeds balance"
);
uint256 baseAmount = (amount * baseSupply) / _totalSupply;
balances[msg.sender] = baseAccountBalance - baseAmount;
_totalSupply -= amount;
baseSupply -= baseAmount;
_removeDust(msg.sender);
emit Transfer(msg.sender, address(0), amount);
}
/**
* @notice Transfer with all fees and burn applied
* @param sender address sending tokens.
* @param recipient address to recieve transferred tokens.
* @param amount Amount to be sent. Fees and burn deducted from this amount
*/
function _transferWithFees(
address sender,
address recipient,
uint256 amount
) private {
// Calculate burn and fee amount
uint256 burnAmount =(amount / baseBurnDivisor) + ((amount**2 / _totalSupply) * whaleBurnMultiplier);
if (burnAmount > amount / 10) {
burnAmount = amount / 10;
}
uint256 externalFeeAmount = amount / externalFeeDivisor;
uint256 hodlerFeeAmount = amount / hodlerFeeDivisor;
uint256 recipientAmount = amount - burnAmount - externalFeeAmount - hodlerFeeAmount;
// Burn/transfer tokens
balances[sender] -= (amount * baseSupply) / _totalSupply;
balances[feeAddress] += (externalFeeAmount * baseSupply) / _totalSupply;
balances[recipient] += (recipientAmount * baseSupply) / _totalSupply;
baseSupply -= ((hodlerFeeAmount + burnAmount) * baseSupply) / _totalSupply;
_totalSupply -= burnAmount;
_removeDust(sender);
emit Transfer(sender, address(0), burnAmount);
emit Transfer(sender, feeAddress, externalFeeAmount);
emit Transfer(sender, recipient, recipientAmount);
}
/**
* @dev Moves @param amount tokens from @param sender to @param recipient
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) private {
require(
recipient != address(0),
"MoonVestToken::_transfer: transfer to the zero address"
);
uint256 baseSenderBalance = balances[sender];
require(
(baseSenderBalance * _totalSupply) / baseSupply >= amount,
"MoonVestToken::_transfer: transfer amount exceeds balance"
);
uint256 baseAmount = (amount * baseSupply) / _totalSupply;
balances[sender] = baseSenderBalance - baseAmount;
balances[recipient] += baseAmount;
_removeDust(sender);
emit Transfer(sender, recipient, amount);
}
/**
* @dev Approves spending to @param spender of up to @param amount tokens from @param owner
*/
function _approve(
address owner,
address spender,
uint256 amount
) private {
allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @notice Remove extremely small balances likely caused by integer division
*/
function _removeDust(address account) private {
if (balances[account] < 5) {
balances[account] = 0;
}
}
}