xrpld
Loading...
Searching...
No Matches
xrpl::ValidVault Class Reference

Invariants: Vault object and MPTokenIssuance for vault shares. More...

#include <VaultInvariant.h>

Collaboration diagram for xrpl::ValidVault:

Classes

struct  Vault
struct  Shares
struct  DeltaInfo

Public Member Functions

void visitEntry (bool, SLE::const_ref, SLE::const_ref)
bool finalize (STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)

Static Public Member Functions

static std::int32_t computeCoarsestScale (std::vector< DeltaInfo > const &numbers)

Private Member Functions

std::int32_t computeVaultMinScale (DeltaInfo const &vaultDelta, Rules const &rules) const
 Compute the minimum STAmount scale for rounding invariant calculations.
std::optional< DeltaInfodeltaAssets (AccountID const &id) const
 Return the vault-asset balance-change delta for an account.
std::optional< DeltaInfodeltaAssetsTxAccount (STTx const &tx, XRPAmount fee) const
 Return the vault-asset delta for the transaction's sending account, adjusted for the fee.
std::optional< DeltaInfodeltaShares (AccountID const &id) const
 Return the vault-share balance-change delta for an account.
bool finalizeLoanSet (ReadView const &view, beast::Journal const &j) const
 Invariant check for ttLOAN_SET.

Static Private Member Functions

static bool isVaultEmpty (Vault const &vault)
 Check whether a vault holds no assets.

Private Attributes

std::vector< VaultafterVault_
std::vector< SharesafterMPTs_
std::vector< VaultbeforeVault_
std::vector< SharesbeforeMPTs_
std::unordered_map< uint256, DeltaInfodeltas_

Static Private Attributes

static constexpr Number kZero {}

Detailed Description

