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/MPTIssue.h>
8#include <xrpl/protocol/Rate.h>
9#include <xrpl/protocol/STAmount.h>
10#include <xrpl/protocol/TER.h>
11
12#include <initializer_list>
13#include <optional>
14
15namespace xrpl {
16
17//------------------------------------------------------------------------------
18//
19// Freeze checking (MPT-specific)
20//
21//------------------------------------------------------------------------------
22
23[[nodiscard]] bool
24isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
25
26[[nodiscard]] bool
27isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
28
29[[nodiscard]] bool
31 ReadView const& view,
32 AccountID const& account,
33 MPTIssue const& mptIssue,
34 std::uint8_t depth = 0);
35
36[[nodiscard]] bool
38 ReadView const& view,
39 std::initializer_list<AccountID> const& accounts,
40 MPTIssue const& mptIssue,
41 std::uint8_t depth = 0);
42
43//------------------------------------------------------------------------------
44//
45// Transfer rate (MPT-specific)
46//
47//------------------------------------------------------------------------------
48
54[[nodiscard]] Rate
55transferRate(ReadView const& view, MPTID const& issuanceID);
56
57//------------------------------------------------------------------------------
58//
59// Holding checks (MPT-specific)
60//
61//------------------------------------------------------------------------------
62
63[[nodiscard]] TER
64canAddHolding(ReadView const& view, MPTIssue const& mptIssue);
65
66//------------------------------------------------------------------------------
67//
68// Authorization (MPT-specific)
69//
70//------------------------------------------------------------------------------
71
72[[nodiscard]] TER
74 ApplyView& view,
75 XRPAmount const& priorBalance,
76 MPTID const& mptIssuanceID,
77 AccountID const& account,
78 beast::Journal journal,
79 std::uint32_t flags = 0,
80 std::optional<AccountID> holderID = std::nullopt);
81
89[[nodiscard]] TER
91 ReadView const& view,
92 MPTIssue const& mptIssue,
93 AccountID const& account,
94 AuthType authType = AuthType::Legacy,
95 std::uint8_t depth = 0);
96
103[[nodiscard]] TER
105 ApplyView& view,
106 MPTID const& mptIssuanceID,
107 AccountID const& account,
108 XRPAmount const& priorBalance,
109 beast::Journal j);
110
124[[nodiscard]] Asset
125assetOfHolding(SLE const& sleShareIssuance, SLE const& sleHolding);
126
150[[nodiscard]] TER
152 ReadView const& view,
153 MPTIssue const& mptIssue,
154 AccountID const& from,
155 AccountID const& to,
157 std::uint8_t depth = 0);
158
171[[nodiscard]] TER
172canTrade(ReadView const& view, Asset const& asset, std::uint8_t depth = 0);
173
176[[nodiscard]] TER
178 ReadView const& v,
179 Asset const& asset,
180 AccountID const& from,
181 AccountID const& to);
182
183//------------------------------------------------------------------------------
184//
185// Empty holding operations (MPT-specific)
186//
187//------------------------------------------------------------------------------
188
189[[nodiscard]] TER
191 ApplyView& view,
192 AccountID const& accountID,
193 XRPAmount priorBalance,
194 MPTIssue const& mptIssue,
195 beast::Journal journal);
196
197[[nodiscard]] TER
199 ApplyView& view,
200 AccountID const& accountID,
201 MPTIssue const& mptIssue,
202 beast::Journal journal);
203
204//------------------------------------------------------------------------------
205//
206// Escrow operations (MPT-specific)
207//
208//------------------------------------------------------------------------------
209
210TER
212 ApplyView& view,
213 AccountID const& uGrantorID,
214 STAmount const& saAmount,
215 beast::Journal j);
216
217TER
219 ApplyView& view,
220 AccountID const& uGrantorID,
221 AccountID const& uGranteeID,
222 STAmount const& netAmount,
223 STAmount const& grossAmount,
224 beast::Journal j);
225
226TER
228 ApplyView& view,
229 MPTID const& mptIssuanceID,
230 AccountID const& account,
231 std::uint32_t const flags);
232
233TER
235 xrpl::ApplyView& view,
236 xrpl::MPTIssue const& mptIssue,
237 xrpl::AccountID const& holder,
238 beast::Journal j);
239
240//------------------------------------------------------------------------------
241//
242// MPT Overflow related
243//
244//------------------------------------------------------------------------------
245
246// MaximumAmount doesn't exceed 2**63-1
247std::int64_t
248maxMPTAmount(SLE const& sleIssuance);
249
250// OutstandingAmount may overflow and available amount might be negative.
251// But available amount is always <= |MaximumAmount - OutstandingAmount|.
252std::int64_t
253availableMPTAmount(SLE const& sleIssuance);
254
255std::int64_t
256availableMPTAmount(ReadView const& view, MPTID const& mptID);
257
266bool
268 std::int64_t sendAmount,
269 std::uint64_t outstandingAmount,
270 std::int64_t maximumAmount,
271 AllowMPTOverflow allowOverflow);
272
280[[nodiscard]] STAmount
281issuerFundsToSelfIssue(ReadView const& view, MPTIssue const& issue);
282
286void
287issuerSelfDebitHookMPT(ApplyView& view, MPTIssue const& issue, std::uint64_t amount);
288
289} // namespace xrpl
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:118
A view into a ledger.
Definition ReadView.h:31
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::int64_t maxMPTAmount(SLE const &sleIssuance)
bool isIndividualFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue)
TER checkCreateMPT(xrpl::ApplyView &view, xrpl::MPTIssue const &mptIssue, xrpl::AccountID const &holder, beast::Journal j)
AllowMPTOverflow
Controls whether accountSend is allowed to overflow OutstandingAmount.
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, MPTIssue const &mptIssue, beast::Journal journal)
TER lockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, STAmount const &saAmount, beast::Journal j)
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 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)
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)
TER createMPToken(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, std::uint32_t const flags)
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:44
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)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
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:634
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.
TER enforceMPTokenAuthorization(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, XRPAmount const &priorBalance, beast::Journal j)
Enforce account has MPToken to match its authorization.
void issuerSelfDebitHookMPT(ApplyView &view, MPTIssue const &issue, std::uint64_t amount)
Facilitate tracking of MPT sold by an issuer owning MPT sell offer.
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
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.
Represents a transfer rate.
Definition Rate.h:20