Section 12 of 15

Build
+15 Lynx

TroveManager: Redistribution and Batch Liquidation

Key takeaway: This section turns on the redistribution half of the liquidation cascade — what happens when the Stability Pool can't fully absorb a Trove's debt. The accounting trick is the same one the Stability Pool uses, but additive instead of multiplicative: a global L_ETH (cumulative ETH redistributed per unit stake) and L_LUSDDebt (cumulative debt redistributed per unit stake). Each remaining Trove's true coll and debt include their share of these accumulators, computed lazily from the snapshot they captured at their last touch. liquidateTroves(uint _n) scans up to _n Troves from the tail of SortedTroves (lowest NICR first), liquidates everything below MCR, and updates L_* once with the batch totals. The system can liquidate a hundred underwater Troves in O(n) gas, with each non-liquidated Trove's storage untouched.

What You Are Building

Four new pieces:

  1. _redistributeDebtAndColl(activePool, defaultPool, debt, coll) — the real implementation. Updates L_ETH and L_LUSDDebt, moves the ETH from ActivePool to DefaultPool.
  2. liquidateTroves(uint _n) — the public batch liquidator. Iterates from the tail of SortedTroves, liquidates everything below MCR.
  3. _getTotalsFromLiquidateTrovesSequence_NormalMode(...) — the loop that accumulates per-Trove liquidation values into batch totals.
  4. _updateSystemSnapshots_excludeCollRemainder(...) — captures totalStakes and totalCollateral after a liquidation, so new Troves get correct stakes.

Plus _addLiquidationValuesToTotals (the accumulator) and the real _computeNewStake / updateStakeAndTotalStakes from section 7.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

Sign up free — keep reading + earn 15 Lynx

Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.

Sign up free to continue

Already have an account? Log in