xrpld
Loading...
Searching...
No Matches
VaultClawback.cpp
1#include <xrpl/tx/transactors/vault/VaultClawback.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/utility/Zero.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/core/ServiceRegistry.h>
9#include <xrpl/ledger/helpers/AccountRootHelpers.h>
10#include <xrpl/ledger/helpers/TokenHelpers.h>
11#include <xrpl/ledger/helpers/VaultHelpers.h>
12#include <xrpl/protocol/AccountID.h>
13#include <xrpl/protocol/Asset.h>
14#include <xrpl/protocol/Feature.h>
15#include <xrpl/protocol/Indexes.h>
16#include <xrpl/protocol/Issue.h>
17#include <xrpl/protocol/LedgerFormats.h>
18#include <xrpl/protocol/MPTIssue.h>
19#include <xrpl/protocol/Protocol.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/STAmount.h>
22#include <xrpl/protocol/STLedgerEntry.h>
23#include <xrpl/protocol/STNumber.h> // IWYU pragma: keep
24#include <xrpl/protocol/STTakesAsset.h>
25#include <xrpl/protocol/STTx.h>
26#include <xrpl/protocol/TER.h>
27#include <xrpl/protocol/XRPAmount.h>
28#include <xrpl/tx/Transactor.h>
29
30#include <expected>
31#include <optional>
32#include <stdexcept>
33#include <utility>
34
35namespace xrpl {
38{
39 if (ctx.tx[sfVaultID] == beast::kZero)
40 {
41 JLOG(ctx.j.debug()) << "VaultClawback: zero/empty vault ID.";
42 return temMALFORMED;
43 }
44
45 auto const amount = ctx.tx[~sfAmount];
46 if (amount)
47 {
48 // Note, zero amount is valid, it means "all". It is also the default.
49 if (*amount < beast::kZero)
50 {
51 return temBAD_AMOUNT;
52 }
53 if (isXRP(amount->asset()))
54 {
55 JLOG(ctx.j.debug()) << "VaultClawback: cannot clawback XRP.";
56 return temMALFORMED;
57 }
58 }
59
60 return tesSUCCESS;
61}
62
63[[nodiscard]] STAmount
65 SLE::ConstRef vault,
66 std::optional<STAmount> const& maybeAmount,
67 AccountID const& account)
68{
69 if (maybeAmount)
70 return *maybeAmount;
71
72 Asset const share = MPTIssue{vault->at(sfShareMPTID)};
73 if (account == vault->at(sfOwner))
74 return STAmount{share};
75
76 return STAmount{vault->at(sfAsset)};
77}
78
79TER
81{
82 auto const vault = ctx.view.read(keylet::vault(ctx.tx[sfVaultID]));
83 if (!vault)
84 return tecNO_ENTRY;
85
86 Asset const vaultAsset = vault->at(sfAsset);
87 auto const account = ctx.tx[sfAccount];
88 auto const holder = ctx.tx[sfHolder];
89 auto const maybeAmount = ctx.tx[~sfAmount];
90 auto const mptIssuanceID = vault->at(sfShareMPTID);
91 auto const sleShareIssuance = ctx.view.read(keylet::mptokenIssuance(mptIssuanceID));
92 if (!sleShareIssuance)
93 {
94 // LCOV_EXCL_START
95 JLOG(ctx.j.error()) << "VaultClawback: missing issuance of vault shares.";
96 return tefINTERNAL;
97 // LCOV_EXCL_STOP
98 }
99
100 // Pre-fixCleanup3_5_0: a missing holder fails later in doApply, and the fee is still charged.
101 // Post-fixCleanup3_5_0: refused here, as the other clawback transactions do.
102 if (ctx.view.rules().enabled(fixCleanup3_5_0) && !ctx.view.exists(keylet::account(holder)))
103 {
104 JLOG(ctx.j.debug()) << "VaultClawback: holder account does not exist.";
105 return terNO_ACCOUNT;
106 }
107
108 // A pseudo-account holds no vault shares, so a clawback naming one is a no-op: the vault's own
109 // pseudo-account issues the shares, and no flow hands them to another one.
110 // Pre-fixCleanup3_4_0: an implicit amount ends in tecPRECISION_LOSS, an explicit one debits the
111 // vault and trips the "shares must move" invariant.
112 // Post-fixCleanup3_4_0: refused here.
113 if (ctx.view.rules().enabled(fixCleanup3_4_0) && isPseudoAccount(ctx.view, holder))
114 {
115 JLOG(ctx.j.debug()) << "VaultClawback: holder is a pseudo-account.";
116 return tecPSEUDO_ACCOUNT;
117 }
118
119 Asset const share = MPTIssue{mptIssuanceID};
120
121 // Ambiguous case: If Issuer is Owner they must specify the asset
122 if (!maybeAmount && !vaultAsset.native() && vaultAsset.getIssuer() == vault->at(sfOwner))
123 {
124 JLOG(ctx.j.debug()) << "VaultClawback: must specify amount when issuer is owner.";
125 return tecWRONG_ASSET;
126 }
127
128 auto const amount = clawbackAmount(vault, maybeAmount, account);
129
130 // There is a special case that allows the VaultOwner to use clawback to
131 // burn shares when Vault assets total and available are zero, but
132 // shares remain. However, that case is handled in doApply() directly,
133 // so here we just enforce checks.
134 if (amount.asset() == share)
135 {
136 // Only the Vault Owner may clawback shares
137 if (account != vault->at(sfOwner))
138 {
139 JLOG(ctx.j.debug()) << "VaultClawback: only vault owner can clawback shares.";
140 return tecNO_PERMISSION;
141 }
142
143 auto const assetsTotal = vault->at(sfAssetsTotal);
144 auto const assetsAvailable = vault->at(sfAssetsAvailable);
145 auto const sharesTotal = sleShareIssuance->at(sfOutstandingAmount);
146
147 // Owner can clawback funds when the vault has shares but no assets
148 if (sharesTotal == 0 || (assetsTotal != 0 || assetsAvailable != 0))
149 {
150 JLOG(ctx.j.debug()) << "VaultClawback: vault owner can clawback shares only"
151 " when vault has no assets.";
152 return tecNO_PERMISSION;
153 }
154
155 // If amount is non-zero, the VaultOwner must burn all shares
156 if (amount != beast::kZero)
157 {
158 Number const& sharesHeld = accountHolds(
159 ctx.view,
160 holder,
161 share,
164 ctx.j);
165
166 // The VaultOwner must burn all shares
167 if (amount != sharesHeld)
168 {
169 JLOG(ctx.j.debug()) << "VaultClawback: vault owner must clawback all "
170 "shares.";
171 return tecLIMIT_EXCEEDED;
172 }
173 }
174
175 return tesSUCCESS;
176 }
177
178 // The asset that is being clawed back is the vault asset
179 if (amount.asset() == vaultAsset)
180 {
181 // XRP cannot be clawed back
182 if (vaultAsset.native())
183 {
184 JLOG(ctx.j.debug()) << "VaultClawback: cannot clawback XRP.";
185 return tecNO_PERMISSION;
186 }
187
188 // Only the Asset Issuer may clawback the asset
189 if (account != vaultAsset.getIssuer())
190 {
191 JLOG(ctx.j.debug()) << "VaultClawback: only asset issuer can clawback asset.";
192 return tecNO_PERMISSION;
193 }
194
195 // The issuer cannot clawback from itself
196 if (account == holder)
197 {
198 JLOG(ctx.j.debug()) << "VaultClawback: issuer cannot be the holder.";
199 return tecNO_PERMISSION;
200 }
201
202 return vaultAsset.visit(
203 [&](MPTIssue const& issue) -> TER {
204 auto const mptIssue = ctx.view.read(keylet::mptokenIssuance(issue.getMptID()));
205 if (mptIssue == nullptr)
206 return tecOBJECT_NOT_FOUND;
207
208 if (!mptIssue->isFlag(lsfMPTCanClawback))
209 {
210 JLOG(ctx.j.debug()) << "VaultClawback: cannot clawback "
211 "MPT vault asset.";
212 return tecNO_PERMISSION;
213 }
214
215 return tesSUCCESS;
216 },
217 [&](Issue const&) -> TER {
218 auto const issuerSle = ctx.view.read(keylet::account(account));
219 if (!issuerSle)
220 {
221 // LCOV_EXCL_START
222 JLOG(ctx.j.error()) << "VaultClawback: missing submitter account.";
223 return tefINTERNAL;
224 // LCOV_EXCL_STOP
225 }
226
227 if (!issuerSle->isFlag(lsfAllowTrustLineClawback) || issuerSle->isFlag(lsfNoFreeze))
228 {
229 JLOG(ctx.j.debug()) << "VaultClawback: cannot clawback "
230 "IOU vault asset.";
231 return tecNO_PERMISSION;
232 }
233
234 return tesSUCCESS;
235 });
236 }
237
238 // Invalid asset
239 return tecWRONG_ASSET;
240}
241
242std::expected<std::pair<STAmount, STAmount>, TER>
244 SLE::Ref vault,
245 SLE::ConstRef sleShareIssuance,
246 AccountID const& holder,
248{
249 bool const fix340Enabled = ctx_.view().rules().enabled(fixCleanup3_4_0);
250 if (clawbackAmount.asset() != vault->at(sfAsset))
251 {
252 // preclaim should have blocked this , now it's an internal error
253 // LCOV_EXCL_START
254 JLOG(j_.error()) << "VaultClawback: asset mismatch in clawback.";
256 // LCOV_EXCL_STOP
257 }
258
259 auto const assetsAvailable = vault->at(sfAssetsAvailable);
260 auto const mptIssuanceID = *vault->at(sfShareMPTID);
261 MPTIssue const share{mptIssuanceID};
262
263 // Pre-fixCleanup3_1_3: zero-amount clawback returned early without
264 // clamping to assetsAvailable, allowing more assets to be recovered
265 // than available when there was an outstanding loan. Retained for
266 // ledger replay compatibility.
267 if (!ctx_.view().rules().enabled(fixCleanup3_1_3) && clawbackAmount == beast::kZero)
268 {
269 auto const sharesDestroyed = accountHolds(
271 auto const maybeAssets = sharesToAssetsWithdraw(vault, sleShareIssuance, sharesDestroyed);
272 if (!maybeAssets)
273 return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
274
275 return std::make_pair(*maybeAssets, sharesDestroyed);
276 }
277
278 STAmount sharesDestroyed;
279 STAmount assetsRecovered;
280
281 // Number arithmetic can throw overflow_error when Scale and totals are large.
282 try
283 {
284 // Do not discount a sole holder's shares: clawing back AssetsAvailable at the discounted
285 // rate can burn every share while loan assets remain.
286 auto const waiveUnrealizedLoss =
287 fix340Enabled && isSoleShareholder(view(), holder, sleShareIssuance)
290
292 {
293 // Zero amount clawbacks all shares of the holder; derive the corresponding asset
294 // amount from the share balance. isSoleShareholder already established that the holder
295 // owns the entire outstanding share supply whenever the waiver applies, so
296 // sfOutstandingAmount gives sharesDestroyed directly, avoiding a redundant MPToken read
297 // via accountHolds.
298 sharesDestroyed = waiveUnrealizedLoss == WaiveUnrealizedLoss::Yes
299 ? STAmount{share, sleShareIssuance->at(sfOutstandingAmount)}
300 : accountHolds(
301 view(),
302 holder,
303 share,
306 j_);
307 auto const maybeAssets = sharesToAssetsWithdraw(
308 vault, sleShareIssuance, sharesDestroyed, waiveUnrealizedLoss);
309 if (!maybeAssets)
310 return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
311
312 assetsRecovered = *maybeAssets;
313 }
314 else
315 {
316 // Pre-fixCleanup3_4_0: shares were rounded to nearest, so the round-trip back to assets
317 // could exceed clawbackAmount.
318 // Post-fixCleanup3_4_0: truncate shares so assetsRecovered <= clawbackAmount by
319 // construction.
320 auto const truncate = fix340Enabled ? TruncateShares::Yes : TruncateShares::No;
321 auto const maybeShares = assetsToSharesWithdraw(
322 vault, sleShareIssuance, clawbackAmount, truncate, waiveUnrealizedLoss);
323 if (!maybeShares)
324 return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
325 sharesDestroyed = *maybeShares;
326
327 auto const maybeAssets = sharesToAssetsWithdraw(
328 vault, sleShareIssuance, sharesDestroyed, waiveUnrealizedLoss);
329 if (!maybeAssets)
330 return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
331 assetsRecovered = *maybeAssets;
332 }
333
334 if (assetsRecovered > *assetsAvailable)
335 {
336 assetsRecovered = *assetsAvailable;
337 {
338 auto const maybeShares = assetsToSharesWithdraw(
339 vault,
340 sleShareIssuance,
341 assetsRecovered,
343 waiveUnrealizedLoss);
344 if (!maybeShares)
345 return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
346 sharesDestroyed = *maybeShares;
347 }
348
349 auto const maybeAssets = sharesToAssetsWithdraw(
350 vault, sleShareIssuance, sharesDestroyed, waiveUnrealizedLoss);
351 if (!maybeAssets)
352 return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
353 assetsRecovered = *maybeAssets;
354 // Truncation should guarantee the invariant holds. If it does not, a conversion
355 // helper is broken; refuse rather than over-recover.
356 if (assetsRecovered > *assetsAvailable)
357 {
358 // LCOV_EXCL_START
359 JLOG(j_.error()) << "VaultClawback: invalid rounding of shares.";
361 // LCOV_EXCL_STOP
362 }
363 }
364
365 // On a coarsened Vault, an AssetsDeployed below half a unit of AssetsAvailable's grid
366 // rounds away: the conversion equals AssetsAvailable exactly, the clamp above never runs,
367 // and every share would be burned while AssetsDeployed is still outstanding.
369 sharesDestroyed == STAmount{share, sleShareIssuance->at(sfOutstandingAmount)} &&
370 Number(vault->at(sfAssetsDeployed)) != beast::kZero)
371 {
372 JLOG(j_.debug())
373 << "VaultClawback: cannot burn all shares while AssetsDeployed is non-zero";
375 }
376
377 // Post-fixCleanup3_4_0: round the recovery down at the posterior scale of the balance
378 // - AssetsAvailable on FixedPrecision Vault
379 // - AssetsTotal on Legacy/CashBasis Vault
380 // All rails change by the same representable delta.
381 // sharesDestroyed is intentionally NOT re-derived here: the holder's shares are burned for
382 // their pre-clamp value, so any sub-ULP trimmed off stays in the vault for the remaining
383 // shareholders.
384 if (fix340Enabled && assetsRecovered > beast::kZero)
385 {
386 auto const maybeClamped = clampVaultOutflow(vault, -assetsRecovered);
387 if (!maybeClamped)
388 return std::unexpected(maybeClamped.error());
389 assetsRecovered = *maybeClamped;
390 }
391 }
392 catch (std::overflow_error const&)
393 {
394 // It's easy to hit this exception from Number with large enough
395 // Scale so we avoid spamming the log and only use debug here.
396 JLOG(j_.debug()) //
397 << "VaultClawback: overflow error with"
398 << " scale=" << (int)vault->at(sfScale).value() //
399 << ", assetsTotal=" << vault->at(sfAssetsTotal).value()
400 << ", sharesTotal=" << sleShareIssuance->at(sfOutstandingAmount)
401 << ", amount=" << clawbackAmount.value();
402 // Overflow means this transaction cannot apply, but ledger state is still consistent.
403 // Return tecPATH_DRY rather than a hard internal error.
405 }
406
407 return std::make_pair(assetsRecovered, sharesDestroyed);
408}
409
410TER
412{
413 auto const& tx = ctx_.tx;
414 auto const vault = view().peek(keylet::vault(tx[sfVaultID]));
415 if (!vault)
416 return tefINTERNAL; // LCOV_EXCL_LINE
417
418 auto const mptIssuanceID = *vault->at(sfShareMPTID);
419 auto const sleIssuance = view().read(keylet::mptokenIssuance(mptIssuanceID));
420 if (!sleIssuance)
421 {
422 // LCOV_EXCL_START
423 JLOG(j_.error()) << "VaultClawback: missing issuance of vault shares.";
424 return tefINTERNAL;
425 // LCOV_EXCL_STOP
426 }
427 MPTIssue const share{mptIssuanceID};
428
429 Asset const vaultAsset = vault->at(sfAsset);
430 STAmount const amount = clawbackAmount(vault, tx[~sfAmount], accountID_);
431
432 AccountID const holder = tx[sfHolder];
433 STAmount sharesDestroyed = {share};
434 STAmount assetsRecovered = {vault->at(sfAsset)};
435
436 // The Owner is burning shares
437 if (accountID_ == vault->at(sfOwner) && amount.asset() == share)
438 {
439 sharesDestroyed = accountHolds(
441 }
442 else // The Issuer is clawbacking vault assets
443 {
444 XRPL_ASSERT(amount.asset() == vaultAsset, "xrpl::VaultClawback::doApply : matching asset");
445
446 auto const clawbackParts = assetsToClawback(vault, sleIssuance, holder, amount);
447 if (!clawbackParts)
448 return clawbackParts.error();
449
450 assetsRecovered = clawbackParts->first;
451 sharesDestroyed = clawbackParts->second;
452 }
453
454 // The holder has no shares (or the recovery clamped to zero). Nothing to burn; refuse rather
455 // than modifying vault state.
456 if (sharesDestroyed == beast::kZero)
457 return tecPRECISION_LOSS;
458
459 // Number arithmetic can throw overflow_error when Scale and totals are large.
460 if (view().rules().enabled(fixCleanup3_4_0))
461 {
462 // A non-zero recovery can be too small to change the stored balance at
463 // STAmount's precision. Shares would still be burned, reject it instead.
464 if (auto const ter = checkDebitNotDust(vault, assetsRecovered, j_, "VaultClawback");
465 !isTesSuccess(ter))
466 return ter; // LCOV_EXCL_LINE
467 }
468
469 if (auto const ter = adjustVaultCash(vault, -assetsRecovered, j_); !isTesSuccess(ter))
470 return ter; // LCOV_EXCL_LINE
471 view().update(vault);
472
473 auto const& vaultAccount = vault->at(sfAccount);
474 // Transfer shares from holder to vault.
475 if (auto const ter = accountSend(
476 view(), holder, vaultAccount, sharesDestroyed, j_, {}, WaiveTransferFee::Yes);
477 !isTesSuccess(ter))
478 return ter;
479
480 // Try to remove MPToken for shares, if the holder balance is zero. Vault
481 // pseudo-account will never set lsfMPTAuthorized, so we ignore flags.
482 // Keep MPToken if holder is the vault owner.
483 if (holder != vault->at(sfOwner))
484 {
485 if (auto const ter =
486 removeEmptyHolding(ctx_.getApplyViewContext(), holder, sharesDestroyed.asset(), j_);
487 isTesSuccess(ter))
488 {
489 JLOG(j_.debug()) //
490 << "VaultClawback: removed empty MPToken for vault shares"
491 << " MPTID=" << to_string(mptIssuanceID) //
492 << " account=" << toBase58(holder);
493 }
494 else if (ter != tecHAS_OBLIGATIONS)
495 {
496 // LCOV_EXCL_START
497 JLOG(j_.error()) //
498 << "VaultClawback: failed to remove MPToken for vault shares"
499 << " MPTID=" << to_string(mptIssuanceID) //
500 << " account=" << toBase58(holder) //
501 << " with result: " << transToken(ter);
502 return ter;
503 // LCOV_EXCL_STOP
504 }
505 // else quietly ignore, holder balance is not zero
506 }
507
508 if (assetsRecovered > beast::kZero)
509 {
510 // Transfer assets from vault to issuer.
511 if (auto const ter = accountSend(
512 view(), vaultAccount, accountID_, assetsRecovered, j_, {}, WaiveTransferFee::Yes);
513 !isTesSuccess(ter))
514 return ter;
515
516 // Sanity check
517 if (accountHolds(
518 view(),
519 vaultAccount,
520 assetsRecovered.asset(),
523 j_) < beast::kZero)
524 {
525 // LCOV_EXCL_START
526 JLOG(j_.error()) << "VaultClawback: negative balance of vault assets.";
527 return tefINTERNAL;
528 // LCOV_EXCL_STOP
529 }
530 }
531
532 associateAsset(*vault, vaultAsset);
533
534 return tesSUCCESS;
535}
536
537void
539{
540 // No transaction-specific invariants yet (future work).
541}
542
543bool
545 STTx const&,
546 TER,
547 XRPAmount,
548 ReadView const&,
549 beast::Journal const&)
550{
551 // No transaction-specific invariants yet (future work).
552 return true;
553}
554
555} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream error() const
Definition Journal.h:362
Stream debug() const
Definition Journal.h:344
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::Ref sle)=0
Indicate changes to a peeked SLE.
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:117
constexpr bool native() const
Definition Asset.h:125
AccountID const & getIssuer() const
Definition Asset.cpp:21
A currency issued by an account.
Definition Issue.h:18
constexpr MPTID const & getMptID() const
Definition MPTIssue.h:43
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
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:182
Asset const & asset() const
Definition STAmount.h:496
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry > const & Ref
beast::Journal const j_
Definition Transactor.h:164
ApplyView & view()
Definition Transactor.h:184
AccountID const accountID_
Definition Transactor.h:166
ApplyContext & ctx_
Definition Transactor.h:162
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static NotTEC preflight(PreflightContext const &ctx)
std::expected< std::pair< STAmount, STAmount >, TER > assetsToClawback(SLE::Ref vault, SLE::ConstRef sleShareIssuance, AccountID const &holder, STAmount const &clawbackAmount)
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
T make_pair(T... args)
constexpr Zero kZero
Definition Zero.h:30
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Definition Indexes.cpp:565
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Definition Indexes.cpp:541
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:219
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.
std::expected< STAmount, TER > clampVaultOutflow(SLE::ConstRef vault, STAmount const &delta)
Outflow clamp dispatcher for VaultWithdraw and VaultClawback: rounds a negative delta to the scale ap...
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...
STAmount clawbackAmount(SLE::ConstRef vault, std::optional< STAmount > const &maybeAmount, AccountID const &account)
bool isXRP(AccountID const &c)
Definition AccountID.h:84
TER removeEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
@ tefINTERNAL
Definition TER.h:167
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
std::string transToken(TER code)
Definition TER.cpp:259
TER adjustVaultCash(SLE::Ref vault, STAmount const &delta, beast::Journal j)
Apply a signed cash movement to a Vault of any version.
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:617
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, SLE::Ref sponsorSle={}, WaiveTransferFee waiveFee=WaiveTransferFee::No, AllowMPTOverflow allowOverflow=AllowMPTOverflow::No)
Calls static accountSendIOU if saAmount represents Issue.
TER checkDebitNotDust(SLE::ConstRef vault, Number const &amount, beast::Journal j, std::string_view name)
Reject a cash outflow that is dust (see debitIsNonZeroDust) or whose check overflows Number,...
bool isPseudoAccount(SLE::const_pointer sleAcct)
Returns true if and only if sleAcct is a pseudo-account of any kind (i.e.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
@ temMALFORMED
Definition TER.h:75
@ temBAD_AMOUNT
Definition TER.h:77
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecWRONG_ASSET
Definition TER.h:371
@ tecPSEUDO_ACCOUNT
Definition TER.h:373
@ tecNO_ENTRY
Definition TER.h:317
@ tecPATH_DRY
Definition TER.h:305
@ tecOBJECT_NOT_FOUND
Definition TER.h:337
@ tecINTERNAL
Definition TER.h:321
@ tecPRECISION_LOSS
Definition TER.h:374
@ tecLIMIT_EXCEEDED
Definition TER.h:372
@ tecNO_PERMISSION
Definition TER.h:316
@ tecHAS_OBLIGATIONS
Definition TER.h:328
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
VaultVersion getVaultVersion(SLE::ConstRef vault)
Resolves a Vault's LEVersion.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=SpendableHandling::SimpleBalance)
@ tesSUCCESS
Definition TER.h:253
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:92
ReadView const & view
Definition Transactor.h:95
beast::Journal const j
Definition Transactor.h:100
State information when preflighting a tx.
Definition Transactor.h:39
beast::Journal const j
Definition Transactor.h:46
T unexpected(T... args)