rippled
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/ledger/ReadView.h>
7#include <xrpl/protocol/MPTIssue.h>
8#include <xrpl/protocol/STTx.h>
9#include <xrpl/protocol/TER.h>
10
11#include <unordered_map>
12#include <vector>
13
14namespace xrpl {
15
16/*
17 * @brief Invariants: Vault object and MPTokenIssuance for vault shares
18 *
19 * - vault deleted and vault created is empty
20 * - vault created must be linked to pseudo-account for shares and assets
21 * - vault must have MPTokenIssuance for shares
22 * - vault without shares outstanding must have no shares
23 * - loss unrealized does not exceed the difference between assets total and
24 * assets available
25 * - assets available do not exceed assets total
26 * - vault deposit increases assets and share issuance, and adds to:
27 * total assets, assets available, shares outstanding
28 * - vault withdrawal and clawback reduce assets and share issuance, and
29 * subtracts from: total assets, assets available, shares outstanding
30 * - vault set must not alter the vault assets or shares balance
31 * - no vault transaction can change loss unrealized (it's updated by loan
32 * transactions)
33 *
34 */
36{
37 Number static constexpr zero{};
38
39 struct Vault final
40 {
41 uint256 key = beast::zero;
45 uint192 shareMPTID = beast::zero;
50
51 Vault static make(SLE const&);
52 };
53
54 struct Shares final
55 {
59
60 Shares static make(SLE const&);
61 };
62
68
69public:
70 void
72
73 bool
74 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
75};
76
77} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Number is a floating point type that can represent a wide range of values.
Definition Number.h:207
A view into a ledger.
Definition ReadView.h:31
void visitEntry(bool, std::shared_ptr< SLE const > const &, std::shared_ptr< SLE const > const &)
static Number constexpr zero
std::vector< Shares > afterMPTs_
std::unordered_map< uint256, Number > deltas_
std::vector< Vault > afterVault_
std::vector< Shares > beforeMPTs_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
std::vector< Vault > beforeVault_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
static Shares make(SLE const &)
static Vault make(SLE const &)