Skip to content

Commit

Permalink
contracts: economic simulation: Adapt to last changes
Browse files Browse the repository at this point in the history
Troves cannot be closed in Recovery Mode.
Besides, catch reverts when the result would leave the system in
Recovery Mode.
(TODO: predict it in advance to avoid the try/catch)
  • Loading branch information
bingen committed Mar 22, 2021
1 parent 442033d commit 9b1cb7d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/contracts/tests/simulation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,15 @@ def close_troves(accounts, contracts, active_accounts, inactive_accounts, price_
account = accounts[account_index]
pending = get_lusd_to_repay(accounts, contracts, active_accounts, inactive_accounts, account, get_total_debt(contracts, account))
if pending == 0:
contracts.borrowerOperations.closeTrove({ 'from': account })
inactive_accounts.append(account_index)
active_accounts.pop(drops[i])
# TODO: try to predict it!
try: # to skip “BorrowerOps: An operation that would result in TCR < CCR is not permitted” errors
contracts.borrowerOperations.closeTrove({ 'from': account })
inactive_accounts.append(account_index)
active_accounts.pop(drops[i])
except:
print("\n ***Error closing Trove!")
if is_recovery_mode(contracts, price_ether_current):
break

return [number_closetroves]

Expand Down

0 comments on commit 9b1cb7d

Please sign in to comment.