xrpld
Loading...
Searching...
No Matches
VaultInvariant.h
1#pragma once
2
3#include <xrpl/basics/Number.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/Zero.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Asset.h>
10#include <xrpl/protocol/MPTIssue.h>
11#include <xrpl/protocol/Rules.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STTx.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/XRPAmount.h>
16
17#include <cstdint>
18#include <optional>
19#include <unordered_map>
20#include <vector>
21
22namespace xrpl {
23
54{
55 static constexpr Number kZero{};
56
74
75 struct Shares final
76 {
80
81 Shares static make(SLE const&);
82 };
83
84public:
85 struct DeltaInfo final
86 {
89
90 // Compute the delta between two Numbers, taking the coarsest scale
91 [[nodiscard]] static DeltaInfo
92 makeDelta(Number const& before, Number const& after, Asset const& asset);
93 };
94
95private:
101
114 [[nodiscard]] std::int32_t
115 computeVaultMinScale(DeltaInfo const& vaultDelta, Rules const& rules) const;
116
127 [[nodiscard]] std::optional<DeltaInfo>
128 deltaAssets(AccountID const& id) const;
129
143 [[nodiscard]] std::optional<DeltaInfo>
144 deltaAssetsTxAccount(STTx const& tx, XRPAmount fee) const;
145
156 [[nodiscard]] std::optional<DeltaInfo>
157 deltaShares(AccountID const& id) const;
158
166 [[nodiscard]] static bool
167 isVaultEmpty(Vault const& vault);
168
177 [[nodiscard]] bool
178 finalizeLoanSet(ReadView const& view, beast::Journal const& j) const;
179
180public:
181 // Compute the coarsest scale required to represent all numbers
182 [[nodiscard]] static std::int32_t
184
185 void
187
188 bool
189 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
190};
191
192} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Number is a floating point type that can represent a wide range of values.
Definition Number.h:351
A view into a ledger.
Definition ReadView.h:41
Rules controlling protocol behavior.
Definition Rules.h:40
std::shared_ptr< STLedgerEntry const > const & const_ref
Invariants: Vault object and MPTokenIssuance for vault shares.
std::unordered_map< uint256, DeltaInfo > deltas_
std::vector< Shares > afterMPTs_
static bool isVaultEmpty(Vault const &vault)
Check whether a vault holds no assets.
std::vector< Vault > afterVault_
std::optional< DeltaInfo > deltaShares(AccountID const &id) const
Return the vault-share balance-change delta for an account.
std::vector< Shares > beforeMPTs_
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
static std::int32_t computeCoarsestScale(std::vector< DeltaInfo > const &numbers)
std::optional< DeltaInfo > deltaAssetsTxAccount(STTx const &tx, XRPAmount fee) const
Return the vault-asset delta for the transaction's sending account, adjusted for the fee.
bool finalizeLoanSet(ReadView const &view, beast::Journal const &j) const
Invariant check for ttLOAN_SET.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< Vault > beforeVault_
static constexpr Number kZero
std::optional< DeltaInfo > deltaAssets(AccountID const &id) const
Return the vault-asset balance-change delta for an account.
std::int32_t computeVaultMinScale(DeltaInfo const &vaultDelta, Rules const &rules) const
Compute the minimum STAmount scale for rounding invariant calculations.
constexpr Zero kZero
Definition Zero.h:30
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
static constexpr Number kNumZero
Definition Number.h:663
BaseUInt< 192 > uint192
Definition base_uint.h:581
STLedgerEntry SLE
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:572
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:647
BaseUInt< 256 > uint256
Definition base_uint.h:580
static DeltaInfo makeDelta(Number const &before, Number const &after, Asset const &asset)
std::optional< int > scale
static Shares make(SLE const &)
std::optional< std::uint8_t > vaultKind
std::optional< std::uint32_t > subscriptionDate
std::optional< std::uint32_t > redemptionDate
static Vault make(SLE const &)