xrpld
Loading...
Searching...
No Matches
VaultHelpers.h
1#pragma once
2
3#include <xrpl/ledger/ReadView.h>
4#include <xrpl/protocol/AccountID.h>
5#include <xrpl/protocol/Protocol.h>
6#include <xrpl/protocol/STAmount.h>
7#include <xrpl/protocol/STLedgerEntry.h>
8
9#include <cstdint>
10#include <optional>
11
12namespace xrpl {
13
14class STTx;
15
27[[nodiscard]] std::optional<STAmount>
28assetsToSharesDeposit(SLE::const_ref vault, SLE::const_ref issuance, STAmount const& assets);
29
41[[nodiscard]] std::optional<STAmount>
42sharesToAssetsDeposit(SLE::const_ref vault, SLE::const_ref issuance, STAmount const& shares);
43
47enum class TruncateShares : bool { No = false, Yes = true };
48
56enum class WaiveUnrealizedLoss : bool { No = false, Yes = true };
57
73[[nodiscard]] std::optional<STAmount>
75 SLE::const_ref vault,
76 SLE::const_ref issuance,
77 STAmount const& assets,
80
94[[nodiscard]] std::optional<STAmount>
96 SLE::const_ref vault,
97 SLE::const_ref issuance,
98 STAmount const& shares,
100
111[[nodiscard]] bool
112isSoleShareholder(ReadView const& view, AccountID const& account, SLE::const_ref issuance);
113
126[[nodiscard]] VaultVersion
128
136[[nodiscard]] VaultKind
138
148[[nodiscard]] VaultKind
149getVaultKind(STTx const& tx);
150
158[[nodiscard]] bool
159isValidVaultKind(STTx const& tx);
160
171[[nodiscard]] bool
173
183[[nodiscard]] VaultPhase
184getVaultPhase(ReadView const& view, SLE::const_ref vault);
185
200[[nodiscard]] VaultPhase
202 ReadView const& view,
204 std::optional<std::uint32_t> subscriptionDate,
205 std::optional<std::uint32_t> redemptionDate);
206
207} // namespace xrpl
std::shared_ptr< STLedgerEntry const > const & const_ref
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
VaultPhase
Lifecycle phase of a vault.
Definition Protocol.h:344
std::optional< STAmount > assetsToSharesWithdraw(SLE::const_ref vault, SLE::const_ref issuance, STAmount const &assets, TruncateShares truncate=TruncateShares::No, WaiveUnrealizedLoss waive=WaiveUnrealizedLoss::No)
From the perspective of a vault, return the number of shares to demand from the depositor when they a...
VaultKind getVaultKind(SLE::const_ref vault)
Resolves the VaultKind of a vault SLE.
bool isValidClosedEndedGap(std::uint32_t sub, std::uint32_t red)
Returns true iff the (SubscriptionDate, RedemptionDate) gap of a closed-ended vault satisfies kMinInv...
VaultPhase getVaultPhase(ReadView const &view, SLE::const_ref vault)
Returns the current lifecycle phase of a vault.
std::optional< STAmount > sharesToAssetsWithdraw(SLE::const_ref vault, SLE::const_ref issuance, STAmount const &shares, WaiveUnrealizedLoss waive=WaiveUnrealizedLoss::No)
From the perspective of a vault, return the number of assets to give the depositor when they redeem a...
VaultKind
Vault kind.
Definition Protocol.h:335
@ Yes
We have consensus along with the network.
@ No
We do not have consensus.
TruncateShares
Controls whether to truncate shares instead of rounding.
VaultVersion
Vault ledger-entry schema versions.
Definition Protocol.h:326
std::optional< STAmount > sharesToAssetsDeposit(SLE::const_ref vault, SLE::const_ref issuance, STAmount const &shares)
From the perspective of a vault, return the number of assets to take from depositor when they receive...
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
bool isSoleShareholder(ReadView const &view, AccountID const &account, SLE::const_ref issuance)
Returns true iff account holds all of the vault's outstanding shares — i.e.
bool isValidVaultKind(STTx const &tx)
Returns true iff sfVaultKind is either absent from tx or is present and equal to a recognised VaultKi...
VaultVersion getVaultVersion(SLE::const_ref vault)
Resolves a Vault's LEVersion, the single point every accounting touch point should call to determine ...
std::optional< STAmount > assetsToSharesDeposit(SLE::const_ref vault, SLE::const_ref issuance, STAmount const &assets)
From the perspective of a vault, return the number of shares to give depositor when they offer a fixe...
WaiveUnrealizedLoss
Controls whether the withdraw conversion helpers (assetsToSharesWithdraw and sharesToAssetsWithdraw) ...