Skip to content

Commit

Permalink
feat: Update to add acceptLender function (SC-9368) (#67)
Browse files Browse the repository at this point in the history
* feat: update to add acceptLender function

* fix: rm unused vars and use expectRevert
  • Loading branch information
Lucas Manuel authored Nov 3, 2022
1 parent b357978 commit 4ee168b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
23 changes: 17 additions & 6 deletions contracts/DebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxiedInternals {
IMapleProxyFactory(_factory()).upgradeInstance(toVersion_, arguments_);
}

/*************************************/
/*** Liquidity Migration Functions ***/
/*************************************/

function acceptLender() override external whenProtocolNotPaused {
require(msg.sender == _loanMigrator, "DL:AL:NOT_MIGRATOR");

IMapleLoanLike(_loan).acceptLender();
}

function setPendingLender(address newLender_) override external whenProtocolNotPaused {
require(msg.sender == _loanMigrator, "DL:SPL:NOT_MIGRATOR");

IMapleLoanLike(_loan).setPendingLender(newLender_);
}


/*******************************/
/*** Pool Delegate Functions ***/
/*******************************/
Expand Down Expand Up @@ -110,12 +127,6 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxiedInternals {
emit FundsToCaptureSet(_fundsToCapture = amount_);
}

function setPendingLender(address newLender_) override external whenProtocolNotPaused {
require(msg.sender == _loanMigrator, "DL:SPL:NOT_MIGRATOR");

IMapleLoanLike(_loan).setPendingLender(newLender_);
}

function setMinRatio(uint256 minRatio_) external override whenProtocolNotPaused {
require(msg.sender == _getPoolDelegate(), "DL:SMR:NOT_PD");

Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/IDebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ interface IDebtLocker is IMapleProxied {
/*** Functions ***/
/*****************/

/**
* @dev Accepts the lender on a Maple Loan.
*/
function acceptLender() external;

/**
* @dev Accept the new loan terms and trigger a refinance.
* @param refinancer_ The address of the refinancer contract.
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/Interfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface IMapleGlobalsLike {

interface IMapleLoanLike {

function acceptLender() external;

function acceptNewTerms(address refinancer_, uint256 deadline_, bytes[] calldata calls_, uint256 amount_) external;

function claimableFunds() external view returns (uint256 claimableFunds_);
Expand Down
19 changes: 18 additions & 1 deletion tests/DebtLocker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface Hevm {
// Sets block timestamp to `x`.
function warp(uint256 x) external view;

function expectRevert(bytes calldata) external;

}

contract DebtLockerTests is TestUtils {
Expand Down Expand Up @@ -1114,7 +1116,6 @@ contract DebtLockerV4Migration is TestUtils {
assertEq(debtLocker_.loanMigrator(), loanMigrator);
}


function test_acl_setPendingLender() external {
( MapleLoan loan, DebtLocker debtLocker ) = _createFundAndDrawdownLoan(1_000_000, 30_000);

Expand All @@ -1133,6 +1134,22 @@ contract DebtLockerV4Migration is TestUtils {
assertEq(loan.pendingLender(), newLender);
}

function test_acl_acceptLender() external {
( , DebtLocker debtLocker ) = _createFundAndDrawdownLoan(1_000_000, 30_000);

LoanMigrator loanMigrator = new LoanMigrator();
LoanMigrator notLoanMigrator = new LoanMigrator();

poolDelegate.debtLocker_upgrade(address(debtLocker), 2, abi.encode(address(loanMigrator)));

loanMigrator.debtLocker_setPendingLender(address(debtLocker), address(debtLocker)); // Set pending lender in Loan to get ACL to work

vm.expectRevert("DL:AL:NOT_MIGRATOR");
notLoanMigrator.debtLocker_acceptLender(address(debtLocker));

loanMigrator.try_debtLocker_acceptLender(address(debtLocker));
}

function _createLoan(uint256 principalRequested_, uint256 collateralRequired_) internal returns (MapleLoan loan_) {
address[2] memory assets = [address(collateralAsset), address(fundsAsset)];
uint256[3] memory termDetails = [uint256(10 days), uint256(30 days), 6];
Expand Down
8 changes: 8 additions & 0 deletions tests/accounts/LoanMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import { IDebtLocker } from "../../contracts/interfaces/IDebtLocker.sol";

contract LoanMigrator {

function debtLocker_acceptLender(address debtLocker_) external {
IDebtLocker(debtLocker_).acceptLender();
}

function debtLocker_setPendingLender(address debtLocker_, address newLender_) external {
IDebtLocker(debtLocker_).setPendingLender(newLender_);
}

function try_debtLocker_acceptLender(address debtLocker_) external returns (bool ok_) {
( ok_, ) = debtLocker_.call(abi.encodeWithSelector(IDebtLocker.acceptLender.selector));
}

function try_debtLocker_setPendingLender(address debtLocker_, address newLender_) external returns (bool ok_) {
( ok_, ) = debtLocker_.call(abi.encodeWithSelector(IDebtLocker.setPendingLender.selector, newLender_));
}
Expand Down
8 changes: 8 additions & 0 deletions tests/mocks/Mocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ contract MockLoan {
return 0;
}

function acceptLender() external {
// Empty, just testing ACL
}

function acceptNewTerms(address refinancer_, bytes[] calldata calls_, uint256 amount_) external {
// Empty, just testing ACL
}

function setPendingLender(address lender_) external {
// Empty, just testing ACL
}

}

contract MockGlobals {
Expand Down

0 comments on commit 4ee168b

Please sign in to comment.