-
Notifications
You must be signed in to change notification settings - Fork 10
/
C_Main.py
1271 lines (1167 loc) · 105 KB
/
C_Main.py
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
#!/usr/bin/python3
#-----------------------------------
#---------- HELPFUL LINKS ----------
#-----------------------------------
# https://faucet.terra.money/
# https://terra.spec.finance/
# https://docs.spec.finance/
# https://github.com/spectrumprotocol/frontend/blob/11de02569898be54abc716b5a651cbf064865db5/src/app/consts/networks.ts
# https://terra.mirror.finance/
# https://docs.mirror.finance/
# https://finder.terra.money/
# https://terra-money.github.io/terra-sdk-python/
# https://docs.anchorprotocol.com/
# https://api.extraterrestrial.money/v1/api/prices
# https://assets.terra.money/cw20/tokens.json
# https://assets.terra.money/cw20/contracts.json
# Terra SDK
from terra_sdk.core.numeric import Dec
# Other assets
from assets.Notifications import Notifications
from assets.Other import Cooldown, Prettify
from assets.Logging import Logger
from assets.Terra import Terra
from assets.Queries import Queries
from assets.Transactions import Transaction
import B_Config as config
# Other imports
from datetime import datetime, timedelta, date
from time import time
from copy import deepcopy
from traceback import format_exc
# import traceback
import asyncio
Transaction_class, Queries_class, Cooldown_class, Logger_class, Terra_class, Prettify_class, Notifications_class = Transaction(), Queries(), Cooldown(), Logger(), Terra, Prettify(), Notifications()
default_logger, report_logger, report_array = Logger_class.default_logger, Logger_class.report_logger, Logger_class.report_array
async def main():
# Other assets
if config.Debug_mode: print(f'main() started.')
begin_time = time()
err = None
try:
tax_rate = Terra.terra.treasury.tax_rate()
cooldowns, \
Mirror_position_info, \
Anchor_borrow_info, \
all_rates,\
wallet_balance, \
general_estimated_tx_fee \
= await asyncio.gather(
Cooldown_class.read_cooldown(),
Queries_class.Mirror_get_position_info(),
Queries_class.Anchor_get_borrow_info(),
Queries_class.get_all_rates(),
Queries_class.get_wallet_balances(),
Queries_class.get_fee_estimation()
)
available_MIR_LP_token_for_withdrawal, \
available_ANC_LP_token_for_withdrawal, \
available_SPEC_LP_token_for_withdrawal, \
claimable_UST = 0, 0, 0, 0
general_estimated_tx_fee = Dec(general_estimated_tx_fee)
if wallet_balance['uusd'] < general_estimated_tx_fee:
report_logger.warning(f'[Script] YOU NEED TO ACT! Your wallet balance of {(wallet_balance["uusd"].__float__() / 1000000):.2f} UST is too low to execute any transaction.')
raise Exception
datetime_now = datetime.now()
status_update = False
action_dict = {'MIR' : 'none','SPEC' : 'none','ANC' : 'none', 'PSI' : 'none'}
claimable_MIR = claimable_SPEC = claimable_ANC = value_of_SPEC_LP_token =available_ANC_LP_token_for_withdrawal = value_of_ANC_LP_token = 0
wallet_balance_before = deepcopy(wallet_balance)
default_logger.debug(f'Wallet_balance_before: {Prettify_class.dict_value_convert_dec_to_float(wallet_balance_before, True)}')
# default_logger.debug(f'------------------------------------------\n'
# f'-------- WITHDRAW FROM LP SECTION --------\n'
# f'------------------------------------------\n')
# Check if the this section for the token is enabled
if config.MIR_withdraw_and_sell_if_min_price_is_reached:
if cooldowns.get('withdraw_MIR_from_pool') is None or cooldowns['withdraw_MIR_from_pool'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
available_MIR_LP_token_for_withdrawal = Queries_class.get_available_LP_token_for_withdrawal(Terra_class.mirrorFarm, Terra_class.MIR_token)
value_of_MIR_LP_token = all_rates['MIR-TOKEN-PER-SHARE'] * available_MIR_LP_token_for_withdrawal * all_rates['MIR']/1000000 \
+ all_rates['MIR-UST-PER-SHARE'] * available_MIR_LP_token_for_withdrawal
# Check if the min_price for the token has been matched
if (all_rates['MIR']/1000000) > config.MIR_min_price:
# Check if there are any LP for that token available
if available_MIR_LP_token_for_withdrawal > 0:
# Check if the min_withdrawal_limit is exceeded
if (value_of_MIR_LP_token/1000000) > config.MIR_min_total_value:
# Unstake / withdrawn LP
withdraw_MIR_from_pool_tx = Transaction_class.withdraw_MIR_from_pool(available_MIR_LP_token_for_withdrawal)
withdraw_MIR_from_pool_tx_status = Queries_class.get_status_of_tx(withdraw_MIR_from_pool_tx)
if withdraw_MIR_from_pool_tx_status == True:
default_logger.debug(f'[MIR LP Withdrawal] Success TX: {withdraw_MIR_from_pool_tx}')
report_logger.info(f'[MIR LP Withdrawal] MIR & UST have been withdrawn from the LP.')
# Mark for sell
action_dict['MIR'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[MIR LP Withdrawal] Failed TX: {withdraw_MIR_from_pool_tx}.\n'
f'[MIR LP Withdrawal] Reason: {withdraw_MIR_from_pool_tx_status}')
cooldowns['withdraw_MIR_from_pool'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[MIR LP Withdrawal] Skipped because withdrawable LP token value ({(value_of_MIR_LP_token.__float__()/1000000):.2f}) below limit ({config.MIR_min_total_value}).')
else:
default_logger.debug(f'[MIR LP Withdrawal] Skipped because no withdrawable LP token ({(available_MIR_LP_token_for_withdrawal.__float__()/1000000):.0f}).')
else:
default_logger.debug(f'[MIR LP Withdrawal] Skipped because minimum price of MIR ({config.MIR_min_price}) not exceeded ({(all_rates["MIR"].__float__()/1000000):.2f}).')
else:
report_logger.warning(f'[MIR LP Withdrawal] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[MIR LP Withdrawal] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["withdraw_MIR_from_pool"]}).')
else:
default_logger.debug(f'[MIR LP Withdrawal] Skipped because disabled by config ({config.MIR_withdraw_and_sell_if_min_price_is_reached}).')
# Check if the this section for the token is enabled
if config.SPEC_withdraw_and_sell_if_min_price_is_reached:
if cooldowns.get('withdraw_SPEC_from_pool') is None or cooldowns['withdraw_SPEC_from_pool'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
available_SPEC_LP_token_for_withdrawal = Queries_class.get_available_LP_token_for_withdrawal(Terra_class.specFarm, Terra_class.SPEC_token)
value_of_SPEC_LP_token = all_rates['SPEC-TOKEN-PER-SHARE'] * available_SPEC_LP_token_for_withdrawal * all_rates['SPEC']/1000000 \
+ all_rates['SPEC-UST-PER-SHARE'] * available_SPEC_LP_token_for_withdrawal
# Check if the min_price for the token has been matched
if (all_rates['SPEC']/1000000) > config.SPEC_min_price:
# Check if there are any LP for that token available
if available_SPEC_LP_token_for_withdrawal > 0:
# Check if the min_withdrawal_limit is exceeded
if (value_of_SPEC_LP_token/1000000) > config.SPEC_min_total_value:
# Unstake / withdrawn LP
withdraw_SPEC_from_pool_tx = Transaction_class.withdraw_SPEC_from_pool(available_SPEC_LP_token_for_withdrawal)
withdraw_SPEC_from_pool_tx_status = Queries_class.get_status_of_tx(withdraw_SPEC_from_pool_tx)
if withdraw_SPEC_from_pool_tx_status == True:
default_logger.debug(f'[SPEC LP Withdrawal] Success TX: {withdraw_SPEC_from_pool_tx}')
report_logger.info(f'[SPEC LP Withdrawal] SPEC & UST have been withdrawn from the LP.')
# Mark for sell
action_dict['SPEC'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[SPEC LP Withdrawal] Failed TX: {withdraw_SPEC_from_pool_tx}.\n'
f'[SPEC LP Withdrawal] Reason: {withdraw_SPEC_from_pool_tx_status}')
cooldowns['withdraw_SPEC_from_pool'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[SPEC LP Withdrawal] Skipped because withdrawable LP token value ({(value_of_SPEC_LP_token.__float__()/1000000):.2f}) below limit ({config.SPEC_min_total_value}).')
else:
default_logger.debug(f'[SPEC LP Withdrawal] Skipped because no withdrawable LP token ({(available_SPEC_LP_token_for_withdrawal.__float__()/1000000):.0f}).')
else:
default_logger.debug(f'[SPEC LP Withdrawal] Skipped because minimum price of SPEC ({config.SPEC_min_price}) not exceeded ({(all_rates["SPEC"].__float__()/1000000):.2f}).')
else:
report_logger.warning(f'[SPEC LP Withdrawal] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[SPEC LP Withdrawal] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["withdraw_SPEC_from_pool"]}).')
else:
default_logger.debug(f'[SPEC LP Withdrawal] Skipped because disabled by config ({config.SPEC_withdraw_and_sell_if_min_price_is_reached}).')
# Check if the this section for the token is enabled
if config.ANC_withdraw_and_sell_if_min_price_is_reached:
if cooldowns.get('withdraw_ANC_from_pool') is None or cooldowns['withdraw_ANC_from_pool'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
available_ANC_LP_token_for_withdrawal = Queries_class.get_available_LP_token_for_withdrawal(Terra_class.anchorFarm, Terra_class.ANC_token)
value_of_ANC_LP_token = all_rates['ANC-TOKEN-PER-SHARE'] * available_ANC_LP_token_for_withdrawal * all_rates['ANC']/1000000 \
+ all_rates['ANC-UST-PER-SHARE'] * available_ANC_LP_token_for_withdrawal
# Check if the min_price for the token has been matched
if (all_rates['ANC']/1000000) > config.ANC_min_price:
# Check if there are any LP for that token available
if available_ANC_LP_token_for_withdrawal > 0:
# Check if the min_withdrawal_limit is exceeded
if (value_of_ANC_LP_token/1000000) > config.ANC_min_total_value:
# Unstake / withdrawn LP
withdraw_ANC_from_pool_tx = Transaction_class.withdraw_ANC_from_pool(available_ANC_LP_token_for_withdrawal)
withdraw_ANC_from_pool_tx_status = Queries_class.get_status_of_tx(withdraw_ANC_from_pool_tx)
if withdraw_ANC_from_pool_tx_status == True:
default_logger.debug(f'[ANC LP Withdrawal] Success TX: {withdraw_ANC_from_pool_tx}')
report_logger.info(f'[ANC LP Withdrawal] ANC & UST have been withdrawn from the LP.')
# Mark for sell
action_dict['ANC'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[ANC LP Withdrawal] Failed TX: {withdraw_ANC_from_pool_tx}.\n'
f'[ANC LP Withdrawal] Reason: {withdraw_ANC_from_pool_tx_status}')
cooldowns['withdraw_ANC_from_pool'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[ANC LP Withdrawal] Skipped because withdrawable LP token value ({(value_of_ANC_LP_token.__float__()/1000000):.2f}) below limit ({config.ANC_min_total_value}).')
else:
default_logger.debug(f'[ANC LP Withdrawal] Skipped because no withdrawable LP token ({(available_ANC_LP_token_for_withdrawal.__float__()/1000000):.0f}).')
else:
default_logger.debug(f'[ANC LP Withdrawal] Skipped because minimum price of ANC ({config.ANC_min_price}) not exceeded ({(all_rates["ANC"].__float__()/1000000):.2f}).')
else:
report_logger.warning(f'[ANC LP Withdrawal] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[ANC LP Withdrawal] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["withdraw_ANC_from_pool"]}).')
else:
default_logger.debug(f'[ANC LP Withdrawal] Skipped because disabled by config ({config.ANC_withdraw_and_sell_if_min_price_is_reached}).')
# default_logger.debug(f'------------------------------------------\n'
# f'------------- CLAIM SECTION --------------\n'
# f'------------------------------------------\n')
# Mirror: Claim MIR
# Check if this section is enabled
if config.MIR_claim_and_sell_token or config.MIR_claim_and_deposit_in_LP:
if cooldowns.get('claim_MIR') is None or cooldowns['claim_MIR'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
claimable_MIR = Queries_class.get_claimable_MIR()
# Check if there is any token claimable
if claimable_MIR > 0:
value_of_MIR_claim = Queries_class.simulate_Token_Swap(claimable_MIR, Terra_class.Mirror_MIR_UST_Pair, Terra_class.MIR_token)
# Check if the amount claimable is bigger than the min_amount
if (value_of_MIR_claim/1000000) >= config.MIR_min_total_value:
# Check if the min_price for a sale has been matched
if config.MIR_claim_and_sell_token and (all_rates['MIR']/1000000) >= config.MIR_min_price:
# Claim MIR
claim_MIR_tx = Transaction_class.claim_MIR()
claim_MIR_tx_status = Queries_class.get_status_of_tx(claim_MIR_tx)
if claim_MIR_tx_status == True:
default_logger.debug(f'[MIR Claim] Success TX: {claim_MIR_tx}')
report_logger.info(f'[MIR Claim] {(claimable_MIR.__float__()/1000000):.2f} MIR have been claimed to be sold.')
# Mark for sale
action_dict['MIR'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[MIR Claim] Failed TX: {claim_MIR_tx}.\n'
f'[MIR Claim] Reason: {claim_MIR_tx_status}')
cooldowns['claim_MIR'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Check if deposit is enabled
elif config.MIR_claim_and_deposit_in_LP:
# Check if enough UST is available to actually deposit it later
UST_to_be_deposited_with_MIR = claimable_MIR * (all_rates['MIR']/1000000 + tax_rate)
if wallet_balance['uusd'] > UST_to_be_deposited_with_MIR:
# Claim and mark for deposit
claim_MIR_tx = Transaction_class.claim_MIR()
claim_MIR_tx_status = Queries_class.get_status_of_tx(claim_MIR_tx)
if claim_MIR_tx_status == True:
default_logger.debug(f'[MIR Claim] Success TX: {claim_MIR_tx}')
# Mark for deposit
action_dict['MIR'] = 'deposit'
report_logger.info(f'[MIR Claim] {(claimable_MIR.__float__()/1000000):.2f} MIR have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[MIR Claim] Failed TX: {claim_MIR_tx}.\n'
f'[MIR Claim] Reason: {claim_MIR_tx_status}')
cooldowns['claim_MIR'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Not enough UST in the wallet to deposit later. Check if allowed to take from Anchor Earn.
elif config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP:
# Check if enough in Anchor Earn to withdraw
if (wallet_balance['aUST'] * all_rates['aUST']/1000000 + wallet_balance['uusd']) > UST_to_be_deposited_with_MIR:
# Withdraw from Anchor Earn
claim_Anchor_withdraw_UST_from_Earn_tx = Transaction_class.Anchor_withdraw_UST_from_Earn(UST_to_be_deposited_with_MIR - wallet_balance['uusd'], 'uusd')
claim_Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(claim_Anchor_withdraw_UST_from_Earn_tx)
if claim_Anchor_withdraw_UST_from_Earn_tx_status:
# ! This can result in a withdraw from Anchor Earn three times (MIR, SPEC, ANC) if you balance is not enough. There is no cumulated withdraw.
report_logger.info(f'[MIR Claim] No enought UST balance to depoit later with MIR, so {(UST_to_be_deposited_with_MIR.__float__()/1000000 - wallet_balance["uusd"].__float__()/1000000):.2f} UST have been withdrawn to be deposited later with.')
# Claim and mark for deposit
claim_MIR_tx = Transaction_class.claim_MIR()
claim_MIR_tx_status = Queries_class.get_status_of_tx(claim_MIR_tx)
if claim_MIR_tx_status == True:
default_logger.debug(f'[MIR Claim] Success TX: {claim_MIR_tx}')
# Mark for deposit
action_dict['MIR'] = 'deposit'
report_logger.info(f'[MIR Claim] {(claimable_MIR.__float__()/1000000):.2f} MIR have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[MIR Claim] Failed TX: {claim_MIR_tx}.\n'
f'[MIR Claim] Reason: {claim_MIR_tx_status}')
cooldowns['claim_MIR'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[MIR Claim] Failed TX: {claim_Anchor_withdraw_UST_from_Earn_tx}.\n'
f'[MIR Claim] Reason: {claim_Anchor_withdraw_UST_from_Earn_tx_status}')
cooldowns['Anchor_withdraw_UST_from_Earn'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[MIR Claim] Skipped because not enough UST/aUST ({(wallet_balance["uusd"].__float__() / 1000000):.2f})/({(wallet_balance["aUST"].__float__() / 1000000):.2f} in wallet to be deposited with MIR later.')
else:
report_logger.warning(f'[MIR Claim] Skipped because not enough UST ({(wallet_balance["uusd"].__float__() / 1000000):.2f}) in wallet to be deposited with MIR later and not enabled to withdraw from Anchor Earn ({config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP}).')
else:
default_logger.debug(f'[MIR Claim] Minimum price ({config.MIR_min_price}) not exceeded for sale ({(all_rates["MIR"].__float__()/1000000):.2f}) and a deposit is not enabled ({config.MIR_claim_and_deposit_in_LP}).')
else:
default_logger.debug(f'[MIR Claim] Skipped because claimable MIR value ({(value_of_MIR_claim.__float__()/1000000):.2f}) below limit ({config.MIR_min_total_value}).')
else:
default_logger.debug(f'[MIR Claim] Skipped because no claimable MIR ({(claimable_MIR.__float__()/1000000):.0f}).')
else:
report_logger.warning(f'[MIR Claim] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[MIR Claim] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["claim_MIR"]}).')
else:
default_logger.debug(f'[MIR Claim] Skipped because disabled by config ({config.MIR_claim_and_sell_token}).')
# Spectrum: Claim SPEC
# Check if this section is enabled
if config.SPEC_claim_and_sell_token or config.SPEC_claim_and_deposit_in_LP:
if cooldowns.get('claim_SPEC') is None or cooldowns['claim_SPEC'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
claimable_SPEC_list = await Queries_class.get_claimable_SPEC()
claimable_SPEC = claimable_SPEC_list[0]
# Check if there is any token claimable
if claimable_SPEC > 0:
value_of_SPEC_claim = Queries_class.simulate_Token_Swap(claimable_SPEC, Terra_class.Spectrum_SPEC_UST_Pair, Terra_class.SPEC_token)
# Check if the amount claimable is bigger than the min_amount
if (value_of_SPEC_claim/1000000) >= config.SPEC_min_total_value:
# Check if the min_price for a sale has been matched
if config.SPEC_claim_and_sell_token and (all_rates['SPEC']/1000000) >= config.SPEC_min_price:
# Claim SPEC
claim_SPEC_tx = Transaction_class.claim_SPEC(claimable_SPEC_list)
claim_SPEC_tx_status = Queries_class.get_status_of_tx(claim_SPEC_tx)
if claim_SPEC_tx_status == True:
default_logger.debug(f'[SPEC Claim] Success TX: {claim_SPEC_tx}')
report_logger.info(f'[SPEC Claim] {(claimable_SPEC.__float__()/1000000):.2f} SPEC have been claimed to be sold.')
# Mark for sale
action_dict['SPEC'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[SPEC Claim] Failed TX: {claim_SPEC_tx}.\n'
f'[SPEC Claim] Reason: {claim_SPEC_tx_status}')
cooldowns['claim_SPEC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Check if deposit is enabled
elif config.SPEC_claim_and_deposit_in_LP:
# Check if enough UST is available to actually deposit it later
UST_to_be_deposited_with_SPEC = claimable_SPEC * (all_rates['SPEC']/1000000 + tax_rate)
if wallet_balance['uusd'] > UST_to_be_deposited_with_SPEC:
# Claim and mark for deposit
claim_SPEC_tx = Transaction_class.claim_SPEC(claimable_SPEC_list)
claim_SPEC_tx_status = Queries_class.get_status_of_tx(claim_SPEC_tx)
if claim_SPEC_tx_status == True:
default_logger.debug(f'[SPEC Claim] Success TX: {claim_SPEC_tx}')
# Mark for deposit
action_dict['SPEC'] = 'deposit'
report_logger.info(f'[SPEC Claim] {(claimable_SPEC.__float__()/1000000):.2f} SPEC have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[SPEC Claim] Failed TX: {claim_SPEC_tx}.\n'
f'[SPEC Claim] Reason: {claim_SPEC_tx_status}')
cooldowns['claim_SPEC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Not enough UST in the wallet to deposit later. Check if allowed to take from Anchor Earn.
elif config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP:
# Check if enough in Anchor Earn to withdraw
if (wallet_balance['aUST'] * all_rates['aUST']/1000000 + wallet_balance['uusd'])> UST_to_be_deposited_with_SPEC:
# Withdraw from Anchor Earn
claim_Anchor_withdraw_UST_from_Earn_tx = Transaction_class.Anchor_withdraw_UST_from_Earn(UST_to_be_deposited_with_SPEC - wallet_balance['uusd'], 'uusd')
claim_Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(claim_Anchor_withdraw_UST_from_Earn_tx)
if claim_Anchor_withdraw_UST_from_Earn_tx_status:
# ! This can result in a withdraw from Anchor Earn three times (MIR, SPEC, ANC) if you balance is not enough. There is no cumulated withdraw.
report_logger.info(f'[SPEC Claim] No enought UST balance to depoit later with SPEC, so {(UST_to_be_deposited_with_SPEC.__float__()/1000000 - wallet_balance["uusd"].__float__()/1000000):.2f} UST have been withdrawn to be deposited later with.')
# Claim and mark for deposit
claim_SPEC_tx = Transaction_class.claim_SPEC(claimable_SPEC_list)
claim_SPEC_tx_status = Queries_class.get_status_of_tx(claim_SPEC_tx)
if claim_SPEC_tx_status == True:
default_logger.debug(f'[SPEC Claim] Success TX: {claim_SPEC_tx}')
# Mark for deposit
action_dict['SPEC'] = 'deposit'
report_logger.info(f'[SPEC Claim] {(claimable_SPEC.__float__()/1000000):.2f} SPEC have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[SPEC Claim] Failed TX: {claim_SPEC_tx}.\n'
f'[SPEC Claim] Reason: {claim_SPEC_tx_status}')
cooldowns['claim_SPEC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[SPEC Claim] Failed TX: {claim_Anchor_withdraw_UST_from_Earn_tx}.\n'
f'[SPEC Claim] Reason: {claim_Anchor_withdraw_UST_from_Earn_tx_status}')
cooldowns['Anchor_withdraw_UST_from_Earn'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[SPEC Claim] Skipped because not enough UST/aUST ({(wallet_balance["uusd"].__float__() / 1000000):.2f})/({(wallet_balance["aUST"].__float__() / 1000000):.2f} in wallet to be deposited with SPEC later.')
else:
report_logger.warning(f'[SPEC Claim] Skipped because not enough UST ({(wallet_balance["uusd"].__float__() / 1000000):.2f}) in wallet to be deposited with SPEC later and not enabled to withdraw from Anchor Earn ({config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP}).')
else:
default_logger.debug(f'[SPEC Claim] Minimum price ({config.SPEC_min_price}) not exceeded for sale ({(all_rates["SPEC"].__float__()/1000000):.2f}) and a deposit is not enabled ({config.SPEC_claim_and_deposit_in_LP}).')
else:
default_logger.debug(f'[SPEC Claim] Skipped because claimable SPEC value ({(value_of_SPEC_claim.__float__()/1000000):.2f}) below limit ({config.SPEC_min_total_value}).')
else:
default_logger.debug(f'[SPEC Claim] Skipped because no claimable SPEC ({(claimable_SPEC.__float__()/1000000):.0f}).')
else:
report_logger.warning(f'[SPEC Claim] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[SPEC Claim] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["claim_SPEC"]}).')
else:
default_logger.debug(f'[SPEC Claim] Skipped because disabled by config ({config.SPEC_claim_and_sell_token}).')
# Anchor: Claim ANC
# Check if this section is enabled
if config.ANC_claim_and_sell_token or config.ANC_claim_and_deposit_in_LP:
if cooldowns.get('claim_ANC') is None or cooldowns['claim_ANC'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
claimable_ANC = await Queries_class.get_claimable_ANC()
# Check if there is any token claimable
if claimable_ANC > 0:
value_of_ANC_claim = Queries_class.simulate_Token_Swap(claimable_ANC, Terra_class.Terraswap_ANC_UST_Pair, Terra_class.ANC_token)
# Check if the amount claimable is bigger than the min_amount
if (value_of_ANC_claim/1000000) >= config.ANC_min_total_value:
# Check if the min_price for a sale has been matched
if config.ANC_claim_and_sell_token and (all_rates['ANC']/1000000) >= config.ANC_min_price:
# Claim ANC
claim_ANC_tx = Transaction_class.claim_ANC()
claim_ANC_tx_status = Queries_class.get_status_of_tx(claim_ANC_tx)
if claim_ANC_tx_status == True:
default_logger.debug(f'[ANC Claim] Success TX: {claim_ANC_tx}')
report_logger.info(f'[ANC Claim] {(claimable_ANC.__float__()/1000000):.2f} ANC have been claimed to be sold.')
# Mark for sale
action_dict['ANC'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[ANC Claim] Failed TX: {claim_ANC_tx}.\n'
f'[ANC Claim] Reason: {claim_ANC_tx_status}')
cooldowns['claim_ANC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Check if deposit is enabled
elif config.ANC_claim_and_deposit_in_LP:
# Check if enough UST is available to actually deposit it later
UST_to_be_deposited_with_ANC = claimable_ANC * (all_rates['ANC']/1000000 + tax_rate)
if wallet_balance['uusd'] > UST_to_be_deposited_with_ANC:
# Claim and mark for deposit
claim_ANC_tx = Transaction_class.claim_ANC()
claim_ANC_tx_status = Queries_class.get_status_of_tx(claim_ANC_tx)
if claim_ANC_tx_status == True:
default_logger.debug(f'[ANC Claim] Success TX: {claim_ANC_tx}')
# Mark for deposit
action_dict['ANC'] = 'deposit'
report_logger.info(f'[ANC Claim] {(claimable_ANC.__float__()/1000000):.2f} ANC have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[ANC Claim] Failed TX: {claim_ANC_tx}.\n'
f'[ANC Claim] Reason: {claim_ANC_tx_status}')
cooldowns['claim_ANC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Not enough UST in the wallet to deposit later. Check if allowed to take from Anchor Earn.
elif config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP:
# Check if enough in Anchor Earn to withdraw
if (wallet_balance['aUST'] * all_rates['aUST']/1000000 + wallet_balance['uusd']) > UST_to_be_deposited_with_ANC:
# Withdraw from Anchor Earn
claim_Anchor_withdraw_UST_from_Earn_tx = Transaction_class.Anchor_withdraw_UST_from_Earn(UST_to_be_deposited_with_ANC - wallet_balance['uusd'], 'uusd')
claim_Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(claim_Anchor_withdraw_UST_from_Earn_tx)
if claim_Anchor_withdraw_UST_from_Earn_tx_status:
# ! This can result in a withdraw from Anchor Earn three times (MIR, SPEC, ANC) if you balance is not enough. There is no cumulated withdraw.
report_logger.info(f'[ANC Claim] No enought UST balance to depoit later with ANC, so {(UST_to_be_deposited_with_ANC.__float__()/1000000 - wallet_balance["uusd"].__float__()/1000000):.2f} UST have been withdrawn to be deposited later with.')
# Claim and mark for deposit
claim_ANC_tx = Transaction_class.claim_ANC()
claim_ANC_tx_status = Queries_class.get_status_of_tx(claim_ANC_tx)
if claim_ANC_tx_status == True:
default_logger.debug(f'[ANC Claim] Success TX: {claim_ANC_tx}')
# Mark for deposit
action_dict['ANC'] = 'deposit'
report_logger.info(f'[ANC Claim] {(claimable_ANC.__float__()/1000000):.2f} ANC have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[ANC Claim] Failed TX: {claim_ANC_tx}.\n'
f'[ANC Claim] Reason: {claim_ANC_tx_status}')
cooldowns['claim_ANC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[ANC Claim] Failed TX: {claim_Anchor_withdraw_UST_from_Earn_tx}.\n'
f'[ANC Claim] Reason: {claim_Anchor_withdraw_UST_from_Earn_tx_status}')
cooldowns['Anchor_withdraw_UST_from_Earn'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[ANC Claim] Skipped because not enough UST/aUST ({(wallet_balance["uusd"].__float__() / 1000000):.2f})/({(wallet_balance["aUST"].__float__() / 1000000):.2f} in wallet to be deposited with ANC later.')
else:
report_logger.warning(f'[ANC Claim] Skipped because not enough UST ({(wallet_balance["uusd"].__float__() / 1000000):.2f}) in wallet to be deposited with ANC later and not enabled to withdraw from Anchor Earn ({config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP}).')
else:
default_logger.debug(f'[ANC Claim] Minimum price ({config.ANC_min_price}) not exceeded for sale ({(all_rates["ANC"].__float__()/1000000):.2f}) and a deposit is not enabled ({config.ANC_claim_and_deposit_in_LP}).')
else:
default_logger.debug(f'[ANC Claim] Skipped because claimable ANC value ({(value_of_ANC_claim.__float__()/1000000):.2f}) below limit ({config.ANC_min_total_value}).')
else:
default_logger.debug(f'[ANC Claim] Skipped because no claimable ANC ({(claimable_ANC.__float__()/1000000):.0f}).')
else:
report_logger.warning(f'[ANC Claim] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[ANC Claim] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["claim_ANC"]}).')
else:
default_logger.debug(f'[ANC Claim] Skipped because disabled by config ({config.ANC_claim_and_sell_token}).')
# Nexus: Claim PSI
# Check if this section is enabled
if config.PSI_claim_and_sell_token or config.PSI_claim_and_deposit_in_LP:
if cooldowns.get('claim_PSI') is None or cooldowns['claim_PSI'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
claimable_PSI = await Queries_class.get_claimable_PSI()
# Check if there is any token claimable
if claimable_PSI > 0:
value_of_PSI_claim = Queries_class.simulate_Token_Swap(claimable_PSI, Terra_class.Nexus_PSI_UST_Pair, Terra_class.PSI_token)
# Check if the amount claimable is bigger than the min_amount
if (value_of_PSI_claim/1000000) >= config.PSI_min_total_value:
# Check if the min_price for a sale has been matched
if config.PSI_claim_and_sell_token and (all_rates['PSI']/1000000) >= config.PSI_min_price:
# Claim PSI
claim_PSI_tx = Transaction_class.claim_PSI()
claim_PSI_tx_status = Queries_class.get_status_of_tx(claim_PSI_tx)
if claim_PSI_tx_status == True:
default_logger.debug(f'[PSI Claim] Success TX: {claim_PSI_tx}')
report_logger.info(f'[PSI Claim] {(claimable_PSI.__float__()/1000000):.2f} PSI have been claimed to be sold.')
# Mark for sale
action_dict['PSI'] = 'sell'
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[PSI Claim] Failed TX: {claim_PSI_tx}.\n'
f'[PSI Claim] Reason: {claim_PSI_tx_status}')
cooldowns['claim_PSI'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Check if deposit is enabled
elif config.PSI_claim_and_deposit_in_LP:
# Check if enough UST is available to actually deposit it later
UST_to_be_deposited_with_PSI = claimable_PSI * (all_rates['PSI']/1000000 + tax_rate)
if wallet_balance['uusd'] > UST_to_be_deposited_with_PSI:
# Claim and mark for deposit
claim_PSI_tx = Transaction_class.claim_PSI()
claim_PSI_tx_status = Queries_class.get_status_of_tx(claim_PSI_tx)
if claim_PSI_tx_status == True:
default_logger.debug(f'[PSI Claim] Success TX: {claim_PSI_tx}')
# Mark for deposit
action_dict['PSI'] = 'deposit'
report_logger.info(f'[PSI Claim] {(claimable_PSI.__float__()/1000000):.2f} PSI have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[PSI Claim] Failed TX: {claim_PSI_tx}.\n'
f'[PSI Claim] Reason: {claim_PSI_tx_status}')
cooldowns['claim_PSI'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Not enough UST in the wallet to deposit later. Check if allowed to take from Anchor Earn.
elif config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP:
# Check if enough in Anchor Earn to withdraw
if (wallet_balance['aUST'] * all_rates['aUST']/1000000 + wallet_balance['uusd']) > UST_to_be_deposited_with_PSI:
# Withdraw from Anchor Earn
claim_Anchor_withdraw_UST_from_Earn_tx = Transaction_class.Anchor_withdraw_UST_from_Earn(UST_to_be_deposited_with_PSI - wallet_balance['uusd'], 'uusd')
claim_Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(claim_Anchor_withdraw_UST_from_Earn_tx)
if claim_Anchor_withdraw_UST_from_Earn_tx_status:
# ! This can result in a withdraw from Anchor Earn three times (MIR, SPEC, ANC, PSI) if you balance is not enough. There is no cumulated withdraw.
report_logger.info(f'[PSI Claim] No enought UST balance to depoit later with PSI, so {(UST_to_be_deposited_with_ANC.__float__()/1000000 - wallet_balance["uusd"].__float__()/1000000):.2f} UST have been withdrawn to be deposited later with.')
# Claim and mark for deposit
claim_PSI_tx = Transaction_class.claim_PSI()
claim_PSI_tx_status = Queries_class.get_status_of_tx(claim_PSI_tx)
if claim_PSI_tx_status == True:
default_logger.debug(f'[PSI Claim] Success TX: {claim_PSI_tx}')
# Mark for deposit
action_dict['PSI'] = 'deposit'
report_logger.info(f'[PSI Claim] {(claimable_PSI.__float__()/1000000):.2f} PSI have been claimed to be deposited.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[PSI Claim] Failed TX: {claim_PSI_tx}.\n'
f'[PSI Claim] Reason: {claim_PSI_tx_status}')
cooldowns['claim_PSI'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[PSI Claim] Failed TX: {claim_Anchor_withdraw_UST_from_Earn_tx}.\n'
f'[PSI Claim] Reason: {claim_Anchor_withdraw_UST_from_Earn_tx_status}')
cooldowns['Anchor_withdraw_UST_from_Earn'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[PSI Claim] Skipped because not enough UST/aUST ({(wallet_balance["uusd"].__float__() / 1000000):.2f})/({(wallet_balance["aUST"].__float__() / 1000000):.2f} in wallet to be deposited with ANC later.')
else:
report_logger.warning(f'[PSI Claim] Skipped because not enough UST ({(wallet_balance["uusd"].__float__() / 1000000):.2f}) in wallet to be deposited with ANC later and not enabled to withdraw from Anchor Earn ({config.Anchor_enable_withdraw_from_Anchor_Earn_to_deposit_in_LP}).')
else:
default_logger.debug(f'[PSI Claim] Minimum price ({config.PSI_min_price}) not exceeded for sale ({(all_rates["ANC"].__float__()/1000000):.2f}) and a deposit is not enabled ({config.ANC_claim_and_deposit_in_LP}).')
else:
default_logger.debug(f'[PSI Claim] Skipped because claimable PSI value ({(value_of_PSI_claim.__float__()/1000000):.2f}) below limit ({config.PSI_min_total_value}).')
else:
default_logger.debug(f'[PSI Claim] Skipped because no claimable PSI ({(claimable_PSI.__float__()/1000000):.0f}).')
else:
report_logger.warning(f'[PSI Claim] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[PSI Claim] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["claim_PSI"]}).')
else:
default_logger.debug(f'[PSI Claim] Skipped because disabled by config ({config.PSI_claim_and_sell_token}).')
# Mirror: Claim un-locked UST
# Check if this section is enabled
if config.Mirror_claim_unlocked_UST:
if cooldowns.get('Mirror_claim_unlocked_UST') is None or cooldowns['Mirror_claim_unlocked_UST'] <= datetime_now:
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
claimable_UST = Queries_class.Mirror_get_claimable_UST(Mirror_position_info)
# Check if there is any token claimable
if claimable_UST > 0:
# Check if the amount claimable is bigger than the min_amount
if (claimable_UST/1000000) > config.Mirror_min_amount_UST_to_claim:
# Claim UST
Mirror_claim_unlocked_UST_tx = Transaction_class.Mirror_claim_unlocked_UST(Mirror_position_info)
Mirror_claim_unlocked_UST_tx_status = Queries_class.get_status_of_tx(Mirror_claim_unlocked_UST_tx)
if Mirror_claim_unlocked_UST_tx_status == True:
default_logger.debug(f'[Mirror Claim UST] Success TX: {Mirror_claim_unlocked_UST_tx}')
report_logger.info(f'[Mirror Claim UST] {(claimable_UST.__float__()/1000000):.2f} UST have been claimed from your Mirror Shorts.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[Mirror Claim UST] Failed TX: {Mirror_claim_unlocked_UST_tx}.\n'
f'[Mirror Claim UST] Reason: {Mirror_claim_unlocked_UST_tx_status}')
cooldowns['Mirror_claim_unlocked_UST'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[Mirror Claim UST] Skipped because claimable UST amount ({(claimable_UST.__float__()/1000000):.0f}) below limit ({config.Mirror_min_amount_UST_to_claim}).')
else:
default_logger.debug(f'[Mirror Claim UST] Skipped because no UST to claim ({(claimable_UST.__float__()/1000000):.0f}).')
else:
report_logger.warning(f'[Mirror Claim UST] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[Mirror Claim UST] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["Mirror_claim_unlocked_UST"]}).')
else:
default_logger.debug(
f'[Mirror Claim UST] Skipped because disabled by config ({config.Mirror_claim_unlocked_UST}) or insufficent funds ({(wallet_balance["uusd"].__float__()/1000000 - general_estimated_tx_fee.__float__()/1000000):.2f}).')
# default_logger.debug(f'---------------------------------------\n'
# f'------------ SELL SECTION -------------\n'
# f'---------------------------------------\n')
wallet_balance['MIR'], \
wallet_balance['SPEC'], \
wallet_balance['ANC'], \
wallet_balance['PSI'] \
= await asyncio.gather(
Queries_class.get_non_native_balance(Terra_class.MIR_token),
Queries_class.get_non_native_balance(Terra_class.SPEC_token),
Queries_class.get_non_native_balance(Terra_class.ANC_token),
Queries_class.get_non_native_balance(Terra_class.PSI_token)
)
# Check if section is enabled
if config.MIR_claim_and_sell_token:
if cooldowns.get('sell_MIR') is None or cooldowns['sell_MIR'] <= datetime_now:
if action_dict['MIR'] == 'sell':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to sell
default_logger.debug(f'[MIR Sell] Updated MIR balance {(wallet_balance["MIR"].__float__()/1000000)}')
MIR_to_be_sold = wallet_balance['MIR'] - wallet_balance_before['MIR']
if MIR_to_be_sold > 0:
# Price and min_value has been checked before therefore sell
sell_MIR_tx = Transaction_class.sell_MIR(MIR_to_be_sold)
sell_MIR_tx_status = Queries_class.get_status_of_tx(sell_MIR_tx)
if sell_MIR_tx_status == True:
default_logger.debug(f'[MIR Sell] Success TX: {sell_MIR_tx}')
report_logger.info(f'[MIR Sell] {(MIR_to_be_sold.__float__()/1000000):.2f} MIR have been sold for {(MIR_to_be_sold.__float__()/1000000 * all_rates["MIR"].__float__()/1000000):.2f} UST total.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[MIR Sell] Failed TX: {sell_MIR_tx}.\n'
f'[MIR Sell] Reason: {sell_MIR_tx_status}')
cooldowns['sell_MIR'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[MIR Sell] Skipped because no MIR ({(MIR_to_be_sold.__float__()/1000000):.0f}) to sell.')
else:
report_logger.warning(f'[MIR Sell] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[MIR Sell] Skipped because no MIR marked to be sold ({action_dict["MIR"]}).')
else:
default_logger.debug(f'[MIR Sell] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["sell_MIR"]}).')
else:
default_logger.debug(f'[MIR Sell] Skipped because disabled by config ({config.MIR_claim_and_sell_token}).')
# Check if section is enabled
if config.SPEC_claim_and_sell_token:
if cooldowns.get('sell_SPEC') is None or cooldowns['sell_SPEC'] <= datetime_now:
if action_dict['SPEC'] == 'sell':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to sell
default_logger.debug(f'[SPEC Sell] Updated SPEC balance {(wallet_balance["SPEC"].__float__()/1000000)}')
SPEC_to_be_sold = wallet_balance['SPEC'] - wallet_balance_before['SPEC']
if SPEC_to_be_sold > 0:
# Price and min_value has been checked before therefore sell
sell_SPEC_tx = Transaction_class.sell_SPEC(SPEC_to_be_sold)
sell_SPEC_tx_status = Queries_class.get_status_of_tx(sell_SPEC_tx)
if sell_SPEC_tx_status == True:
default_logger.debug(f'[SPEC Sell] Success TX: {sell_SPEC_tx}')
report_logger.info(f'[SPEC Sell] {(SPEC_to_be_sold.__float__()/1000000):.2f} SPEC have been sold for {(SPEC_to_be_sold.__float__() / 1000000 * all_rates["SPEC"].__float__()/1000000):.2f} UST total.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[SPEC Sell] Failed TX: {sell_SPEC_tx}.\n'
f'[SPEC Sell] Reason: {sell_SPEC_tx_status}')
cooldowns['sell_SPEC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[SPEC Sell] Skipped because no SPEC ({(SPEC_to_be_sold.__float__()/1000000):.0f}) to sell.')
else:
report_logger.warning(f'[SPEC Sell] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[SPEC Sell] Skipped because no SPEC marked to be sold ({action_dict["SPEC"]}).')
else:
default_logger.debug(f'[SPEC Sell] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["sell_SPEC"]}).')
else:
default_logger.debug(f'[SPEC Sell] Skipped because disabled by config ({config.SPEC_claim_and_sell_token}).')
# Check if section is enabled
if config.ANC_claim_and_sell_token:
if cooldowns.get('sell_ANC') is None or cooldowns['sell_ANC'] <= datetime_now:
if action_dict['ANC'] == 'sell':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to sell
default_logger.debug(f'[ANC Sell] Updated ANC balance {(wallet_balance["ANC"].__float__()/1000000)}')
ANC_to_be_sold = wallet_balance['ANC'] - wallet_balance_before['ANC']
if ANC_to_be_sold > 0:
# Price and min_value has been checked before therefore sell
sell_ANC_tx = Transaction_class.sell_ANC(ANC_to_be_sold)
sell_ANC_tx_status = Queries_class.get_status_of_tx(sell_ANC_tx)
if sell_ANC_tx_status == True:
default_logger.debug(f'[ANC Sell] Success TX: {sell_ANC_tx}')
report_logger.info(f'[ANC Sell] {(ANC_to_be_sold.__float__()/1000000):.2f} ANC have been sold for {(ANC_to_be_sold.__float__()/1000000 * all_rates["ANC"].__float__()/1000000):.2f} UST total.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[ANC Sell] Failed TX: {sell_ANC_tx}.\n'
f'[ANC Sell] Reason: {sell_ANC_tx_status}')
cooldowns['sell_ANC'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[ANC Sell] Skipped because no ANC ({(ANC_to_be_sold.__float__()/1000000):.0f}) to sell.')
else:
report_logger.warning(f'[ANC Sell] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[ANC Sell] Skipped because no ANC marked to be sold ({action_dict["ANC"]}).')
else:
default_logger.debug(f'[ANC Sell] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["sell_ANC"]}).')
else:
default_logger.debug(f'[ANC Sell] Skipped because disabled by config ({config.ANC_claim_and_sell_token}).')
# Check if section is enabled
if config.PSI_claim_and_sell_token:
if cooldowns.get('sell_PSI') is None or cooldowns['sell_PSI'] <= datetime_now:
if action_dict['PSI'] == 'sell':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to sell
default_logger.debug(f'[PSI Sell] Updated PSI balance {(wallet_balance["PSI"].__float__()/1000000)}')
PSI_to_be_sold = wallet_balance['PSI'] - wallet_balance_before['PSI']
if PSI_to_be_sold > 0:
# Price and min_value has been checked before therefore sell
sell_PSI_tx = Transaction_class.sell_PSI(PSI_to_be_sold)
sell_PSI_tx_status = Queries_class.get_status_of_tx(sell_PSI_tx)
if sell_PSI_tx_status == True:
default_logger.debug(f'[PSI Sell] Success TX: {sell_PSI_tx}')
report_logger.info(f'[PSI Sell] {(PSI_to_be_sold.__float__()/1000000):.2f} PSI have been sold for {(PSI_to_be_sold.__float__() / 1000000 * all_rates["PSI"].__float__()/1000000):.2f} UST total.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[PSI Sell] Failed TX: {sell_PSI_tx}.\n'
f'[PSI Sell] Reason: {sell_PSI_tx_status}')
cooldowns['sell_PSI'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[PSI Sell] Skipped because no PSI ({(PSI_to_be_sold.__float__()/1000000):.0f}) to sell.')
else:
report_logger.warning(f'[PSI Sell] Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[PSI Sell] Skipped because no PSI marked to be sold ({action_dict["PSI"]}).')
else:
default_logger.debug(f'[PSI Sell] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["sell_PSI"]}).')
else:
default_logger.debug(f'[PSI Sell] Skipped because disabled by config ({config.PSI_claim_and_sell_token}).')
# default_logger.debug(f'------------------------------------------\n'
# f'------------ DEPOSIT SECTION -------------\n'
# f'------------------------------------------\n')
# Check if this section is enabled
if config.MIR_claim_and_deposit_in_LP:
if cooldowns.get('deposit_MIR_in_pool') is None or cooldowns['deposit_MIR_in_pool'] <= datetime_now:
if action_dict['MIR'] == 'deposit':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to deposit
MIR_to_be_deposited = wallet_balance['MIR'] - wallet_balance_before['MIR']
if MIR_to_be_deposited > 0:
# Price and min_value has been checked before therefore deposit
UST_to_be_deposited_with_MIR = MIR_to_be_deposited * (all_rates['MIR']/1000000 + tax_rate)
deposit_MIR_tx = Transaction_class.deposit_MIR_in_pool(MIR_to_be_deposited, UST_to_be_deposited_with_MIR)
deposit_MIR_tx_status = Queries_class.get_status_of_tx(deposit_MIR_tx)
if deposit_MIR_tx_status == True:
default_logger.debug(f'[MIR LP Deposit] Success TX: {deposit_MIR_tx}')
report_logger.info(f'[MIR LP Deposit] {(MIR_to_be_deposited.__float__()/1000000):.2f} MIR and {(UST_to_be_deposited_with_MIR.__float__()/1000000):.2f} UST have been deposited to LP.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[MIR LP Deposit] Failed TX: {deposit_MIR_tx}.\n'
f'[MIR LP Deposit] Reason: {deposit_MIR_tx_status}')
cooldowns['deposit_MIR_in_pool'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[MIR LP Deposit] Skipped because no MIR ({(MIR_to_be_deposited.__float__()/1000000):.0f}) to deposit.')
else:
report_logger.warning(f'[MIR LP Deposit] YOU NEED TO ACT! Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[MIR LP Deposit] Skipped because no MIR marked to deposited ({action_dict["MIR"]}).')
else:
default_logger.debug(f'[MIR LP Deposit] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["deposit_MIR_in_pool"]}).')
else:
default_logger.debug(f'[MIR LP Deposit] Skipped because disabled by config ({config.MIR_claim_and_deposit_in_LP}).')
# Check if this section is enabled
if config.SPEC_claim_and_deposit_in_LP:
if cooldowns.get('deposit_SPEC_in_pool') is None or cooldowns['deposit_SPEC_in_pool'] <= datetime_now:
if action_dict['SPEC'] == 'deposit':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to deposit
SPEC_to_be_deposited = wallet_balance['SPEC'] - wallet_balance_before['SPEC']
if SPEC_to_be_deposited > 0:
# Price and min_value has been checked before therefore deposit
UST_to_be_deposited_with_SPEC = SPEC_to_be_deposited * (all_rates['SPEC']/1000000 + tax_rate)
deposit_SPEC_tx = Transaction_class.deposit_SPEC_in_pool(SPEC_to_be_deposited, UST_to_be_deposited_with_SPEC)
deposit_SPEC_tx_status = Queries_class.get_status_of_tx(deposit_SPEC_tx)
if deposit_SPEC_tx_status == True:
default_logger.debug(f'[SPEC LP Deposit] Success TX: {deposit_SPEC_tx}')
report_logger.info(f'[SPEC LP Deposit] {(SPEC_to_be_deposited.__float__()/1000000):.2f} SPEC and {(UST_to_be_deposited_with_SPEC.__float__()/1000000):.2f} UST have been deposited to LP.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[SPEC LP Deposit] Failed TX: {deposit_SPEC_tx}.\n'
f'[SPEC LP Deposit] Reason: {deposit_SPEC_tx_status}')
cooldowns['deposit_SPEC_in_pool'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[SPEC LP Deposit] Skipped because no SPEC ({(SPEC_to_be_deposited.__float__()/1000000):.0f}) to deposit.')
else:
report_logger.warning(f'[SPEC LP Deposit] YOU NEED TO ACT! Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[SPEC LP Deposit] Skipped because no SPEC marked to deposited ({action_dict["SPEC"]}).')
else:
default_logger.debug(f'[SPEC LP Deposit] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["deposit_SPEC_in_pool"]}).')
else:
default_logger.debug(f'[SPEC LP Deposit] Skipped because disabled by config ({config.SPEC_claim_and_deposit_in_LP}).')
# Check if this section is enabled
if config.ANC_claim_and_deposit_in_LP:
if cooldowns.get('deposit_ANC_in_pool') is None or cooldowns['deposit_ANC_in_pool'] <= datetime_now:
if action_dict['ANC'] == 'deposit':
# Check if there is enough UST balance in the wallet to pay the transaction fees
if wallet_balance['uusd'] > general_estimated_tx_fee:
# Check if there is any token to deposit
ANC_to_be_deposited = wallet_balance['ANC'] - wallet_balance_before['ANC']
if ANC_to_be_deposited > 0:
# Price and min_value has been checked before therefore deposit
UST_to_be_deposited_with_ANC = ANC_to_be_deposited * (all_rates['ANC']/1000000 + tax_rate)
deposit_ANC_tx = Transaction_class.deposit_ANC_in_pool(ANC_to_be_deposited, UST_to_be_deposited_with_ANC)
deposit_ANC_tx_status = Queries_class.get_status_of_tx(deposit_ANC_tx)
if deposit_ANC_tx_status == True:
default_logger.debug(f'[ANC LP Deposit] Success TX: {deposit_ANC_tx}')
report_logger.info(f'[ANC LP Deposit] {(ANC_to_be_deposited.__float__()/1000000):.2f} ANC and {(UST_to_be_deposited_with_ANC.__float__()/1000000):.2f} UST have been deposited to LP.')
# Update UST balance in wallet
wallet_balance['uusd'] = Dec(Queries_class.get_native_balance('uusd'))
else:
report_logger.warning(f'[ANC LP Deposit] Failed TX: {deposit_ANC_tx}.\n'
f'[ANC LP Deposit] Reason: {deposit_ANC_tx_status}')
cooldowns['deposit_ANC_in_pool'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[ANC LP Deposit] Skipped because no ANC ({(ANC_to_be_deposited.__float__()/1000000):.0f}) to deposit.')
else:
report_logger.warning(f'[ANC LP Deposit] YOU NEED TO ACT! Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
else:
default_logger.debug(f'[ANC LP Deposit] Skipped because no ANC marked to deposited ({action_dict["ANC"]}).')
else:
default_logger.debug(f'[ANC LP Deposit] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["deposit_ANC_in_pool"]}).')
else:
default_logger.debug(f'[ANC LP Deposit] Skipped because disabled by config ({config.ANC_claim_and_deposit_in_LP}).')
# default_logger.debug(f'\n-----------------------------------------------------------\n'
# f'---------- ANCHOR REPAY, BORROW, DEPOSIT SECTION ----------\n'
# f'-----------------------------------------------------------\n')
if Anchor_borrow_info['borrow_limit'] > 0:
default_logger.debug(f'[Anchor] Anchor_borrow_info: {Prettify_class.dict_value_convert_dec_to_float(Anchor_borrow_info, True)}')
# Anchor: Repay loan if necesarry and repayment amount bigger than Anchor_min_repay_limit
Anchor_amount_to_execute_in_ust = Anchor_borrow_info['amount_to_execute_in_ust']
Anchor_action_to_be_executed = Anchor_borrow_info['action_to_be_executed']
if Anchor_action_to_be_executed == 'none':
if wallet_balance['uusd'] < general_estimated_tx_fee:
report_logger.warning(f'[Anchor] YOU NEED TO ACT! Skipped because insufficent funds ({(wallet_balance["uusd"].__float__() / 1000000):.2f}).')
return False
default_logger.debug(f'[Anchor] Anchor is healthy. Current LTV at {(Anchor_borrow_info["cur_col_ratio"].__float__()*100):.2f} %.')
if not config.Anchor_enable_auto_repay_of_debt:
default_logger.debug(f'[Anchor Repay] Skipped because disabled by config ({config.Anchor_enable_auto_repay_of_debt}).')
if not config.Anchor_enable_auto_borrow_UST:
default_logger.debug(f'[Anchor Borrow] Skipped because disabled by config ({config.Anchor_enable_auto_borrow_UST}).')
elif Anchor_action_to_be_executed == 'repay':
if cooldowns.get('Anchor_repay_debt_UST') is None or cooldowns['Anchor_repay_debt_UST'] <= datetime_now:
if Anchor_amount_to_execute_in_ust > config.Anchor_min_repay_limit:
# Check if the wallet has enough UST to repay and for tx fees
if Anchor_amount_to_execute_in_ust < (wallet_balance['uusd'] - general_estimated_tx_fee):
Anchor_repay_debt_UST_tx = Transaction_class.Anchor_repay_debt_UST(Anchor_amount_to_execute_in_ust)
Anchor_repay_debt_UST_tx_status = Queries_class.get_status_of_tx(Anchor_repay_debt_UST_tx)
if Anchor_repay_debt_UST_tx_status == True:
default_logger.debug(f'[Anchor Repay] Success TX: {Anchor_repay_debt_UST_tx}')
report_logger.info(f'[Anchor Repay] {(Anchor_amount_to_execute_in_ust.__float__()/1000000):.2f} UST have been repaid to Anchor Borrow from your wallet.')
else:
report_logger.warning(f'[Anchor Repay] Failed TX: {Anchor_repay_debt_UST_tx}.\n'
f'[Anchor Repay] Reason: {Anchor_repay_debt_UST_tx_status}')
cooldowns['Anchor_repay_debt_UST'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Otherwise check if the balance in the wallet + a withdrawl of UST from Anchor Earn would be enough, and withdraw what is needed
elif config.Anchor_enable_withdraw_of_deposited_UST \
and (wallet_balance['aUST'] * all_rates['aUST']/1000000 + wallet_balance['uusd'] - general_estimated_tx_fee + Dec(config.Anchor_Earn_min_balance_to_keep_in_wallet)* 1000000) >= Anchor_amount_to_execute_in_ust:
Amount_to_be_withdrawn = Anchor_amount_to_execute_in_ust - wallet_balance['uusd'] + general_estimated_tx_fee + Dec(config.Anchor_Earn_min_balance_to_keep_in_wallet)* 1000000
Anchor_withdraw_UST_from_Earn_tx = Transaction_class.Anchor_withdraw_UST_from_Earn(Amount_to_be_withdrawn, 'uusd')
Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(Anchor_withdraw_UST_from_Earn_tx)
if Anchor_withdraw_UST_from_Earn_tx_status == True:
default_logger.debug(f'[Anchor Withdraw] Success TX: {Anchor_withdraw_UST_from_Earn_tx}')
Anchor_repay_debt_UST_tx = Transaction_class.Anchor_repay_debt_UST(Anchor_amount_to_execute_in_ust)
Anchor_repay_debt_UST_tx_status = Queries_class.get_status_of_tx(Anchor_repay_debt_UST_tx)
if Anchor_repay_debt_UST_tx_status == True:
default_logger.debug(f'[Anchor Withdraw] Success TX: {Anchor_repay_debt_UST_tx}')
report_logger.info(f'[Anchor Withdraw] {(Amount_to_be_withdrawn.__float__()/1000000):.2f} UST have been withdrawn from your Anchor Earn and {(Anchor_amount_to_execute_in_ust.__float__()/1000000):.0f} (incl. UST from your wallet) have been repaid to Anchor Borrow.')
else:
report_logger.warning(f'[Anchor Withdraw] Failed TX: {Anchor_repay_debt_UST_tx}.\n'
f'[Anchor Withdraw] Reason: {Anchor_repay_debt_UST_tx_status}')
cooldowns['Anchor_repay_debt_UST'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[Anchor Withdraw] Failed TX: {Anchor_withdraw_UST_from_Earn_tx}.\n'
f'[Anchor Withdraw] Reason: {Anchor_withdraw_UST_from_Earn_tx_status}')
cooldowns['Anchor_withdraw_UST_from_Earn'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
# Otherwise (if allowed) withdraw what is available and repay what is possible if enough tx fees are available
elif config.Anchor_enable_partially_repay_if_not_enough_UST_in_wallet \
and wallet_balance['uusd'] > general_estimated_tx_fee:
Anchor_withdraw_UST_from_Earn_tx = Transaction_class.Anchor_withdraw_UST_from_Earn(wallet_balance['aUST'], 'aUST')
Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(Anchor_withdraw_UST_from_Earn_tx)
if Anchor_withdraw_UST_from_Earn_tx_status == True:
default_logger.debug(f'[Anchor Withdraw] Success TX: {Anchor_withdraw_UST_from_Earn_tx}')
Anchor_repay_amount = Queries_class.get_native_balance('uusd') - general_estimated_tx_fee
Anchor_repay_debt_UST_tx = Transaction_class.Anchor_repay_debt_UST(Anchor_repay_amount)
Anchor_repay_debt_UST_tx_status = Queries_class.get_status_of_tx(Anchor_repay_debt_UST_tx)
if Anchor_repay_debt_UST_tx_status == True:
default_logger.debug(f'[Anchor Repay] Success TX: {Anchor_repay_debt_UST_tx}')
report_logger.warning(f'[Anchor Repay] YOU NEED TO ACT! There was not enough availabe aUST to withdraw and not enough UST in your wallet to repay your Anchor Borrow.\n'
f'{(wallet_balance["aUST"].__float__()/1000000):.2f} aUST has been withdrawn, and combined with your availabe UST in your wallet, {(Anchor_repay_amount.__float__()/1000000):.2f} UST have been repaid to Anchor Borrow.')
else:
report_logger.warning(f'[Anchor Repay] Failed TX: {Anchor_repay_debt_UST_tx}.\n'
f'[Anchor Repay] Reason: {Anchor_repay_debt_UST_tx_status}')
cooldowns['Anchor_repay_debt_UST'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
report_logger.warning(f'[Anchor Withdraw] Failed TX: {Anchor_withdraw_UST_from_Earn_tx}.\n'
f'[Anchor Withdraw] Reason: {Anchor_withdraw_UST_from_Earn_tx_status}')
cooldowns['Anchor_withdraw_UST_from_Earn'] = datetime_now + timedelta(hours=config.Block_failed_transaction_cooldown)
else:
default_logger.debug(f'[Anchor Repay] Skipped because disabled by config Anchor_enable_withdraw_of_deposited_UST({config.Anchor_enable_withdraw_of_deposited_UST}) or\nAnchor_enable_partially_repay_if_not_enough_UST_in_wallet ({config.Anchor_enable_partially_repay_if_not_enough_UST_in_wallet}).')
else:
default_logger.debug(f'[Anchor Repay] Skipped because repay amount ({(Anchor_amount_to_execute_in_ust.__float__()/1000000):.0f}) below repay limit ({config.Anchor_min_repay_limit}).')
else:
default_logger.debug(f'[Anchor Repay] Transaction skipped, since it recently failed. Cooldown until ({cooldowns["Anchor_repay_debt_UST"]}).')
# Anchor: Borrow more UST if possible, allowed, big enough and enough balance for tx fees is available
elif Anchor_action_to_be_executed == 'borrow' \
and Anchor_amount_to_execute_in_ust > config.Anchor_min_borrow_limit \