xrpld
Loading...
Searching...
No Matches
MPTokenHelpers.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/helpers/TokenHelpers.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Asset.h>
9#include <xrpl/protocol/MPTIssue.h>
10#include <xrpl/protocol/Rate.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/UintTypes.h>
15#include <xrpl/protocol/XRPAmount.h>
16
17#include <cstdint>
18#include <initializer_list>
19#include <optional>
20
21namespace xrpl {
22
23//------------------------------------------------------------------------------
24//
25// Freeze checking (MPT-specific)
26//
27//------------------------------------------------------------------------------
28
29[[nodiscard]] bool
30isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
31
32[[nodiscard]] bool
33isGlobalFrozen(SLE const& issuanceSle);
34
46
47[[nodiscard]] bool
48isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
49
50[[nodiscard]] bool
51isIndividualFrozen(SLE const& mptSle);
52
69[[nodiscard]] bool
71 ReadView const& view,
72 AccountID const& account,
73 MPTIssue const& mptIssue,
74 std::uint8_t depth = 0);
75
85[[nodiscard]] bool
86isFrozen(ReadView const& view, AccountID const& account, SLE const& sle, std::uint8_t depth = 0);
87
88[[nodiscard]] bool
90 ReadView const& view,
91 std::initializer_list<AccountID> const& accounts,
92 MPTIssue const& mptIssue,
93 std::uint8_t depth = 0);
94
95//------------------------------------------------------------------------------
96//
97// Transfer rate (MPT-specific)
98//
99//------------------------------------------------------------------------------
100
107[[nodiscard]] Rate
108transferRate(ReadView const& view, MPTID const& issuanceID);
109
110//------------------------------------------------------------------------------
111//
112// Holding checks (MPT-specific)
113//
114//------------------------------------------------------------------------------
115
116[[nodiscard]] TER
117canAddHolding(ReadView const& view, MPTIssue const& mptIssue);
118
119//------------------------------------------------------------------------------
120//
121// Authorization (MPT-specific)
122//
123//------------------------------------------------------------------------------
124
125[[nodiscard]] TER
128 XRPAmount const& priorBalance,
129 MPTID const& mptIssuanceID,
130 AccountID const& account,
131 beast::Journal journal,
132 std::uint32_t flags = 0,
133 std::optional<AccountID> holderID = std::nullopt);
134
143[[nodiscard]] TER
145 ReadView const& view,
146 MPTIssue const& mptIssue,
147 AccountID const& account,
148 AuthType authType = AuthType::Legacy,
149 std::uint8_t depth = 0);
150
158[[nodiscard]] TER
161 MPTID const& mptIssuanceID,
162 AccountID const& account,
163 XRPAmount const& priorBalance,
164 beast::Journal j);
165
180[[nodiscard]] Asset
181assetOfHolding(SLE const& sleShareIssuance, SLE const& sleHolding);
182
207[[nodiscard]] TER
209 ReadView const& view,
210 MPTIssue const& mptIssue,
211 AccountID const& from,
212 AccountID const& to,
214 std::uint8_t depth = 0);
215
229[[nodiscard]] TER
230canTrade(ReadView const& view, Asset const& asset, std::uint8_t depth = 0);
231
235[[nodiscard]] TER
237 ReadView const& v,
238 Asset const& asset,
239 AccountID const& from,
240 AccountID const& to);
241
242//------------------------------------------------------------------------------
243//
244// Empty holding operations (MPT-specific)
245//
246//------------------------------------------------------------------------------
247
248[[nodiscard]] TER
251 AccountID const& accountID,
252 XRPAmount priorBalance,
253 MPTIssue const& mptIssue,
254 beast::Journal journal);
255
256[[nodiscard]] TER
259 AccountID const& accountID,
260 MPTIssue const& mptIssue,
261 beast::Journal journal);
262
263//------------------------------------------------------------------------------
264//
265// Escrow operations (MPT-specific)
266//
267//------------------------------------------------------------------------------
268
269TER
271 ApplyView& view,
272 AccountID const& uGrantorID,
273 STAmount const& saAmount,
274 beast::Journal j);
275
276TER
278 ApplyView& view,
279 AccountID const& uGrantorID,
280 AccountID const& uGranteeID,
281 STAmount const& netAmount,
282 STAmount const& grossAmount,
283 beast::Journal j);
284
285TER
287 ApplyView& view,
288 MPTID const& mptIssuanceID,
289 AccountID const& account,
290 SLE::Ref sponsorSle,
291 std::uint32_t const flags);
292
293TER
295 xrpl::ApplyView& view,
296 xrpl::MPTIssue const& mptIssue,
297 xrpl::AccountID const& holder,
298 SLE::Ref sponsorSle,
299 std::uint32_t flags,
300 beast::Journal j);
301
302TER
304 xrpl::ApplyView& view,
305 xrpl::MPTIssue const& mptIssue,
306 xrpl::AccountID const& holder,
307 beast::Journal j);
308
309//------------------------------------------------------------------------------
310//
311// MPT Overflow related
312//
313//------------------------------------------------------------------------------
314
315// MaximumAmount doesn't exceed 2**63-1
316std::int64_t
317maxMPTAmount(SLE const& sleIssuance);
318
319// OutstandingAmount may overflow and available amount might be negative.
320// But available amount is always <= |MaximumAmount - OutstandingAmount|.
321std::int64_t
322availableMPTAmount(SLE const& sleIssuance);
323
324std::int64_t
325availableMPTAmount(ReadView const& view, MPTID const& mptID);
326
336bool
338 std::int64_t sendAmount,
339 std::uint64_t outstandingAmount,
340 std::int64_t maximumAmount,
341 AllowMPTOverflow allowOverflow);
342
350[[nodiscard]] STAmount
351issuerFundsToSelfIssue(ReadView const& view, MPTIssue const& issue);
352
357void
358issuerSelfDebitHookMPT(ApplyView& view, MPTIssue const& issue, std::uint64_t amount);
359
360} // namespace xrpl
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:141
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry > const & Ref
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TER enforceMPTokenAuthorization(ApplyViewContext ctx, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
std::int64_t maxMPTAmount(SLE const &sleIssuance)
TER checkCreateMPT(xrpl::ApplyView &view, xrpl::MPTIssue const &mptIssue, xrpl::AccountID const &holder, SLE::Ref sponsorSle, std::uint32_t flags, beast::Journal j)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
Returns true if account's MPToken for mptIssue carries the individual-lock flag (lsfMPTLocked).
AllowMPTOverflow
Controls whether accountSend is allowed to overflow OutstandingAmount *.
TER removeEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
TER lockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
TER addEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
TER canMPTTradeAndTransfer(ReadView const &v, Asset const &asset, AccountID const &from, AccountID const &to)
Convenience to combine canTrade/Transfer.
Asset assetOfHolding(SLE const &sleShareIssuance, SLE const &sleHolding)
Resolve the underlying asset of a vault share.
TER unlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to, WaiveMPTCanTransfer waive=WaiveMPTCanTransfer::No, std::uint8_t depth=0)
Check whether to may receive the given MPT from from.
TER canTrade(ReadView const &view, Asset const &asset, std::uint8_t depth=0)
Check whether asset may be traded on the DEX.
STLedgerEntry SLE
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
TER canAddHolding(ReadView const &view, MPTIssue const &mptIssue)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:54
std::int64_t availableMPTAmount(SLE const &sleIssuance)
WaiveMPTCanTransfer
Controls whether canTransfer enforces lsfMPTCanTransfer on MPTs.
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, std::uint8_t depth=0)
Returns true if account cannot send or receive tokens of mptIssue because a freeze applies.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
bool isAnyFrozen(ReadView const &view, std::initializer_list< AccountID > const &accounts, MPTIssue const &mptIssue, std::uint8_t depth=0)
TERSubset< CanCvtToTER > TER
Definition TER.h:654
TER authorizeMPToken(ApplyViewContext ctx, XRPAmount const &priorBalance, MPTID const &mptIssuanceID, AccountID const &account, beast::Journal journal, std::uint32_t flags=0, std::optional< AccountID > holderID=std::nullopt)
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
void issuerSelfDebitHookMPT(ApplyView &view, MPTIssue const &issue, std::uint64_t amount)
Facilitate tracking of MPT sold by an issuer owning MPT sell offer.
TER createMPToken(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, SLE::Ref sponsorSle, std::uint32_t const flags)
bool isMPTOverflow(std::int64_t sendAmount, std::uint64_t outstandingAmount, std::int64_t maximumAmount, AllowMPTOverflow allowOverflow)
Checks for two types of OutstandingAmount overflow during a send operation.
STAmount issuerFundsToSelfIssue(ReadView const &view, MPTIssue const &issue)
Determine funds available for an issuer to sell in an issuer owned offer.
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451
Represents a transfer rate.
Definition Rate.h:21