Skip to content

Commit

Permalink
Fix liquidator test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcintra committed Feb 1, 2024
1 parent f3375af commit 26d4e06
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 0 additions & 3 deletions src/agents/liquidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ def maybe_liquidate(

collateral = controller.COLLATERAL_TOKEN.address

assert (
controller.address in self.paths
), f"Liquidator paths {self.paths} not set for controller {controller.address}."
for path in self.paths[controller.address]:
crvusd_pool = path.crvusd_pool
collat_pool = path.collat_pool
Expand Down
26 changes: 18 additions & 8 deletions test/unit/agents/test_liquidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,28 @@ def test_perform_liquidations(scenario: Scenario) -> None:

liquidator = _scenario.liquidator
liquidator.tolerance = -math.inf # force liquidation

prev_count = liquidator.count()
prev_profit = liquidator.profit()

liquidator.perform_liquidations(_scenario.controllers, _scenario.curr_price)

assert liquidator.count() == prev_count + n
assert liquidator.profit() != prev_profit

to_liquidate = {c.address: c.users_to_liquidate() for c in _scenario.controllers}
n = sum(len(v) for v in to_liquidate.values())
assert n == 0
try:
assert liquidator.count() == n
assert liquidator.profit() != 0
assert n == 0
except AssertionError:
# Sometimes a user has more debt than there is crvUSD
# liquidity in any one crvUSD pool. This is ok, and is the
# whole point of the risk model. However, future work should
# incorporate partial liquidations, or at least more complex
# routing (e.g. source crvUSD from multiple pools for one liquidation.)
for controller, positions in to_liquidate.items():
paths = liquidator.paths[controller]
assert all(
path.crvusd_pool.balances[get_crvusd_index(path.crvusd_pool)]
< position.debt
for position in positions
for path in paths
)


def test_paths(scenario: Scenario) -> None:
Expand Down
2 changes: 1 addition & 1 deletion test/unit/agents/test_liquidity_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
st.integers(min_value=1, max_value=1_000_000), min_size=2, max_size=2
),
)
@settings(max_examples=10)
@settings(max_examples=10, deadline=None)
def test_add_liquidity(scenario: Scenario, i: int, _amounts: List[int]) -> None:
"""
The LP is very simple and just deposits into
Expand Down
5 changes: 4 additions & 1 deletion test/unit/trades/test_liquidations.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def test_liquidation(scenario: Scenario) -> None:
assert position.user not in controller.loan
assert approx(controller.total_debt(), total_debt - debt)
assert approx(sum(controller.AMM.bands_x.values()), bands_x - x)
assert approx(sum(controller.AMM.bands_y.values()), bands_y - y)
assert approx(
sum(controller.AMM.bands_y.values()),
bands_y - y * controller.COLLATERAL_PRECISION,
)
assert approx(amt_out, y)

break

0 comments on commit 26d4e06

Please sign in to comment.