rippled
Loading...
Searching...
No Matches
AMMContext.h
1#ifndef XRPL_APP_PATHS_AMMCONTEXT_H_INCLUDED
2#define XRPL_APP_PATHS_AMMCONTEXT_H_INCLUDED
3
4#include <xrpl/protocol/AccountID.h>
5
6#include <cstdint>
7
8namespace ripple {
9
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 constexpr static std::uint8_t MaxIterations = 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 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 bool
72 {
73 return ammIters_ >= MaxIterations;
74 }
75
77 curIters() const
78 {
79 return ammIters_;
80 }
81
83 account() const
84 {
85 return account_;
86 }
87
91 void
93 {
94 ammUsed_ = false;
95 }
96};
97
98} // namespace ripple
99
100#endif // XRPL_APP_PATHS_AMMCONTEXT_H_INCLUDED
Maintains AMM info per overall payment engine execution and individual iteration.
Definition AMMContext.h:17
AccountID account() const
Definition AMMContext.h:83
AMMContext(AMMContext const &)=delete
std::uint16_t ammIters_
Definition AMMContext.h:32
~AMMContext()=default
AMMContext & operator=(AMMContext const &)=delete
std::uint16_t curIters() const
Definition AMMContext.h:77
AMMContext(AccountID const &account, bool multiPath)
Definition AMMContext.h:35
bool multiPath() const
Definition AMMContext.h:45
bool maxItersReached() const
Definition AMMContext.h:71
void setMultiPath(bool fs)
Definition AMMContext.h:51
void clear()
Strand execution may fail.
Definition AMMContext.h:92
static constexpr std::uint8_t MaxIterations
Definition AMMContext.h:22
AccountID account_
Definition AMMContext.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6