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
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 static constexpr std::uint8_t kMaxIterations = 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:
38 ~AMMContext() = default;
39 AMMContext(AMMContext const&) = delete;
41 operator=(AMMContext const&) = delete;
42
43 [[nodiscard]] bool
44 multiPath() const
45 {
46 return multiPath_;
47 }
48
49 void
50 setMultiPath(bool fs)
51 {
52 multiPath_ = fs;
53 }
54
55 void
57 {
58 ammUsed_ = true;
59 }
60
61 void
63 {
64 if (ammUsed_)
65 ++ammIters_;
66 ammUsed_ = false;
67 }
68
69 [[nodiscard]] bool
71 {
72 return ammIters_ >= kMaxIterations;
73 }
74
75 [[nodiscard]] std::uint16_t
76 curIters() const
77 {
78 return ammIters_;
79 }
80
81 [[nodiscard]] AccountID
82 account() const
83 {
84 return accountID_;
85 }
86
90 void
92 {
93 ammUsed_ = false;
94 }
95};
96
97} // namespace xrpl
AccountID account() const
Definition AMMContext.h:82
static constexpr std::uint8_t kMaxIterations
Definition AMMContext.h:21
AMMContext(AMMContext const &)=delete
bool maxItersReached() const
Definition AMMContext.h:70
void setMultiPath(bool fs)
Definition AMMContext.h:50
AMMContext & operator=(AMMContext const &)=delete
AMMContext(AccountID const &account, bool multiPath)
Definition AMMContext.h:34
void clear()
Strand execution may fail.
Definition AMMContext.h:91
AccountID accountID_
Definition AMMContext.h:25
std::uint16_t ammIters_
Definition AMMContext.h:31
~AMMContext()=default
bool multiPath() const
Definition AMMContext.h:44
std::uint16_t curIters() const
Definition AMMContext.h:76
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:28