xrpld
Loading...
Searching...
No Matches
AMMContext.h
1#pragma once
2
3#include <xrpl/protocol/AccountID.h>
4
5#include <cstdint>
6
7namespace xrpl {
8
17{
18public:
19 // Restrict number of AMM offers. If this restriction is removed
20 // then need to restrict in some other way because AMM offers are
21 // not counted in the BookStep offer counter.
22 static constexpr std::uint8_t kMaxIterations = 30;
23
24private:
25 // Tx account owner is required to get the AMM trading fee in BookStep
27 // true if payment has multiple paths
28 bool multiPath_{false};
29 // Is true if AMM offer is consumed during a payment engine iteration.
30 bool ammUsed_{false};
31 // Counter of payment engine iterations with consumed AMM
33
34public:
39 ~AMMContext() = default;
40 AMMContext(AMMContext const&) = delete;
42 operator=(AMMContext const&) = delete;
43
44 [[nodiscard]] bool
45 multiPath() const
46 {
47 return multiPath_;
48 }
49
50 void
51 setMultiPath(bool fs)
52 {
53 multiPath_ = fs;
54 }
55
56 void
58 {
59 ammUsed_ = true;
60 }
61
62 void
64 {
65 if (ammUsed_)
66 ++ammIters_;
67 ammUsed_ = false;
68 }
69
70 [[nodiscard]] bool
72 {
73 return ammIters_ >= kMaxIterations;
74 }
75
76 [[nodiscard]] std::uint16_t
77 curIters() const
78 {
79 return ammIters_;
80 }
81
82 [[nodiscard]] AccountID
83 account() const
84 {
85 return accountID_;
86 }
87
92 void
94 {
95 ammUsed_ = false;
96 }
97};
98
99} // namespace xrpl
AccountID account() const
Definition AMMContext.h:83
static constexpr std::uint8_t kMaxIterations
Definition AMMContext.h:22
AMMContext(AMMContext const &)=delete
bool maxItersReached() const
Definition AMMContext.h:71
void setMultiPath(bool fs)
Definition AMMContext.h:51
AMMContext & operator=(AMMContext const &)=delete
AMMContext(AccountID const &account, bool multiPath)
Definition AMMContext.h:35
void clear()
Strand execution may fail.
Definition AMMContext.h:93
AccountID accountID_
Definition AMMContext.h:26
std::uint16_t ammIters_
Definition AMMContext.h:32
~AMMContext()=default
bool multiPath() const
Definition AMMContext.h:45
std::uint16_t curIters() const
Definition AMMContext.h:77
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34