adds LEVersion field to Vault

This commit is contained in:
Vito
2026-07-21 15:25:25 +02:00
parent c0bd10ccec
commit cc03abd79b
14 changed files with 450 additions and 45 deletions

View File

@@ -304,7 +304,7 @@ loanOriginationDeltas(Number const& principalRequested, Number const& interestDu
// LoanManage impair/unimpair/default: the vault's exposure to this loan
Number
loanVaultExposure(SLE::ref loanSle);
loanVaultExposure(SLE::const_ref loanSle);
// LoanPay: what's added to Vault.AssetsTotal and subtracted from LoanBroker.DebtTotal for a payment
AccountingDeltas
@@ -317,10 +317,10 @@ loanPaymentDeltas(LoanPaymentParts const& parts);
namespace CashBasis {
AccountingDeltas
loanOriginationDeltas(Number const& principalRequested, Number const& interestDue);
loanOriginationDeltas(Number const& principalRequested);
Number
loanVaultExposure(SLE::ref loanSle);
loanVaultExposure(SLE::const_ref loanSle);
AccountingDeltas
loanPaymentDeltas(LoanPaymentParts const& parts);
@@ -328,18 +328,21 @@ loanPaymentDeltas(LoanPaymentParts const& parts);
} // namespace CashBasis
// Public dispatchers: pick CashBasis:: if featureLendingProtocolV1_1 is
// enabled, else Accrual::. These are the only entry points transactors call.
// enabled AND the Vault's LEVersion (VaultHelpers::getVaultVersion) is
// VaultVersion::CashBasis, else Accrual::. These are the only entry points
// transactors call.
AccountingDeltas
loanOriginationDeltas(
Rules const& rules,
SLE::const_ref vaultSle,
Number const& principalRequested,
Number const& interestDue);
Number
loanVaultExposure(Rules const& rules, SLE::ref loanSle);
loanVaultExposure(Rules const& rules, SLE::const_ref vaultSle, SLE::const_ref loanSle);
AccountingDeltas
loanPaymentDeltas(Rules const& rules, LoanPaymentParts const& parts);
loanPaymentDeltas(Rules const& rules, SLE::const_ref vaultSle, LoanPaymentParts const& parts);
namespace detail {
// These classes and functions should only be accessed by LendingHelper

View File

@@ -2,6 +2,7 @@
#include <xrpl/ledger/ReadView.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>
@@ -107,4 +108,17 @@ sharesToAssetsWithdraw(
[[nodiscard]] bool
isSoleShareholder(ReadView const& view, AccountID const& account, SLE::const_ref issuance);
/**
* Resolves a Vault's LEVersion, the single point every accounting touch
* point should call to determine which recognition model (accrual vs.
* cash-basis) a Vault uses. Vaults created before featureLendingProtocolV1_1
* activated never have sfLEVersion set, which resolves here to 0 (legacy).
*
* @param vault The vault SLE.
*
* @return The Vault's LEVersion, or 0 if the field is absent.
*/
[[nodiscard]] VaultVersion
getVaultVersion(SLE::const_ref vault);
} // namespace xrpl

View File

@@ -316,6 +316,18 @@ constexpr std::uint8_t kVaultDefaultIouScale = 6;
*/
constexpr std::uint8_t kVaultMaximumIouScale = 18;
/**
* Vault ledger-entry schema versions. Assigned to newly created
* Vaults once featureLendingProtocolV1_1 is enabled. Vaults created before
* activation are left without LEVersion (implicit legacy version 0,
* accrual-basis accounting).
*/
enum class VaultVersion : uint8_t {
Legacy = 0,
Invalid,
CashBasis,
};
/**
* Maximum recursion depth for vault shares being put as an asset inside
* another vault; counted from 0

View File

@@ -505,6 +505,7 @@ LEDGER_ENTRY(ltVAULT, 0x0084, Vault, vault, ({
{sfShareMPTID, SoeRequired},
{sfWithdrawalPolicy, SoeRequired},
{sfScale, SoeDefault},
{sfLEVersion, SoeDefault},
// no SharesTotal ever (use MPTIssuance.sfOutstandingAmount)
// no PermissionedDomainID ever (use MPTIssuance.sfDomainID)
}))

View File

@@ -18,6 +18,7 @@ TYPED_SFIELD(sfMethod, UINT8, 2)
TYPED_SFIELD(sfTransactionResult, UINT8, 3)
TYPED_SFIELD(sfScale, UINT8, 4)
TYPED_SFIELD(sfAssetScale, UINT8, 5)
TYPED_SFIELD(sfLEVersion, UINT8, 6)
// 8-bit integers (uncommon)
TYPED_SFIELD(sfTickSize, UINT8, 16)