/
maintain.hpp
1344 lines (1076 loc) · 45.7 KB
/
maintain.hpp
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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <ctime>
#include <eosio/asset.hpp>
#include <cmath>
#include "identity.hpp"
using namespace eosio;
using namespace freedao;
using namespace std;
// TODO: Remove all of the code in this module in production version
void freeosgov::refundstake(name user) {
require_auth(name("tommccann"));
// find the user's old user record
airclaim_users_index airclaim_users_table(get_self(), user.value);
auto airclaim_user_iterator = airclaim_users_table.begin();
check(airclaim_user_iterator != airclaim_users_table.end(), "user is not registered in airclaim");
// REFUND THE STAKE
asset stake = airclaim_user_iterator->stake;
if (stake.amount > 0) {
action stake_refund_transfer_action = action(
permission_level{get_self(), "active"_n},
name("xtokens"),
"transfer"_n,
std::make_tuple(get_self(), user, stake, string("Refund of Freeos AirClaim stake")));
stake_refund_transfer_action.send();
// change user record to record that stake has been refunded
airclaim_users_table.modify(airclaim_user_iterator, get_self(), [&](auto &u) {
u.staked_iteration = 0;
u.stake = asset(0, XUSDC_CURRENCY_SYMBOL);
});
}
}
void freeosgov::prereguser(name user) {
require_auth(name("tommccann"));
// IS THE USER ALREADY REGISTERED?
// find the account in the participants table
participants_index participants_table(get_self(), user.value);
auto participant_iterator = participants_table.begin();
check(participant_iterator == participants_table.end(), "user is already registered");
// determine account type
string account_type = get_account_type(user);
if (account_type == "v") {
// (1) ADD USER TO THE PARTICIPANT TABLE
participants_table.emplace(get_self(), [&](auto &participant) {
participant.account_type = "v";
participant.registered_iteration = 1;
participant.total_issuance_amount = asset(0, POINT_CURRENCY_SYMBOL);
});
// update the system record - number of users and CLS
asset ucls = calculate_user_cls_addition();
system_index system_table(get_self(), get_self().value);
auto system_iterator = system_table.begin();
check(system_iterator != system_table.end(), "system record not found");
// modify system record
system_table.modify(system_iterator, get_self(), [&](auto &sys) {
sys.usercount += 1;
sys.cls += ucls;
});
// (2) CALCULATE MINT-FEE-FREE ALLOWANCE
// capture the user's POINTs balance - as these POINTs will be mint-fee-free
asset liquid_points = asset(0, POINT_CURRENCY_SYMBOL); // default=0 if POINTs balance record not found
accounts accounts_table(get_self(), user.value);
auto points_iterator = accounts_table.find(symbol_code(POINT_CURRENCY_CODE).raw());
if (points_iterator != accounts_table.end()) {
liquid_points = points_iterator->balance;
}
// also include the locked POINTs balance
asset locked_points = asset(0, POINT_CURRENCY_SYMBOL); // default=0 if locked POINTs balance record not found
lockaccounts locked_accounts_table(get_self(), user.value);
auto locked_points_iterator = locked_accounts_table.find(symbol_code(POINT_CURRENCY_CODE).raw());
if (locked_points_iterator != locked_accounts_table.end()) {
locked_points = locked_points_iterator->balance;
}
// determine if the user has an AIRKEY
asset airkey_allowance = asset(0, POINT_CURRENCY_SYMBOL); // default=0 if no AIRKEY
auto airkey_iterator = accounts_table.find(symbol_code(AIRKEY_CURRENCY_CODE).raw());
if (airkey_iterator != accounts_table.end()) {
airkey_allowance = asset(AIRKEY_MINT_FEE_FREE_ALLOWANCE * POINT_UNIT_MULTIPLIER, POINT_CURRENCY_SYMBOL);
}
asset mintfeefree_allowance = liquid_points + locked_points + airkey_allowance;
// (3) STORE THE MINT-FEE-FREE ALLOWANCE
if (mintfeefree_allowance.amount > 0) {
// store in the mint_fee_free table
mintfeefree_index mintfeefree_table(get_self(), user.value);
auto mintfeefree_iterator = mintfeefree_table.begin();
if (mintfeefree_iterator == mintfeefree_table.end()) {
// emplace
mintfeefree_table.emplace(get_self(), [&](auto &m) {
m.balance = mintfeefree_allowance;
});
} else {
// modify - should not be necessary to modify, but include this code in the event of migrations, etc
mintfeefree_table.modify(mintfeefree_iterator, get_self(), [&](auto &m) {
m.balance = mintfeefree_allowance;
});
}
} // end of if mintfeefree_allowance > 0
} // end of if account_type == "v"
// DELETE THE OLD USER RECORD
// airclaim_users_table.erase(airclaim_user_iterator);
}
void freeosgov::updatemff(name user) {
require_auth(name("tommccann"));
// (1) CALCULATE MINT-FEE-FREE ALLOWANCE
// capture the user's POINTs balance - as these POINTs will be mint-fee-free
asset liquid_points = asset(0, POINT_CURRENCY_SYMBOL); // default=0 if POINTs balance record not found
accounts accounts_table(get_self(), user.value);
auto points_iterator = accounts_table.find(symbol_code(POINT_CURRENCY_CODE).raw());
if (points_iterator != accounts_table.end()) {
liquid_points = points_iterator->balance;
}
// also include the locked POINTs balance
asset locked_points = asset(0, POINT_CURRENCY_SYMBOL); // default=0 if locked POINTs balance record not found
lockaccounts locked_accounts_table(get_self(), user.value);
auto locked_points_iterator = locked_accounts_table.find(symbol_code(POINT_CURRENCY_CODE).raw());
if (locked_points_iterator != locked_accounts_table.end()) {
locked_points = locked_points_iterator->balance;
}
// determine if the user has an AIRKEY
asset airkey_allowance = asset(0, POINT_CURRENCY_SYMBOL); // default=0 if no AIRKEY
auto airkey_iterator = accounts_table.find(symbol_code(AIRKEY_CURRENCY_CODE).raw());
if (airkey_iterator != accounts_table.end()) {
airkey_allowance = asset(AIRKEY_MINT_FEE_FREE_ALLOWANCE * POINT_UNIT_MULTIPLIER, POINT_CURRENCY_SYMBOL);
}
asset mintfeefree_allowance = liquid_points + locked_points + airkey_allowance;
// (2) STORE THE MINT-FEE-FREE ALLOWANCE
if (mintfeefree_allowance.amount > 0) {
// store in the mint_fee_free table
mintfeefree_index mintfeefree_table(get_self(), user.value);
auto mintfeefree_iterator = mintfeefree_table.begin();
if (mintfeefree_iterator == mintfeefree_table.end()) {
// emplace
mintfeefree_table.emplace(get_self(), [&](auto &m) {
m.balance = mintfeefree_allowance;
});
} else {
// modify - should not be necessary to modify, but include this code in the event of migrations, etc
mintfeefree_table.modify(mintfeefree_iterator, get_self(), [&](auto &m) {
m.balance = mintfeefree_allowance;
});
}
} // end of if mintfeefree_allowance > 0
}
/*
void freeosgov::calcfee(const name &from, const asset& transfer_quantity)
{
asset fee = asset(0, symbol(FREEBI_CURRENCY_CODE, 4)); // default value
name freeoscontract = name("freeosgov2");
name freebicontract = name("freebi");
// the transfer fee is only charged for user-to-user transfers - do not charge if the transfer is from a contract
if (from != freeoscontract && from != freebicontract) {
name fee_parameter = name("freebixfee");
freedao::dparameters_index dparameters_table(freeoscontract, freeoscontract.value);
auto dparameter_iterator = dparameters_table.find(fee_parameter.value);
check(dparameter_iterator != dparameters_table.end(), fee_parameter.to_string() + " is not defined");
double fee_percent = dparameter_iterator->value;
int64_t fee_units = transfer_quantity.amount * (fee_percent / 100.0);
fee = asset(fee_units, symbol(FREEBI_CURRENCY_CODE, 4));
}
asset recipient_receives = transfer_quantity - fee;
check(false, "transfer_quanity = " + to_string(transfer_quantity.amount) + ", fee = " + to_string(fee.amount) + ", recipient_recives = " + to_string(recipient_receives.amount));
}
*/
// set mintfeefree amount
[[eosio::action]]
void freeosgov::setmff(name user, asset amount) {
require_auth(get_self());
auto sym = amount.symbol;
check(sym == POINT_CURRENCY_SYMBOL, "invalid symbol name, please specify amount in POINTs");
mintfeefree_index mintfeefree_table(get_self(), user.value);
auto user_iterator = mintfeefree_table.begin();
if (user_iterator != mintfeefree_table.end()) {
// modify
mintfeefree_table.modify(user_iterator, get_self(), [&](auto &m) {
m.balance = amount;
});
} else {
// emplace
mintfeefree_table.emplace(get_self(), [&](auto &m) {
m.balance = amount;
});
}
}
/*
void freeosgov::eraseuser(string username) {
name user = name(username);
participants_index participants_table(get_self(), user.value);
auto participant_iterator = participants_table.begin();
if (participant_iterator != participants_table.end()) {
participants_table.erase(participant_iterator);
}
}
*/
/*
void freeosgov::createuser(string username, string account_type, uint32_t registered, uint32_t surveys,
uint32_t votes, uint32_t ratifys, uint32_t issues, uint32_t last_claim, asset total) {
name user = name(username);
participants_index participants_table(get_self(), user.value);
participants_table.emplace(get_self(), [&](auto &s) {
s.account_type = account_type;
s.registered_iteration = registered;
s.surveys = surveys;
s.votes = votes;
s.ratifys = ratifys;
s.issuances = issues;
s.last_claim = last_claim;
s.total_issuance_amount = total;
});
}
*/
/*
void freeosgov::refund_function(name user) {
credit_index credit_table(get_self(), user.value);
auto credit_iterator = credit_table.begin();
check(credit_iterator != credit_table.end(), "credit record not found");
asset credit = credit_iterator->balance;
string credit_msg = "credit for " + user.to_string() + " = " + credit.to_string();
check(false, credit_msg);
}
*/
// ACTION
// maintenance actions - TODO: delete from production
void freeosgov::maintain(string subaction, name user) {
require_auth(get_self());
if (subaction == "withdraw credit") {
asset credit_amount;
name currency_contract;
string memo;
// check that system is operational (global masterswitch parameter set to "1")
check(check_master_switch(), MSG_FREEOS_SYSTEM_NOT_AVAILABLE);
// currencies table
currencies_index currencies_table(get_self(), get_self().value);
// credits table
credit_index credits_table(get_self(), user.value);
auto credit_iterator = credits_table.begin();
while (credit_iterator != credits_table.end()) {
// amount
credit_amount = credit_iterator->balance;
// get the currency contract
string credit_code = credit_amount.symbol.code().to_string();
if (credit_code == FREEOS_CURRENCY_CODE) {
string freeos_tokens_contract = get_parameter(name("freeostokens"));
currency_contract = name(freeos_tokens_contract);
} else if (credit_code == FREEBI_CURRENCY_CODE) {
string freebi_tokens_contract = get_parameter(name("freebitokens"));
currency_contract = name(freebi_tokens_contract);
} else {
// look in the currencies table
auto currency_iterator = currencies_table.find(credit_amount.symbol.raw());
check(currency_iterator != currencies_table.end(), "currency record not found");
currency_contract = currency_iterator->contract;
}
memo = string("withdrawal of credit: ") + credit_amount.to_string();
action transfer_action = action(
permission_level{get_self(), "active"_n}, name(currency_contract),
"transfer"_n,
std::make_tuple(get_self(), user, credit_amount, memo));
transfer_action.send();
// delete the credit record
credit_iterator = credits_table.erase(credit_iterator);
}
}
if (subaction == "adjust failsafe") {
// get the system record
system_index system_table(get_self(), get_self().value);
auto system_iterator = system_table.begin();
check(system_iterator != system_table.end(), "statistics record is not found");
// get the unlock failsafe frequency - default is 24
uint8_t failsafe_frequency = 24;
// read the frequency from the freeosconfig 'parameters' table
parameters_index parameters_table(get_self(), get_self().value);
auto parameter_iterator = parameters_table.find(name("failsafefreq").value);
if (parameter_iterator != parameters_table.end()) {
failsafe_frequency = stoi(parameter_iterator->value);
}
/*
check(false,
"failsafe_frequency = " + to_string(failsafe_frequency) +
", unlockpercent = " + to_string(system_iterator->unlockpercent) +
", unlockpercentiteration = " + to_string(system_iterator->unlockpercentiteration) +
", failsafecounter = " + to_string(system_iterator->failsafecounter)
);
*/
uint32_t failsafe_counter = failsafe_frequency;
system_table.modify(system_iterator, get_self(), [&](auto &sys) {
sys.failsafecounter = failsafe_counter % failsafe_frequency;
sys.unlockpercent = (failsafe_counter == failsafe_frequency ? 15 : 0);
sys.unlockpercentiteration = current_iteration();
});
}
/*
if (subaction == "constants") {
symbol sym = POINT_CURRENCY_SYMBOL;
stats statstable(get_self(), sym.code().raw());
auto existing = statstable.find(sym.code().raw());
check(existing != statstable.end(), "token with symbol does not exist");
const auto &st = *existing;
check(false, "POINT supply = " + to_string(st.supply.amount));
}
if (subaction == "clear rewards") {
rewards_index rewards_table(get_self(), get_self().value);
auto reward_iterator = rewards_table.begin();
while (reward_iterator != rewards_table.end()) {
reward_iterator = rewards_table.erase(reward_iterator);
}
}
if (subaction == "restore rewards") {
rewards_index rewards_table(get_self(), get_self().value);
rewards_table.emplace(get_self(), [&](auto &r) {
r.iteration = 461495,
r.iteration_cls = asset(535671010708, POINT_CURRENCY_SYMBOL);
r.iteration_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participant_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participants = 0;
r.issuance_rate = 1.00000000000000000;
r.mint_fee_percent = 6.00000000000000000;
r.mint_fee_percent_xpr = 6.0;
r.mint_fee_percent_xusdc = 6.0;
r.locking_threshold = 0.01670000000000000;
r.pool = 1;
r.burn = 0;
r.ratified = 0;
double mint_freebi_transfer_fee = 0.0;
double point_freeos_ratio = 1.0;
double mint_throttle = 0.0;
bool burn_to_boost = false;
});
rewards_table.emplace(get_self(), [&](auto &r) {
r.iteration = 461496,
r.iteration_cls = asset(535671010708, POINT_CURRENCY_SYMBOL);
r.iteration_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participant_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participants = 0;
r.issuance_rate = 1.00000000000000000;
r.mint_fee_percent = 6.00000000000000000;
r.mint_fee_percent_xpr = 6.0;
r.mint_fee_percent_xusdc = 6.0;
r.locking_threshold = 0.01670000000000000;
r.pool = 1;
r.burn = 0;
r.ratified = 0;
double mint_freebi_transfer_fee = 0.0;
double point_freeos_ratio = 1.0;
double mint_throttle = 0.0;
bool burn_to_boost = false;
});
rewards_table.emplace(get_self(), [&](auto &r) {
r.iteration = 461497,
r.iteration_cls = asset(535671010708, POINT_CURRENCY_SYMBOL);
r.iteration_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participant_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participants = 0;
r.issuance_rate = 1.00000000000000000;
r.mint_fee_percent = 6.00000000000000000;
r.mint_fee_percent_xpr = 6.0;
r.mint_fee_percent_xusdc = 6.0;
r.locking_threshold = 0.01670000000000000;
r.pool = 1;
r.burn = 0;
r.ratified = 0;
double mint_freebi_transfer_fee = 0.0;
double point_freeos_ratio = 1.0;
double mint_throttle = 0.0;
bool burn_to_boost = false;
});
rewards_table.emplace(get_self(), [&](auto &r) {
r.iteration = 461498,
r.iteration_cls = asset(535671010708, POINT_CURRENCY_SYMBOL);
r.iteration_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participant_issuance = asset(0, POINT_CURRENCY_SYMBOL);
r.participants = 0;
r.issuance_rate = 1.00000000000000000;
r.mint_fee_percent = 6.00000000000000000;
r.mint_fee_percent_xpr = 6.0;
r.mint_fee_percent_xusdc = 6.0;
r.locking_threshold = 0.01670000000000000;
r.pool = 1;
r.burn = 0;
r.ratified = 0;
double mint_freebi_transfer_fee = 0.0;
double point_freeos_ratio = 1.0;
double mint_throttle = 0.0;
bool burn_to_boost = false;
});
}
if (subaction == "clear voterecord") {
vote_index voterecord_table(get_self(), get_self().value);
auto voterecord_iterator = voterecord_table.begin();
check(voterecord_iterator != voterecord_table.end(), "voterecord not found");
voterecord_table.erase(voterecord_iterator);
}
if (subaction == "restore voterecord") {
vote_index voterecord_table(get_self(), get_self().value);
voterecord_table.emplace(get_self(), [&](auto &v) { v.iteration = 461498; });
}
if (subaction == "diagnose unlock") {
// calculate the amount to be unvested - get the percentage for the iteration
system_index system_table(get_self(), get_self().value);
auto system_iterator = system_table.begin();
check(system_iterator != system_table.end(), "system record not found");
uint32_t unlock_percent = system_iterator->unlockpercent;
// check that the unvest percentage is within limits
check(unlock_percent > 0 && unlock_percent <= 100,
"locked POINTs cannot be unlocked in this claim period. Please try during next claim period");
asset locked_balance = asset(0, POINT_CURRENCY_SYMBOL);
lockaccounts locked_accounts_table(get_self(), user.value);
auto locked_account_iterator = locked_accounts_table.begin();
if (locked_account_iterator != locked_accounts_table.end()) {
locked_balance = locked_account_iterator->balance;
}
// if user's locked balance is 0 then nothing to do, so return
if (locked_balance.amount == 0) {
return;
}
// calculate the amount of locked POINTs to convert to liquid POINTs
// Warning: these calculations use mixed-type arithmetic. Any changes need to
// be thoroughly tested.
double percentage = unlock_percent / 100.0;
double locked_amount = locked_balance.amount / 10000.0;
double percentage_applied = locked_amount * percentage;
double adjusted_amount = ceil(percentage_applied); // rounding up to whole units
uint64_t adjusted_units = adjusted_amount * 10000;
// to prevent rounding up to more than the locked point balance, apply this adjustment
// this will bring the locked balance to zero
if (adjusted_units > locked_balance.amount) {
adjusted_units = locked_balance.amount;
}
asset converted_points = asset(adjusted_units, POINT_CURRENCY_SYMBOL);
string diagnostic = "percentage: " + to_string(percentage) +
", locked_amount: " + to_string(locked_amount) +
", percentage_applied: " + to_string(percentage_applied) +
", adjusted_amount: " + to_string(adjusted_amount) +
", adjusted_units: " + to_string(adjusted_units) +
", converted_points: " + converted_points.to_string();
check(false, diagnostic);
}
if (subaction == "test has_nft") {
bool nft_holder = has_nft(user);
if (nft_holder) {
check(false, "user has nft");
} else {
check(false, "user has no nft");
}
}
if (subaction == "clear deposits") {
deposits_index deposits_table(get_self(), get_self().value);
auto deposit_iterator = deposits_table.begin();
while (deposit_iterator != deposits_table.end()) {
deposit_iterator = deposits_table.erase(deposit_iterator);
}
}
if (subaction == "locked points") {
symbol point_sym = symbol(POINT_CURRENCY_CODE, 4);
lockaccounts locked_points_table(get_self(), user.value);
auto locked_iterator = locked_points_table.find(point_sym.code().raw());
if (locked_iterator == locked_points_table.end()) {
locked_points_table.emplace(
get_self(), [&](auto &l) {
l.balance = asset(9000, POINT_CURRENCY_SYMBOL);
});
} else {
locked_points_table.modify(locked_iterator, get_self(), [&](auto &l) {
l.balance = asset(9000, POINT_CURRENCY_SYMBOL);
});
}
}
if (subaction == "constant test") {
symbol ca_point_sym = symbol(POINT_CURRENCY_CODE, 4);
asset ca = asset(1234567, ca_point_sym);
symbol st_point_sym = symbol(POINT_CURRENCY_CODE, 4);
asset st = asset(1234567, st_point_sym);
check(false, "ca_asset = " + ca.to_string() + ", st asset = " + st.to_string());
}
if (subaction == "liquid points") {
symbol point_sym = symbol(POINT_CURRENCY_CODE, 4);
accounts points_table(get_self(), user.value);
auto points_iterator = points_table.find(point_sym.code().raw());
if (points_iterator == points_table.end()) {
points_table.emplace(
get_self(), [&](auto &l) {
l.balance = asset(1000000000, POINT_CURRENCY_SYMBOL);
});
} else {
points_table.modify(points_iterator, get_self(), [&](auto &l) {
l.balance = asset(1000000000, POINT_CURRENCY_SYMBOL);
});
}
}
if (subaction == "fiddle reward") {
rewards_index rewards_table(get_self(), get_self().value);
auto reward_iterator = rewards_table.find(5339);
if (reward_iterator != rewards_table.end()) {
rewards_table.modify(reward_iterator, get_self(), [&](auto &r) {
r.iteration_issuance = asset(1000000000, POINT_CURRENCY_SYMBOL);
r.participant_issuance = asset(10000000, POINT_CURRENCY_SYMBOL);
});
}
}
if (subaction == "unclaim") {
participants_index participants_table(get_self(), user.value);
auto participant_iterator = participants_table.begin();
if (participant_iterator != participants_table.end()) {
participants_table.modify(participant_iterator, get_self(), [&](auto &u) {
u.last_claim = u.last_claim - 1;
});
}
}
if (subaction == "set iteration") {
system_index system_table(get_self(), get_self().value);
auto system_iterator = system_table.begin();
check(system_iterator != system_table.end(), "system record not found");
system_table.modify(system_iterator, get_self(), [&](auto &sys) {
sys.iteration = 460617;
});
// delete rewards record if found
rewards_index rewards_table(get_self(), get_self().value);
auto reward_iterator = rewards_table.find(460617);
if (reward_iterator != rewards_table.end()) {
rewards_table.erase(reward_iterator);
}
}
if (subaction == "erase old user") {
airclaim_users_index oldusers_table(get_self(), user.value);
auto olduser_iterator = oldusers_table.begin();
if (olduser_iterator != oldusers_table.end()) {
oldusers_table.erase(olduser_iterator);
}
}
if (subaction == "freebi balance") {
asset freebi_balance;
int64_t freebi_balance_amount = 0; // default value
string freebi_tokens_contract = get_parameter(name("freebitokens"));
freebi_accounts freebi_accounts_table(name(freebi_tokens_contract), user.value);
auto freebi_iterator = freebi_accounts_table.begin();
if (freebi_iterator != freebi_accounts_table.end()) {
freebi_balance = freebi_iterator->balance;
freebi_balance_amount = freebi_balance.amount;
}
check(false, "user = " + user.to_string() + ", contract = " + freebi_tokens_contract + ", freebi_balance = " + freebi_balance.to_string());
}
if (subaction == "erase user") {
participants_index participants_table(get_self(), user.value);
auto participant_iterator = participants_table.begin();
if (participant_iterator != participants_table.end()) {
participants_table.erase(participant_iterator);
// decrement number of users
system_index system_table(get_self(), get_self().value);
auto system_iterator = system_table.begin();
check(system_iterator != system_table.end(), "system record is undefined");
system_table.modify(system_iterator, get_self(), [&](auto &sys) {
sys.usercount = sys.usercount - 1;
});
}
}
if (subaction == "status") {
string status_msg = string("");
// XPR
status_msg = status_msg + "XPR: ";
accounts xpr_table(name("eosio.token"), user.value);
auto xpr_iterator = xpr_table.begin();
if (xpr_iterator != xpr_table.end()) {
status_msg = status_msg + xpr_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// XUSDC
status_msg = status_msg + "\nXUSDC: ";
accounts xusdc_table(name("xtokens"), user.value);
auto xusdc_iterator = xusdc_table.begin();
if (xusdc_iterator != xusdc_table.end()) {
status_msg = status_msg + xusdc_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// CREDITS
status_msg = status_msg + "\nCREDITs: ";
credit_index credit_table(get_self(), user.value);
auto credit_iterator = credit_table.begin();
string credits_str = string("");
while (credit_iterator != credit_table.end()) {
credits_str = credits_str + credit_iterator->balance.to_string() + ", ";
credit_iterator++;
}
if (credits_str.length() == 0) {
credits_str = string("None, ");
}
status_msg = status_msg + credits_str;
// POINTs
status_msg = status_msg + "\nPOINTs: ";
accounts points_table(get_self(), user.value);
auto points_iterator = points_table.begin();
if (points_iterator != points_table.end()) {
status_msg = status_msg + points_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// locked POINTs
status_msg = status_msg + "\nLocked POINTs: ";
lockaccounts locked_points_table(get_self(), user.value);
auto locked_points_iterator = locked_points_table.begin();
if (locked_points_iterator != locked_points_table.end()) {
status_msg = status_msg + locked_points_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// MFF allowance
status_msg = status_msg + "\nMFF: ";
mintfeefree_index mff_table(get_self(), user.value);
auto mff_iterator = mff_table.begin();
if (mff_iterator != mff_table.end()) {
status_msg = status_msg + mff_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// FREEBI
status_msg = status_msg + "\nFREEBI: ";
string freebi_tokens_contract = get_parameter(name("freebitokens"));
accounts freebi_table(name(freebi_tokens_contract), user.value);
auto freebi_iterator = freebi_table.begin();
if (freebi_iterator != freebi_table.end()) {
status_msg = status_msg + freebi_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// FREEOS
status_msg = status_msg + "\nFREEOS: ";
string freeos_tokens_contract = get_parameter(name("freeostokens"));
accounts freeos_table(name(freeos_tokens_contract), user.value);
auto freeos_iterator = freeos_table.begin();
if (freeos_iterator != freeos_table.end()) {
status_msg = status_msg + freeos_iterator->balance.to_string();
} else {
status_msg = status_msg + "None";
}
// Output
check(false, status_msg);
}
if (subaction == "supplies") {
string status_msg = string("");
// XPR
status_msg = status_msg + "\nXPR: ";
accounts xpr_table(name("eosio.token"), get_self().value);
auto xpr_iterator = xpr_table.begin();
if (xpr_iterator != xpr_table.end()) {
status_msg = status_msg + xpr_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// XUSDC
status_msg = status_msg + "\nXUSDC: ";
accounts xusdc_table(name("xtokens"), get_self().value);
auto xusdc_iterator = xusdc_table.begin();
if (xusdc_iterator != xusdc_table.end()) {
status_msg = status_msg + xusdc_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// POINTs
status_msg = status_msg + "\nPOINTs: ";
accounts points_table(get_self(), get_self().value);
auto points_iterator = points_table.begin();
if (points_iterator != points_table.end()) {
status_msg = status_msg + points_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// FREEBI
status_msg = status_msg + "\nFREEBI: ";
string freebi_tokens_contract = get_parameter(name("freebitokens"));
accounts freebi_table(name(freebi_tokens_contract), get_self().value);
auto freebi_iterator = freebi_table.begin();
if (freebi_iterator != freebi_table.end()) {
status_msg = status_msg + freebi_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// FREEOS
status_msg = status_msg + "\nFREEOS: ";
string freeos_tokens_contract = get_parameter(name("freebitokens"));
accounts freeos_table(name(freeos_tokens_contract), user.value);
auto freeos_iterator = freeos_table.begin();
if (freeos_iterator != freeos_table.end()) {
status_msg = status_msg + freeos_iterator->balance.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// supply POINT
status_msg = status_msg + "\nPOINT supply: ";
symbol point_sym = symbol(POINT_CURRENCY_CODE, 4);
stats point_stat_table(get_self(), point_sym.code().raw());
auto point_stat_iterator = point_stat_table.find(point_sym.code().raw());
if (point_stat_iterator != point_stat_table.end()) {
status_msg = status_msg + point_stat_iterator->supply.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// supply FREEBI
status_msg = status_msg + "\nFREEBI supply: ";
symbol freebi_sym = symbol(FREEBI_CURRENCY_CODE, 4);
stats freebi_stat_table(name(freebi_tokens_contract), freebi_sym.code().raw());
auto freebi_stat_iterator = freebi_stat_table.find(freebi_sym.code().raw());
if (freebi_stat_iterator != freebi_stat_table.end()) {
status_msg = status_msg + freebi_stat_iterator->supply.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// supply FREEOS
status_msg = status_msg + "\nFREEOS supply: ";
symbol freeos_sym = symbol(FREEOS_CURRENCY_CODE, 4);
stats freeos_stat_table(name(freeos_tokens_contract), freeos_sym.code().raw());
auto freeos_stat_iterator = freeos_stat_table.find(freeos_sym.code().raw());
if (freeos_stat_iterator != freeos_stat_table.end()) {
status_msg = status_msg + freeos_stat_iterator->supply.to_string() + ", ";
} else {
status_msg = status_msg + "None, ";
}
// Output
check(false, status_msg);
}
if (subaction == "user credit XPR") {
symbol xpr_sym = symbol(XPR_CURRENCY_CODE, 4);
credit_index credit_table(get_self(), user.value);
auto credit_iterator = credit_table.find(xpr_sym.code().raw());
check(credit_iterator != credit_table.end(), "credit record not found");
asset credit = credit_iterator->balance;
string credit_msg = "credit for " + user.to_string() + " = " + credit.to_string();
check(false, credit_msg);
}
if (subaction == "user credit FREEBI") {
symbol xpr_sym = symbol(FREEBI_CURRENCY_CODE, 4);
credit_index credit_table(get_self(), user.value);
auto credit_iterator = credit_table.find(xpr_sym.code().raw());
check(credit_iterator != credit_table.end(), "credit record not found");
asset credit = credit_iterator->balance;
string credit_msg = "credit for " + user.to_string() + " = " + credit.to_string();
check(false, credit_msg);
}
if (subaction == "clear user credit") {
credit_index credit_table(get_self(), user.value);
auto credit_iterator = credit_table.begin();
check(credit_iterator != credit_table.end(), "credit record not found");
credit_table.erase(credit_iterator);
}
if (subaction == "user credit function") {
refund_function(user);
}
if (subaction == "last reward") {
rewards_index rewards_table(get_self(), get_self().value);
auto reward_iterator = rewards_table.rbegin();
check(false, "latest reward is for iteration " + to_string(reward_iterator->iteration));
}
if (subaction == "clear participants") {
eraseuser("bigvern");
eraseuser("billbeaumont");
eraseuser("celiacollins");
eraseuser("deliadally");
eraseuser("dennisedolan");
eraseuser("smcpher1");
eraseuser("vennievans");
eraseuser("veronicavale");
eraseuser("verovera");
eraseuser("vickvindaloo");
eraseuser("vivcoleman");
eraseuser("vivvestin");
}
if (subaction == "migrate") {
// old users record
old_users_index old_users_table(get_self(), user.value);
auto old_user_iterator = old_users_table.begin();
check(old_user_iterator != old_users_table.end(), "user not found in old users table");
// new users table
participants_index participants_table(get_self(), user.value);
participants_table.emplace(
get_self(), [&](auto &p) {
p.account_type = old_user_iterator->account_type;
p.registered_iteration = old_user_iterator->registered_iteration;
p.issuances = old_user_iterator->issuances;
p.total_issuance_amount = old_user_iterator->total_issuance_amount;
p.votes = old_user_iterator->votes;
p.last_claim = old_user_iterator->last_claim;
});
}
if (subaction == "restore participants") {
createuser("bigvern", "v", 460614, 3, 6, 4, 3, 460691, asset(122788996, POINT_CURRENCY_SYMBOL));
createuser("billbeaumont", "e", 3216, 0, 0, 0, 0, 0, asset(0, POINT_CURRENCY_SYMBOL));
createuser("celiacollins", "e", 3216, 0, 0, 0, 0, 0, asset(0, POINT_CURRENCY_SYMBOL));
createuser("deliadally", "v", 460757, 0, 1, 0, 0, 0, asset(0, POINT_CURRENCY_SYMBOL));
createuser("dennisedolan", "e", 3216, 0, 0, 0, 0, 0, asset(0, POINT_CURRENCY_SYMBOL));
createuser("smcpher1", "v", 1529, 21, 19, 5, 1, 460942, asset(85760977, POINT_CURRENCY_SYMBOL));
createuser("vennievans", "e", 5690, 0, 0, 0, 1, 5711, asset(4404400, POINT_CURRENCY_SYMBOL));
createuser("veronicavale", "v", 460756, 4, 4, 4, 1, 460777, asset(96793509, POINT_CURRENCY_SYMBOL));
createuser("verovera", "v", 3673, 10, 15, 10, 13, 461088, asset(162375366, POINT_CURRENCY_SYMBOL));
createuser("vickvindaloo", "v", 5545, 0, 0, 0, 9, 459629, asset(23948788, POINT_CURRENCY_SYMBOL));
createuser("vivcoleman", "v", 1569, 0, 1, 0, 0, 0, asset(0, POINT_CURRENCY_SYMBOL));
createuser("vivvestin", "v", 3503, 5, 2, 1, 11, 459629, asset(29548929, POINT_CURRENCY_SYMBOL));