Skip to content

Commit

Permalink
contracts: economic simulation: Check SP on every liquidation
Browse files Browse the repository at this point in the history
To avoid reverting in recovery mode if it becomes empty during the
process of liquidation.
  • Loading branch information
bingen committed Mar 22, 2021
1 parent d837b84 commit 442033d
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 @@ -15,6 +15,8 @@
#n_sim = 8640
n_sim = year

# number of liquidations for each call to `liquidateTroves`
NUM_LIQUIDATIONS = 10

MIN_NET_DEBT = 1950.0
MAX_FEE = Wei(1e18)
Expand Down Expand Up @@ -260,8 +262,12 @@ def pending_liquidations(contracts, price_ether_current):
return False

stability_pool_balance = contracts.stabilityPool.getTotalLUSDDeposits()
if stability_pool_balance > 0:
return True
trove = last_trove
for i in range(NUM_LIQUIDATIONS):
debt = contracts.troveManager.getEntireDebtAndColl(trove)[0]
if stability_pool_balance >= debt:
return True
trove = contracts.sortedTroves.getPrev(trove)

return False

Expand All @@ -285,7 +291,7 @@ def liquidate_troves(accounts, contracts, active_accounts, inactive_accounts, pr
stability_pool_eth_previous = contracts.stabilityPool.getETH() / 1e18

while pending_liquidations(contracts, price_ether_current):
tx = contracts.troveManager.liquidateTroves(10)
tx = contracts.troveManager.liquidateTroves(NUM_LIQUIDATIONS, { 'from': accounts[0] })
#print(tx.events['TroveLiquidated'])
remove_accounts_from_events(accounts, active_accounts, inactive_accounts, tx.events['TroveLiquidated'], '_borrower')

Expand Down

0 comments on commit 442033d

Please sign in to comment.