1#include <xrpld/app/tx/detail/LoanBrokerCoverWithdraw.h>
3#include <xrpld/app/misc/LendingHelpers.h>
4#include <xrpld/app/tx/detail/Payment.h>
6#include <xrpl/ledger/CredentialHelpers.h>
19 if (ctx.
tx[sfLoanBrokerID] == beast::zero)
22 auto const dstAmount = ctx.
tx[sfAmount];
23 if (dstAmount <= beast::zero)
29 if (
auto const destination = ctx.
tx[~sfDestination])
31 if (*destination == beast::zero)
43 auto const& tx = ctx.
tx;
45 auto const account = tx[sfAccount];
46 auto const brokerID = tx[sfLoanBrokerID];
47 auto const amount = tx[sfAmount];
49 auto const dstAcct = tx[~sfDestination].value_or(account);
54 JLOG(ctx.
j.
warn()) <<
"LoanBroker does not exist.";
57 if (account != sleBroker->at(sfOwner))
59 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the LoanBroker.";
66 JLOG(ctx.
j.
fatal()) <<
"Vault is missing for Broker " << brokerID;
71 auto const vaultAsset = vault->at(sfAsset);
72 if (amount.asset() != vaultAsset)
76 auto const pseudoAccountID = sleBroker->at(sfAccount);
85 if (account != dstAcct)
96 if (
auto const ter =
requireAuth(ctx.
view, vaultAsset, dstAcct, authType))
100 if (dstAcct != vaultAsset.getIssuer())
103 if (
auto const ret =
checkFrozen(ctx.
view, pseudoAccountID, vaultAsset))
110 auto const coverAvail = sleBroker->at(sfCoverAvailable);
112 auto const currentDebtTotal = sleBroker->at(sfDebtTotal);
113 auto const minimumCover = [&]() {
122 currentDebtTotal.exponent());
124 if (coverAvail < amount)
126 if ((coverAvail - amount) < minimumCover)
146 auto const brokerID = tx[sfLoanBrokerID];
147 auto const amount = tx[sfAmount];
148 auto const dstAcct = tx[~sfDestination].value_or(
account_);
154 auto const brokerPseudoID = *broker->at(sfAccount);
157 broker->at(sfCoverAvailable) -= amount;
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static bool checkExtraFeatures(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Keylet loanbroker(AccountID const &owner, std::uint32_t seq) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
Number roundToAsset(A const &asset, Number const &value, std::int32_t scale, Number::rounding_mode rounding=Number::getround())
Round an arbitrary precision Number to the precision of a given Asset.
TER doWithdraw(ApplyView &view, STTx const &tx, AccountID const &senderAcct, AccountID const &dstAcct, AccountID const &sourceAcct, XRPAmount priorBalance, STAmount const &amount, beast::Journal j)
constexpr T tenthBipsOfValue(T value, TenthBips< TBips > bips)
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
bool isLegalNet(STAmount const &value)
bool checkLendingProtocolDependencies(PreflightContext const &ctx)
TenthBips< std::uint32_t > TenthBips32
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to)
Check if the destination account is allowed to receive MPT.
TER canWithdraw(AccountID const &from, ReadView const &view, AccountID const &to, SLE::const_ref toSle, bool hasDestinationTag)
Checks that can withdraw funds from an object to itself or a destination.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.