Skip to content

Commit

Permalink
fix: Minor urgent redemption optimizations (Dedaub A9, A10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Aug 27, 2024
1 parent 70903ad commit c40bb55
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents {
error TroveNotOpen(uint256 _troveId);
error OnlyOneTroveLeft();
error NotShutDown();
error NotEnoughBoldBalance();
error MinCollNotReached(uint256 _coll);

// --- Events ---
Expand Down Expand Up @@ -812,6 +813,7 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents {

function urgentRedemption(uint256 _boldAmount, uint256[] calldata _troveIds, uint256 _minCollateral) external {
_requireIsShutDown();
_requireBoldBalanceCoversRedemption(boldToken, msg.sender, _boldAmount);

IActivePool activePoolCached = activePool;
TroveChange memory totalsTroveChange;
Expand Down Expand Up @@ -842,6 +844,7 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents {
totalsTroveChange.oldWeightedRecordedDebt += singleRedemption.oldWeightedRecordedDebt;

remainingBold -= singleRedemption.boldLot;
if (remainingBold == 0) break;
}

if (totalsTroveChange.collDecrease < _minCollateral) {
Expand Down Expand Up @@ -1129,6 +1132,16 @@ contract TroveManager is LiquityBase, ITroveManager, ITroveEvents {
}
}

function _requireBoldBalanceCoversRedemption(IBoldToken _boldToken, address _redeemer, uint256 _amount)
internal
view
{
uint256 boldBalance = _boldToken.balanceOf(_redeemer);
if (boldBalance < _amount) {
revert NotEnoughBoldBalance();
}
}

// --- Trove property getters ---

function getUnbackedPortionPriceAndRedeemability() external returns (uint256, uint256, bool) {
Expand Down

0 comments on commit c40bb55

Please sign in to comment.