xrpld
Loading...
Searching...
No Matches
Protocol.h
1#pragma once
2
3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/safe_cast.h>
7#include <xrpl/protocol/Units.h>
8
9#include <mpt_protocol.h>
10#include <secp256k1_mpt.h>
11
12#include <chrono>
13#include <cstddef>
14#include <cstdint>
15
16namespace xrpl {
17
33
38
43
48
53
58
65
70
75
80
85
97
115constexpr Bips32 kBipsPerUnity(100 * 100);
116static_assert(kBipsPerUnity == Bips32{10'000});
118static_assert(kTenthBipsPerUnity == TenthBips32(100'000));
119
120constexpr Bips32
122{
123 return Bips32(percentage * kBipsPerUnity.value() / 100);
124}
125constexpr TenthBips32
127{
128 return TenthBips32(percentage * kTenthBipsPerUnity.value() / 100);
129}
130template <typename T, class TBips>
131constexpr T
133{
134 return value * bips.value() / kBipsPerUnity.value();
135}
136template <typename T, class TBips>
137constexpr T
139{
140 return value * bips.value() / kTenthBipsPerUnity.value();
141}
142
143namespace lending {
151static_assert(kMaxManagementFeeRate == TenthBips16(std::uint16_t(10'000u)));
152
159static_assert(kMaxCoverRate == TenthBips32(100'000u));
160
167static_assert(kMaxOverpaymentFee == TenthBips32(100'000u));
168
175static_assert(kMaxInterestRate == TenthBips32(100'000u));
176
184static_assert(kMaxLateInterestRate == TenthBips32(100'000u));
185
193static_assert(kMaxCloseInterestRate == TenthBips32(100'000u));
194
202static_assert(kMaxOverpaymentInterestRate == TenthBips32(100'000u));
203
214static constexpr int kLoanPaymentsPerFeeIncrement = 5;
215
239static constexpr int kLoanMaximumPaymentsPerTransaction = 100;
240} // namespace lending
241
246
251
256
261
266
271
276
281
287
292
296constexpr std::uint64_t kMaxMpTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;
297static_assert(Number::kMaxRep >= kMaxMpTokenAmount);
298
303
308
319
326enum class VaultVersion : uint8_t {
329};
330
339
350
358// This is 946708560 seconds which 30 x 365.2425 days (the average length of a Gregorian year).
360
366
371
373
377bool
379
383bool
385
391using TxID = uint256;
392
398
403
408
413
418
424
429
433constexpr std::size_t kMaxTrim = 25;
434
439
444
449
453constexpr std::size_t kEcScalarLength = kMPT_SCALAR_SIZE;
454
459
463constexpr std::size_t kEcCiphertextComponentLength = kMPT_ELGAMAL_CIPHER_SIZE;
464
468constexpr std::size_t kEcGamalEncryptedTotalLength = kMPT_ELGAMAL_TOTAL_SIZE;
469
473constexpr std::size_t kEcPubKeyLength = kMPT_PUBKEY_SIZE;
474
478constexpr std::size_t kEcPrivKeyLength = kMPT_PRIVKEY_SIZE;
479
483constexpr std::size_t kEcBlindingFactorLength = kMPT_BLINDING_FACTOR_SIZE;
484
488constexpr std::size_t kEcSchnorrProofLength = kMPT_SCHNORR_PROOF_SIZE;
489
493constexpr std::size_t kEcPedersenCommitmentLength = kMPT_PEDERSEN_COMMIT_SIZE;
494
498constexpr std::size_t kEcSingleBulletproofLength = kMPT_SINGLE_BULLETPROOF_SIZE;
499
503constexpr std::size_t kEcDoubleBulletproofLength = kMPT_DOUBLE_BULLETPROOF_SIZE;
504
508constexpr std::size_t kEcSendSigmaProofLength = SECP256K1_COMPACT_STANDARD_PROOF_SIZE;
509
514
518constexpr std::size_t kEcConvertBackSigmaProofLength = SECP256K1_COMPACT_CONVERTBACK_PROOF_SIZE;
519
525
529constexpr std::size_t kEcClawbackProofLength = SECP256K1_COMPACT_CLAWBACK_PROOF_SIZE;
530
535
540
545
546} // namespace xrpl
static constexpr internalrep kMaxRep
Definition Number.h:364
constexpr value_type value() const
Returns the underlying value.
Definition Units.h:338
T count(T... args)
static constexpr int kLoanPaymentsPerFeeIncrement
LoanPay transaction cost will be one base fee per X combined payments.
Definition Protocol.h:214
constexpr TenthBips32 kMaxOverpaymentFee
The maximum overpayment fee on a loan in 1/10 bips.
Definition Protocol.h:166
constexpr TenthBips32 kMaxCoverRate
The maximum coverage rate required of a loan broker in 1/10 bips.
Definition Protocol.h:158
constexpr TenthBips16 kMaxManagementFeeRate(unsafeCast< std::uint16_t >(percentageToTenthBips(10).value()))
The maximum management fee rate allowed by a loan broker in 1/10 bips.
constexpr TenthBips32 kMaxCloseInterestRate
The maximum close interest rate charged for repaying a loan early in 1/10 bips.
Definition Protocol.h:192
static constexpr int kLoanMaximumPaymentsPerTransaction
Maximum number of combined payments that a LoanPay transaction will process.
Definition Protocol.h:239
constexpr TenthBips32 kMaxLateInterestRate
The maximum premium added to the interest rate for late payments on a loan in 1/10 bips.
Definition Protocol.h:183
constexpr TenthBips32 kMaxOverpaymentInterestRate
The maximum overpayment interest rate charged on loan overpayments in 1/10 bips.
Definition Protocol.h:201
constexpr TenthBips32 kMaxInterestRate
Annualized interest rate of the Loan in 1/10 bips.
Definition Protocol.h:174
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
VaultPhase
Lifecycle phase of a vault.
Definition Protocol.h:344
constexpr std::size_t kEcPubKeyLength
Length of EC public key (compressed).
Definition Protocol.h:473
constexpr std::uint8_t kEcCompressedPrefixEvenY
Compressed EC point prefix for even y-coordinate.
Definition Protocol.h:539
constexpr std::size_t kMaxBatchSigners
The maximum number of batch signers.
Definition Protocol.h:448
bool isFlagLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a flag ledgerIndex.
Definition Protocol.cpp:11
constexpr std::size_t kDirNodeMaxEntries
The maximum number of entries per directory page.
Definition Protocol.h:57
constexpr std::size_t kEcBlindingFactorLength
Length of the EC blinding factor in bytes.
Definition Protocol.h:483
constexpr std::size_t kMaxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
Definition Protocol.h:275
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
constexpr std::size_t kMaxPriceScale
The maximum price scaling factor.
Definition Protocol.h:428
constexpr std::size_t kCompressedEcPointLength
Length of EC point (compressed).
Definition Protocol.h:458
constexpr T bipsOfValue(T value, Bips< TBips > bips)
Definition Protocol.h:132
constexpr TenthBips32 percentageToTenthBips(std::uint32_t percentage)
Definition Protocol.h:126
constexpr std::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT transactions.
Definition Protocol.h:534
constexpr std::size_t kMaxBatchTxCount
The maximum number of transactions that can be in a batch.
Definition Protocol.h:443
constexpr T tenthBipsOfValue(T value, TenthBips< TBips > bips)
Definition Protocol.h:138
constexpr std::size_t kMaxTokenUriLength
The maximum length of a URI inside an NFT.
Definition Protocol.h:245
constexpr std::size_t kTxMinSizeBytes
Protocol specific constants.
Definition Protocol.h:32
constexpr std::size_t kPermissionMaxSize
The maximum number of delegate permissions an account can grant.
Definition Protocol.h:438
constexpr std::size_t kEcClawbackProofLength
Length of the ZKProof for ConfidentialMPTClawback.
Definition Protocol.h:529
constexpr std::uint8_t kVaultMaximumIouScale
Maximum scale factor for a Vault.
Definition Protocol.h:318
constexpr std::uint8_t kEcCompressedPrefixOddY
Compressed EC point prefix for odd y-coordinate.
Definition Protocol.h:544
Bips< std::uint32_t > Bips32
Definition Units.h:450
constexpr std::uint32_t kMaxInvestmentPeriod
Definition Protocol.h:359
constexpr std::size_t kEcSchnorrProofLength
Length of Schnorr ZKProof for public key registration (compact form) in bytes.
Definition Protocol.h:488
constexpr std::size_t kMaxLastUpdateTimeDelta
The maximum allowed time difference between lastUpdateTime and the time of the last closed ledger.
Definition Protocol.h:423
constexpr std::size_t kEcGamalEncryptedTotalLength
EC ElGamal ciphertext length: two compressed EC points concatenated.
Definition Protocol.h:468
constexpr std::size_t kMaxDidDataLength
The maximum length of an Attestation inside a DID.
Definition Protocol.h:260
TenthBips< std::uint32_t > TenthBips32
Definition Units.h:454
constexpr std::uint64_t kDirNodeMaxPages
The maximum number of pages allowed in a directory.
Definition Protocol.h:64
TenthBips< std::uint16_t > TenthBips16
Definition Units.h:453
VaultKind
Vault kind.
Definition Protocol.h:335
constexpr std::uint16_t kMaxDeletableAmmTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
Definition Protocol.h:397
constexpr Dest unsafeCast(Src s) noexcept
Definition safe_cast.h:55
constexpr Bips32 kBipsPerUnity(100 *100)
There are 10,000 basis points (bips) in 100%.
constexpr std::size_t kMaxDataPayloadLength
The maximum length of Data payload.
Definition Protocol.h:302
constexpr std::size_t kEcConvertBackProofLength
128 bytes compact sigma proof + 688 bytes single bulletproof.
Definition Protocol.h:523
constexpr std::size_t kExpiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Definition Protocol.h:47
constexpr std::size_t kMaxDidUriLength
The maximum length of a URI inside a DID.
Definition Protocol.h:255
constexpr std::size_t kMaxDeletableTokenOfferEntries
The maximum number of offers in an offer directory for NFT to be burnable.
Definition Protocol.h:84
constexpr TenthBips32 kTenthBipsPerUnity(kBipsPerUnity.value() *10)
bool isVotingLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a voting ledgerIndex.
Definition Protocol.cpp:5
constexpr std::size_t kMaxOracleSymbolClass
The maximum length of a SymbolClass inside an Oracle.
Definition Protocol.h:417
constexpr auto megabytes(T value) noexcept
constexpr std::size_t kEcConvertBackSigmaProofLength
Length of the compact sigma proof component for ConfidentialMPTConvertBack.
Definition Protocol.h:518
constexpr std::uint8_t kVaultDefaultIouScale
Default IOU scale factor for a Vault.
Definition Protocol.h:312
constexpr std::size_t kEcSingleBulletproofLength
Length of single bulletproof (range proof for 1 commitment) in bytes.
Definition Protocol.h:498
VaultVersion
Vault ledger-entry schema versions.
Definition Protocol.h:326
constexpr std::size_t kMaxCredentialsArraySize
The maximum number of credentials can be passed in array.
Definition Protocol.h:280
constexpr std::size_t kEcPedersenCommitmentLength
Length of Pedersen Commitment (compressed).
Definition Protocol.h:493
constexpr std::size_t kEcCiphertextComponentLength
Length of one compressed EC point component in an EC ElGamal ciphertext.
Definition Protocol.h:463
constexpr std::uint8_t kMaxAssetCheckDepth
Maximum recursion depth for vault shares being put as an asset inside another vault; counted from 0.
Definition Protocol.h:365
constexpr std::size_t kMaxOracleProvider
The maximum length of a Provider inside an Oracle.
Definition Protocol.h:407
constexpr std::size_t kMaxDidDocumentLength
The maximum length of a Data element inside a DID.
Definition Protocol.h:250
constexpr std::size_t kMaxMpTokenMetadataLength
The maximum length of MPTokenMetadata.
Definition Protocol.h:291
constexpr std::size_t kEcSendSigmaProofLength
Length of the compact sigma proof component for ConfidentialMPTSend.
Definition Protocol.h:508
constexpr std::size_t kEcDoubleBulletproofLength
Length of double bulletproof (range proof for 2 commitments) in bytes.
Definition Protocol.h:503
constexpr std::size_t kMaxTokenOfferCancelCount
The maximum number of token offers that can be canceled at once.
Definition Protocol.h:79
constexpr std::size_t kMaxOracleUri
The maximum length of a URI inside an Oracle.
Definition Protocol.h:402
constexpr std::size_t kMaxTrim
The maximum percentage of outliers to trim.
Definition Protocol.h:433
constexpr Bips32 percentageToBips(std::uint32_t percentage)
Definition Protocol.h:121
constexpr std::size_t kEcScalarLength
Length of a secp256k1 scalar in bytes.
Definition Protocol.h:453
constexpr std::uint16_t kMaxTransferFee
The maximum token transfer fee allowed.
Definition Protocol.h:96
constexpr std::size_t kMaxCredentialUriLength
The maximum length of a URI inside a Credential.
Definition Protocol.h:270
constexpr std::size_t kEcSendProofLength
192 bytes compact sigma proof + 754 bytes double bulletproof.
Definition Protocol.h:513
unit::ValueUnit< unit::BipsTag, T > Bips
Definition Units.h:448
constexpr std::size_t kDirMaxTokensPerPage
The maximum number of items in an NFT page.
Definition Protocol.h:69
constexpr std::uint8_t kVaultStrategyFirstComeFirstServe
Vault withdrawal policies.
Definition Protocol.h:307
constexpr std::size_t kMaxPermissionedDomainCredentialsArraySize
The maximum number of credentials can be passed in array for permissioned domain.
Definition Protocol.h:286
unit::ValueUnit< unit::TenthBipsTag, T > TenthBips
Definition Units.h:452
constexpr std::size_t kUnfundedOfferRemoveLimit
The maximum number of unfunded offers to delete at once.
Definition Protocol.h:42
constexpr std::size_t kOversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
Definition Protocol.h:52
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
Definition Protocol.h:296
constexpr std::size_t kEcPrivKeyLength
Length of EC private key in bytes.
Definition Protocol.h:478
constexpr std::uint32_t kMinInvestmentPeriod
Bounds on the length of a closed-ended vault's Investment phase (RedemptionDate - SubscriptionDate).
Definition Protocol.h:356
BaseUInt< 256 > uint256
Definition base_uint.h:580
uint256 TxID
A transaction identifier.
Definition Protocol.h:391
constexpr std::size_t kMaxDeletableDirEntries
The maximum number of owner directory entries for account to be deletable.
Definition Protocol.h:74
constexpr std::size_t kMaxOracleDataSeries
The maximum size of a data series array inside an Oracle.
Definition Protocol.h:412
constexpr std::size_t kMaxDomainLength
The maximum length of a domain.
Definition Protocol.h:265
constexpr std::size_t kTxMaxSizeBytes
Largest legal byte size of a transaction.
Definition Protocol.h:37
constexpr std::uint32_t kFlagLedgerInterval
Definition Protocol.h:372