1#include <xrpl/tx/transactors/lending/LoanBrokerDelete.h>
3#include <xrpl/ledger/helpers/AccountRootHelpers.h>
4#include <xrpl/ledger/helpers/TokenHelpers.h>
5#include <xrpl/protocol/STTakesAsset.h>
6#include <xrpl/tx/transactors/lending/LendingHelpers.h>
19 if (ctx.
tx[sfLoanBrokerID] == beast::zero)
28 auto const& tx = ctx.
tx;
30 auto const account = tx[sfAccount];
31 auto const brokerID = tx[sfLoanBrokerID];
36 JLOG(ctx.
j.
warn()) <<
"LoanBroker does not exist.";
40 auto const brokerOwner = sleBroker->at(sfOwner);
42 if (account != brokerOwner)
44 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the LoanBroker.";
47 if (
auto const ownerCount = sleBroker->at(sfOwnerCount); ownerCount != 0)
49 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Owner count is " << ownerCount;
57 JLOG(ctx.
j.
fatal()) <<
"Vault is missing for Broker " << brokerID;
62 Asset const asset = vault->at(sfAsset);
64 if (
auto const debtTotal = sleBroker->at(sfDebtTotal); debtTotal != beast::zero)
72 if (rounded != beast::zero)
75 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Debt total is " << debtTotal
76 <<
", which rounds to " << rounded;
82 auto const coverAvailable =
STAmount{asset, sleBroker->at(sfCoverAvailable)};
85 if (coverAvailable > beast::zero)
89 JLOG(ctx.
j.
warn()) <<
"Broker owner account is frozen.";
102 auto const brokerID = tx[sfLoanBrokerID];
108 auto const vaultID = broker->at(sfVaultID);
112 auto const vaultPseudoID = sleVault->at(sfAccount);
113 auto const vaultAsset = sleVault->at(sfAsset);
115 auto const brokerPseudoID = broker->at(sfAccount);
117 if (!
view().dirRemove(
122 if (!
view().dirRemove(
129 auto const coverAvailable =
STAmount{vaultAsset, broker->at(sfCoverAvailable)};
139 if (!brokerPseudoSLE)
144 if (*brokerPseudoSLE->at(sfBalance))
146 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account has a balance";
149 if (brokerPseudoSLE->at(sfOwnerCount) != 0)
151 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account still owns objects";
156 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)
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.
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.