20#include <xrpld/app/tx/detail/VaultClawback.h>
21#include <xrpld/ledger/View.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/MPTIssue.h>
26#include <xrpl/protocol/STAmount.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()) <<
"VaultClawback: zero/empty vault ID.";
56 JLOG(ctx.
j.
debug()) <<
"VaultClawback: issuer cannot be holder.";
60 auto const amount = ctx.
tx[~sfAmount];
64 if (*amount < beast::zero)
66 else if (
isXRP(amount->asset()))
68 JLOG(ctx.
j.
debug()) <<
"VaultClawback: cannot clawback XRP.";
71 else if (amount->asset().getIssuer() != issuer)
74 <<
"VaultClawback: only asset issuer can clawback.";
89 auto account = ctx.
tx[sfAccount];
94 JLOG(ctx.
j.
error()) <<
"VaultClawback: missing issuer account.";
99 Asset const vaultAsset = vault->at(sfAsset);
100 if (
auto const amount = ctx.
tx[~sfAmount];
101 amount && vaultAsset != amount->asset())
106 JLOG(ctx.
j.
debug()) <<
"VaultClawback: cannot clawback XRP.";
109 else if (vaultAsset.
getIssuer() != account)
111 JLOG(ctx.
j.
debug()) <<
"VaultClawback: only asset issuer can clawback.";
118 auto const mptIssue =
120 if (mptIssue ==
nullptr)
123 std::uint32_t const issueFlags = mptIssue->getFieldU32(sfFlags);
127 <<
"VaultClawback: cannot clawback MPT vault asset.";
133 std::uint32_t const issuerFlags = issuer->getFieldU32(sfFlags);
138 <<
"VaultClawback: cannot clawback IOU vault asset.";
154 auto const mptIssuanceID = (*vault)[sfShareMPTID];
159 JLOG(
j_.
error()) <<
"VaultClawback: missing issuance of vault shares.";
164 Asset const asset = vault->at(sfAsset);
166 auto const maybeAmount = tx[~sfAmount];
169 return {sfAmount, asset, 0};
172 amount.
asset() == asset,
173 "ripple::VaultClawback::doApply : matching asset");
177 if (amount == beast::zero)
179 Asset share = *(*vault)[sfShareMPTID];
196 Number maxAssets = *vault->at(sfAssetsAvailable);
197 if (assets > maxAssets)
203 if (shares == beast::zero)
206 vault->at(sfAssetsTotal) -= assets;
207 vault->at(sfAssetsAvailable) -= assets;
210 auto const& vaultAccount = vault->at(sfAccount);
231 JLOG(
j_.
error()) <<
"VaultClawback: 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.
constexpr TIss const & get() const
AccountID const & getIssuer() const
constexpr bool holds() const
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 NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
Set the expected result code for a JTx The test will fail if the code doesn't match.
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.
bool isXRP(AccountID const &c)
STAmount sharesToAssetsWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &shares)
@ lsfAllowTrustLineClawback
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
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)
STAmount assetsToSharesWithdraw(std::shared_ptr< SLE const > const &vault, std::shared_ptr< SLE const > const &issuance, STAmount const &assets)
constexpr std::uint32_t tfUniversalMask
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.