xrpld
Loading...
Searching...
No Matches
VaultHelpers.h
1#pragma once
2
3#include <xrpl/basics/Number.h>
4#include <xrpl/ledger/ReadView.h>
5#include <xrpl/protocol/AccountID.h>
6#include <xrpl/protocol/Asset.h>
7#include <xrpl/protocol/Protocol.h>
8#include <xrpl/protocol/STAmount.h>
9#include <xrpl/protocol/STLedgerEntry.h>
10#include <xrpl/protocol/TER.h>
11
12#include <cstdint>
13#include <expected>
14#include <optional>
15
16namespace xrpl {
17
18class STTx;
19
31[[nodiscard]] std::optional<STAmount>
32assetsToSharesDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount const& assets);
33
45[[nodiscard]] std::optional<STAmount>
46sharesToAssetsDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount const& shares);
47
71[[nodiscard]] std::expected<STAmount, TER>
73
77enum class TruncateShares : bool { No = false, Yes = true };
78
86enum class WaiveUnrealizedLoss : bool { No = false, Yes = true };
87
97[[nodiscard]] Number
99
114[[nodiscard]] bool
115debitIsNonZeroDust(Asset const& asset, Number const& total, Number const& amount);
116
132[[nodiscard]] std::optional<STAmount>
134 SLE::ConstRef vault,
135 SLE::ConstRef issuance,
136 STAmount const& assets,
139
153[[nodiscard]] std::optional<STAmount>
155 SLE::ConstRef vault,
156 SLE::ConstRef issuance,
157 STAmount const& shares,
159
170[[nodiscard]] bool
171isSoleShareholder(ReadView const& view, AccountID const& account, SLE::ConstRef issuance);
172
185[[nodiscard]] VaultVersion
187
195[[nodiscard]] VaultKind
197
207[[nodiscard]] VaultKind
208getVaultKind(STTx const& tx);
209
217[[nodiscard]] bool
218isValidVaultKind(STTx const& tx);
219
230[[nodiscard]] bool
232
242[[nodiscard]] VaultPhase
243getVaultPhase(ReadView const& view, SLE::ConstRef vault);
244
259[[nodiscard]] VaultPhase
261 ReadView const& view,
263 std::optional<std::uint32_t> subscriptionDate,
264 std::optional<std::uint32_t> redemptionDate);
265
272enum class SuppressExpired : bool { No = false, Yes = true };
273
295[[nodiscard]] TER
297 ReadView const& view,
298 SLE::ConstRef issuance,
299 AccountID const& subject,
300 SuppressExpired suppressExpired);
301
302} // namespace xrpl
std::shared_ptr< STLedgerEntry const > const & ConstRef
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:345
std::optional< STAmount > sharesToAssetsWithdraw(SLE::ConstRef vault, SLE::ConstRef 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...
bool isSoleShareholder(ReadView const &view, AccountID const &account, SLE::ConstRef issuance)
Returns true iff account holds all of the vault's outstanding shares — i.e.
bool debitIsNonZeroDust(Asset const &asset, Number const &total, Number const &amount)
Returns true if debiting amount from total (the current value of a vault's sfAssetsTotal or sfAssetsA...
TER checkVaultDomain(ReadView const &view, SLE::ConstRef issuance, AccountID const &subject, SuppressExpired suppressExpired)
Checks that subject belongs to the permissioned domain governing a vault's shares.
std::optional< STAmount > assetsToSharesWithdraw(SLE::ConstRef vault, SLE::ConstRef 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...
bool isValidClosedEndedGap(std::uint32_t sub, std::uint32_t red)
Returns true iff the (SubscriptionDate, RedemptionDate) gap of a closed-ended vault satisfies kMinInv...
std::optional< STAmount > sharesToAssetsDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount const &shares)
From the perspective of a vault, return the number of assets to take from depositor when they receive...
Number assetsTotalForWithdrawal(SLE::ConstRef vault, WaiveUnrealizedLoss waive)
Returns the assets backing outstanding shares for a withdrawal: sfAssetsTotal minus sfLossUnrealized,...
std::expected< STAmount, TER > clampToAssetsTotalScale(SLE::ConstRef vault, STAmount const &delta)
Adjusts a requested asset change (delta) to match the decimal scale of the updated total vault assets...
VaultKind
Vault kind.
Definition Protocol.h:336
@ 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:327
std::optional< STAmount > assetsToSharesDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount const &assets)
From the perspective of a vault, return the number of shares to give depositor when they offer a fixe...
VaultPhase getVaultPhase(ReadView const &view, SLE::ConstRef vault)
Returns the current lifecycle phase of a vault.
VaultKind getVaultKind(SLE::ConstRef vault)
Resolves the VaultKind of a vault SLE.
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
SuppressExpired
Controls whether checkVaultDomain reports an expired credential as an error.
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::ConstRef vault)
Resolves a Vault's LEVersion, the single point every accounting touch point should call to determine ...
WaiveUnrealizedLoss
Controls whether the withdraw conversion helpers (assetsToSharesWithdraw and sharesToAssetsWithdraw) ...