rippled
Loading...
Searching...
No Matches
LoanSet.cpp
1#include <xrpld/app/tx/detail/LoanSet.h>
2//
3#include <xrpld/app/misc/LendingHelpers.h>
4
5#include <xrpl/protocol/TxFlags.h>
6
7namespace xrpl {
8
9bool
14
20
23{
24 using namespace Lending;
25
26 auto const& tx = ctx.tx;
27
28 // Special case for Batch inner transactions
29 if (tx.isFlag(tfInnerBatchTxn) && ctx.rules.enabled(featureBatch) &&
30 !tx.isFieldPresent(sfCounterparty))
31 {
32 auto const parentBatchId = ctx.parentBatchId.value_or(uint256{0});
33 JLOG(ctx.j.debug()) << "BatchTrace[" << parentBatchId << "]: "
34 << "no Counterparty for inner LoanSet transaction.";
35 return temBAD_SIGNER;
36 }
37
38 // These extra hoops are because STObjects cannot be Proxy'd from STObject.
39 auto const counterPartySig = [&tx]() -> std::optional<STObject const> {
40 if (tx.isFieldPresent(sfCounterpartySignature))
41 return tx.getFieldObject(sfCounterpartySignature);
42 return std::nullopt;
43 }();
44 if (!tx.isFlag(tfInnerBatchTxn) && !counterPartySig)
45 {
46 JLOG(ctx.j.warn())
47 << "LoanSet transaction must have a CounterpartySignature.";
48 return temBAD_SIGNER;
49 }
50
51 if (counterPartySig)
52 {
53 if (auto const ret =
54 xrpl::detail::preflightCheckSigningKey(*counterPartySig, ctx.j))
55 return ret;
56 }
57
58 if (auto const data = tx[~sfData]; data && !data->empty() &&
60 return temINVALID;
61 for (auto const& field :
62 {&sfLoanServiceFee, &sfLatePaymentFee, &sfClosePaymentFee})
63 {
64 if (!validNumericMinimum(tx[~*field]))
65 return temINVALID;
66 }
67 // Principal Requested is required
68 if (auto const p = tx[sfPrincipalRequested]; p <= 0)
69 return temINVALID;
70 else if (!validNumericRange(tx[~sfLoanOriginationFee], p))
71 return temINVALID;
72 if (!validNumericRange(tx[~sfInterestRate], maxInterestRate))
73 return temINVALID;
74 if (!validNumericRange(tx[~sfOverpaymentFee], maxOverpaymentFee))
75 return temINVALID;
76 if (!validNumericRange(tx[~sfLateInterestRate], maxLateInterestRate))
77 return temINVALID;
78 if (!validNumericRange(tx[~sfCloseInterestRate], maxCloseInterestRate))
79 return temINVALID;
81 tx[~sfOverpaymentInterestRate], maxOverpaymentInterestRate))
82 return temINVALID;
83
84 if (auto const paymentTotal = tx[~sfPaymentTotal];
85 paymentTotal && *paymentTotal <= 0)
86 return temINVALID;
87
88 if (auto const paymentInterval = tx[~sfPaymentInterval];
90 return temINVALID;
91
92 else if (!validNumericRange(
93 tx[~sfGracePeriod],
94 paymentInterval.value_or(LoanSet::defaultPaymentInterval)))
95 return temINVALID;
96
97 // Copied from preflight2
98 if (counterPartySig)
99 {
100 if (auto const ret = xrpl::detail::preflightCheckSimulateKeys(
101 ctx.flags, *counterPartySig, ctx.j))
102 return *ret;
103 }
104
105 if (auto const brokerID = ctx.tx[~sfLoanBrokerID];
106 brokerID && *brokerID == beast::zero)
107 return temINVALID;
108
109 return tesSUCCESS;
110}
111
112NotTEC
114{
115 if (auto ret = Transactor::checkSign(ctx))
116 return ret;
117
118 // Counter signer is optional. If it's not specified, it's assumed to be
119 // `LoanBroker.Owner`. Note that we have not checked whether the
120 // loanbroker exists at this point.
121 auto const counterSigner = [&]() -> std::optional<AccountID> {
122 if (auto const c = ctx.tx.at(~sfCounterparty))
123 return c;
124
125 if (auto const broker =
126 ctx.view.read(keylet::loanbroker(ctx.tx[sfLoanBrokerID])))
127 return broker->at(sfOwner);
128 return std::nullopt;
129 }();
130 if (!counterSigner)
131 return temBAD_SIGNER;
132
133 // Counterparty signature is optional. Presence is checked in preflight.
134 if (!ctx.tx.isFieldPresent(sfCounterpartySignature))
135 return tesSUCCESS;
136 auto const counterSig = ctx.tx.getFieldObject(sfCounterpartySignature);
138 ctx.view,
139 ctx.flags,
140 ctx.parentBatchId,
141 *counterSigner,
142 counterSig,
143 ctx.j);
144}
145
148{
149 auto const normalCost = Transactor::calculateBaseFee(view, tx);
150
151 // Compute the additional cost of each signature in the
152 // CounterpartySignature, whether a single signature or a multisignature
153 XRPAmount const baseFee = view.fees().base;
154
155 // Counterparty signature is optional, but getFieldObject will return an
156 // empty object if it's not present.
157 auto const counterSig = tx.getFieldObject(sfCounterpartySignature);
158 // Each signer adds one more baseFee to the minimum required fee
159 // for the transaction. Note that unlike the base class, the single signer
160 // is counted if present. It will only be absent in a batch inner
161 // transaction.
162 std::size_t const signerCount = [&counterSig]() {
163 // Compute defensively. Assure that "tx" cannot be accessed and cause
164 // confusion or miscalculations.
165 return counterSig.isFieldPresent(sfSigners)
166 ? counterSig.getFieldArray(sfSigners).size()
167 : (counterSig.isFieldPresent(sfTxnSignature) ? 1 : 0);
168 }();
169
170 return normalCost + (signerCount * baseFee);
171}
172
175{
176 static std::vector<OptionaledField<STNumber>> const valueFields{
177 ~sfPrincipalRequested,
178 ~sfLoanOriginationFee,
179 ~sfLoanServiceFee,
180 ~sfLatePaymentFee,
181 ~sfClosePaymentFee
182 // Overpayment fee is really a rate. Don't check it here.
183 };
184
185 return valueFields;
186}
187
188static std::uint32_t
190{
191 return view.header().closeTime.time_since_epoch().count();
192}
193
194TER
196{
197 auto const& tx = ctx.tx;
198
199 {
200 // Check for numeric overflow of the schedule before we load any
201 // objects. The Grace Period for the last payment ends at:
202 // startDate + (paymentInterval * paymentTotal) + gracePeriod.
203 // If that value is larger than "maxTime", the value
204 // overflows, and we kill the transaction.
205 using timeType = decltype(sfNextPaymentDueDate)::type::value_type;
207 timeType constexpr maxTime = std::numeric_limits<timeType>::max();
208 static_assert(maxTime == 4'294'967'295);
209
210 auto const timeAvailable = maxTime - getStartDate(ctx.view);
211
212 auto const interval =
213 ctx.tx.at(~sfPaymentInterval).value_or(defaultPaymentInterval);
214 auto const total =
215 ctx.tx.at(~sfPaymentTotal).value_or(defaultPaymentTotal);
216 auto const grace =
217 ctx.tx.at(~sfGracePeriod).value_or(defaultGracePeriod);
218
219 // The grace period can't be larger than the interval. Check it first,
220 // mostly so that unit tests can test that specific case.
221 if (grace > timeAvailable)
222 {
223 JLOG(ctx.j.warn()) << "Grace period exceeds protocol time limit.";
224 return tecKILLED;
225 }
226
227 if (interval > timeAvailable)
228 {
229 JLOG(ctx.j.warn())
230 << "Payment interval exceeds protocol time limit.";
231 return tecKILLED;
232 }
233
234 if (total > timeAvailable)
235 {
236 JLOG(ctx.j.warn()) << "Payment total exceeds protocol time limit.";
237 return tecKILLED;
238 }
239
240 auto const timeLastPayment = timeAvailable - grace;
241
242 if (timeLastPayment / interval < total)
243 {
244 JLOG(ctx.j.warn()) << "Last payment due date, or grace period for "
245 "last payment exceeds protocol time limit.";
246 return tecKILLED;
247 }
248 }
249
250 auto const account = tx[sfAccount];
251 auto const brokerID = tx[sfLoanBrokerID];
252
253 auto const brokerSle = ctx.view.read(keylet::loanbroker(brokerID));
254 if (!brokerSle)
255 {
256 // This can only be hit if there's a counterparty specified, otherwise
257 // it'll fail in the signature check
258 JLOG(ctx.j.warn()) << "LoanBroker does not exist.";
259 return tecNO_ENTRY;
260 }
261 auto const brokerOwner = brokerSle->at(sfOwner);
262 auto const counterparty = tx[~sfCounterparty].value_or(brokerOwner);
263 if (account != brokerOwner && counterparty != brokerOwner)
264 {
265 JLOG(ctx.j.warn()) << "Neither Account nor Counterparty are the owner "
266 "of the LoanBroker.";
267 return tecNO_PERMISSION;
268 }
269 auto const brokerPseudo = brokerSle->at(sfAccount);
270
271 auto const borrower = counterparty == brokerOwner ? account : counterparty;
272 if (auto const borrowerSle = ctx.view.read(keylet::account(borrower));
273 !borrowerSle)
274 {
275 // It may not be possible to hit this case, because it'll fail the
276 // signature check with terNO_ACCOUNT.
277 JLOG(ctx.j.warn()) << "Borrower does not exist.";
278 return terNO_ACCOUNT;
279 }
280
281 auto const vault = ctx.view.read(keylet::vault(brokerSle->at(sfVaultID)));
282 if (!vault)
283 // Should be impossible
284 return tefBAD_LEDGER; // LCOV_EXCL_LINE
285 Asset const asset = vault->at(sfAsset);
286
287 auto const vaultPseudo = vault->at(sfAccount);
288
289 // Check that relevant values can be represented as the vault asset type.
290 // This check is almost duplicated in doApply, but that check is done after
291 // the overall loan scale is known. This is mostly only relevant for
292 // integral (non-IOU) types
293 {
294 for (auto const& field : getValueFields())
295 {
296 if (auto const value = tx[field];
297 value && STAmount{asset, *value} != *value)
298 {
299 JLOG(ctx.j.warn()) << field.f->getName() << " (" << *value
300 << ") can not be represented as a(n) "
301 << to_string(asset) << ".";
302 return tecPRECISION_LOSS;
303 }
304 }
305 }
306
307 if (auto const ter = canAddHolding(ctx.view, asset))
308 return ter;
309
310 // vaultPseudo is going to send funds, so it can't be frozen.
311 if (auto const ret = checkFrozen(ctx.view, vaultPseudo, asset))
312 {
313 JLOG(ctx.j.warn()) << "Vault pseudo-account is frozen.";
314 return ret;
315 }
316
317 // brokerPseudo is the fallback account to receive LoanPay fees, even if the
318 // broker owner is unable to accept them. Don't create the loan if it is
319 // deep frozen.
320 if (auto const ret = checkDeepFrozen(ctx.view, brokerPseudo, asset))
321 {
322 JLOG(ctx.j.warn()) << "Broker pseudo-account is frozen.";
323 return ret;
324 }
325
326 // borrower is eventually going to have to pay back the loan, so it can't be
327 // frozen now. It is also going to receive funds, so it can't be deep
328 // frozen, but being frozen is a prerequisite for being deep frozen, so
329 // checking the one is sufficient.
330 if (auto const ret = checkFrozen(ctx.view, borrower, asset))
331 {
332 JLOG(ctx.j.warn()) << "Borrower account is frozen.";
333 return ret;
334 }
335 // brokerOwner is going to receive funds if there's an origination fee, so
336 // it can't be deep frozen
337 if (auto const ret = checkDeepFrozen(ctx.view, brokerOwner, asset))
338 {
339 JLOG(ctx.j.warn()) << "Broker owner account is frozen.";
340 return ret;
341 }
342
343 return tesSUCCESS;
344}
345
346TER
348{
349 auto const& tx = ctx_.tx;
350 auto& view = ctx_.view();
351
352 auto const brokerID = tx[sfLoanBrokerID];
353
354 auto const brokerSle = view.peek(keylet::loanbroker(brokerID));
355 if (!brokerSle)
356 return tefBAD_LEDGER; // LCOV_EXCL_LINE
357 auto const brokerOwner = brokerSle->at(sfOwner);
358 auto const brokerOwnerSle = view.peek(keylet::account(brokerOwner));
359 if (!brokerOwnerSle)
360 return tefBAD_LEDGER; // LCOV_EXCL_LINE
361
362 auto const vaultSle = view.peek(keylet ::vault(brokerSle->at(sfVaultID)));
363 if (!vaultSle)
364 return tefBAD_LEDGER; // LCOV_EXCL_LINE
365 auto const vaultPseudo = vaultSle->at(sfAccount);
366 Asset const vaultAsset = vaultSle->at(sfAsset);
367
368 auto const counterparty = tx[~sfCounterparty].value_or(brokerOwner);
369 auto const borrower = counterparty == brokerOwner ? account_ : counterparty;
370 auto const borrowerSle = view.peek(keylet::account(borrower));
371 if (!borrowerSle)
372 {
373 return tefBAD_LEDGER; // LCOV_EXCL_LINE
374 }
375
376 auto const brokerPseudo = brokerSle->at(sfAccount);
377 auto const brokerPseudoSle = view.peek(keylet::account(brokerPseudo));
378 if (!brokerPseudoSle)
379 {
380 return tefBAD_LEDGER; // LCOV_EXCL_LINE
381 }
382 auto const principalRequested = tx[sfPrincipalRequested];
383
384 auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable);
385 auto vaultTotalProxy = vaultSle->at(sfAssetsTotal);
386 auto const vaultScale = getVaultScale(vaultSle);
387 if (vaultAvailableProxy < principalRequested)
388 {
389 JLOG(j_.warn())
390 << "Insufficient assets available in the Vault to fund the loan.";
392 }
393
394 TenthBips32 const interestRate{tx[~sfInterestRate].value_or(0)};
395
396 auto const paymentInterval =
397 tx[~sfPaymentInterval].value_or(defaultPaymentInterval);
398 auto const paymentTotal = tx[~sfPaymentTotal].value_or(defaultPaymentTotal);
399
400 auto const properties = computeLoanProperties(
401 vaultAsset,
402 principalRequested,
403 interestRate,
404 paymentInterval,
405 paymentTotal,
406 TenthBips16{brokerSle->at(sfManagementFeeRate)},
407 vaultScale);
408
409 // Check that relevant values won't lose precision. This is mostly only
410 // relevant for IOU assets.
411 {
412 for (auto const& field : getValueFields())
413 {
414 if (auto const value = tx[field];
415 value && !isRounded(vaultAsset, *value, properties.loanScale))
416 {
417 JLOG(j_.warn())
418 << field.f->getName() << " (" << *value
419 << ") has too much precision. Total loan value is "
420 << properties.totalValueOutstanding << " with a scale of "
421 << properties.loanScale;
422 return tecPRECISION_LOSS;
423 }
424 }
425 }
426
427 if (auto const ret = checkLoanGuards(
428 vaultAsset,
429 principalRequested,
430 interestRate != beast::zero,
431 paymentTotal,
432 properties,
433 j_))
434 return ret;
435
436 // Check that the other computed values are valid
437 if (properties.managementFeeOwedToBroker < 0 ||
438 properties.totalValueOutstanding <= 0 ||
439 properties.periodicPayment <= 0)
440 {
441 // LCOV_EXCL_START
442 JLOG(j_.warn())
443 << "Computed loan properties are invalid. Does not compute.";
444 return tecINTERNAL;
445 // LCOV_EXCL_STOP
446 }
447
448 LoanState const state = constructLoanState(
449 properties.totalValueOutstanding,
450 principalRequested,
451 properties.managementFeeOwedToBroker);
452
453 auto const originationFee = tx[~sfLoanOriginationFee].value_or(Number{});
454
455 auto const loanAssetsToBorrower = principalRequested - originationFee;
456
457 auto const newDebtDelta = principalRequested + state.interestDue;
458 auto const newDebtTotal = brokerSle->at(sfDebtTotal) + newDebtDelta;
459 if (auto const debtMaximum = brokerSle->at(sfDebtMaximum);
460 debtMaximum != 0 && debtMaximum < newDebtTotal)
461 {
462 JLOG(j_.warn())
463 << "Loan would exceed the maximum debt limit of the LoanBroker.";
464 return tecLIMIT_EXCEEDED;
465 }
466 TenthBips32 const coverRateMinimum{brokerSle->at(sfCoverRateMinimum)};
467 {
468 // Round the minimum required cover up to be conservative. This ensures
469 // CoverAvailable never drops below the theoretical minimum, protecting
470 // the broker's solvency.
472 if (brokerSle->at(sfCoverAvailable) <
473 tenthBipsOfValue(newDebtTotal, coverRateMinimum))
474 {
475 JLOG(j_.warn())
476 << "Insufficient first-loss capital to cover the loan.";
478 }
479 }
480
481 adjustOwnerCount(view, borrowerSle, 1, j_);
482 {
483 auto const ownerCount = borrowerSle->at(sfOwnerCount);
484 auto const balance = account_ == borrower
486 : borrowerSle->at(sfBalance).value().xrp();
487 if (balance < view.fees().accountReserve(ownerCount))
489 }
490
491 // Account for the origination fee using two payments
492 //
493 // 1. Transfer loanAssetsAvailable (principalRequested - originationFee)
494 // from vault pseudo-account to the borrower.
495 // Create a holding for the borrower if one does not already exist.
496
497 XRPL_ASSERT_PARTS(
498 borrower == account_ || borrower == counterparty,
499 "xrpl::LoanSet::doApply",
500 "borrower signed transaction");
501 if (auto const ter = addEmptyHolding(
502 view,
503 borrower,
504 borrowerSle->at(sfBalance).value().xrp(),
505 vaultAsset,
506 j_);
507 ter && ter != tecDUPLICATE)
508 // ignore tecDUPLICATE. That means the holding already exists, and
509 // is fine here
510 return ter;
511
512 if (auto const ter =
513 requireAuth(view, vaultAsset, borrower, AuthType::StrongAuth))
514 return ter;
515
516 // 2. Transfer originationFee, if any, from vault pseudo-account to
517 // LoanBroker owner.
518 if (originationFee != beast::zero)
519 {
520 // Create the holding if it doesn't already exist (necessary for MPTs).
521 // The owner may have deleted their MPT / line at some point.
522 XRPL_ASSERT_PARTS(
523 brokerOwner == account_ || brokerOwner == counterparty,
524 "xrpl::LoanSet::doApply",
525 "broker owner signed transaction");
526
527 if (auto const ter = addEmptyHolding(
528 view,
529 brokerOwner,
530 brokerOwnerSle->at(sfBalance).value().xrp(),
531 vaultAsset,
532 j_);
533 ter && ter != tecDUPLICATE)
534 // ignore tecDUPLICATE. That means the holding already exists,
535 // and is fine here
536 return ter;
537
538 if (auto const ter = requireAuth(
539 view, vaultAsset, brokerOwner, AuthType::StrongAuth))
540 return ter;
541 }
542
543 if (auto const ter = accountSendMulti(
544 view,
545 vaultPseudo,
546 vaultAsset,
547 {{borrower, loanAssetsToBorrower}, {brokerOwner, originationFee}},
548 j_,
550 return ter;
551
552 // Get shortcuts to the loan property values
553 auto const startDate = getStartDate(view);
554 auto loanSequenceProxy = brokerSle->at(sfLoanSequence);
555
556 // Create the loan
557 auto loan =
558 std::make_shared<SLE>(keylet::loan(brokerID, *loanSequenceProxy));
559
560 // Prevent copy/paste errors
561 auto setLoanField =
562 [&loan, &tx](auto const& field, std::uint32_t const defValue = 0) {
563 // at() is smart enough to unseat a default field set to the default
564 // value
565 loan->at(field) = tx[field].value_or(defValue);
566 };
567
568 // Set required and fixed tx fields
569 loan->at(sfLoanScale) = properties.loanScale;
570 loan->at(sfStartDate) = startDate;
571 loan->at(sfPaymentInterval) = paymentInterval;
572 loan->at(sfLoanSequence) = *loanSequenceProxy;
573 loan->at(sfLoanBrokerID) = brokerID;
574 loan->at(sfBorrower) = borrower;
575 // Set all other transaction fields directly from the transaction
576 if (tx.isFlag(tfLoanOverpayment))
577 loan->setFlag(lsfLoanOverpayment);
578 setLoanField(~sfLoanOriginationFee);
579 setLoanField(~sfLoanServiceFee);
580 setLoanField(~sfLatePaymentFee);
581 setLoanField(~sfClosePaymentFee);
582 setLoanField(~sfOverpaymentFee);
583 setLoanField(~sfInterestRate);
584 setLoanField(~sfLateInterestRate);
585 setLoanField(~sfCloseInterestRate);
586 setLoanField(~sfOverpaymentInterestRate);
587 setLoanField(~sfGracePeriod, defaultGracePeriod);
588 // Set dynamic / computed fields to their initial values
589 loan->at(sfPrincipalOutstanding) = principalRequested;
590 loan->at(sfPeriodicPayment) = properties.periodicPayment;
591 loan->at(sfTotalValueOutstanding) = properties.totalValueOutstanding;
592 loan->at(sfManagementFeeOutstanding) = properties.managementFeeOwedToBroker;
593 loan->at(sfPreviousPaymentDate) = 0;
594 loan->at(sfNextPaymentDueDate) = startDate + paymentInterval;
595 loan->at(sfPaymentRemaining) = paymentTotal;
596 view.insert(loan);
597
598 // Update the balances in the vault
599 vaultAvailableProxy -= principalRequested;
600 vaultTotalProxy += state.interestDue;
601 XRPL_ASSERT_PARTS(
602 *vaultAvailableProxy <= *vaultTotalProxy,
603 "xrpl::LoanSet::doApply",
604 "assets available must not be greater than assets outstanding");
605 view.update(vaultSle);
606
607 // Update the balances in the loan broker
609 brokerSle->at(sfDebtTotal), newDebtDelta, vaultAsset, vaultScale);
610 // The broker's owner count is solely for the number of outstanding loans,
611 // and is distinct from the broker's pseudo-account's owner count
612 adjustOwnerCount(view, brokerSle, 1, j_);
613 loanSequenceProxy += 1;
614 // The sequence should be extremely unlikely to roll over, but fail if it
615 // does
616 if (loanSequenceProxy == 0)
618 view.update(brokerSle);
619
620 // Put the loan into the pseudo-account's directory
621 if (auto const ter = dirLink(view, brokerPseudo, loan, sfLoanBrokerNode))
622 return ter;
623 // Borrower is the owner of the loan
624 if (auto const ter = dirLink(view, borrower, loan, sfOwnerNode))
625 return ter;
626
627 return tesSUCCESS;
628}
629
630//------------------------------------------------------------------------------
631
632} // namespace xrpl
Stream debug() const
Definition Journal.h:309
Stream warn() const
Definition Journal.h:321
STTx const & tx
ApplyView & view()
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
Definition LoanSet.cpp:16
static TER preclaim(PreclaimContext const &ctx)
Definition LoanSet.cpp:195
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition LoanSet.cpp:147
static std::uint32_t constexpr minPaymentInterval
Definition LoanSet.h:47
static std::vector< OptionaledField< STNumber > > const & getValueFields()
Definition LoanSet.cpp:174
static NotTEC preflight(PreflightContext const &ctx)
Definition LoanSet.cpp:22
static std::uint32_t constexpr defaultPaymentInterval
Definition LoanSet.h:48
static NotTEC checkSign(PreclaimContext const &ctx)
Definition LoanSet.cpp:113
static std::uint32_t constexpr defaultPaymentTotal
Definition LoanSet.h:44
static bool checkExtraFeatures(PreflightContext const &ctx)
Definition LoanSet.cpp:10
TER doApply() override
Definition LoanSet.cpp:347
static std::uint32_t constexpr defaultGracePeriod
Definition LoanSet.h:51
A view into a ledger.
Definition ReadView.h:32
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
virtual std::shared_ptr< SLE const > 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:111
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1055
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:673
AccountID const account_
Definition Transactor.h:128
static NotTEC checkSign(PreclaimContext const &ctx)
static bool validNumericMinimum(std::optional< T > value, T min=T{})
Minimum will usually be zero.
Definition Transactor.h:439
beast::Journal const j_
Definition Transactor.h:126
ApplyView & view()
Definition Transactor.h:144
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
XRPAmount mPriorBalance
Definition Transactor.h:129
static bool validDataLength(std::optional< Slice > const &slice, std::size_t maxLength)
ApplyContext & ctx_
Definition Transactor.h:124
static bool validNumericRange(std::optional< T > value, T max, T min=T{})
Definition Transactor.h:420
constexpr value_type value() const
Returns the underlying value.
Definition XRPAmount.h:220
T is_same_v
T max(T... args)
NotTEC preflightCheckSigningKey(STObject const &sigObject, beast::Journal j)
Checks the validity of the transactor signing key.
std::optional< NotTEC > preflightCheckSimulateKeys(ApplyFlags flags, STObject const &sigObject, beast::Journal j)
Checks the special signing key state needed for simulation.
Keylet loanbroker(AccountID const &owner, std::uint32_t seq) noexcept
Definition Indexes.cpp:552
Keylet loan(uint256 const &loanBrokerID, std::uint32_t loanSeq) noexcept
Definition Indexes.cpp:558
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Definition Indexes.cpp:546
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:166
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
Definition View.h:269
@ terNO_ACCOUNT
Definition TER.h:198
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
Any transactors that call addEmptyHolding() in doApply must call canAddHolding() in preflight with th...
Definition View.cpp:1439
TER canAddHolding(ReadView const &view, Asset const &asset)
Definition View.cpp:1322
constexpr std::uint32_t tfInnerBatchTxn
Definition TxFlags.h:42
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
constexpr T tenthBipsOfValue(T value, TenthBips< TBips > bips)
Definition Protocol.h:108
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
Definition View.h:160
void adjustImpreciseNumber(NumberProxy value, Number const &adjustment, Asset const &asset, int vaultScale)
@ tefBAD_LEDGER
Definition TER.h:151
bool checkLendingProtocolDependencies(PreflightContext const &ctx)
constexpr std::uint32_t const tfLoanOverpayment
Definition TxFlags.h:273
std::size_t constexpr maxDataPayloadLength
The maximum length of Data payload.
Definition Protocol.h:238
TER checkLoanGuards(Asset const &vaultAsset, Number const &principalRequested, bool expectInterest, std::uint32_t paymentTotal, LoanProperties const &properties, beast::Journal j)
TERSubset< CanCvtToTER > TER
Definition TER.h:630
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:1134
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
Definition View.cpp:3096
constexpr std::uint32_t const tfLoanSetMask
Definition TxFlags.h:284
static std::uint32_t getStartDate(ReadView const &view)
Definition LoanSet.cpp:189
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
Definition View.cpp:1160
int getVaultScale(SLE::const_ref vaultSle)
@ temINVALID
Definition TER.h:91
@ temBAD_SIGNER
Definition TER.h:96
@ tecNO_ENTRY
Definition TER.h:288
@ tecINTERNAL
Definition TER.h:292
@ tecINSUFFICIENT_FUNDS
Definition TER.h:307
@ tecPRECISION_LOSS
Definition TER.h:345
@ tecINSUFFICIENT_RESERVE
Definition TER.h:289
@ tecKILLED
Definition TER.h:298
@ tecMAX_SEQUENCE_REACHED
Definition TER.h:302
@ tecLIMIT_EXCEEDED
Definition TER.h:343
@ tecNO_PERMISSION
Definition TER.h:287
@ tecDUPLICATE
Definition TER.h:297
@ lsfLoanOverpayment
TER accountSendMulti(ApplyView &view, AccountID const &senderID, Asset const &asset, MultiplePaymentDestinations const &receivers, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Like accountSend, except one account is sending multiple payments (with the same asset!...
Definition View.cpp:2798
LoanProperties computeLoanProperties(Asset const &asset, Number principalOutstanding, TenthBips32 interestRate, std::uint32_t paymentInterval, std::uint32_t paymentsRemaining, TenthBips32 managementFeeRate, std::int32_t minimumScale)
LoanState constructLoanState(Number const &totalValueOutstanding, Number const &principalOutstanding, Number const &managementFeeOutstanding)
@ tesSUCCESS
Definition TER.h:226
bool isRounded(Asset const &asset, Number const &value, std::int32_t scale)
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
XRPAmount base
NetClock::time_point closeTime
This structure captures the parts of a loan state.
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
ReadView const & view
Definition Transactor.h:64
beast::Journal const j
Definition Transactor.h:69
std::optional< uint256 const > const parentBatchId
Definition Transactor.h:68
State information when preflighting a tx.
Definition Transactor.h:16
beast::Journal const j
Definition Transactor.h:23
std::optional< uint256 const > parentBatchId
Definition Transactor.h:22
T time_since_epoch(T... args)