Skip to content

Commit

Permalink
feat: Add liquidator address to pullFunds parameters (SC-4344) (#51)
Browse files Browse the repository at this point in the history
* feat: add liquidator address to pullFunds parameters

* formatting: alignment

Co-authored-by: Lucas Manuel <[email protected]>
  • Loading branch information
JGcarv and Lucas Manuel authored Dec 14, 2021
1 parent cd94071 commit 52fe628
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions contracts/DebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxied {
return _repossessed ? _handleClaimOfRepossessed(msg.sender, _loan) : _handleClaim(msg.sender, _loan);
}

function pullFundsFromLiquidator(address token_, address destination_, uint256 amount_) external override {
function pullFundsFromLiquidator(address liquidator_, address token_, address destination_, uint256 amount_) external override {
require(msg.sender == _getPoolDelegate(), "DL:SA:NOT_PD");

Liquidator(_liquidator).pullFunds(token_, destination_, amount_);
Liquidator(liquidator_).pullFunds(token_, destination_, amount_);
}

function setAllowedSlippage(uint256 allowedSlippage_) external override whenProtocolNotPaused {
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/IDebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ interface IDebtLocker is IMapleProxied {

/**
* @dev Allows the poolDelegate to pull some funds from liquidator contract
* @param liquidator_ The liquidator to which pull funds from.
* @param token_ The token address of the funds.
* @param destination_ The destination address of captured funds.
* @param amount_ The amount to pull.
*/
function pullFundsFromLiquidator(address token_, address destination_, uint256 amount_) external;
function pullFundsFromLiquidator(address liquidator_, address token_, address destination_, uint256 amount_) external;

/**
* @dev Returns the address of the Pool Delegate that has control of the DebtLocker.
Expand Down
31 changes: 31 additions & 0 deletions contracts/test/DebtLocker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,37 @@ contract DebtLockerTests is TestUtils {
pool.claim(address(debtLocker)); // Can successfully claim
}

function test_liquidation_pullFunds(uint256 principalRequested_, uint256 collateralRequired_) external {

/**********************************/
/*** Create Loan and DebtLocker ***/
/**********************************/

principalRequested_ = constrictToRange(principalRequested_, 1_000_000, MAX_TOKEN_AMOUNT);
collateralRequired_ = constrictToRange(collateralRequired_, 1, principalRequested_ / 10); // Need collateral for liquidator deployment

( MapleLoan loan, DebtLocker debtLocker ) = _createFundAndDrawdownLoan(principalRequested_, collateralRequired_);

/*************************************/
/*** Trigger default and liquidate ***/
/*************************************/

hevm.warp(loan.nextPaymentDueDate() + loan.gracePeriod() + 1);

pool.triggerDefault(address(debtLocker));

address liquidator = debtLocker.liquidator();

assertEq(collateralAsset.balanceOf(address(this)), 0);
assertEq(collateralAsset.balanceOf(address(liquidator)), collateralRequired_);

assertTrue(!notPoolDelegate.try_debtLocker_pullFunds(address(debtLocker), address(liquidator), address(collateralAsset), address(this), collateralRequired_));
assertTrue( poolDelegate.try_debtLocker_pullFunds(address(debtLocker), address(liquidator), address(collateralAsset), address(this), collateralRequired_));

assertEq(collateralAsset.balanceOf(address(this)), collateralRequired_);
assertEq(collateralAsset.balanceOf(address(liquidator)), 0);
}

/****************************/
/*** Access Control Tests ***/
/****************************/
Expand Down
8 changes: 8 additions & 0 deletions contracts/test/accounts/PoolDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ contract PoolDelegate is ProxyUser {
IDebtLocker(debtLocker_).acceptNewTerms(refinancer_, calls_, amount_);
}

function debtLocker_pullFunds(address debtLocker_, address liquidator_, address token_, address destination_, uint256 amount_) external {
IDebtLocker(debtLocker_).pullFundsFromLiquidator(liquidator_, token_, destination_, amount_);
}

function debtLocker_setAllowedSlippage(address debtLocker_, uint256 allowedSlippage_) external {
IDebtLocker(debtLocker_).setAllowedSlippage(allowedSlippage_);
}
Expand Down Expand Up @@ -52,6 +56,10 @@ contract PoolDelegate is ProxyUser {
( ok_, ) = debtLocker_.call(abi.encodeWithSelector(IDebtLocker.acceptNewTerms.selector, refinancer_, calls_, amount_));
}

function try_debtLocker_pullFunds(address debtLocker_, address liquidator_, address token_, address destination_, uint256 amount_) external returns (bool ok_) {
( ok_, ) = debtLocker_.call(abi.encodeWithSelector(IDebtLocker.pullFundsFromLiquidator.selector, liquidator_, token_, destination_, amount_));
}

function try_debtLocker_setAllowedSlippage(address debtLocker_, uint256 allowedSlippage_) external returns (bool ok_) {
( ok_, ) = debtLocker_.call(abi.encodeWithSelector(IDebtLocker.setAllowedSlippage.selector, allowedSlippage_));
}
Expand Down

0 comments on commit 52fe628

Please sign in to comment.