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