20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/app/tx/detail/MPTokenAuthorize.h>
22#include <xrpld/app/tx/detail/VaultDeposit.h>
23#include <xrpld/ledger/View.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/LedgerFormats.h>
28#include <xrpl/protocol/MPTIssue.h>
29#include <xrpl/protocol/STNumber.h>
30#include <xrpl/protocol/TER.h>
31#include <xrpl/protocol/TxFlags.h>
47 if (ctx.
tx[sfVaultID] == beast::zero)
49 JLOG(ctx.
j.
debug()) <<
"VaultDeposit: zero/empty vault ID.";
53 if (ctx.
tx[sfAmount] <= beast::zero)
66 auto const account = ctx.
tx[sfAccount];
67 auto const assets = ctx.
tx[sfAmount];
68 auto const vaultAsset = vault->at(sfAsset);
69 if (assets.asset() != vaultAsset)
72 if (vaultAsset.native())
74 else if (vaultAsset.holds<
MPTIssue>())
76 auto mptID = vaultAsset.get<
MPTIssue>().getMptID();
84 <<
"VaultDeposit: vault assets are non-transferable.";
89 else if (vaultAsset.holds<
Issue>())
97 <<
"VaultDeposit: missing issuer of vault assets.";
103 auto const mptIssuanceID = vault->at(sfShareMPTID);
104 auto const vaultShare =
MPTIssue(mptIssuanceID);
105 if (vaultShare == assets.asset())
109 <<
"VaultDeposit: vault shares and assets cannot be same.";
119 <<
"VaultDeposit: missing issuance of vault shares.";
128 <<
"VaultDeposit: issuance of vault shares is locked.";
141 if (vault->isFlag(
tfVaultPrivate) && account != vault->at(sfOwner))
143 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
186 auto const assets =
ctx_.
tx[sfAmount];
188 auto const mptIssuanceID = (*vault)[sfShareMPTID];
193 JLOG(
j_.
error()) <<
"VaultDeposit: missing issuance of vault shares.";
198 auto const& vaultAccount = vault->at(sfAccount);
216 {.priorBalance = mPriorBalance,
217 .mptIssuanceID = mptIssuanceID->value(),
218 .account = account_});
230 .priorBalance = mPriorBalance,
231 .mptIssuanceID = mptIssuanceID->value(),
232 .account = sleIssuance->at(sfIssuer),
233 .holderID = account_,
243 shares.asset() != assets.asset(),
244 "ripple::VaultDeposit::doApply : assets are not shares");
246 vault->at(sfAssetsTotal) += assets;
247 vault->at(sfAssetsAvailable) += assets;
251 auto const maximum = *vault->at(sfAssetsMaximum);
252 if (maximum != 0 && *vault->at(sfAssetsTotal) > maximum)
270 JLOG(
j_.
error()) <<
"VaultDeposit: negative balance of account assets.";
beast::Journal const journal
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.
A currency issued by an account.
static TER authorize(ApplyView &view, beast::Journal journal, MPTAuthorizeArgs const &args)
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.
std::uint32_t getFlags() const
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
TER validDomain(ReadView const &view, uint256 domainID, AccountID const &subject)
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) 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 requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType)
Check if the account lacks required authorization.
constexpr std::uint32_t const tfVaultPrivate
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
bool isTesSuccess(TER x) noexcept
constexpr std::uint32_t tfUniversalMask
STAmount assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
Calls static accountSendIOU if saAmount represents Issue.
TERSubset< CanCvtToNotTEC > NotTEC
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.