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#include <limits>
16
17namespace xrpl {
18
34
39
44
49
54
59
66
71
76
81
86
98
116constexpr Bips32 kBipsPerUnity(100 * 100);
117static_assert(kBipsPerUnity == Bips32{10'000});
119static_assert(kTenthBipsPerUnity == TenthBips32(100'000));
120
121constexpr Bips32
123{
124 return Bips32(percentage * kBipsPerUnity.value() / 100);
125}
126constexpr TenthBips32
128{
129 return TenthBips32(percentage * kTenthBipsPerUnity.value() / 100);
130}
131template <typename T, class TBips>
132constexpr T
134{
135 return value * bips.value() / kBipsPerUnity.value();
136}
137template <typename T, class TBips>
138constexpr T
140{
141 return value * bips.value() / kTenthBipsPerUnity.value();
142}
143
144namespace lending {
152static_assert(kMaxManagementFeeRate == TenthBips16(std::uint16_t(10'000u)));
153
160static_assert(kMaxCoverRate == TenthBips32(100'000u));
161
168static_assert(kMaxOverpaymentFee == TenthBips32(100'000u));
169
176static_assert(kMaxInterestRate == TenthBips32(100'000u));
177
185static_assert(kMaxLateInterestRate == TenthBips32(100'000u));
186
194static_assert(kMaxCloseInterestRate == TenthBips32(100'000u));
195
203static_assert(kMaxOverpaymentInterestRate == TenthBips32(100'000u));
204
215static constexpr int kLoanPaymentsPerFeeIncrement = 5;
216
240static constexpr int kLoanMaximumPaymentsPerTransaction = 100;
241} // namespace lending
242
247
252
257
262
267
272
277
282
288
293
297constexpr std::uint64_t kMaxMpTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;
298static_assert(Number::kMaxRep >= kMaxMpTokenAmount);
299
304
309
320
327enum class VaultVersion : uint8_t {
330};
331
340
351
358
370// This is 946708560 seconds which 30 x 365.2425 days (the average length of a Gregorian year).
372
378
383
385
389bool
391
395bool
397
403using TxID = UInt256;
404
410
415
420
425
430
436
441
445constexpr std::size_t kMaxTrim = 25;
446
451
456
461
465constexpr std::size_t kEcScalarLength = kMPT_SCALAR_SIZE;
466
471
475constexpr std::size_t kEcCiphertextComponentLength = kMPT_ELGAMAL_CIPHER_SIZE;
476
480constexpr std::size_t kEcGamalEncryptedTotalLength = kMPT_ELGAMAL_TOTAL_SIZE;
481
485constexpr std::size_t kEcPubKeyLength = kMPT_PUBKEY_SIZE;
486
490constexpr std::size_t kEcPrivKeyLength = kMPT_PRIVKEY_SIZE;
491
495constexpr std::size_t kEcBlindingFactorLength = kMPT_BLINDING_FACTOR_SIZE;
496
500constexpr std::size_t kEcSchnorrProofLength = kMPT_SCHNORR_PROOF_SIZE;
501
505constexpr std::size_t kEcPedersenCommitmentLength = kMPT_PEDERSEN_COMMIT_SIZE;
506
510constexpr std::size_t kEcSingleBulletproofLength = kMPT_SINGLE_BULLETPROOF_SIZE;
511
515constexpr std::size_t kEcDoubleBulletproofLength = kMPT_DOUBLE_BULLETPROOF_SIZE;
516
520constexpr std::size_t kEcSendSigmaProofLength = SECP256K1_COMPACT_STANDARD_PROOF_SIZE;
521
526
530constexpr std::size_t kEcConvertBackSigmaProofLength = SECP256K1_COMPACT_CONVERTBACK_PROOF_SIZE;
531
537
541constexpr std::size_t kEcClawbackProofLength = SECP256K1_COMPACT_CLAWBACK_PROOF_SIZE;
542
547
552
557
562
567
568} // 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)
T max(T... args)
static constexpr int kLoanPaymentsPerFeeIncrement
LoanPay transaction cost will be one base fee per X combined payments.
Definition Protocol.h:215
constexpr TenthBips32 kMaxOverpaymentFee
The maximum overpayment fee on a loan in 1/10 bips.
Definition Protocol.h:167
constexpr TenthBips32 kMaxCoverRate
The maximum coverage rate required of a loan broker in 1/10 bips.
Definition Protocol.h:159
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:193
static constexpr int kLoanMaximumPaymentsPerTransaction
Maximum number of combined payments that a LoanPay transaction will process.
Definition Protocol.h:240
constexpr TenthBips32 kMaxLateInterestRate
The maximum premium added to the interest rate for late payments on a loan in 1/10 bips.
Definition Protocol.h:184
constexpr TenthBips32 kMaxOverpaymentInterestRate
The maximum overpayment interest rate charged on loan overpayments in 1/10 bips.
Definition Protocol.h:202
constexpr TenthBips32 kMaxInterestRate
Annualized interest rate of the Loan in 1/10 bips.
Definition Protocol.h:175
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:345
constexpr std::size_t kEcPubKeyLength
Length of EC public key (compressed).
Definition Protocol.h:485
constexpr std::uint8_t kEcCompressedPrefixEvenY
Compressed EC point prefix for even y-coordinate.
Definition Protocol.h:561
constexpr std::size_t kMaxBatchSigners
The maximum number of batch signers.
Definition Protocol.h:460
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:58
constexpr std::size_t kEcBlindingFactorLength
Length of the EC blinding factor in bytes.
Definition Protocol.h:495
constexpr std::size_t kMaxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
Definition Protocol.h:276
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:382
constexpr std::size_t kMaxPriceScale
The maximum price scaling factor.
Definition Protocol.h:440
constexpr std::size_t kCompressedEcPointLength
Length of EC point (compressed).
Definition Protocol.h:470
constexpr T bipsOfValue(T value, Bips< TBips > bips)
Definition Protocol.h:133
constexpr TenthBips32 percentageToTenthBips(std::uint32_t percentage)
Definition Protocol.h:127
constexpr std::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT transactions.
Definition Protocol.h:551
constexpr std::size_t kMaxBatchTxCount
The maximum number of transactions that can be in a batch.
Definition Protocol.h:455
constexpr T tenthBipsOfValue(T value, TenthBips< TBips > bips)
Definition Protocol.h:139
constexpr std::size_t kMaxTokenUriLength
The maximum length of a URI inside an NFT.
Definition Protocol.h:246
constexpr std::size_t kTxMinSizeBytes
Protocol specific constants.
Definition Protocol.h:33
constexpr std::size_t kPermissionMaxSize
The maximum number of delegate permissions an account can grant.
Definition Protocol.h:450
constexpr std::size_t kEcClawbackProofLength
Length of the ZKProof for ConfidentialMPTClawback.
Definition Protocol.h:541
constexpr std::uint8_t kVaultMaximumIouScale
Maximum scale factor for a Vault.
Definition Protocol.h:319
constexpr std::uint8_t kEcCompressedPrefixOddY
Compressed EC point prefix for odd y-coordinate.
Definition Protocol.h:566
Bips< std::uint32_t > Bips32
Definition Units.h:450
UInt256 TxID
A transaction identifier.
Definition Protocol.h:403
constexpr std::uint32_t kMaxInvestmentPeriod
Definition Protocol.h:371
constexpr std::size_t kEcSchnorrProofLength
Length of Schnorr ZKProof for public key registration (compact form) in bytes.
Definition Protocol.h:500
constexpr std::size_t kMaxLastUpdateTimeDelta
The maximum allowed time difference between lastUpdateTime and the time of the last closed ledger.
Definition Protocol.h:435
constexpr std::size_t kEcGamalEncryptedTotalLength
EC ElGamal ciphertext length: two compressed EC points concatenated.
Definition Protocol.h:480
constexpr std::size_t kMaxDidDataLength
The maximum length of an Attestation inside a DID.
Definition Protocol.h:261
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:65
TenthBips< std::uint16_t > TenthBips16
Definition Units.h:453
VaultKind
Vault kind.
Definition Protocol.h:336
constexpr std::uint16_t kMaxDeletableAmmTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
Definition Protocol.h:409
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:303
constexpr std::size_t kEcConvertBackProofLength
128 bytes compact sigma proof + 688 bytes single bulletproof.
Definition Protocol.h:535
constexpr std::size_t kExpiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Definition Protocol.h:48
constexpr std::size_t kMaxDidUriLength
The maximum length of a URI inside a DID.
Definition Protocol.h:256
constexpr std::size_t kMaxDeletableTokenOfferEntries
The maximum number of offers in an offer directory for NFT to be burnable.
Definition Protocol.h:85
constexpr TenthBips32 kTenthBipsPerUnity(kBipsPerUnity.value() *10)
BaseUInt< 256 > UInt256
Definition base_uint.h:580
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:429
constexpr auto megabytes(T value) noexcept
constexpr std::size_t kEcConvertBackSigmaProofLength
Length of the compact sigma proof component for ConfidentialMPTConvertBack.
Definition Protocol.h:530
constexpr std::uint8_t kVaultDefaultIouScale
Default IOU scale factor for a Vault.
Definition Protocol.h:313
constexpr std::size_t kEcSingleBulletproofLength
Length of single bulletproof (range proof for 1 commitment) in bytes.
Definition Protocol.h:510
VaultVersion
Vault ledger-entry schema versions.
Definition Protocol.h:327
constexpr std::size_t kMaxCredentialsArraySize
The maximum number of credentials can be passed in array.
Definition Protocol.h:281
constexpr std::size_t kEcPedersenCommitmentLength
Length of Pedersen Commitment (compressed).
Definition Protocol.h:505
constexpr std::size_t kEcCiphertextComponentLength
Length of one compressed EC point component in an EC ElGamal ciphertext.
Definition Protocol.h:475
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:377
constexpr std::size_t kMaxOracleProvider
The maximum length of a Provider inside an Oracle.
Definition Protocol.h:419
constexpr std::size_t kMaxDidDocumentLength
The maximum length of a Data element inside a DID.
Definition Protocol.h:251
constexpr std::size_t kMaxMpTokenMetadataLength
The maximum length of MPTokenMetadata.
Definition Protocol.h:292
constexpr std::size_t kEcSendSigmaProofLength
Length of the compact sigma proof component for ConfidentialMPTSend.
Definition Protocol.h:520
constexpr std::size_t kEcDoubleBulletproofLength
Length of double bulletproof (range proof for 2 commitments) in bytes.
Definition Protocol.h:515
constexpr std::size_t kMaxTokenOfferCancelCount
The maximum number of token offers that can be canceled at once.
Definition Protocol.h:80
constexpr std::size_t kMaxOracleUri
The maximum length of a URI inside an Oracle.
Definition Protocol.h:414
constexpr std::size_t kEcEqualityProofLength
Length of compact equality proof.
Definition Protocol.h:546
constexpr std::size_t kMaxTrim
The maximum percentage of outliers to trim.
Definition Protocol.h:445
constexpr std::uint32_t kMaxKeyEpoch
Maximum value a confidential MPT key epoch may reach.
Definition Protocol.h:556
constexpr Bips32 percentageToBips(std::uint32_t percentage)
Definition Protocol.h:122
constexpr std::size_t kEcScalarLength
Length of a secp256k1 scalar in bytes.
Definition Protocol.h:465
constexpr std::uint16_t kMaxTransferFee
The maximum token transfer fee allowed.
Definition Protocol.h:97
constexpr std::size_t kMaxCredentialUriLength
The maximum length of a URI inside a Credential.
Definition Protocol.h:271
constexpr std::size_t kEcSendProofLength
192 bytes compact sigma proof + 754 bytes double bulletproof.
Definition Protocol.h:525
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:70
constexpr std::uint8_t kVaultStrategyFirstComeFirstServe
Vault withdrawal policies.
Definition Protocol.h:308
constexpr std::size_t kMaxPermissionedDomainCredentialsArraySize
The maximum number of credentials can be passed in array for permissioned domain.
Definition Protocol.h:287
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:43
constexpr std::uint32_t kLoanRedemptionBuffer
Minimum gap between a closed-ended loan's final scheduled payment and the vault's RedemptionDate.
Definition Protocol.h:357
constexpr std::size_t kOversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
Definition Protocol.h:53
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
Definition Protocol.h:297
constexpr std::size_t kEcPrivKeyLength
Length of EC private key in bytes.
Definition Protocol.h:490
constexpr std::uint32_t kMinInvestmentPeriod
Bounds on the length of a closed-ended vault's Investment phase (RedemptionDate - SubscriptionDate).
Definition Protocol.h:369
constexpr std::size_t kMaxDeletableDirEntries
The maximum number of owner directory entries for account to be deletable.
Definition Protocol.h:75
constexpr std::size_t kMaxOracleDataSeries
The maximum size of a data series array inside an Oracle.
Definition Protocol.h:424
constexpr std::size_t kMaxDomainLength
The maximum length of a domain.
Definition Protocol.h:266
constexpr std::size_t kTxMaxSizeBytes
Largest legal byte size of a transaction.
Definition Protocol.h:38
constexpr std::uint32_t kFlagLedgerInterval
Definition Protocol.h:384