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 7, 2024
1 parent 0cf47ac commit fbbf1af
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 61 deletions.
11 changes: 6 additions & 5 deletions contracts/src/CollateralRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ contract CollateralRegistry is LiquityBase, ICollateralRegistry {
uint256 redeemedAmount;
}

function redeemCollateral(uint256 _boldAmount, uint256 _maxIterationsPerCollateral, uint256 _maxFeePercentage) external {
function redeemCollateral(uint256 _boldAmount, uint256 _maxIterationsPerCollateral, uint256 _maxFeePercentage)
external
{
_requireValidMaxFeePercentage(_maxFeePercentage);
_requireAmountGreaterThanZero(_boldAmount);
_requireBoldBalanceCoversRedemption(boldToken, msg.sender, _boldAmount);
Expand All @@ -135,7 +137,8 @@ contract CollateralRegistry is LiquityBase, ICollateralRegistry {
// We only compute it here, and update it at the end,
// because the final redeemed amount may be less than the requested amount
// Redeemers should take this into account in order to request the optimal amount to not overpay
uint256 redemptionRate = _calcRedemptionRate(_getUpdatedBaseRateFromRedemption(_boldAmount, totals.boldSupplyAtStart));
uint256 redemptionRate =
_calcRedemptionRate(_getUpdatedBaseRateFromRedemption(_boldAmount, totals.boldSupplyAtStart));
require(redemptionRate <= _maxFeePercentage, "CR: Fee exceeded provided maximum");
// Implicit by the above and the _requireValidMaxFeePercentage checks
//require(newBaseRate < DECIMAL_PRECISION, "CR: Fee would eat up all collateral");
Expand Down Expand Up @@ -195,9 +198,7 @@ contract CollateralRegistry is LiquityBase, ICollateralRegistry {
}

// Updates the `baseRate` state with math from `_getUpdatedBaseRateFromRedemption`
function _updateBaseRateAndGetRedemptionRate(uint256 _boldAmount, uint256 _totalBoldSupplyAtStart)
internal
{
function _updateBaseRateAndGetRedemptionRate(uint256 _boldAmount, uint256 _totalBoldSupplyAtStart) internal {
uint256 newBaseRate = _getUpdatedBaseRateFromRedemption(_boldAmount, _totalBoldSupplyAtStart);

//assert(newBaseRate <= DECIMAL_PRECISION); // This is already enforced in `_getUpdatedBaseRateFromRedemption`
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import "../../CollateralRegistry.sol";
for testing the parent's internal functions. */

contract CollateralRegistryTester is CollateralRegistry {
constructor(IBoldToken _boldToken, IERC20[] memory _tokens, ITroveManager[] memory _troveManagers) CollateralRegistry(_boldToken, _tokens, _troveManagers) {}
constructor(IBoldToken _boldToken, IERC20[] memory _tokens, ITroveManager[] memory _troveManagers)
CollateralRegistry(_boldToken, _tokens, _troveManagers)
{}

function unprotectedDecayBaseRateFromBorrowing() external returns (uint256) {
baseRate = _calcDecayedBaseRate();
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 @@ -166,7 +166,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 @@ -200,11 +203,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 @@ -214,17 +220,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
Loading

0 comments on commit fbbf1af

Please sign in to comment.