From 05dce15894eb684a1ae0a3d3411c065e749a3f93 Mon Sep 17 00:00:00 2001 From: Brice Stacey Date: Fri, 28 Oct 2022 14:55:29 -0400 Subject: [PATCH] Extract ILoanFees struct This is necessary because we ran out of call stack --- contracts/Loan.sol | 15 ++++++--------- contracts/LoanFactory.sol | 6 ++---- contracts/interfaces/ILoan.sol | 5 +++++ test/Loan.test.ts | 6 ++++-- test/support/loan.ts | 5 ++++- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/contracts/Loan.sol b/contracts/Loan.sol index b6106ad0..e9a50d19 100644 --- a/contracts/Loan.sol +++ b/contracts/Loan.sol @@ -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_` @@ -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; @@ -116,7 +114,7 @@ contract Loan is ILoan { apr = apr_; liquidityAsset = liquidityAsset_; principal = principal_; - latePaymentFee = latePaymentFee_; + fees = fees_; LoanLib.validateLoan( serviceConfiguration, @@ -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) @@ -324,7 +321,7 @@ contract Loan is ILoan { payment, _serviceConfiguration.firstLossFeeBps(), IPool(_pool).poolFeePercentOfInterest(), - latePaymentFee, + fees.latePayment, paymentDueDate ); @@ -355,7 +352,7 @@ contract Loan is ILoan { amount, _serviceConfiguration.firstLossFeeBps(), IPool(_pool).poolFeePercentOfInterest(), - latePaymentFee, + fees.latePayment, paymentDueDate ); diff --git a/contracts/LoanFactory.sol b/contracts/LoanFactory.sol index 8f8f6178..b3287996 100644 --- a/contracts/LoanFactory.sol +++ b/contracts/LoanFactory.sol @@ -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, @@ -60,8 +59,7 @@ contract LoanFactory { liquidityAsset, principal, dropDeadDate, - latePaymentFee, - originationFee + fees ); address addr = address(loan); emit LoanCreated(addr); diff --git a/contracts/interfaces/ILoan.sol b/contracts/interfaces/ILoan.sol index 659c6cf9..0c124611 100644 --- a/contracts/interfaces/ILoan.sol +++ b/contracts/interfaces/ILoan.sol @@ -26,6 +26,11 @@ struct ILoanNonFungibleCollateral { uint256 tokenId; } +struct ILoanFees { + uint256 latePayment; + uint256 originationBps; +} + interface ILoan { /** * @dev Emitted when loan is funded. diff --git a/test/Loan.test.ts b/test/Loan.test.ts index 7845c42a..6edce602 100644 --- a/test/Loan.test.ts +++ b/test/Loan.test.ts @@ -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(); diff --git a/test/support/loan.ts b/test/support/loan.ts index 38a17d6a..d1132057 100644 --- a/test/support/loan.ts +++ b/test/support/loan.ts @@ -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();