rippled
Loading...
Searching...
No Matches
QualityFunction.h
1#ifndef XRPL_PROTOCOL_QUALITYFUNCTION_H_INCLUDED
2#define XRPL_PROTOCOL_QUALITYFUNCTION_H_INCLUDED
3
4#include <xrpl/basics/Number.h>
5#include <xrpl/protocol/AMMCore.h>
6#include <xrpl/protocol/Quality.h>
7
8namespace ripple {
9
21{
22private:
23 // slope
25 // intercept
27 // seated if QF is for CLOB offer.
29
30public:
31 struct AMMTag
32 {
33 };
34 // AMMOffer for multi-path is like CLOB, i.e. the offer size
35 // changes proportionally to its quality.
37 {
38 };
39 QualityFunction(Quality const& quality, CLOBLikeTag);
40 template <typename TIn, typename TOut>
42 TAmounts<TIn, TOut> const& amounts,
43 std::uint32_t tfee,
44 AMMTag);
45
48 void
49 combine(QualityFunction const& qf);
50
56 outFromAvgQ(Quality const& quality);
57
60 bool
61 isConst() const
62 {
63 return quality_.has_value();
64 }
65
67 quality() const
68 {
69 return quality_;
70 }
71};
72
73template <typename TIn, typename TOut>
75 TAmounts<TIn, TOut> const& amounts,
76 std::uint32_t tfee,
78{
79 if (amounts.in <= beast::zero || amounts.out <= beast::zero)
80 Throw<std::runtime_error>("QualityFunction amounts are 0.");
81 Number const cfee = feeMult(tfee);
82 m_ = -cfee / amounts.in;
83 b_ = amounts.out * cfee / amounts.in;
84}
85
86} // namespace ripple
87
88#endif // XRPL_PROTOCOL_QUALITYFUNCTION_H_INCLUDED
Average quality of a path as a function of out: q(out) = m * out + b, where m = -1 / poolGets,...
QualityFunction(Quality const &quality, CLOBLikeTag)
void combine(QualityFunction const &qf)
Combines QF with the next step QF.
std::optional< Number > outFromAvgQ(Quality const &quality)
Find output to produce the requested average quality.
std::optional< Quality > const & quality() const
bool isConst() const
Return true if the quality function is constant.
std::optional< Quality > quality_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Number feeMult(std::uint16_t tfee)
Get fee multiplier (1 - tfee) @tfee trading fee in basis points.
Definition AMMCore.h:91
T has_value(T... args)