20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/app/tx/detail/VaultWithdraw.h>
22#include <xrpld/ledger/View.h>
24#include <xrpl/protocol/AccountID.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/SField.h>
27#include <xrpl/protocol/STNumber.h>
28#include <xrpl/protocol/TER.h>
29#include <xrpl/protocol/TxFlags.h>
45 if (ctx.
tx[sfVaultID] == beast::zero)
47 JLOG(ctx.
j.
debug()) <<
"VaultWithdraw: zero/empty vault ID.";
51 if (ctx.
tx[sfAmount] <= beast::zero)
54 if (
auto const destination = ctx.
tx[~sfDestination];
55 destination && *destination == beast::zero)
57 JLOG(ctx.
j.
debug()) <<
"VaultWithdraw: zero/empty destination account.";
71 auto const assets = ctx.
tx[sfAmount];
72 auto const vaultAsset = vault->at(sfAsset);
73 auto const vaultShare = vault->at(sfShareMPTID);
74 if (assets.asset() != vaultAsset && assets.asset() != vaultShare)
77 if (vaultAsset.native())
79 else if (vaultAsset.holds<
MPTIssue>())
81 auto mptID = vaultAsset.get<
MPTIssue>().getMptID();
89 <<
"VaultWithdraw: vault assets are non-transferable.";
94 else if (vaultAsset.holds<
Issue>())
102 <<
"VaultWithdraw: missing issuer of vault assets.";
112 JLOG(ctx.
j.
error()) <<
"VaultWithdraw: invalid withdrawal policy.";
117 auto const account = ctx.
tx[sfAccount];
118 auto const dstAcct = [&]() ->
AccountID {
126 if (account != dstAcct)
129 if (sleDst ==
nullptr)
164 auto const mptIssuanceID = (*vault)[sfShareMPTID];
169 JLOG(
j_.
error()) <<
"VaultWithdraw: missing issuance of vault shares.";
179 auto amount =
ctx_.
tx[sfAmount];
180 auto const asset = vault->at(sfAsset);
181 auto const share =
MPTIssue(mptIssuanceID);
183 if (amount.asset() == asset)
189 else if (amount.asset() == share)
206 JLOG(
j_.
debug()) <<
"VaultWithdraw: account doesn't hold enough shares";
213 if (*vault->at(sfAssetsAvailable) < assets)
215 JLOG(
j_.
debug()) <<
"VaultWithdraw: vault doesn't hold enough assets";
219 vault->at(sfAssetsTotal) -= assets;
220 vault->at(sfAssetsAvailable) -= assets;
223 auto const& vaultAccount = vault->at(sfAccount);
229 auto const dstAcct = [&]() ->
AccountID {
250 JLOG(
j_.
error()) <<
"VaultWithdraw: negative balance of vault assets.";
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.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Asset const & asset() const
AccountID getAccountID(SField const &field) const
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
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.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STAmount sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
TER requireAuth(ReadView const &view, Issue const &issue, AccountID const &account)
Check if the account lacks required authorization.
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
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
STAmount assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
constexpr std::uint32_t tfUniversalMask
std::uint8_t constexpr vaultStrategyFirstComeFirstServe
Vault withdrawal policies.
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.