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
43[[nodiscard]] bool
44isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue);
45
46[[nodiscard]] bool
48 ReadView const& view,
49 AccountID const& account,
50 MPTIssue const& mptIssue,
51 std::uint8_t depth = 0);
52
53[[nodiscard]] bool
55 ReadView const& view,
56 std::initializer_list<AccountID> const& accounts,
57 MPTIssue const& mptIssue,
58 std::uint8_t depth = 0);
59
60//------------------------------------------------------------------------------
61//
62// Transfer rate (MPT-specific)
63//
64//------------------------------------------------------------------------------
65
72[[nodiscard]] Rate
73transferRate(ReadView const& view, MPTID const& issuanceID);
74
75//------------------------------------------------------------------------------
76//
77// Holding checks (MPT-specific)
78//
79//------------------------------------------------------------------------------
80
81[[nodiscard]] TER
82canAddHolding(ReadView const& view, MPTIssue const& mptIssue);
83
84//------------------------------------------------------------------------------
85//
86// Authorization (MPT-specific)
87//
88//------------------------------------------------------------------------------
89
90[[nodiscard]] TER
93 XRPAmount const& priorBalance,
94 MPTID const& mptIssuanceID,
95 AccountID const& account,
96 beast::Journal journal,
97 std::uint32_t flags = 0,
98 std::optional<AccountID> holderID = std::nullopt);
99
108[[nodiscard]] TER
110 ReadView const& view,
111 MPTIssue const& mptIssue,
112 AccountID const& account,
113 AuthType authType = AuthType::Legacy,
114 std::uint8_t depth = 0);
115
123[[nodiscard]] TER
126 MPTID const& mptIssuanceID,
127 AccountID const& account,
128 XRPAmount const& priorBalance,
129 beast::Journal j);
130
145[[nodiscard]] Asset
146assetOfHolding(SLE const& sleShareIssuance, SLE const& sleHolding);
147
172[[nodiscard]] TER
174 ReadView const& view,
175 MPTIssue const& mptIssue,
176 AccountID const& from,
177 AccountID const& to,
179 std::uint8_t depth = 0);
180
194[[nodiscard]] TER
195canTrade(ReadView const& view, Asset const& asset, std::uint8_t depth = 0);
196
200[[nodiscard]] TER
202 ReadView const& v,
203 Asset const& asset,
204 AccountID const& from,
205 AccountID const& to);
206
207//------------------------------------------------------------------------------
208//
209// Empty holding operations (MPT-specific)
210//
211//------------------------------------------------------------------------------
212
213[[nodiscard]] TER
216 AccountID const& accountID,
217 XRPAmount priorBalance,
218 MPTIssue const& mptIssue,
219 beast::Journal journal);
220
221[[nodiscard]] TER
224 AccountID const& accountID,
225 MPTIssue const& mptIssue,
226 beast::Journal journal);
227
228//------------------------------------------------------------------------------
229//
230// Escrow operations (MPT-specific)
231//
232//------------------------------------------------------------------------------
233
234TER
236 ApplyView& view,
237 AccountID const& uGrantorID,
238 STAmount const& saAmount,
239 beast::Journal j);
240
241TER
243 ApplyView& view,
244 AccountID const& uGrantorID,
245 AccountID const& uGranteeID,
246 STAmount const& netAmount,
247 STAmount const& grossAmount,
248 beast::Journal j);
249
250TER
252 ApplyView& view,
253 MPTID const& mptIssuanceID,
254 AccountID const& account,
255 SLE::ref sponsorSle,
256 std::uint32_t const flags);
257
258TER
260 xrpl::ApplyView& view,
261 xrpl::MPTIssue const& mptIssue,
262 xrpl::AccountID const& holder,
263 SLE::ref sponsorSle,
264 std::uint32_t flags,
265 beast::Journal j);
266
267TER
269 xrpl::ApplyView& view,
270 xrpl::MPTIssue const& mptIssue,
271 xrpl::AccountID const& holder,
272 beast::Journal j);
273
274//------------------------------------------------------------------------------
275//
276// MPT Overflow related
277//
278//------------------------------------------------------------------------------
279
280// MaximumAmount doesn't exceed 2**63-1
281std::int64_t
282maxMPTAmount(SLE const& sleIssuance);
283
284// OutstandingAmount may overflow and available amount might be negative.
285// But available amount is always <= |MaximumAmount - OutstandingAmount|.
286std::int64_t
287availableMPTAmount(SLE const& sleIssuance);
288
289std::int64_t
290availableMPTAmount(ReadView const& view, MPTID const& mptID);
291
301bool
303 std::int64_t sendAmount,
304 std::uint64_t outstandingAmount,
305 std::int64_t maximumAmount,
306 AllowMPTOverflow allowOverflow);
307
315[[nodiscard]] STAmount
316issuerFundsToSelfIssue(ReadView const& view, MPTIssue const& issue);
317
322void
323issuerSelfDebitHookMPT(ApplyView& view, MPTIssue const& issue, std::uint64_t amount);
324
325} // namespace xrpl
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:134
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 createMPToken(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, SLE::ref sponsorSle, std::uint32_t const flags)
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)
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:647
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.
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:444
Represents a transfer rate.
Definition Rate.h:21