From 7ff2f58a980b59f73dc56c93f65d340a1aa3271d Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Tue, 6 May 2025 19:24:06 -0400 Subject: [PATCH] fixup! Update to match latest spec: compute interest, LoanBroker reserves --- src/xrpld/app/tx/detail/LoanSet.cpp | 44 +++++++++++------------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/xrpld/app/tx/detail/LoanSet.cpp b/src/xrpld/app/tx/detail/LoanSet.cpp index 112a1bce13..fd6f9c294b 100644 --- a/src/xrpld/app/tx/detail/LoanSet.cpp +++ b/src/xrpld/app/tx/detail/LoanSet.cpp @@ -243,34 +243,24 @@ LoanSet::preclaim(PreclaimContext const& ctx) return tecINSUFFICIENT_FUNDS; } - // Check that the lender will not make a profit on the lending fee if the - // loan defaults. (Not yet in spec. May not be included.) - TenthBips32 const interestRate{tx[~sfInterestRate].value_or(0)}; - auto const paymentInterval = - tx[~sfPaymentInterval].value_or(defaultPaymentInterval); - auto const paymentTotal = tx[~sfPaymentTotal].value_or(defaultPaymentTotal); - TenthBips32 const coverRateLiquidation{ - brokerSle->at(sfCoverRateLiquidation)}; - TenthBips32 const managementFeeRate{brokerSle->at(sfManagementFeeRate)}; - - auto const totalInterestToVault = LoanInterestOutstandingToVault( - asset, - principalRequested, - interestRate, - paymentInterval, - paymentTotal, - managementFeeRate); - - auto const maximumOriginationFee = tenthBipsOfValue( - tenthBipsOfValue(newDebtTotal, coverRateMinimum), coverRateLiquidation); - - if (auto const originationFee = tx[~sfLoanOriginationFee]; - originationFee && *originationFee > maximumOriginationFee) + if (auto const originationFee = tx[~sfLoanOriginationFee]) { - JLOG(ctx.j.warn()) - << "Loan origination fee is too high. The lender will make a " - "profit on the lending fee if the loan defaults."; - return tecINSUFFICIENT_FUNDS; + // Check that the lender will not make an unfair profit on the lending + // fee if the loan defaults. (Not yet in spec. May not be included.) + TenthBips32 const coverRateLiquidation{ + brokerSle->at(sfCoverRateLiquidation)}; + + auto const maximumOriginationFee = tenthBipsOfValue( + tenthBipsOfValue(newDebtTotal, coverRateMinimum), + coverRateLiquidation); + + if (*originationFee > maximumOriginationFee) + { + JLOG(ctx.j.warn()) + << "Loan origination fee is too high. The lender will make a " + "profit on the lending fee if the loan defaults."; + return tecINSUFFICIENT_FUNDS; + } } return tesSUCCESS;