Implement Lending Protocol (unsupported) (#5270)

- Spec: XLS-66
- Introduces amendment "LendingProtocol", but leaves it UNSUPPORTED to
  allow for standalone testing, future development work, and potential
  bug fixes.
- AccountInfo RPC will indicate the type of pseudo-account when
  appropriate.
- Refactors and improves several existing classes and functional areas,
  including Number, STAmount, STObject, json_value, Asset, directory
  handling, View helper functions, and unit test helpers.
This commit is contained in:
Ed Hennis
2025-12-02 11:38:17 -05:00
committed by GitHub
parent c9f17dd85d
commit 6c67f1f525
86 changed files with 18810 additions and 553 deletions

View File

@@ -279,7 +279,7 @@ STAmount::xrp() const
IOUAmount
STAmount::iou() const
{
if (native() || !holds<Issue>())
if (integral())
Throw<std::logic_error>("Cannot return non-IOU STAmount as IOUAmount");
auto mantissa = static_cast<std::int64_t>(mValue);
@@ -830,7 +830,7 @@ STAmount::isDefault() const
void
STAmount::canonicalize()
{
if (native() || mAsset.holds<MPTIssue>())
if (integral())
{
// native and MPT currency amounts should always have an offset of zero
// log(2^64,10) ~ 19.2
@@ -859,8 +859,10 @@ STAmount::canonicalize()
};
if (native())
set(XRPAmount{num});
else
else if (mAsset.holds<MPTIssue>())
set(MPTAmount{num});
else
Throw<std::runtime_error>("Unknown integral asset type");
mOffset = 0;
}
else
@@ -1461,6 +1463,33 @@ canonicalizeRoundStrict(
}
}
STAmount
roundToScale(
STAmount const& value,
std::int32_t scale,
Number::rounding_mode rounding)
{
// Nothing to do for integral types.
if (value.integral())
return value;
// If the value's exponent is greater than or equal to the scale, then
// rounding will do nothing, and might even lose precision, so just return
// the value.
if (value.exponent() >= scale)
return value;
STAmount const referenceValue{
value.asset(), STAmount::cMinValue, scale, value.negative()};
NumberRoundModeGuard mg(rounding);
// With an IOU, the the result of addition will be truncated to the
// precision of the larger value, which in this case is referenceValue. Then
// remove the reference value via subtraction, and we're left with the
// rounded value.
return (value + referenceValue) - referenceValue;
}
namespace {
// We need a class that has an interface similar to NumberRoundModeGuard