-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRewardsController.sol
More file actions
736 lines (678 loc) · 30.1 KB
/
Copy pathRewardsController.sol
File metadata and controls
736 lines (678 loc) · 30.1 KB
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
//*~~~> SPDX-License-Identifier: MIT make it better, stronger, faster
/*~~~>
Thank you Phunks for your inspiration and phriendship.
Never stop phighting, never surrender, always stand up for what is right and make the best of all situations towards all people.
Phunks are phreedom phighters!
"When the power of love overcomes the love of power the world will know peace." - Jimi Hendrix <3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(((((((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(((((((((((((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((((((((((((((((((((((@@@@@##############################%%%%%@@@@@((((((((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((((((((((((((((((((((@@@@@##############################%%%%%@@@@@((((((((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((@@@@@########################################%%%%%@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((@@@@@########################################%%%%%@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###############@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###############@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@##########@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((@@PhunkyJON was here programming trustless unstoppable contracts@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@/////////////////////////////////////////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@/////////////////////////////////////////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@#PHUNKYJON///////////////#PHUNKYJON//////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@#PHUNKYJON///////////////#PHUNKYJON//////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@/////@EYES////////////////////@EYES///////////////@@@@@((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@/////@EYES////////////////////@EYES///////////////EAR@@((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@//////////////////////////////////////////////////EAR@@((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@//////////////////////////////////////////////////EAR@@((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@/////////////////////////////////////////////@@@@@@@@@@((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@/////////////////////////////////////////////@@@@@@@@@@((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@//////////NOSE@NOSE@////////////////////#####@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((SMOKE((((((((((@@@@@//////////NOSE@NOSE@////////////////////#####@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((@@@@@#####//////////////////////////////##########@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((@@@@@#####//////////////////////////////##########@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((@SPLIFF@SPLIFF@SPLIFF@SPLIFF@@###################################@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((@SPLIFF@SPLIFF@SPLIFF@SPLIFF@@###################################@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((EMBER(((((,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@MOUTH&&&&&####################@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((EMBER(((((,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@MOUTH&&&&&####################@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((@SPLIFF@SPLIFF@SPLIFF@SPLIFF@@##############################/////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((@SPLIFF@SPLIFF@SPLIFF@SPLIFF@@##############################/////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((((((((((((((((((((((@@@@@##############################//////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%(((((((((((((((((((((((((((((((((((@@@@@##############################//////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@///////////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((@@@@@@@@@@@@@@@@@@@@@@@@@///////////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((@@@@@///////////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((@@@@@///////////////@@@@@(((((((((((((((((((((((((%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@///////////////@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@///////////////@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<~~~*/
pragma solidity 0.8.7;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "./interfaces/IRoleProvider.sol";
import "./interfaces/IEscrow.sol";
contract RewardsControl is ReentrancyGuard {
address public roleAdd;
//*~~~> Platform fee
uint public fee;
//*~~~> upgradable proxy contract addresses
bytes32 public constant DAO = keccak256("DAO");
bytes32 public constant NFTADD = keccak256("NFT");
bytes32 public constant MINT = keccak256("MINT");
/*~~~> Open storage indexes <~~~*/
uint[] private openStorage;
/*~~~> I envisioned, designed and initally created these contracts <~~~*/
address private JON = 0x39a79815fA7431434E49757ED4118b873Ca1F580;
/*~~~>
Thank you WhaleGoddess!!!
None of this would have been possible without your patience, love and support!
You helped me completely revise and rewrite these complex contracts into this present state,
but what I hold most importantly is that you took the time to hear me and debate ideas,
to scrutinize the things out of order and be patient with me!
Not many were able to help and I was completely alone for months,
but your cheerful assistance and enthusiastic nature shines brightly of what a true friend
and compassionate human is.
<~~~*/
address private WHALE = 0x41538872240Ef02D6eD9aC45cf4Ff864349D51ED;
uint private devCount;
uint private userCount;
uint private nftHodlerCount;
uint private tokenCount;
mapping(uint256 => User) private idToUser; //Internal index => User
mapping(uint256 => NftHodler) private nftIdToHodler; // Tracking NFT ids => Hodler placement, to limit claims
mapping(address => User) private addressToUser;
mapping(address => uint256) private addressToId; //For user Id
mapping(address => uint256) private addressToTokenId; // For token Id
mapping(address => uint256) public addressToRewardsId;
mapping(uint256 => RewardsToken) public idToRewardsToken;
mapping(uint256 => DevTeam) private idToDevTeam;
mapping(address => uint256) private addressToDevTeamId;
mapping(uint256 => ClaimClock) private idToClock;
//*~~~> set initial ERC20 to avoid accessing an out-of-bounds or negative index
constructor(address newRole, address getPhunky) {
roleAdd = newRole;
addressToTokenId[getPhunky]=1;
fee = 200;
}
//*~~~> Declaring object structures for Split Rewards & Tokens <~~~*/
struct User {
bool canClaim;
uint claims;
uint timestamp;
uint userId;
address userAddress;
}
struct NftHodler {
uint timestamp;
uint hodlerId;
uint tokenId;
}
struct DevTeam {
uint timestamp;
uint devId;
address devAddress;
}
struct RewardsToken {
uint tokenId;
uint tokenAmount;
address tokenAddress;
}
struct ClaimClock {
uint alpha; // initial claim cutoff
uint delta; // mid claim cutoff
uint omega; // final claim cutoff
uint howManyUsers; // total user count set with each distribution call
}
/*~~~>
Roles for designated accessibility
<~~~*/
bytes32 public constant PROXY_ROLE = keccak256("PROXY_ROLE");
bytes32 public constant DEV = keccak256("DEV");
modifier hasAdmin(){
require(IRoleProvider(roleAdd).hasTheRole(PROXY_ROLE, msg.sender), "DOES NOT HAVE ADMIN ROLE");
_;
}
modifier hasDevAdmin(){
require(IRoleProvider(roleAdd).hasTheRole(DEV, msg.sender), "DOES NOT HAVE DEV ROLE");
_;
}
modifier hasContractAdmin(){
require(IRoleProvider(roleAdd).hasContractRole(msg.sender), "DOES NOT HAVE CONTRACT ROLE");
_;
}
// Admin only functions to set proxy addresses
function setRoleAddress(address newRole) external hasAdmin returns(bool){
roleAdd = newRole;
return true;
}
//*~~~> Declaring event structures
event NewUser(uint indexed userId, address indexed userAddress);
event RewardsClaimed(address indexed userAddress, uint amount, uint[] erc20Amount, address[] contractAddress);
event NewDev(address indexed devAddress);
event RemovedDev(address indexed devAddress);
event DevClaimed(address indexed devAddress, uint amount, uint[] erc20Amount, address[] contractAddress);
event DaoClaimed(address indexed daoAddress, uint amount, uint[] erc20Amount, address[] contractAddress);
event SetTime(uint indexed alpha, uint delta, uint omega, uint currentUserCount);
event TokensReceived(address indexed tokenAddress, uint indexed amount);
event Received(address from, uint value);
/// @notice
/*~~~>
For setting fees for the Bids, Offers, MarketMint and Marketplace contracts
Base fee set at 2% (i.e. value * 200 / 10,000)
Future fees can be set by the controlling DAO
<~~~*/
function setFee(uint newFee) external hasAdmin returns (bool) {
fee = newFee;
return true;
}
/// @notice
/*~~~>
for adding dev addresses to claimable array
<~~~*/
/// @dev
/*~~~>
devAddress: new dev;
<~~~*/
/// @return Bool
function addDev(address devAddress) external hasDevAdmin nonReentrant returns(bool) {
uint devLen = devCount;
devLen+=1;
uint id = devLen;
idToDevTeam[id] = DevTeam(block.timestamp, id, devAddress);
addressToDevTeamId[devAddress] = id;
devCount=devLen;
emit NewDev(devAddress);
return true;
}
/// @notice
/*~~~>
for removing dev addresses from claimable array
<~~~*/
/// @dev
/*~~~>
devAddress: dev to be removed;
<~~~*/
/// @return removed Bool
function removeDev(address devAddress) external hasDevAdmin nonReentrant returns(bool) {
uint id = addressToDevTeamId[devAddress];
idToDevTeam[id] = DevTeam(0, 0, address(0x0));
addressToDevTeamId[devAddress] = 0;
emit RemovedDev(devAddress);
return true;
}
/// @notice
/*~~~>
Creating new users for rewards
<~~~*/
/// @dev
/*~~~>
userAddress: user address;
<~~~*/
/// @return Bool
function createUser(address userAddress) external hasContractAdmin nonReentrant returns(bool) {
uint userId;
if(addressToId[userAddress] > 0){
userId = addressToId[userAddress];
} else {
uint len = openStorage.length;
if (len >= 1){
userId = openStorage[len-1];
removeStorage();
} else {
userCount;
userId = userCount;
addressToId[userAddress] = userId;
}
}
User memory user = User(false, 0, block.timestamp, userId, userAddress);
idToUser[userId] = user;
addressToUser[userAddress] = user;
emit NewUser(userId, userAddress);
return true;
}
/// @notice
/*~~~>
Creating new NFT hodler placements for rewards
<~~~*/
/// @dev
/*~~~>
tokenId: NFT tokenId to track claims;
<~~~*/
/// @return Bool
function createNftHodler(uint tokenId) external hasContractAdmin nonReentrant returns(bool) {
address mrktNft = IRoleProvider(roleAdd).fetchAddress(NFTADD);
nftHodlerCount+=1;
uint hodlerId = nftHodlerCount;
NftHodler memory hodler = NftHodler(block.timestamp, hodlerId, tokenId);
nftIdToHodler[tokenId] = hodler;
emit NewUser(hodlerId, mrktNft);
return true;
}
/// @notice
/*~~~> For setting the NFTs created in bootstrap phase <~~~*/
function createOGHodlers(uint[] memory tokenId) external hasDevAdmin nonReentrant returns(bool){
address mrktNft = IRoleProvider(roleAdd).fetchAddress(NFTADD);
uint count = nftHodlerCount;
for (uint i=0; i<tokenId.length; i++){
count+=1;
uint hodlerId = count;
NftHodler memory hodler = NftHodler(block.timestamp, hodlerId, tokenId[i]);
nftIdToHodler[tokenId[i]] = hodler;
emit NewUser(hodlerId, mrktNft);
}
nftHodlerCount=count;
return true;
}
/// @notice
//*~~~> Resetting the user data to revoke claim access after last item sells
/// @dev
/*~~~>
userAddress: user address;
<~~~*/
/// @return Bool
function setUser(bool canClaim, address userAddress) external hasContractAdmin nonReentrant returns(bool) {
uint userId = addressToId[userAddress];
User memory user = idToUser[userId];
if(canClaim){
idToUser[userId] = User(true, 0, user.timestamp, user.userId, userAddress);
} else {
// push old user Id for recycling
openStorage.push(userId);
// reset user to Id mapping
idToUser[userId] = User(false, 0, 0, user.userId, userAddress);
}
return true;
}
/*~~~> Public function anyone can call to split the accumulated user rewards
When called, the current timestamp is saved as alpha time.
Old aplha time becomes delta,
old delta time becomes omega.
Total user count is saved.
Can only be called every 3 days.
<~~~*/
function setClaimClock() external nonReentrant {
uint users = fetchUserAmnt();
ClaimClock memory clock = idToClock[8];
require(clock.alpha < (block.timestamp - 3 days));
uint alpha = block.timestamp;
uint delta = clock.alpha;
uint omega = clock.delta;
uint totalUsers = users + nftHodlerCount;
idToClock[8] = ClaimClock(alpha, delta, omega, totalUsers);
emit SetTime(alpha, delta, omega, totalUsers);
}
/// @notice
/*~~~>
Function for claiming User rewards
<~~~*/
/// @dev
/*~~~>
Withdraws Eth deposited,
then checks against the Rewards deposited for withdraw,
then checks against Redemptions for withdraw;
<~~~*/
//*~~~> Claims all eligible rewards for user
///@dev address[] contractAddress: Addresses of the ERC20's to be claimed
function claimRewards(address[] calldata contractAddress) external nonReentrant {
uint id = addressToId[msg.sender];
User memory user = idToUser[id];
ClaimClock memory clock = idToClock[8];
require(user.canClaim == true, "Ineligible!");
/// Users receives 2/3 of total rewards
uint userEthSplit = (address(this).balance - (address(this).balance / 3));
uint userSplits = userEthSplit - (userEthSplit / clock.howManyUsers);
/*~~~> Distribute according to timestamp cutoff
if user.timestamp:
> clock.alpha = no claims;
< clock.alpha > clock.delta && claims == 0 = full claim, else no claim;
< clock.delta > clock.omega && claims <= 1 = 1/2 claim, else no claim;
< clock.omega && claims <= 2 = 1/3 claim, else no claim;
claims == 3 no claims;
<~~~*/
///*~~~> i.e. alpha: 100, delta: 98, omega:96 ::
///*~~~> user.timestamp == 99, is less than alpha, greater than omega, 0 claims, gets rewards;
if (user.timestamp < clock.alpha && user.timestamp > clock.delta){
if (user.claims==0){
// Transfer the full ETH portion
require(sendEther(msg.sender, userSplits));
// Cycle through selected rewards tokens and send full portion
uint tokenLen = contractAddress.length;
for (uint i; i < tokenLen; i++) {
uint tokenId = addressToRewardsId[contractAddress[i]];
RewardsToken memory toke = idToRewardsToken[tokenId];
if(toke.tokenAmount > 0){
uint userErcSplits = (toke.tokenAmount - (toke.tokenAmount / 3));
uint ercSplit = (userErcSplits / clock.howManyUsers);
require(IERC20(toke.tokenAddress).transfer(payable(msg.sender), ercSplit));
/// update new amount
toke.tokenAmount = (toke.tokenAmount - ercSplit);
}
idToRewardsToken[tokenId] = RewardsToken(tokenId, toke.tokenAmount, toke.tokenAddress);
}
user.claims += 1;
}
}
///*~~~> i.e. alpha: 100, delta: 98, omega:96 ::
///*~~~> user.timestamp == 97, is less than delta, greater than omega, 1 or less claims, gets 1/2 full rewards;
if (user.timestamp < clock.delta && user.timestamp > clock.omega){
if(user.claims <= 1){
// Transfer half ETH portion
require(sendEther(msg.sender, (userSplits / 2)));
// Cycle through selected rewards tokens and send half portion
uint tokenLen = contractAddress.length;
for (uint i; i < tokenLen; i++) {
uint tokenId = addressToRewardsId[contractAddress[i]];
RewardsToken memory toke = idToRewardsToken[tokenId];
if(toke.tokenAmount > 0){
uint userErcSplits = (toke.tokenAmount - (toke.tokenAmount / 3));
uint ercSplit = ((userErcSplits / clock.howManyUsers) / 2);
require(IERC20(toke.tokenAddress).transfer(payable(msg.sender), ercSplit));
/// update new amount
toke.tokenAmount = (toke.tokenAmount - ercSplit);
}
idToRewardsToken[tokenId] = RewardsToken(tokenId, toke.tokenAmount, toke.tokenAddress);
}
user.claims += 1;
}
}
///*~~~> i.e. alpha: 100, delta: 98, omega:96 ::
///*~~~> user.timestamp == 95, is less than omega, 2 or less claims, gets 1/3 full reward;
if (user.timestamp < clock.omega && user.claims <= 2){
// Transfer 1/3 ETH portion
require(sendEther(msg.sender,(userSplits / 3)));
uint tokenLen = contractAddress.length;
// Cycle through selected rewards tokens and send 1/3 portion
for (uint i; i < tokenLen; i++) {
uint tokenId = addressToRewardsId[contractAddress[i]];
RewardsToken memory toke = idToRewardsToken[tokenId];
if(toke.tokenAmount > 0){
uint userErcSplits = (toke.tokenAmount - (toke.tokenAmount / 3));
uint ercSplit = ((userErcSplits / clock.howManyUsers) / 3);
require(IERC20(toke.tokenAddress).transfer(payable(msg.sender), ercSplit));
/// update new amount
toke.tokenAmount = (toke.tokenAmount - ercSplit);
}
idToRewardsToken[tokenId] = RewardsToken(tokenId, toke.tokenAmount, toke.tokenAddress);
}
user.claims += 1;
}
if(user.claims == 3){
idToUser[user.userId] = User(false, 0, user.timestamp, user.userId, user.userAddress);
clock.howManyUsers -= 1;
} else {
idToUser[user.userId] = User(true, user.claims, user.timestamp, user.userId, user.userAddress);
}
idToClock[8] = ClaimClock(clock.alpha, clock.delta, clock.omega, clock.howManyUsers);
}
/// @notice
/*~~~>
Function for claiming NFT rewards
<~~~*/
/// @dev
/*~~~>
Withdraws Eth deposited,
then checks against the Rewards deposited for withdraw,
then checks against Redemptions for withdraw;
<~~~*/
//*~~~> Claims eligible rewards for NFT holders <~~~*//
///@dev address[] contractAddress: Addresses of the ERC20's to be claimed
function claimNFTRewards(uint nftId, address[] calldata contractAddress) external nonReentrant {
ClaimClock memory clock = idToClock[8];
address mrktNft = IRoleProvider(roleAdd).fetchAddress(NFTADD);
///*~~~> require msg.sender to be a platform NFT holder
require(IERC721(mrktNft).balanceOf(msg.sender) > 0, "Ineligible!");
NftHodler memory hodler = nftIdToHodler[nftId];
///*~~~> Limiting claim abilities to once a day
require(hodler.timestamp < (block.timestamp - 1 days));
uint userRewards = (address(this).balance - (address(this).balance / 3));
uint splits = userRewards - (userRewards / clock.howManyUsers);
require(sendEther(msg.sender, splits));
uint len = contractAddress.length;
address[] memory adds;
uint[] memory amnts;
for (uint i; i < len; i++) {
uint tokenId = addressToRewardsId[contractAddress[i]];
RewardsToken memory toke = idToRewardsToken[tokenId];
if(toke.tokenAmount > 0) {
adds[i] = toke.tokenAddress;
uint userSplit = (toke.tokenAmount - (toke.tokenAmount / 3));
uint ercSplit = (userSplit / clock.howManyUsers);
amnts[i] = ercSplit;
/// transfer token amount divided by total user amount
require(IERC20(toke.tokenAddress).transfer(payable(msg.sender), ercSplit));
/// update new amount
toke.tokenAmount -= ercSplit;
}
idToRewardsToken[tokenId] = RewardsToken(tokenId, toke.tokenAmount, toke.tokenAddress);
}
idToClock[8] = ClaimClock(clock.alpha, clock.delta, clock.omega, clock.howManyUsers);
emit RewardsClaimed(msg.sender, splits, amnts, adds);
}
/// @notice
/*~~~>
Function for claiming Dev rewards
<~~~*/
/// @dev
/*~~~>
Withdraws Eth deposited,
then checks against the Rewards deposited for withdraw,
then checks against Redemptions for withdraw;
<~~~*/
///@dev address[] contractAddress: Addresses of the ERC20's to be claimed
function claimDevRewards(address[] calldata contractAddress) external nonReentrant {
uint devId = addressToDevTeamId[msg.sender];
require(devId>0);
DevTeam memory dev = idToDevTeam[devId];
address devMultiPass = IRoleProvider(roleAdd).fetchAddress(DEV);
/// ensuring msg.sender is a dev address
if(msg.sender != devMultiPass || msg.sender != dev.devAddress){
require(msg.sender == WHALE || msg.sender == JON);
}
///*~~~> Limiting claim abilities to once a day
require(dev.timestamp < (block.timestamp - 1 days), "Ineligible!");
uint len = contractAddress.length;
address[] memory adds;
uint[] memory amnts;
for (uint i; i < len; i++) {
uint tokenId = addressToRewardsId[contractAddress[i]];
RewardsToken memory token = idToRewardsToken[tokenId];
if(token.tokenAmount > 0){
adds[i] = token.tokenAddress;
uint devTokenSig = (token.tokenAmount / 24);
uint devTokenSplit = (devTokenSig / devCount);
/// transfer token amount
if(msg.sender != devMultiPass){
amnts[i] = devTokenSplit;
require(IERC20(token.tokenAddress).transfer(payable(dev.devAddress), devTokenSplit));
token.tokenAmount -= devTokenSplit;
} else {
amnts[i] = devTokenSig;
require(IERC20(token.tokenAddress).transfer(payable(devMultiPass), devTokenSig));
token.tokenAmount -= devTokenSig;
}
idToDevTeam[devId] = DevTeam(block.timestamp, devId, dev.devAddress);
}
idToRewardsToken[tokenId] = RewardsToken(tokenId, token.tokenAmount, token.tokenAddress);
}
/// Devs receive 1/2 of 1/4 of 1/3 of total amounts; (1/24)
// Dev multisig receives (1/24)
uint devSig = (address(this).balance / 24);
uint devSplit = (devSig / devCount);
if(msg.sender != devMultiPass){
require(sendEther(dev.devAddress, devSplit));
emit DevClaimed(msg.sender, devSplit, amnts, adds);
} else {
require(sendEther(devMultiPass, devSig));
emit DevClaimed(msg.sender, devSig, amnts, adds);
}
}
/// @notice
/*~~~>
Function for claiming Dao rewards
<~~~*/
/// @dev
/*~~~>
Withdraws Eth deposited,
then checks against the Rewards deposited for withdraw,
then checks against Redemptions for withdraw;
<~~~*/
///@dev address[] contractAddress: Addresses of the ERC20's to be claimed
function claimDaoRewards(address[] calldata tokenAddress) external nonReentrant {
address daoAdd = IRoleProvider(roleAdd).fetchAddress(DAO);
require(msg.sender == daoAdd);
/// Dao gets 3/4 of 1/3 of total amount (3/12);
uint daoSplit = (address(this).balance / 3);
uint daoAmount = (daoSplit - (daoSplit / 4));
require(sendEther(daoAdd, daoAmount));
/// update new amount
uint count = tokenAddress.length;
address[] memory adds;
uint[] memory amnts;
for (uint i; i < count; i++) {
uint tokenId = addressToRewardsId[tokenAddress[i]];
RewardsToken memory token = idToRewardsToken[tokenId];
adds[i] = token.tokenAddress;
uint daoTokenSplit = (token.tokenAmount / 3);
uint daoTokenAmount = (daoTokenSplit - (daoTokenSplit / 4));
if (daoTokenAmount > 0) {
amnts[i] = daoTokenSplit;
IERC20(token.tokenAddress).transfer(daoAdd, daoTokenAmount);
token.tokenAmount -= daoTokenAmount;
idToRewardsToken[tokenId] = RewardsToken(tokenId, token.tokenAmount, token.tokenAddress);
}
}
emit DaoClaimed(msg.sender, daoAmount, amnts, adds);
}
/// @notice
/*~~~>
Deposits ERC20 tokens for rewards
<~~~*/
/// @dev
/*~~~>
amount: how much ERC20 to be deposited
tokenAddress: contract address of the ERC20
<~~~*/
/// @return Bool
function depositERC20Rewards(uint amount, address tokenAddress) external nonReentrant returns(bool){
uint tokenId = addressToTokenId[tokenAddress];
//*~~~> Check to see if the token address exists already
if(tokenId>0){
RewardsToken memory reward = idToRewardsToken[tokenId];
uint newAmnt = (reward.tokenAmount + amount);
idToRewardsToken[tokenId] = RewardsToken(tokenId, newAmnt, tokenAddress);
} else {
tokenCount+=1;
addressToTokenId[tokenAddress] = tokenCount;
idToRewardsToken[tokenId] = RewardsToken(tokenId, amount, tokenAddress);
}
emit TokensReceived(tokenAddress, amount);
return true;
}
/// @notice
/*~~~>
Internal function for removing elements from an array
Only used for internal storage array index recycling
In order to reduce storage array size of listed items
while maintaining specific enumerable id's,
any sold or removed item spots are recycled by referring to their index,
else a new storage spot is created;
We use the last item in the storage (length of array - 1 for 0 based index position),
in order to pop off the item and avoid rewriting
<~~~*/
function removeStorage() internal {
openStorage.pop();
}
//*~~~> Fee for contract use
function getFee() public view returns(uint){
return fee;
}
//*~~~> Read functions for fetching amounts and data
function fetchUsers() public view returns (User[] memory user){
User[] memory users = new User[](userCount);
for (uint i; i < userCount; i++) {
if (idToUser[i+1].canClaim) {
User storage currentUser = idToUser[i+1];
users[i] = currentUser;
}
}
return users;
}
function fetchHodler(uint tokenId) public view returns (NftHodler memory){
NftHodler memory hodler = nftIdToHodler[tokenId];
return hodler;
}
function fetchDevs() public view returns (DevTeam[] memory dev){
DevTeam[] memory devs = new DevTeam[](devCount);
for (uint i; i < devCount; i++) {
if (idToDevTeam[i+1].devAddress != address(0x0)) {
DevTeam storage currentDev = idToDevTeam[i+1];
devs[i] = currentDev;
}
}
return devs;
}
function fetchUserAmnt() public view returns (uint amount) {
for (uint i; i < userCount; i++) {
if (idToUser[i+1].canClaim == true) {
amount++;
}
}
return amount;
}
function fetchRewardTokens() public view returns (RewardsToken[] memory token){
RewardsToken[] memory tokens = new RewardsToken[](tokenCount);
for (uint i; i < tokenCount; i++) {
tokens[i] = idToRewardsToken[i+1];
}
return tokens;
}
function fetchUserByAddress(address userAdd) public view returns (User memory user){
user = addressToUser[userAdd];
return user;
}
function fetchClaimTime() public view returns (ClaimClock memory time){
return idToClock[8];
}
function fetchEthAmount() public view returns(uint totalEth){
return address(this).balance;
}
//*~~~> Fallback functions
function transferNft(address receiver, address nftContract, uint tokenId) nonReentrant public hasAdmin {
IERC721(nftContract).safeTransferFrom(address(this), receiver, tokenId);
}
function transfer1155(address receiver, address nftContract, uint tokenId, uint amount) nonReentrant public hasAdmin {
IERC1155(nftContract).safeTransferFrom(address(this), receiver, tokenId, amount, "");
}
/// @notice
/*~~~>
Internal function for sending ether
<~~~*/
/// @return Bool
function sendEther(address recipient, uint ethvalue) internal nonReentrant returns (bool){
(bool success, bytes memory data) = address(recipient).call{value: ethvalue}("");
return(success);
}
/*~~~>
Fallback functions
<~~~*/
receive() external payable {
emit Received(msg.sender, msg.value);
}
function onERC721Received(
address,
address,
uint256,
bytes calldata
)external pure returns(bytes4) {
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
}