Skip to content

Commit

Permalink
fix: improve the credit line migration logic (#35)
Browse files Browse the repository at this point in the history
* fix: add the credit line address check within during the migration
* fix: increase the patch part of the version
* fix: add the initialization of the admin for the owner role
  • Loading branch information
EvgeniiZaitsevCW authored Nov 28, 2024
1 parent 791196d commit 0965830
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 259 deletions.
9 changes: 9 additions & 0 deletions contracts/LendingMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -750,4 +750,13 @@ contract LendingMarket is

/// @inheritdoc ILendingMarket
function proveLendingMarket() external pure {}

// -------------------------------------------- //
// Service functions //
// -------------------------------------------- //

/// @dev Initialized the admin for the `OWNER_ROLE` role.
function initOwnerRoleAdmin() external onlyRole(OWNER_ROLE) {
_setRoleAdmin(OWNER_ROLE, OWNER_ROLE);
}
}
2 changes: 1 addition & 1 deletion contracts/common/Versionable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ abstract contract Versionable is IVersionable {
* @inheritdoc IVersionable
*/
function $__VERSION() external pure returns (Version memory) {
return Version(1, 1, 0);
return Version(1, 1, 1);
}
}
24 changes: 15 additions & 9 deletions contracts/credit-lines/CreditLineConfigurable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,16 @@ contract CreditLineConfigurable is
}
for (; loanId < endLoanId; ++loanId) {
Loan.State memory loan = ILendingMarket(_market).getLoanState(loanId);
BorrowerState storage state = _borrowerStates[loan.borrower];
if (loan.trackedBalance != 0) {
state.activeLoanCount += 1;
state.totalActiveLoanAmount += loan.borrowAmount;
} else {
state.closedLoanCount += 1;
state.totalClosedLoanAmount += loan.borrowAmount;
address creditLine = ILendingMarket(_market).getProgramCreditLine(loan.programId);
if (creditLine == address(this)) {
BorrowerState storage state = _borrowerStates[loan.borrower];
if (loan.trackedBalance != 0) {
state.activeLoanCount += 1;
state.totalActiveLoanAmount += loan.borrowAmount;
} else {
state.closedLoanCount += 1;
state.totalClosedLoanAmount += loan.borrowAmount;
}
}
}
_migrationState.nextLoanId = uint128(endLoanId);
Expand All @@ -537,15 +540,18 @@ contract CreditLineConfigurable is
}
}

/// @dev TODO
/// @dev Sets the specified pause state in the configuration of borrowers.
/// @param newPausedState The new state of the pause: `true` -- paused, `false` -- unpaused.
function setBorrowerConfigurationPause(bool newPausedState) external onlyRole(ADMIN_ROLE) {
if (!_migrationState.done) {
return;
}
_migrationState.borrowerConfigurationPaused = newPausedState;
}

/// @dev TODO
/// @dev Sets a new value of the max borrow amount for a borrower.
/// @param borrower The address of the borrower to set the new value for.
/// @param newMaxBorrowAmount The new value.
function setMaxBorrowAmount(
address borrower,
uint64 newMaxBorrowAmount
Expand Down
10 changes: 7 additions & 3 deletions contracts/mocks/LendingMarketMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract LendingMarketMock is ILendingMarket {

mapping(uint256 => Loan.State) private _loanStates;
uint256 private _loanIdCounter;
mapping(uint256 => address) private _creditLineByProgramId;

// -------------------------------------------- //
// ILendingMarket functions //
Expand Down Expand Up @@ -139,9 +140,8 @@ contract LendingMarketMock is ILendingMarket {
revert Error.NotImplemented();
}

function getProgramCreditLine(uint32 programId) external pure returns (address) {
programId; // To prevent compiler warning about unused variable
revert Error.NotImplemented();
function getProgramCreditLine(uint32 programId) external view returns (address) {
return _creditLineByProgramId[programId];
}

function getProgramLiquidityPool(uint32 programId) external pure returns (address) {
Expand Down Expand Up @@ -223,5 +223,9 @@ contract LendingMarketMock is ILendingMarket {
emit HookCallResult(ICreditLine(creditLine).onAfterLoanRevocation(loanId));
}

function setProgramCreditLine(uint32 programId, address creditLine) external {
_creditLineByProgramId[programId] = creditLine;
}

function proveLendingMarket() external pure {}
}
Loading

0 comments on commit 0965830

Please sign in to comment.