Review feedback from @gregtatcam:

- In progress
- Add explanatory comments, and start refactoring
  loanComputePaymentParts into functions for readability.
This commit is contained in:
Ed Hennis
2025-09-17 19:37:59 -04:00
parent b9a2eb3399
commit b5ddc812ea
5 changed files with 130 additions and 48 deletions

View File

@@ -695,6 +695,17 @@ divRoundStrict(
std::uint64_t
getRate(STAmount const& offerOut, STAmount const& offerIn);
/** Round an arbitrary precision Amount to the precision of a reference Amount.
*
* This is used to ensure that calculations involving IOU amounts do not collect
* dust beyond the precision of the reference value.
*
* @param value The value to be rounded
* @param referenceValue A reference value to establish the precision limit of
* `value`. Should be larger than `value`.
* @param rounding Optional Number rounding mode
*
*/
STAmount
roundToReference(
STAmount const value,
@@ -702,12 +713,16 @@ roundToReference(
Number::rounding_mode rounding = Number::getround());
/** Round an arbitrary precision Number to the precision of a given Asset.
*
* This is used to ensure that calculations do not collect dust beyond the
* precision of the reference value for IOUs, or fractional amounts for the
* integral types XRP and MPT.
*
* @param asset The relevant asset
* @param value The value to be rounded
* @param referenceValue Only relevant to IOU assets. A reference value to
* establish the precision limit of `value`. Should be larger than
* `value`.
* `value`.
* @param rounding Optional Number rounding mode
*/
template <AssetType A>
@@ -722,6 +737,8 @@ roundToAsset(
STAmount const ret{asset, value};
if (ret.asset().native() || !ret.asset().holds<Issue>())
return ret;
// Not that the ctor will round integral types (XRP, MPT) via canonicalize,
// so no extra work is needed for those.
return roundToReference(ret, STAmount{asset, referenceValue});
}