Skip to content

Commit

Permalink
Merge pull request #143 from liquity/remove__getTotalsFromLiquidateTr…
Browse files Browse the repository at this point in the history
…ovesSequence_NormalMode

fix: Remove unused functions for sequence liquidations
  • Loading branch information
bingen authored May 1, 2024
2 parents d183913 + 4646b12 commit 8776049
Showing 1 changed file with 0 additions and 101 deletions.
101 changes: 0 additions & 101 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -530,107 +530,6 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
singleLiquidation.collToRedistribute = 0;
}

/*
* This function is used when the liquidateTroves sequence starts during Recovery Mode. However, it
* handle the case where the system *leaves* Recovery Mode, part way through the liquidation sequence
*/
function _getTotalsFromLiquidateTrovesSequence_RecoveryMode(
ContractsCache memory _contractsCache,
uint256 _price,
uint256 _boldInStabPool,
uint256 _n
) internal returns (LiquidationTotals memory totals) {
LocalVariables_LiquidationSequence memory vars;
LiquidationValues memory singleLiquidation;

vars.remainingBoldInStabPool = _boldInStabPool;
vars.backToNormalMode = false;
vars.entireSystemDebt = getEntireSystemDebt();
vars.entireSystemColl = getEntireSystemColl();

vars.troveId = _contractsCache.sortedTroves.getLast();
uint256 firstUser = _contractsCache.sortedTroves.getFirst();
for (vars.i = 0; vars.i < _n && vars.troveId != firstUser; vars.i++) {
// we need to cache it, because current trove is likely going to be deleted
uint256 nextUser = _contractsCache.sortedTroves.getPrev(vars.troveId);

vars.ICR = getCurrentICR(vars.troveId, _price);

if (!vars.backToNormalMode) {
// Break the loop if ICR is greater than MCR and Stability Pool is empty
if (vars.ICR >= MCR && vars.remainingBoldInStabPool == 0) break;

uint256 TCR = LiquityMath._computeCR(vars.entireSystemColl, vars.entireSystemDebt, _price);

singleLiquidation = _liquidateRecoveryMode(
_contractsCache.activePool,
_contractsCache.defaultPool,
vars.troveId,
vars.ICR,
vars.remainingBoldInStabPool,
TCR,
_price
);

// Update aggregate trackers
vars.remainingBoldInStabPool = vars.remainingBoldInStabPool - singleLiquidation.debtToOffset;
vars.entireSystemDebt = vars.entireSystemDebt - singleLiquidation.debtToOffset;
vars.entireSystemColl = vars.entireSystemColl - singleLiquidation.collToSendToSP
- singleLiquidation.collGasCompensation - singleLiquidation.collSurplus;

// Add liquidation values to their respective running totals
totals = _addLiquidationValuesToTotals(totals, singleLiquidation);

vars.backToNormalMode =
!_checkPotentialRecoveryMode(vars.entireSystemColl, vars.entireSystemDebt, _price);
} else if (vars.backToNormalMode && vars.ICR < MCR) {
singleLiquidation = _liquidateNormalMode(
_contractsCache.activePool, _contractsCache.defaultPool, vars.troveId, vars.remainingBoldInStabPool
);

vars.remainingBoldInStabPool = vars.remainingBoldInStabPool - singleLiquidation.debtToOffset;

// Add liquidation values to their respective running totals
totals = _addLiquidationValuesToTotals(totals, singleLiquidation);
} else {
break;
} // break if the loop reaches a Trove with ICR >= MCR

vars.troveId = nextUser;
}
}

function _getTotalsFromLiquidateTrovesSequence_NormalMode(
IActivePool _activePool,
IDefaultPool _defaultPool,
uint256 _price,
uint256 _boldInStabPool,
uint256 _n
) internal returns (LiquidationTotals memory totals) {
LocalVariables_LiquidationSequence memory vars;
LiquidationValues memory singleLiquidation;
ISortedTroves sortedTrovesCached = sortedTroves;

vars.remainingBoldInStabPool = _boldInStabPool;

for (vars.i = 0; vars.i < _n; vars.i++) {
vars.troveId = sortedTrovesCached.getLast();
vars.ICR = getCurrentICR(vars.troveId, _price);

if (vars.ICR < MCR) {
singleLiquidation =
_liquidateNormalMode(_activePool, _defaultPool, vars.troveId, vars.remainingBoldInStabPool);

vars.remainingBoldInStabPool = vars.remainingBoldInStabPool - singleLiquidation.debtToOffset;

// Add liquidation values to their respective running totals
totals = _addLiquidationValuesToTotals(totals, singleLiquidation);
} else {
break;
} // break if the loop reaches a Trove with ICR >= MCR
}
}

/*
* Attempt to liquidate a custom list of troves provided by the caller.
*/
Expand Down

0 comments on commit 8776049

Please sign in to comment.