From 3bd9a8c855678be9cf8db17d423948ef8a292b85 Mon Sep 17 00:00:00 2001 From: Hendrik Schicke Date: Fri, 22 Oct 2021 10:50:48 +0800 Subject: [PATCH] fixed Anchor Withdraw --- C_Main.py | 4 ++-- assets/Transactions.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/C_Main.py b/C_Main.py index d70f5cd..68e250c 100644 --- a/C_Main.py +++ b/C_Main.py @@ -789,9 +789,9 @@ def main(): # 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'] * Queries_class.get_aUST_rate() + wallet_balance['UST'] - general_estimated_tx_fee) >= Anchor_amount_to_execute_in_ust: + and (wallet_balance['aUST'] * all_rates['aUST'] + wallet_balance['UST'] - 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['UST'] + general_estimated_tx_fee + Amount_to_be_withdrawn = Anchor_amount_to_execute_in_ust - wallet_balance['UST'] + 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, 'UST') Anchor_withdraw_UST_from_Earn_tx_status = Queries_class.get_status_of_tx(Anchor_withdraw_UST_from_Earn_tx) diff --git a/assets/Transactions.py b/assets/Transactions.py index d25191f..be367f0 100644 --- a/assets/Transactions.py +++ b/assets/Transactions.py @@ -322,7 +322,7 @@ def sell_ANC(self, amount:Dec): def Anchor_deposit_UST_for_Earn(self, amount:Dec): # Depoit a bit less, to have some UST for tx feess - amount = int(amount - fee_estimation * config.Safety_multiple_on_transaction_fees) + amount = int(amount - fee_estimation * Dec(config.Safety_multiple_on_transaction_fees)) if amount > 0: @@ -343,11 +343,15 @@ def Anchor_deposit_UST_for_Earn(self, amount:Dec): def Anchor_withdraw_UST_from_Earn(self, amount:Dec, denom:str): - amount = int(amount + config.Safety_multiple_on_transaction_fees * fee_estimation) + amount = int(amount + Dec(config.Safety_multiple_on_transaction_fees) * fee_estimation) # Convert amount UST into aUST for withdrawl and add a bit more for fees if denom == 'UST': - amount = int(amount / Queries_class.all_rates['aUST']) + amount = int(amount / Queries_class.all_rates['aUST'] * 1000000) + elif denom == 'aUST': + amount = amount + else: + raise Exception # Todo contract=Terra.aTerra execute_msg={ @@ -365,7 +369,7 @@ def Anchor_withdraw_UST_from_Earn(self, amount:Dec, denom:str): def Anchor_repay_debt_UST(self, amount:Dec): # Deduct the fee incl safety so there is still some UST left - amount = int(amount - fee_estimation * config.Safety_multiple_on_transaction_fees) + amount = int(amount - fee_estimation * Dec(config.Safety_multiple_on_transaction_fees)) if amount > 0: @@ -386,7 +390,7 @@ def Anchor_repay_debt_UST(self, amount:Dec): def Anchor_borrow_more_UST(self, amount:Dec): - amount = int(amount + fee_estimation * config.Safety_multiple_on_transaction_fees) + amount = int(amount + fee_estimation * Dec(config.Safety_multiple_on_transaction_fees)) contract=Terra.mmMarket execute_msg={