Skip to content

Commit

Permalink
fixed Anchor Withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik Schicke committed Oct 22, 2021
1 parent eed64b1 commit 3bd9a8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions C_Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 9 additions & 5 deletions assets/Transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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={
Expand All @@ -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:

Expand All @@ -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={
Expand Down

0 comments on commit 3bd9a8c

Please sign in to comment.