1#include <xrpld/app/tx/detail/LoanBrokerSet.h>
3#include <xrpld/app/misc/LendingHelpers.h>
16 using namespace Lending;
18 auto const& tx = ctx.
tx;
19 if (
auto const data = tx[~sfData]; data && !data->empty() &&
32 if (tx.isFieldPresent(sfLoanBrokerID))
36 if (tx.isFieldPresent(sfManagementFeeRate) ||
37 tx.isFieldPresent(sfCoverRateMinimum) ||
38 tx.isFieldPresent(sfCoverRateLiquidation))
41 if (tx[sfLoanBrokerID] == beast::zero)
45 if (
auto const vaultID = tx.at(~sfVaultID))
47 if (*vaultID == beast::zero)
52 auto const minimumZero = tx[~sfCoverRateMinimum].value_or(0) == 0;
53 auto const liquidationZero =
54 tx[~sfCoverRateLiquidation].value_or(0) == 0;
56 if (minimumZero != liquidationZero)
68 auto const& tx = ctx.
tx;
70 auto const account = tx[sfAccount];
71 auto const vaultID = tx[sfVaultID];
73 if (
auto const brokerID = tx[~sfLoanBrokerID])
78 JLOG(ctx.
j.
warn()) <<
"LoanBroker does not exist.";
81 if (vaultID != sleBroker->at(sfVaultID))
84 <<
"Can not change VaultID on an existing LoanBroker.";
87 if (account != sleBroker->at(sfOwner))
89 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the LoanBroker.";
98 JLOG(ctx.
j.
warn()) <<
"Vault does not exist.";
101 if (account != sleVault->at(sfOwner))
103 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the Vault.";
118 if (
auto const brokerID = tx[~sfLoanBrokerID])
126 JLOG(
j_.
fatal()) <<
"LoanBroker does not exist.";
131 if (
auto const data = tx[~sfData])
132 broker->at(sfData) = *data;
133 if (
auto const debtMax = tx[~sfDebtMaximum])
134 broker->at(sfDebtMaximum) = *debtMax;
141 auto const vaultID = tx[sfVaultID];
147 JLOG(
j_.
fatal()) <<
"Vault does not exist.";
151 auto const vaultPseudoID = sleVault->at(sfAccount);
152 auto const sequence = tx.getSeqValue();
159 JLOG(
j_.
fatal()) <<
"Account does not exist.";
168 if (
auto const ter =
dirLink(
view, vaultPseudoID, broker, sfVaultNode))
174 auto const ownerCount = owner->at(sfOwnerCount);
181 return maybePseudo.error();
182 auto& pseudo = *maybePseudo;
183 auto pseudoId = pseudo->at(sfAccount);
190 broker->at(sfSequence) = sequence;
191 broker->at(sfVaultID) = vaultID;
193 broker->at(sfAccount) = pseudoId;
195 broker->at(sfLoanSequence) = 1;
196 if (
auto const data = tx[~sfData])
197 broker->at(sfData) = *data;
198 if (
auto const rate = tx[~sfManagementFeeRate])
199 broker->at(sfManagementFeeRate) = *rate;
200 if (
auto const debtMax = tx[~sfDebtMaximum])
201 broker->at(sfDebtMaximum) = *debtMax;
202 if (
auto const coverMin = tx[~sfCoverRateMinimum])
203 broker->at(sfCoverRateMinimum) = *coverMin;
204 if (
auto const coverLiq = tx[~sfCoverRateLiquidation])
205 broker->at(sfCoverRateLiquidation) = *coverLiq;
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 NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
static bool validDataLength(std::optional< Slice > const &slice, std::size_t maxLength)
static bool validNumericRange(std::optional< T > value, T max, T min=T{})
Keylet loanbroker(AccountID const &owner, std::uint32_t seq) noexcept
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 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...
TER canAddHolding(ReadView const &view, Asset const &asset)
std::uint64_t constexpr maxMPTokenAmount
The maximum amount of MPTokenIssuance.
bool checkLendingProtocolDependencies(PreflightContext const &ctx)
std::size_t constexpr maxDataPayloadLength
The maximum length of Data payload.
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object, SF_UINT64 const &node=sfOwnerNode)
@ tecINSUFFICIENT_RESERVE
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.