1#include <xrpld/app/tx/detail/LoanBrokerDelete.h>
3#include <xrpld/app/misc/LendingHelpers.h>
5#include <xrpl/protocol/STTakesAsset.h>
18 if (ctx.
tx[sfLoanBrokerID] == beast::zero)
27 auto const& tx = ctx.
tx;
29 auto const account = tx[sfAccount];
30 auto const brokerID = tx[sfLoanBrokerID];
35 JLOG(ctx.
j.
warn()) <<
"LoanBroker does not exist.";
39 auto const brokerOwner = sleBroker->at(sfOwner);
41 if (account != brokerOwner)
43 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the LoanBroker.";
46 if (
auto const ownerCount = sleBroker->at(sfOwnerCount); ownerCount != 0)
48 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Owner count is " << ownerCount;
56 JLOG(ctx.
j.
fatal()) <<
"Vault is missing for Broker " << brokerID;
61 Asset const asset = vault->at(sfAsset);
63 if (
auto const debtTotal = sleBroker->at(sfDebtTotal); debtTotal != beast::zero)
71 if (rounded != beast::zero)
74 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Debt total is " << debtTotal <<
", which rounds to " << rounded;
80 auto const coverAvailable =
STAmount{asset, sleBroker->at(sfCoverAvailable)};
83 if (coverAvailable > beast::zero)
87 JLOG(ctx.
j.
warn()) <<
"Broker owner account is frozen.";
100 auto const brokerID = tx[sfLoanBrokerID];
106 auto const vaultID = broker->at(sfVaultID);
110 auto const vaultPseudoID = sleVault->at(sfAccount);
111 auto const vaultAsset = sleVault->at(sfAsset);
113 auto const brokerPseudoID = broker->at(sfAccount);
125 auto const coverAvailable =
STAmount{vaultAsset, broker->at(sfCoverAvailable)};
134 if (!brokerPseudoSLE)
139 if (*brokerPseudoSLE->at(sfBalance))
141 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account has a balance";
144 if (brokerPseudoSLE->at(sfOwnerCount) != 0)
146 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account still owns objects";
151 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account has a directory";
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static bool checkExtraFeatures(PreflightContext 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 ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
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)
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
int getAssetsTotalScale(SLE::const_ref vaultSle)
bool checkLendingProtocolDependencies(PreflightContext const &ctx)
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
void roundToAsset(A const &asset, Number &value)
Round an arbitrary precision Number IN PLACE to the precision of a given Asset.
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.