From 63724e4405b6dc397f92eba980f63298bd19b699 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Sun, 23 Nov 2025 00:03:52 -0500 Subject: [PATCH] Review feedback from @gregtatcam: seconds per year - Define a constexpr secondsInYear in LedgerHelpers.h --- src/test/app/Loan_test.cpp | 4 ++-- src/xrpld/app/misc/LendingHelpers.h | 2 ++ src/xrpld/app/misc/detail/LendingHelpers.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index 97078f8d95..608a384199 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -2388,7 +2388,7 @@ protected: // the below BEAST_EXPECTs may not hold across assets. Number const interval = state.paymentInterval; auto const periodicRate = - interval * Number(12, -2) / (365 * 24 * 60 * 60); + interval * Number(12, -2) / secondsInYear; BEAST_EXPECT( periodicRate == Number(2283105022831050, -21, Number::unchecked{})); @@ -2620,7 +2620,7 @@ protected: // the below BEAST_EXPECTs may not hold across assets. Number const interval = state.paymentInterval; auto const periodicRate = - interval * Number(12, -2) / (365 * 24 * 60 * 60); + interval * Number(12, -2) / secondsInYear; BEAST_EXPECT( periodicRate == Number(2283105022831050, -21, Number::unchecked{})); diff --git a/src/xrpld/app/misc/LendingHelpers.h b/src/xrpld/app/misc/LendingHelpers.h index 89ac0fb041..d2ff79d9b5 100644 --- a/src/xrpld/app/misc/LendingHelpers.h +++ b/src/xrpld/app/misc/LendingHelpers.h @@ -12,6 +12,8 @@ struct PreflightContext; bool checkLendingProtocolDependencies(PreflightContext const& ctx); +static constexpr std::uint32_t secondsInYear = 365 * 24 * 60 * 60; + Number loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval); diff --git a/src/xrpld/app/misc/detail/LendingHelpers.cpp b/src/xrpld/app/misc/detail/LendingHelpers.cpp index 9f88001c05..bbee329ff5 100644 --- a/src/xrpld/app/misc/detail/LendingHelpers.cpp +++ b/src/xrpld/app/misc/detail/LendingHelpers.cpp @@ -54,7 +54,7 @@ loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval) * other places. */ return tenthBipsOfValue(Number(paymentInterval), interestRate) / - (365 * 24 * 60 * 60); + secondsInYear; } bool