Section 12 of 15
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) andL_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_nTroves from the tail of SortedTroves (lowest NICR first), liquidates everything below MCR, and updatesL_*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:
_redistributeDebtAndColl(activePool, defaultPool, debt, coll)— the real implementation. UpdatesL_ETHandL_LUSDDebt, moves the ETH from ActivePool to DefaultPool.liquidateTroves(uint _n)— the public batch liquidator. Iterates from the tail of SortedTroves, liquidates everything below MCR._getTotalsFromLiquidateTrovesSequence_NormalMode(...)— the loop that accumulates per-Trove liquidation values into batch totals._updateSystemSnapshots_excludeCollRemainder(...)— capturestotalStakesandtotalCollateralafter a liquidation, so new Troves get correct stakes.
Plus _addLiquidationValuesToTotals (the accumulator) and the real _computeNewStake / updateStakeAndTotalStakes from section 7.
Your Code
Requirements
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 continueAlready have an account? Log in