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
57{
58 static constexpr Number kZero{};
59
77
78 struct Shares final
79 {
83
84 Shares static make(SLE const&);
85 };
86
87public:
88 struct DeltaInfo final
89 {
92
93 // Compute the delta between two Numbers, taking the coarsest scale
94 [[nodiscard]] static DeltaInfo
95 makeDelta(Number const& before, Number const& after, Asset const& asset);
96 };
97
98private:
104
117 [[nodiscard]] std::int32_t
118 computeVaultMinScale(DeltaInfo const& vaultDelta, Rules const& rules) const;
119
130 [[nodiscard]] std::optional<DeltaInfo>
131 deltaAssets(AccountID const& id) const;
132
147 [[nodiscard]] static std::optional<AccountID>
148 feePayerAccountRoot(ReadView const& view, STTx const& tx);
149
178 [[nodiscard]] std::optional<DeltaInfo>
180 ReadView const& view,
181 AccountID const& id,
182 STTx const& tx,
183 XRPAmount fee,
184 bool fix340Enabled) const;
185
196 [[nodiscard]] std::optional<DeltaInfo>
197 deltaShares(AccountID const& id) const;
198
206 [[nodiscard]] static bool
207 isVaultEmpty(Vault const& vault);
208
217 [[nodiscard]] bool
218 finalizeLoanSet(ReadView const& view, beast::Journal const& j) const;
219
220public:
221 // Compute the coarsest scale required to represent all numbers
222 [[nodiscard]] static std::int32_t
224
225 void
227
228 bool
229 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
230};
231
232} // 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 & ConstRef
Invariants: Vault object and MPTokenIssuance for vault shares.
static std::optional< AccountID > feePayerAccountRoot(ReadView const &view, STTx const &tx)
Return the AccountRoot whose XRP balance actually absorbed a transaction's fee, if any.
std::unordered_map< UInt256, DeltaInfo > deltas_
std::vector< Shares > afterMPTs_
std::optional< DeltaInfo > deltaAssetsForParty(ReadView const &view, AccountID const &id, STTx const &tx, XRPAmount fee, bool fix340Enabled) const
Return the vault-asset delta for a party inspected as a withdrawal/deposit counterparty,...
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.
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
std::vector< Shares > beforeMPTs_
static std::int32_t computeCoarsestScale(std::vector< DeltaInfo > const &numbers)
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
BaseUInt< 256 > UInt256
Definition base_uint.h:580
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:644
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:654
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 &)