Skip to content

Commit

Permalink
Apply interest in RM and fix hardhat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RickGriff committed Mar 25, 2024
1 parent 35c3f0a commit 3afa7aa
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 324 deletions.
22 changes: 16 additions & 6 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,12 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
singleLiquidation.entireTroveColl,
vars.pendingDebtReward,
vars.pendingCollReward, ) = getEntireDebtAndColl(_borrower);

singleLiquidation.weightedRecordedTroveDebt = getTroveWeightedRecordedDebt(_borrower);

//TODO - GAS: We already read this inside getEntireDebtAndColl - so add it to the returned vals?
singleLiquidation.recordedTroveDebt = Troves[_borrower].debt;

singleLiquidation.collGasCompensation = _getCollGasCompensation(singleLiquidation.entireTroveColl);
singleLiquidation.BoldGasCompensation = BOLD_GAS_COMPENSATION;
vars.collToLiquidate = singleLiquidation.entireTroveColl - singleLiquidation.collGasCompensation;
Expand Down Expand Up @@ -410,7 +413,13 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
assert(_boldInStabPool != 0);

_removeStake(_borrower);
singleLiquidation = _getCappedOffsetVals(singleLiquidation.entireTroveDebt, singleLiquidation.entireTroveColl, _price);
singleLiquidation = _getCappedOffsetVals(
singleLiquidation.entireTroveDebt,
singleLiquidation.entireTroveColl,
singleLiquidation.recordedTroveDebt,
singleLiquidation.weightedRecordedTroveDebt,
_price
);

_closeTrove(_borrower, Status.closedByLiquidation);
if (singleLiquidation.collSurplus > 0) {
Expand All @@ -424,7 +433,6 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
LiquidationValues memory zeroVals;
return zeroVals;
}

return singleLiquidation;
}

Expand Down Expand Up @@ -471,6 +479,8 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
(
uint _entireTroveDebt,
uint _entireTroveColl,
uint256 _recordedTroveDebt,
uint256 _weightedRecordedTroveDebt,
uint _price
)
internal
Expand All @@ -479,6 +489,8 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
{
singleLiquidation.entireTroveDebt = _entireTroveDebt;
singleLiquidation.entireTroveColl = _entireTroveColl;
singleLiquidation.recordedTroveDebt = _recordedTroveDebt;
singleLiquidation.weightedRecordedTroveDebt = _weightedRecordedTroveDebt;
uint cappedCollPortion = _entireTroveDebt * MCR / _price;

singleLiquidation.collGasCompensation = _getCollGasCompensation(cappedCollPortion);
Expand Down Expand Up @@ -680,7 +692,7 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
uint TCR = LiquityMath._computeCR(vars.entireSystemColl, vars.entireSystemDebt, _price);

singleLiquidation = _liquidateRecoveryMode(_activePool, _defaultPool, vars.user, vars.ICR, vars.remainingBoldInStabPool, TCR, _price);

// Update aggregate trackers
vars.remainingBoldInStabPool = vars.remainingBoldInStabPool - singleLiquidation.debtToOffset;
vars.entireSystemDebt = vars.entireSystemDebt - singleLiquidation.debtToOffset;
Expand Down Expand Up @@ -790,7 +802,6 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {
uint _partialRedemptionHintNICR
)
internal returns (SingleRedemptionValues memory singleRedemption)

{
// Determine the remaining amount (lot) to be redeemed, capped by the entire debt of the Trove minus the liquidation reserve
singleRedemption.BoldLot = LiquityMath._min(_maxBoldamount, Troves[_borrower].debt - BOLD_GAS_COMPENSATION);
Expand Down Expand Up @@ -826,7 +837,6 @@ contract TroveManager is LiquityBase, ITroveManager, Ownable, CheckContract {

_contractsCache.sortedTroves.reInsert(_borrower, newNICR, _upperPartialRedemptionHint, _lowerPartialRedemptionHint);

// TODO: update aggregate weighted sum with new reduced debt
Troves[_borrower].debt = newDebt;
Troves[_borrower].coll = newColl;
_updateStakeAndTotalStakes(_borrower);
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/AccessControlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ contract(
it("increaseBoldDebt(): reverts when called by an account that is not BO nor TroveM", async () => {
// Attempt call from alice
try {
const txAlice = await activePool.increaseBoldDebt(100, {
const txAlice = await activePool.increaseRecordedDebtSum(100, {
from: alice,
});
} catch (err) {
Expand All @@ -227,7 +227,7 @@ contract(
it("decreaseBoldDebt(): reverts when called by an account that is not BO nor TroveM nor SP", async () => {
// Attempt call from alice
try {
const txAlice = await activePool.decreaseBoldDebt(100, {
const txAlice = await activePool.decreaseRecordedDebtSum(100, {
from: alice,
});
} catch (err) {
Expand Down
Loading

0 comments on commit 3afa7aa

Please sign in to comment.