Skip to content

Commit

Permalink
Extract ILoanFees struct
Browse files Browse the repository at this point in the history
This is necessary because we ran out of call stack
  • Loading branch information
bricestacey committed Oct 28, 2022
1 parent 57c320a commit 05dce15
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
15 changes: 6 additions & 9 deletions contracts/Loan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ contract Loan is ILoan {
uint256 public immutable payment;
uint256 public paymentsRemaining;
uint256 public paymentDueDate;
uint256 public latePaymentFee;
uint256 public originationFeeBps;
uint256 public originationFee;
ILoanFees fees;

/**
* @dev Modifier that requires the Loan be in the given `state_`
Expand Down Expand Up @@ -100,8 +99,7 @@ contract Loan is ILoan {
address liquidityAsset_,
uint256 principal_,
uint256 dropDeadTimestamp,
uint256 latePaymentFee_,
uint256 originationFeeBps_
ILoanFees memory fees_
) {
_serviceConfiguration = serviceConfiguration;
_factory = factory;
Expand All @@ -116,7 +114,7 @@ contract Loan is ILoan {
apr = apr_;
liquidityAsset = liquidityAsset_;
principal = principal_;
latePaymentFee = latePaymentFee_;
fees = fees_;

LoanLib.validateLoan(
serviceConfiguration,
Expand All @@ -136,9 +134,8 @@ contract Loan is ILoan {
payment = paymentsTotal.mul(RAY).div(paymentsRemaining).div(RAY);

// Persist origination fee and cache the computed value
originationFeeBps = originationFeeBps_;
originationFee = principal
.mul(originationFeeBps)
.mul(fees.originationBps)
.mul(duration.mul(RAY).div(360))
.div(paymentsRemaining)
.div(RAY)
Expand Down Expand Up @@ -324,7 +321,7 @@ contract Loan is ILoan {
payment,
_serviceConfiguration.firstLossFeeBps(),
IPool(_pool).poolFeePercentOfInterest(),
latePaymentFee,
fees.latePayment,
paymentDueDate
);

Expand Down Expand Up @@ -355,7 +352,7 @@ contract Loan is ILoan {
amount,
_serviceConfiguration.firstLossFeeBps(),
IPool(_pool).poolFeePercentOfInterest(),
latePaymentFee,
fees.latePayment,
paymentDueDate
);

Expand Down
6 changes: 2 additions & 4 deletions contracts/LoanFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ contract LoanFactory {
address liquidityAsset,
uint256 principal,
uint256 dropDeadDate,
uint256 latePaymentFee,
uint256 originationFee
ILoanFees memory fees
) public virtual returns (address LoanAddress) {
require(
_serviceConfiguration.paused() == false,
Expand All @@ -60,8 +59,7 @@ contract LoanFactory {
liquidityAsset,
principal,
dropDeadDate,
latePaymentFee,
originationFee
fees
);
address addr = address(loan);
emit LoanCreated(addr);
Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/ILoan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct ILoanNonFungibleCollateral {
uint256 tokenId;
}

struct ILoanFees {
uint256 latePayment;
uint256 originationBps;
}

interface ILoan {
/**
* @dev Emitted when loan is funded.
Expand Down
6 changes: 4 additions & 2 deletions test/Loan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ describe("Loan", () => {
liquidityAsset.address,
500_000,
Math.floor(Date.now() / 1000) + SEVEN_DAYS,
1_000,
loanSettings.originationFee
{
latePayment: 1_000,
originationBps: loanSettings.originationFee
}
);
const tx2Receipt = await tx2.wait();

Expand Down
5 changes: 4 additions & 1 deletion test/support/loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export async function deployLoan(
liquidityAsset,
1_000_000,
Math.floor(Date.now() / 1000) + SEVEN_DAYS,
0
{
latePayment: 1_000,
originationBps: 0
}
);

const txnReceipt = await txn.wait();
Expand Down

0 comments on commit 05dce15

Please sign in to comment.