Skip to content

Commit

Permalink
chore: forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed May 3, 2024
1 parent c315fdc commit 3aedd9f
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 167 deletions.
46 changes: 33 additions & 13 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
// TODO: Use oldDebt and assert in fuzzing, remove before deployment
uint256 oldDebt = troveManager.getTroveEntireDebt(_troveId);
_adjustTrove(msg.sender, _troveId, 0, false, _boldAmount, false, 0, contractsCache);
assert(troveManager.getTroveEntireDebt(_troveId) < oldDebt);
assert(troveManager.getTroveEntireDebt(_troveId) < oldDebt);
}

function adjustTrove(
Expand All @@ -298,12 +298,19 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
ContractsCacheTMAPBT memory contractsCache = ContractsCacheTMAPBT(troveManager, activePool, boldToken);
_requireTroveIsActive(contractsCache.troveManager, _troveId);
_adjustTrove(
msg.sender, _troveId, _collChange, _isCollIncrease, _boldChange, _isDebtIncrease, _maxFeePercentage, contractsCache
msg.sender,
_troveId,
_collChange,
_isCollIncrease,
_boldChange,
_isDebtIncrease,
_maxFeePercentage,
contractsCache
);
}

function adjustUnredeemableTrove(
uint256 _troveId,
uint256 _troveId,
uint256 _maxFeePercentage,
uint256 _collChange,
bool _isCollIncrease,
Expand All @@ -314,12 +321,21 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
) external override {
ContractsCacheTMAPBT memory contractsCache = ContractsCacheTMAPBT(troveManager, activePool, boldToken);
_requireTroveIsUnredeemable(contractsCache.troveManager, _troveId);
// TODO: Gas - pass the cached TM down here, since we fetch it again inside _adjustTrove?
// TODO: Gas - pass the cached TM down here, since we fetch it again inside _adjustTrove?
_adjustTrove(
msg.sender, _troveId, _collChange, _isCollIncrease, _boldChange, _isDebtIncrease, _maxFeePercentage, contractsCache
msg.sender,
_troveId,
_collChange,
_isCollIncrease,
_boldChange,
_isDebtIncrease,
_maxFeePercentage,
contractsCache
);
troveManager.setTroveStatusToActive(_troveId);
sortedTroves.insert(_troveId, contractsCache.troveManager.getTroveAnnualInterestRate(_troveId), _upperHint, _lowerHint);
sortedTroves.insert(
_troveId, contractsCache.troveManager.getTroveAnnualInterestRate(_troveId), _upperHint, _lowerHint
);
}