Invariants: Vault object and MPTokenIssuance for vault shares.

  • vault deleted and vault created is empty
  • vault created must be linked to pseudo-account for shares and assets
  • vault must have MPTokenIssuance for shares
  • vault without shares outstanding must have no shares
  • loss unrealized does not exceed the difference between assets total and assets available
  • assets available do not exceed assets total
  • vault deposit increases assets and share issuance, and adds to: total assets, assets available, shares outstanding
  • vault withdrawal and clawback reduce assets and share issuance, and subtracts from: total assets, assets available, shares outstanding
  • vault set must not alter the vault assets or shares balance
  • no vault transaction can change loss unrealized (it's updated by loan transactions)
  • a created closed-ended vault must satisfy MIN_INVESTMENT_PERIOD <= RedemptionDate - SubscriptionDate < MAX_INVESTMENT_PERIOD
  • vault deposit may only succeed when the vault phase is NoPhase or Subscription
  • vault withdrawal may not succeed when the vault phase is Investment
  • closed-ended loan origination (ttLOAN_SET) may only succeed when the vault phase is Investment

Immutability of VaultKind, SubscriptionDate and RedemptionDate is enforced by NoModifiedUnmodifiableFields (see InvariantCheck.cpp).

Definition at line 53 of file VaultInvariant.h.

Member Function Documentation

◆ computeVaultMinScale()

std::int32_t xrpl::ValidVault::computeVaultMinScale ( DeltaInfo const & vaultDelta,
Rules const & rules ) const
nodiscardprivate

Compute the minimum STAmount scale for rounding invariant calculations.

Post-amendment (fixCleanup3_2_0) this is simply the posterior assetsTotal scale. Pre-amendment it is the coarsest scale across vaultDelta and both asset-field deltas.

Parameters
vaultDeltaDelta of the vault's asset balance for this transaction.
rulesActive ledger rules (used to check the amendment).
Returns
The minimum scale to apply when rounding vault-related amounts.

Definition at line 309 of file VaultInvariant.cpp.

◆ deltaAssets()

std::optional< ValidVault::DeltaInfo > xrpl::ValidVault::deltaAssets ( AccountID const & id) const
nodiscardprivate

Return the vault-asset balance-change delta for an account.

Looks up the ledger-entry delta recorded during visitEntry for the account entry (XRP), trust line (IOU), or MPToken (MPT) that corresponds to the vault asset held by id.

Parameters
idAccount whose asset delta is requested.
Returns
The delta, or std::nullopt if the entry was not touched.

Definition at line 206 of file VaultInvariant.cpp.

◆ deltaAssetsTxAccount()

std::optional< ValidVault::DeltaInfo > xrpl::ValidVault::deltaAssetsTxAccount ( STTx const & tx,
XRPAmount fee ) const
nodiscardprivate

Return the vault-asset delta for the transaction's sending account, adjusted for the fee.

Calls deltaAssets for tx[sfAccount] and, for non-delegated XRP transactions, adds the consumed fee back so the invariant sees the net asset movement rather than the fee-reduced balance change.

Parameters
txThe transaction being applied.
feeFee charged by this transaction.
Returns
The fee-adjusted delta, or std::nullopt if the net delta is zero or the account entry was not touched.

Definition at line 238 of file VaultInvariant.cpp.

◆ deltaShares()

std::optional< ValidVault::DeltaInfo > xrpl::ValidVault::deltaShares ( AccountID const & id) const
nodiscardprivate

Return the vault-share balance-change delta for an account.

For the vault's pseudo-account the MPTokenIssuance outstanding-amount delta is returned; for all other accounts the MPToken delta is returned.

Parameters
idAccount whose share delta is requested.
Returns
The delta, or std::nullopt if the entry was not touched.

Definition at line 259 of file VaultInvariant.cpp.

◆ isVaultEmpty()

bool xrpl::ValidVault::isVaultEmpty ( Vault const & vault)
staticnodiscardprivate

Check whether a vault holds no assets.

Parameters
vaultSnapshot of the vault to test.
Returns
true when both assetsAvailable and assetsTotal are zero.

Definition at line 272 of file VaultInvariant.cpp.

◆ finalizeLoanSet()

bool xrpl::ValidVault::finalizeLoanSet ( ReadView const & view,
beast::Journal const & j ) const
nodiscardprivate

Invariant check for ttLOAN_SET.

For a closed-ended vault, a loan may only be originated while the vault is in the Investment phase (strictly past SubscriptionDate and before RedemptionDate). Open-ended vaults (NoPhase) are unaffected. The complementary maturity bound (final payment strictly precedes RedemptionDate) is enforced by ValidLoan.

Definition at line 278 of file VaultInvariant.cpp.

◆ computeCoarsestScale()

std::int32_t xrpl::ValidVault::computeCoarsestScale ( std::vector< DeltaInfo > const & numbers)
staticnodiscard

Definition at line 1191 of file VaultInvariant.cpp.

◆ visitEntry()

void xrpl::ValidVault::visitEntry ( bool isDelete,
SLE::const_ref before,
SLE::const_ref after )

Definition at line 85 of file VaultInvariant.cpp.

◆ finalize()

bool xrpl::ValidVault::finalize ( STTx const & tx,
TER const ret,
XRPAmount const fee,
ReadView const & view,
beast::Journal const & j )

Definition at line 335 of file VaultInvariant.cpp.

Member Data Documentation

◆ kZero

Number xrpl::ValidVault::kZero {}
staticconstexprprivate

Definition at line 55 of file VaultInvariant.h.

◆ afterVault_

std::vector<Vault> xrpl::ValidVault::afterVault_
private

Definition at line 96 of file VaultInvariant.h.

◆ afterMPTs_

std::vector<Shares> xrpl::ValidVault::afterMPTs_
private

Definition at line 97 of file VaultInvariant.h.

◆ beforeVault_

std::vector<Vault> xrpl::ValidVault::beforeVault_
private

Definition at line 98 of file VaultInvariant.h.

◆ beforeMPTs_

std::vector<Shares> xrpl::ValidVault::beforeMPTs_
private

Definition at line 99 of file VaultInvariant.h.

◆ deltas_

std::unordered_map<uint256, DeltaInfo> xrpl::ValidVault::deltas_
private

Definition at line 100 of file VaultInvariant.h.