rippled
Loading...
Searching...
No Matches
AMMContext.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2023 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_PATHS_AMMCONTEXT_H_INCLUDED
21#define RIPPLE_APP_PATHS_AMMCONTEXT_H_INCLUDED
22
23#include <xrpl/protocol/AccountID.h>
24
25#include <cstdint>
26
27namespace ripple {
28
36{
37public:
38 // Restrict number of AMM offers. If this restriction is removed
39 // then need to restrict in some other way because AMM offers are
40 // not counted in the BookStep offer counter.
41 constexpr static std::uint8_t MaxIterations = 30;
42
43private:
44 // Tx account owner is required to get the AMM trading fee in BookStep
46 // true if payment has multiple paths
47 bool multiPath_{false};
48 // Is true if AMM offer is consumed during a payment engine iteration.
49 bool ammUsed_{false};
50 // Counter of payment engine iterations with consumed AMM
52
53public:
58 ~AMMContext() = default;
59 AMMContext(AMMContext const&) = delete;
61 operator=(AMMContext const&) = delete;
62
63 bool
64 multiPath() const
65 {
66 return multiPath_;
67 }
68
69 void
70 setMultiPath(bool fs)
71 {
72 multiPath_ = fs;
73 }
74
75 void
77 {
78 ammUsed_ = true;
79 }
80
81 void
83 {
84 if (ammUsed_)
85 ++ammIters_;
86 ammUsed_ = false;
87 }
88
89 bool
91 {
92 return ammIters_ >= MaxIterations;
93 }
94
96 curIters() const
97 {
98 return ammIters_;
99 }
100
102 account() const
103 {
104 return account_;
105 }
106
110 void
112 {
113 ammUsed_ = false;
114 }
115};
116
117} // namespace ripple
118
119#endif // RIPPLE_APP_PATHS_AMMCONTEXT_H_INCLUDED
Maintains AMM info per overall payment engine execution and individual iteration.
Definition AMMContext.h:36
AccountID account() const
Definition AMMContext.h:102
AMMContext(AMMContext const &)=delete
std::uint16_t ammIters_
Definition AMMContext.h:51
~AMMContext()=default
AMMContext & operator=(AMMContext const &)=delete
std::uint16_t curIters() const
Definition AMMContext.h:96
AMMContext(AccountID const &account, bool multiPath)
Definition AMMContext.h:54
bool multiPath() const
Definition AMMContext.h:64
bool maxItersReached() const
Definition AMMContext.h:90
void setMultiPath(bool fs)
Definition AMMContext.h:70
void clear()
Strand execution may fail.
Definition AMMContext.h:111
static constexpr std::uint8_t MaxIterations
Definition AMMContext.h:41
AccountID account_
Definition AMMContext.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25