function adjustTroveInterestRate(
Expand Down Expand Up @@ -636,17 +652,19 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
uint256 _boldChange,
bool _isDebtIncrease
) internal {
if (_isDebtIncrease) { // implies _boldChange > 0
if (_isDebtIncrease) {
// implies _boldChange > 0
address borrower = _troveManager.ownerOf(_troveId);
_boldToken.mint(borrower, _boldChange);
} else if (_boldChange > 0 ){
} else if (_boldChange > 0) {
_boldToken.burn(msg.sender, _boldChange);
}

if (_isCollIncrease) { // implies _collChange > 0
if (_isCollIncrease) {
// implies _collChange > 0
// Pull ETH tokens from sender and move them to the Active Pool
_pullETHAndSendToActivePool(_activePool, _collChange);
} else if (_collChange > 0 ){
} else if (_collChange > 0) {
address borrower = _troveManager.ownerOf(_troveId);
// Pull ETH from Active Pool and decrease its recorded ETH balance
_activePool.sendETH(borrower, _collChange);
Expand Down Expand Up @@ -713,11 +731,13 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
}

function _requireTroveIsUnredeemable(ITroveManager _troveManager, uint256 _troveId) internal view {
require(_troveManager.checkTroveIsUnredeemable(_troveId), "BorrowerOps: Trove does not have unredeemable status");
require(
_troveManager.checkTroveIsUnredeemable(_troveId), "BorrowerOps: Trove does not have unredeemable status"
);
}

function _requireTroveIsNotOpen(ITroveManager _troveManager, uint256 _troveId) internal view {
require(!_troveManager.checkTroveIsOpen(_troveId),"BorrowerOps: Trove is open");
function _requireTroveIsNotOpen(ITroveManager _troveManager, uint256 _troveId) internal view {
require(!_troveManager.checkTroveIsOpen(_troveId), "BorrowerOps: Trove is open");
}

function _requireNonZeroCollChange(uint256 _collChange) internal pure {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/HintHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract HintHelpers is LiquityBase, Ownable, CheckContract {
uint256 currentId = troveManager.getTroveFromTroveIdsArray(arrayIndex);

// Skip this Trove if it's unredeeamable and not in the sorted list
if (!sortedTroves.contains(currentId)) { continue; }
if (!sortedTroves.contains(currentId)) continue;

uint256 currentInterestRate = troveManager.getTroveAnnualInterestRate(currentId);

Expand Down
12 changes: 7 additions & 5 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,9 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
if (collRedistributionPortion > 0) {
(collToRedistribute, collSurplus) = _getCollPenaltyAndSurplus(
collRedistributionPortion + collSurplus, // Coll surplus from offset can be eaten up by red. penalty
debtToRedistribute, LIQUIDATION_PENALTY_REDISTRIBUTION, _price
debtToRedistribute,
LIQUIDATION_PENALTY_REDISTRIBUTION,
_price
);
}
}
Expand Down Expand Up @@ -1045,7 +1047,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
uint256 snapshotETH = rewardSnapshots[_troveId].ETH;
uint256 rewardPerUnitStaked = L_ETH - snapshotETH;

if (rewardPerUnitStaked == 0 || !checkTroveIsOpen(_troveId)) {return 0;}
if (rewardPerUnitStaked == 0 || !checkTroveIsOpen(_troveId)) return 0;

uint256 stake = Troves[_troveId].stake;

Expand All @@ -1059,7 +1061,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
uint256 snapshotBoldDebt = rewardSnapshots[_troveId].boldDebt;
uint256 rewardPerUnitStaked = L_boldDebt - snapshotBoldDebt;

if (rewardPerUnitStaked == 0 || !checkTroveIsOpen(_troveId)) {return 0;}
if (rewardPerUnitStaked == 0 || !checkTroveIsOpen(_troveId)) return 0;

uint256 stake = Troves[_troveId].stake;

Expand All @@ -1074,7 +1076,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
* this indicates that rewards have occured since the snapshot was made, and the user therefore has
* redistribution gains
*/
if (!checkTroveIsOpen(_troveId)) {return false;}
if (!checkTroveIsOpen(_troveId)) return false;

return (rewardSnapshots[_troveId].ETH < L_ETH);
}
Expand Down Expand Up @@ -1224,7 +1226,7 @@ contract TroveManager is ERC721, LiquityBase, Ownable, ITroveManager {
rewardSnapshots[_troveId].boldDebt = 0;

_removeTroveId(_troveId, TroveIdsArrayLength);
if (prevStatus == Status.active) {sortedTroves.remove(_troveId);}
if (prevStatus == Status.active) sortedTroves.remove(_troveId);

// burn ERC721
// TODO: Should we do it?
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/test/SortedTroves.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ contract MockTroveManager {
function _sortedTroves_removeFromBatch(TroveId id) external {
_sortedTroves.removeFromBatch(TroveId.unwrap(id));
}

function _sortedTroves_findInsertPosition(uint256 annualInterestRate, Hints memory hints)
external
view
Expand Down
26 changes: 18 additions & 8 deletions contracts/src/test/TestContracts/DevTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ contract DevTestSetup is BaseTest {
return (ATroveId, BTroveId, CTroveId, DTroveId);
}

function _setupForRedemption(TroveInterestRates memory _troveInterestRates) internal returns (uint256, uint256, TroveIDs memory) {
function _setupForRedemption(TroveInterestRates memory _troveInterestRates)
internal
returns (uint256, uint256, TroveIDs memory)
{
TroveIDs memory troveIDs;

priceFeed.setPrice(2000e18);
Expand Down Expand Up @@ -202,11 +205,14 @@ contract DevTestSetup is BaseTest {
return _setupForRedemption(troveInterestRates);
}


function _redeemAndCreateZombieTrovesAAndB(TroveIDs memory _troveIDs) internal returns (uint256, uint256, TroveIDs memory) {
function _redeemAndCreateZombieTrovesAAndB(TroveIDs memory _troveIDs)
internal
returns (uint256, uint256, TroveIDs memory)
{
// Redeem enough to leave to leave A with 0 debt and B with debt < MIN_NET_DEBT
uint256 redeemFromA = troveManager.getTroveEntireDebt(_troveIDs.A) - troveManager.BOLD_GAS_COMPENSATION();
uint256 redeemFromB = troveManager.getTroveEntireDebt(_troveIDs.B) - troveManager.BOLD_GAS_COMPENSATION() - troveManager.MIN_NET_DEBT() / 2;
uint256 redeemFromB = troveManager.getTroveEntireDebt(_troveIDs.B) - troveManager.BOLD_GAS_COMPENSATION()
- troveManager.MIN_NET_DEBT() / 2;
uint256 redeemAmount = redeemFromA + redeemFromB;

// Fully redeem A and leave B with debt < MIN_NET_DEBT
Expand All @@ -216,17 +222,21 @@ contract DevTestSetup is BaseTest {
assertEq(troveManager.getTroveEntireDebt(_troveIDs.A), BOLD_GAS_COMP);
assertLt(troveManager.getTroveEntireDebt(_troveIDs.B) - BOLD_GAS_COMP, troveManager.MIN_NET_DEBT());

// Check A and B tagged as Zombie troves
// Check A and B tagged as Zombie troves
assertEq(troveManager.getTroveStatus(_troveIDs.A), 5); // status 'unredeemable'
assertEq(troveManager.getTroveStatus(_troveIDs.A), 5); // status 'unredeemable'
}

function _redeemAndCreateZombieTroveAAndHitB(TroveIDs memory _troveIDs) internal returns (uint256, uint256, TroveIDs memory) {
function _redeemAndCreateZombieTroveAAndHitB(TroveIDs memory _troveIDs)
internal
returns (uint256, uint256, TroveIDs memory)
{
// Redeem enough to leave to leave A with 0 debt and B with debt < MIN_NET_DEBT
uint256 redeemFromA = troveManager.getTroveEntireDebt(_troveIDs.A) - troveManager.BOLD_GAS_COMPENSATION();
// Leave B with net_debt > min_net_debt
uint256 redeemFromB = troveManager.getTroveEntireDebt(_troveIDs.B) - troveManager.BOLD_GAS_COMPENSATION() - troveManager.MIN_NET_DEBT() - 37;

uint256 redeemFromB = troveManager.getTroveEntireDebt(_troveIDs.B) - troveManager.BOLD_GAS_COMPENSATION()
- troveManager.MIN_NET_DEBT() - 37;

uint256 redeemAmount = redeemFromA + redeemFromB;

// Fully redeem A and leave B with debt > MIN_NET_DEBT
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/test/interestRateAggregate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,7 @@ contract InterestRateAggregate is DevTestSetup {
// Check recorded debt sum has changed correctly
assertEq(activePool.aggWeightedDebtSum(), expectedAggWeightedRecordedDebt);
}

// TODO: mixed collateral & debt adjustment opps
// TODO: tests with pending debt redist. gain >0
// TODO: tests that show total debt change under user ops
Expand Down
11 changes: 4 additions & 7 deletions contracts/src/test/multicollateral.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,11 @@ contract MulticollateralTest is DevTestSetup {
_spBoldAmount2 = bound(_spBoldAmount2, 0, boldAmount - 200e18);
_spBoldAmount3 = bound(_spBoldAmount3, 0, boldAmount - 200e18);
_spBoldAmount4 = bound(_spBoldAmount4, 0, boldAmount - 200e18 - minBoldBalance);
_redemptionFraction = bound(
_redemptionFraction,
DECIMAL_PRECISION / minBoldBalance,
DECIMAL_PRECISION
);
_redemptionFraction = bound(_redemptionFraction, DECIMAL_PRECISION / minBoldBalance, DECIMAL_PRECISION);

_testMultiCollateralRedemption(boldAmount, _spBoldAmount1, _spBoldAmount2, _spBoldAmount3, _spBoldAmount4, _redemptionFraction);
_testMultiCollateralRedemption(
boldAmount, _spBoldAmount1, _spBoldAmount2, _spBoldAmount3, _spBoldAmount4, _redemptionFraction
);
}

function testMultiCollateralRedemptionMaxSPAmount() public {
Expand Down Expand Up @@ -225,7 +223,6 @@ contract MulticollateralTest is DevTestSetup {
testValues3.price = contractsArray[2].priceFeed.getPrice();
testValues4.price = contractsArray[3].priceFeed.getPrice();


// First collateral
openMulticollateralTroveNoHints100pctMaxFeeWithIndex(0, A, 0, 10e18, _boldAmount, 5e16);
if (_spBoldAmount1 > 0) makeMulticollateralSPDeposit(0, A, _spBoldAmount1);
Expand Down
Loading

0 comments on commit 3aedd9f

Please sign in to comment.