Skip to content

Commit

Permalink
chore: forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Apr 23, 2024
1 parent 46a42b6 commit 63b24c7
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 104 deletions.
19 changes: 9 additions & 10 deletions contracts/src/BoldToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ contract BoldToken is CheckContract, IBoldToken {
event BorrowerOperationsAddressAdded(address _newBorrowerOperationsAddress);
event ActivePoolAddressAdded(address _newActivePoolAddress);

constructor
(
) {
constructor() {
bytes32 hashedName = keccak256(bytes(_NAME));
bytes32 hashedVersion = keccak256(bytes(_VERSION));

Expand Down Expand Up @@ -264,16 +262,16 @@ contract BoldToken is CheckContract, IBoldToken {
}

function _requireCallerIsBOorAP() internal view {
require(borrowerOperationsAddresses[msg.sender] ||
activePoolAddresses[msg.sender],
"BoldToken: Caller is not BO or AP");
require(
borrowerOperationsAddresses[msg.sender] || activePoolAddresses[msg.sender],
"BoldToken: Caller is not BO or AP"
);
}

function _requireCallerIsBOorTroveMorSP() internal view {
require(
borrowerOperationsAddresses[msg.sender] ||
troveManagerAddresses[msg.sender] ||
stabilityPoolAddresses[msg.sender],
borrowerOperationsAddresses[msg.sender] || troveManagerAddresses[msg.sender]
|| stabilityPoolAddresses[msg.sender],
"Bold: Caller is neither BorrowerOperations nor TroveManager nor StabilityPool"
);
}
Expand All @@ -285,7 +283,8 @@ contract BoldToken is CheckContract, IBoldToken {
function _requireCallerIsTroveMorSP() internal view {
require(
troveManagerAddresses[msg.sender] || stabilityPoolAddresses[msg.sender],
"Bold: Caller is neither TroveManager nor StabilityPool");
"Bold: Caller is neither TroveManager nor StabilityPool"
);
}

// --- Optional functions ---
Expand Down
71 changes: 37 additions & 34 deletions contracts/src/CollateralRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import "./Interfaces/ICollateralRegistry.sol";

//import "forge-std/console.sol";


contract CollateralRegistry is LiquityBase, ICollateralRegistry {
// mapping from Collateral token address to the corresponding TroveManagers
//mapping(address => address) troveManagers;
Expand Down Expand Up @@ -111,7 +110,7 @@ contract CollateralRegistry is LiquityBase, ICollateralRegistry {
for (uint256 index = 0; index < numCollaterals; index++) {
uint256 unbackedPortion = unbackedPortions[index];
if (unbackedPortion > 0) {
uint256 redeemAmount = _boldAmount * unbackedPortion / totalUnbacked;
uint256 redeemAmount = _boldAmount * unbackedPortion / totalUnbacked;
if (redeemAmount > 0) {
ITroveManager troveManager = getTroveManager(index);
uint256 feePercentage = troveManager.redeemCollateral(msg.sender, redeemAmount, _maxIterations);
Expand All @@ -127,50 +126,54 @@ contract CollateralRegistry is LiquityBase, ICollateralRegistry {
}

function getTroveManager(uint256 _index) public view returns (ITroveManager) {
if (_index == 0) { return _troveManager0; }
else if (_index == 1) { return _troveManager1; }
else if (_index == 2) { return _troveManager2; }
else if (_index == 3) { return _troveManager3; }
else if (_index == 4) { return _troveManager4; }
else if (_index == 5) { return _troveManager5; }
else if (_index == 6) { return _troveManager6; }
else if (_index == 7) { return _troveManager7; }
else if (_index == 8) { return _troveManager8; }
else if (_index == 9) { return _troveManager9; }
else {
revert("Invalid index");
}
if (_index == 0) return _troveManager0;
else if (_index == 1) return _troveManager1;
else if (_index == 2) return _troveManager2;
else if (_index == 3) return _troveManager3;
else if (_index == 4) return _troveManager4;
else if (_index == 5) return _troveManager5;
else if (_index == 6) return _troveManager6;
else if (_index == 7) return _troveManager7;
else if (_index == 8) return _troveManager8;
else if (_index == 9) return _troveManager9;
else revert("Invalid index");
}

function getToken(uint256 _index) external view returns (IERC20) {
if (_index == 0) { return _token0; }
else if (_index == 1) { return _token1; }
else if (_index == 2) { return _token2; }
else if (_index == 3) { return _token3; }
else if (_index == 4) { return _token4; }
else if (_index == 5) { return _token5; }
else if (_index == 6) { return _token6; }
else if (_index == 7) { return _token7; }
else if (_index == 8) { return _token8; }
else if (_index == 9) { return _token9; }
else {
revert("Invalid index");
}
if (_index == 0) return _token0;
else if (_index == 1) return _token1;
else if (_index == 2) return _token2;
else if (_index == 3) return _token3;
else if (_index == 4) return _token4;
else if (_index == 5) return _token5;
else if (_index == 6) return _token6;
else if (_index == 7) return _token7;
else if (_index == 8) return _token8;
else if (_index == 9) return _token9;
else revert("Invalid index");
}

// require functions

function _requireValidMaxFeePercentage(uint _maxFeePercentage) internal pure {
require(_maxFeePercentage >= REDEMPTION_FEE_FLOOR && _maxFeePercentage <= DECIMAL_PRECISION,
"Max fee percentage must be between 0.5% and 100%");
function _requireValidMaxFeePercentage(uint256 _maxFeePercentage) internal pure {
require(
_maxFeePercentage >= REDEMPTION_FEE_FLOOR && _maxFeePercentage <= DECIMAL_PRECISION,
"Max fee percentage must be between 0.5% and 100%"
);
}

function _requireAmountGreaterThanZero(uint _amount) internal pure {
function _requireAmountGreaterThanZero(uint256 _amount) internal pure {
require(_amount > 0, "TroveManager: Amount must be greater than zero");
}

function _requireBoldBalanceCoversRedemption(IBoldToken _boldToken, address _redeemer, uint _amount) internal view {
require(_boldToken.balanceOf(_redeemer) >= _amount, "TroveManager: Requested redemption amount must be <= user's Bold token balance");
function _requireBoldBalanceCoversRedemption(IBoldToken _boldToken, address _redeemer, uint256 _amount)
internal
view
{
require(
_boldToken.balanceOf(_redeemer) >= _amount,
"TroveManager: Requested redemption amount must be <= user's Bold token balance"
);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/Dependencies/LiquityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ contract LiquityBase is BaseMath, ILiquityBase {

uint256 public constant PERCENT_DIVISOR = 200; // dividing by 200 yields 0.5%

uint constant public BORROWING_FEE_FLOOR = DECIMAL_PRECISION / 1000 * 5; // 0.5%
uint constant public REDEMPTION_FEE_FLOOR = DECIMAL_PRECISION / 1000 * 5; // 0.5%
uint256 public constant BORROWING_FEE_FLOOR = DECIMAL_PRECISION / 1000 * 5; // 0.5%
uint256 public constant REDEMPTION_FEE_FLOOR = DECIMAL_PRECISION / 1000 * 5; // 0.5%

IActivePool public activePool;

Expand Down
1 change: 0 additions & 1 deletion contracts/src/Interfaces/ICollateralRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.18;
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "./ITroveManager.sol";


interface ICollateralRegistry {
function redeemCollateral(uint256 _boldamount, uint256 _maxIterations, uint256 _maxFeePercentage) external;
// getters
Expand Down
8 changes: 3 additions & 5 deletions contracts/src/Interfaces/ITroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ interface ITroveManager is IERC721, ILiquityBase {

function batchLiquidateTroves(uint256[] calldata _troveArray) external;

function redeemCollateral(
address _sender,
uint _boldAmount,
uint _maxIterations
) external returns (uint256 _feePercentage);
function redeemCollateral(address _sender, uint256 _boldAmount, uint256 _maxIterations)
external
returns (uint256 _feePercentage);

function updateStakeAndTotalStakes(uint256 _troveId) external returns (uint256);

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/SortedTroves.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ uint256 constant ROOT_NODE_ID = 0;
*
* The annual interest rate is stored on the Trove struct in TroveManager, not directly on the Node.
*
* A node need only be re-inserted when the borrower adjusts their interest rate. Interest rate order is preserved
* A node need only be re-inserted when the borrower adjusts their interest rate. Interest rate order is preserved
* under all other system operations.
*
* The list is a modification of the following audited SortedDoublyLinkedList:
Expand Down
17 changes: 3 additions & 14 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -948,25 +948,15 @@ contract TroveManager is ERC721, LiquityBase, Ownable, CheckContract, ITroveMana
* redemption will stop after the last completely redeemed Trove and the sender will keep the remaining Bold amount, which they can attempt
* to redeem later.
*/
function redeemCollateral(
address _sender,
uint _boldamount,
uint _maxIterations
)
function redeemCollateral(address _sender, uint256 _boldamount, uint256 _maxIterations)
external
override
returns (uint256 _feePercentage)
{
_requireIsCollateralRegistry();

ContractsCache memory contractsCache = ContractsCache(
activePool,
defaultPool,
boldToken,
sortedTroves,
collSurplusPool,
gasPoolAddress
);
ContractsCache memory contractsCache =
ContractsCache(activePool, defaultPool, boldToken, sortedTroves, collSurplusPool, gasPoolAddress);
RedemptionTotals memory totals;

totals.price = priceFeed.fetchPrice();
Expand Down Expand Up @@ -1519,7 +1509,6 @@ contract TroveManager is ERC721, LiquityBase, Ownable, CheckContract, ITroveMana
require(checkTroveIsActive(_troveId), "TroveManager: Trove does not exist or is closed");
}


function _requireMoreThanOneTroveInSystem(uint256 TroveIdsArrayLength) internal view {
require(TroveIdsArrayLength > 1 && sortedTroves.getSize() > 1, "TroveManager: Only one trove in the system");
}
Expand Down
12 changes: 9 additions & 3 deletions contracts/src/deployment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ struct LiquityContracts {
IERC20 WETH;
}

function _deployAndConnectContracts() returns (LiquityContracts memory contracts, ICollateralRegistry collateralRegistry, IBoldToken boldToken) {
function _deployAndConnectContracts()
returns (LiquityContracts memory contracts, ICollateralRegistry collateralRegistry, IBoldToken boldToken)
{
LiquityContracts[] memory contractsArray;
(contractsArray, collateralRegistry, boldToken) = _deployAndConnectContracts(1);
contracts = contractsArray[0];
}

function _deployAndConnectContracts(uint256 _numCollaterals) returns (LiquityContracts[] memory contractsArray, ICollateralRegistry collateralRegistry, IBoldToken boldToken) {
function _deployAndConnectContracts(uint256 _numCollaterals)
returns (LiquityContracts[] memory contractsArray, ICollateralRegistry collateralRegistry, IBoldToken boldToken)
{
boldToken = new BoldToken();

contractsArray = new LiquityContracts[](_numCollaterals);
Expand Down Expand Up @@ -81,7 +85,9 @@ function _deployAndConnectContracts(uint256 _numCollaterals) returns (LiquityCon
}
}

function _deployAndConnectCollateralContracts(IERC20 _collateralToken, IBoldToken _boldToken) returns (LiquityContracts memory contracts) {
function _deployAndConnectCollateralContracts(IERC20 _collateralToken, IBoldToken _boldToken)
returns (LiquityContracts memory contracts)
{
// TODO: optimize deployment order & constructor args & connector functions

contracts.WETH = _collateralToken;
Expand Down
7 changes: 6 additions & 1 deletion contracts/src/test/TestContracts/DevTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ contract DevTestSetup is BaseTest {
return giveAndApproveCollateral(WETH, _account, _amount, address(borrowerOperations));
}

function giveAndApproveCollateral(IERC20 _token, address _account, uint256 _amount, address _borrowerOperationsAddress) public {
function giveAndApproveCollateral(
IERC20 _token,
address _account,
uint256 _amount,
address _borrowerOperationsAddress
) public {
// Give some Collateral to test accounts
deal(address(_token), _account, _amount);

Expand Down
6 changes: 1 addition & 5 deletions contracts/src/test/basicOps.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ contract BasicOps is DevTestSetup {

// A redeems 1k BOLD
vm.startPrank(A);
collateralRegistry.redeemCollateral(
redemptionAmount,
10,
1e18
);
collateralRegistry.redeemCollateral(redemptionAmount, 10, 1e18);

// Check B's coll and debt reduced
uint256 debt_2 = troveManager.getTroveDebt(B_Id);
Expand Down
Loading

0 comments on commit 63b24c7

Please sign in to comment.