20#include <xrpld/app/tx/detail/MPTokenAuthorize.h>
21#include <xrpld/app/tx/detail/VaultDeposit.h>
23#include <xrpl/ledger/CredentialHelpers.h>
24#include <xrpl/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/SField.h>
30#include <xrpl/protocol/STNumber.h>
31#include <xrpl/protocol/TER.h>
32#include <xrpl/protocol/TxFlags.h>
48 if (ctx.
tx[sfVaultID] == beast::zero)
50 JLOG(ctx.
j.
debug()) <<
"VaultDeposit: zero/empty vault ID.";
54 if (ctx.
tx[sfAmount] <= beast::zero)
67 auto const account = ctx.
tx[sfAccount];
68 auto const assets = ctx.
tx[sfAmount];
69 auto const vaultAsset = vault->at(sfAsset);
70 if (assets.asset() != vaultAsset)
73 if (vaultAsset.native())
75 else if (vaultAsset.holds<
MPTIssue>())
77 auto mptID = vaultAsset.get<
MPTIssue>().getMptID();
85 <<
"VaultDeposit: vault assets are non-transferable.";
90 else if (vaultAsset.holds<
Issue>())
98 <<
"VaultDeposit: missing issuer of vault assets.";
104 auto const mptIssuanceID = vault->at(sfShareMPTID);
105 auto const vaultShare =
MPTIssue(mptIssuanceID);
106 if (vaultShare == assets.asset())
110 <<
"VaultDeposit: vault shares and assets cannot be same.";
120 <<
"VaultDeposit: missing issuance of vault shares.";
129 <<
"VaultDeposit: issuance of vault shares is locked.";
144 auto const maybeDomainID = sleIssuance->at(~sfDomainID);
187 auto const amount =
ctx_.
tx[sfAmount];
189 auto const mptIssuanceID = (*vault)[sfShareMPTID];
194 JLOG(
j_.
error()) <<
"VaultDeposit: missing issuance of vault shares.";
199 auto const& vaultAccount = vault->at(sfAccount);
217 mptIssuanceID->
value(),
230 "ripple::VaultDeposit::doApply : account is owner");
234 mptIssuanceID->
value(),
235 sleIssuance->at(sfIssuer),
245 STAmount sharesCreated = {vault->at(sfShareMPTID)}, assetsDeposited;
250 auto const maybeShares =
254 sharesCreated = *maybeShares;
256 if (sharesCreated == beast::zero)
259 auto const maybeAssets =
263 else if (*maybeAssets > amount)
266 JLOG(
j_.
error()) <<
"VaultDeposit: would take more than offered.";
270 assetsDeposited = *maybeAssets;
277 <<
"VaultDeposit: overflow error with"
278 <<
" scale=" << (int)vault->at(sfScale).value()
279 <<
", assetsTotal=" << vault->at(sfAssetsTotal).value()
280 <<
", sharesTotal=" << sleIssuance->at(sfOutstandingAmount)
281 <<
", amount=" << amount;
286 sharesCreated.
asset() != assetsDeposited.asset(),
287 "ripple::VaultDeposit::doApply : assets are not shares");
289 vault->at(sfAssetsTotal) += assetsDeposited;
290 vault->at(sfAssetsAvailable) += assetsDeposited;
294 auto const maximum = *vault->at(sfAssetsMaximum);
295 if (maximum != 0 && *vault->at(sfAssetsTotal) > maximum)
313 assetsDeposited.asset(),
319 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.
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.
Asset const & asset() const
std::uint32_t getFlags() const
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
constexpr value_type value() const
Returns the underlying value.
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.
std::optional< STAmount > sharesToAssetsDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
std::optional< STAmount > assetsToSharesDeposit(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
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.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account, AuthType authType=AuthType::Legacy)
Check if the account lacks required authorization.
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
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
TER authorizeMPToken(ApplyView &view, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags=0, std::optional< AccountID > holderID=std::nullopt)
TERSubset< CanCvtToNotTEC > NotTEC
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.