Skip to content

Commit

Permalink
feat: Add acceptNewTerms and rejectNewTerms deadlines to DebtLock…
Browse files Browse the repository at this point in the history
…er (#60)

* Draft

* feat: all tests passing with fees included

* feat: add rejectNewTerms test

Co-authored-by: Michael De Luca <[email protected]>
  • Loading branch information
Lucas Manuel and deluca-mike authored Mar 8, 2022
1 parent b5a1f50 commit 4d340b0
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 89 deletions.
10 changes: 8 additions & 2 deletions contracts/DebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxiedInternals {
/*** Pool Delegate Functions ***/
/*******************************/

function acceptNewTerms(address refinancer_, bytes[] calldata calls_, uint256 amount_) external override whenProtocolNotPaused {
function acceptNewTerms(address refinancer_, uint256 deadline_, bytes[] calldata calls_, uint256 amount_) external override whenProtocolNotPaused {
require(msg.sender == _getPoolDelegate(), "DL:ANT:NOT_PD");

address loanAddress = _loan;
Expand All @@ -65,7 +65,7 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxiedInternals {
"DL:ANT:TRANSFER_FAILED"
);

IMapleLoanLike(loanAddress).acceptNewTerms(refinancer_, calls_, uint256(0));
IMapleLoanLike(loanAddress).acceptNewTerms(refinancer_, deadline_, calls_, uint256(0));

// NOTE: This must be set after accepting the new terms, which affects the loan principal.
_principalRemainingAtLastClaim = IMapleLoanLike(loanAddress).principal();
Expand All @@ -83,6 +83,12 @@ contract DebtLocker is IDebtLocker, DebtLockerStorage, MapleProxiedInternals {
Liquidator(liquidator_).pullFunds(token_, destination_, amount_);
}

function rejectNewTerms(address refinancer_, uint256 deadline_, bytes[] calldata calls_) external override {
require(msg.sender == _getPoolDelegate(), "DL:ANT:NOT_PD");

IMapleLoanLike(_loan).rejectNewTerms(refinancer_, deadline_, calls_);
}

function setAllowedSlippage(uint256 allowedSlippage_) external override whenProtocolNotPaused {
require(msg.sender == _getPoolDelegate(), "DL:SAS:NOT_PD");
require(allowedSlippage_ <= uint256(10_000), "DL:SAS:INVALID_SLIPPAGE");
Expand Down
11 changes: 10 additions & 1 deletion contracts/interfaces/IDebtLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ interface IDebtLocker is IMapleProxied {
/**
* @dev Accept the new loan terms and trigger a refinance.
* @param refinancer_ The address of the refinancer contract.
* @param deadline_ The deadline of the new terms proposal.
* @param calls_ The array of encoded data that are to be executed as delegatecalls by the refinancer.
* @param amount_ The amount of `fundsAsset` that is to be sent to the Loan as part of the transaction.
*/
function acceptNewTerms(address refinancer_, bytes[] calldata calls_, uint256 amount_) external;
function acceptNewTerms(address refinancer_, uint256 deadline_, bytes[] calldata calls_, uint256 amount_) external;

/**
* @dev Claims funds to send to Pool. Handles funds from payments and liquidations.
Expand Down Expand Up @@ -84,6 +85,14 @@ interface IDebtLocker is IMapleProxied {
*/
function triggerDefault() external;

/**
* @dev Reject the new loan terms.
* @param refinancer_ The address of the refinancer contract.
* @param deadline_ The deadline of the new terms proposal.
* @param calls_ The array of encoded data that are to be executed as delegatecalls by the refinancer.
*/
function rejectNewTerms(address refinancer_, uint256 deadline_, bytes[] calldata calls_) external;

/**
* @dev Sets the allowed slippage for auctioneer (used to determine expected amount to be returned in flash loan).
* @param allowedSlippage_ Basis points representation of allowed percent slippage from market price.
Expand Down
10 changes: 7 additions & 3 deletions contracts/interfaces/Interfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ interface IMapleGlobalsLike {

interface IMapleLoanLike {

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

function claimableFunds() external view returns (uint256 claimableFunds_);

function claimFunds(uint256 amount_, address destination_) external;

function collateralAsset() external view returns (address collateralAsset_);

function fundsAsset() external view returns (address fundsAsset_);
Expand All @@ -50,10 +52,12 @@ interface IMapleLoanLike {

function principalRequested() external view returns (uint256 principalRequested_);

function claimFunds(uint256 amount_, address destination_) external;

function repossess(address destination_) external returns (uint256 collateralAssetAmount_, uint256 fundsAssetAmount_);

function refinanceCommitment() external view returns (bytes32 refinanceCommitment_);

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

}

interface IPoolLike {
Expand Down
Loading

0 comments on commit 4d340b0

Please sign in to comment.