From afe9c9ba211a44989a3aef0a2e13af414de33295 Mon Sep 17 00:00:00 2001 From: Admazzola Date: Wed, 15 May 2024 15:34:33 -0400 Subject: [PATCH 1/2] add --- .../contracts/libraries/V2Calculations.sol | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/contracts/contracts/libraries/V2Calculations.sol b/packages/contracts/contracts/libraries/V2Calculations.sol index 4a01c336..375ea3c1 100644 --- a/packages/contracts/contracts/libraries/V2Calculations.sol +++ b/packages/contracts/contracts/libraries/V2Calculations.sol @@ -86,13 +86,18 @@ library V2Calculations { _bid.loanDetails.principal - _bid.loanDetails.totalRepaid.principal; - uint256 daysInYear = _paymentCycleType == PaymentCycleType.Monthly + uint256 owedTime = _timestamp - uint256(_lastRepaidTimestamp); + + { + uint256 daysInYear = _paymentCycleType == PaymentCycleType.Monthly ? 360 days : 365 days; - uint256 interestOwedInAYear = owedPrincipal_.percent(_bid.terms.APR); - uint256 owedTime = _timestamp - uint256(_lastRepaidTimestamp); - interest_ = (interestOwedInAYear * owedTime) / daysInYear; + uint256 interestOwedInAYear = owedPrincipal_.percent(_bid.terms.APR); + + interest_ = (interestOwedInAYear * owedTime) / daysInYear; + } + bool isLastPaymentCycle; { @@ -121,10 +126,13 @@ library V2Calculations { // Max payable amount in a cycle // NOTE: the last cycle could have less than the calculated payment amount + //the amount owed for the cycle should never exceed the current payment cycle amount so we use min here + uint256 owedAmountForCycle = Math.min( ((_bid.terms.paymentCycleAmount * owedTime)+interest_ ) / + _paymentCycleDuration , _bid.terms.paymentCycleAmount+interest_ ) ; + uint256 owedAmount = isLastPaymentCycle ? owedPrincipal_ + interest_ - : (_bid.terms.paymentCycleAmount * owedTime) / - _paymentCycleDuration; + : owedAmountForCycle ; duePrincipal_ = Math.min(owedAmount - interest_, owedPrincipal_); } From 8ac0e1037257130c71dc4fbf4829d56c5e343291 Mon Sep 17 00:00:00 2001 From: Admazzola Date: Thu, 13 Jun 2024 14:52:52 -0400 Subject: [PATCH 2/2] remove interst dbl count --- packages/contracts/contracts/libraries/V2Calculations.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/contracts/libraries/V2Calculations.sol b/packages/contracts/contracts/libraries/V2Calculations.sol index 375ea3c1..f913616b 100644 --- a/packages/contracts/contracts/libraries/V2Calculations.sol +++ b/packages/contracts/contracts/libraries/V2Calculations.sol @@ -127,7 +127,7 @@ library V2Calculations { // NOTE: the last cycle could have less than the calculated payment amount //the amount owed for the cycle should never exceed the current payment cycle amount so we use min here - uint256 owedAmountForCycle = Math.min( ((_bid.terms.paymentCycleAmount * owedTime)+interest_ ) / + uint256 owedAmountForCycle = Math.min( ((_bid.terms.paymentCycleAmount * owedTime) ) / _paymentCycleDuration , _bid.terms.paymentCycleAmount+interest_ ) ; uint256 owedAmount = isLastPaymentCycle