rippled
Loading...
Searching...
No Matches
QualityFunction.h
1#pragma once
2
3#include <xrpl/basics/Number.h>
4#include <xrpl/protocol/AMMCore.h>
5#include <xrpl/protocol/Quality.h>
6
7namespace xrpl {
8
20{
21private:
22 // slope
24 // intercept
26 // seated if QF is for CLOB offer.
28
29public:
30 struct AMMTag
31 {
32 };
33 // AMMOffer for multi-path is like CLOB, i.e. the offer size
34 // changes proportionally to its quality.
36 {
37 };
38 QualityFunction(Quality const& quality, CLOBLikeTag);
39 template <typename TIn, typename TOut>
40 QualityFunction(TAmounts<TIn, TOut> const& amounts, std::uint32_t tfee, AMMTag);
41
44 void
45 combine(QualityFunction const& qf);
46
52 outFromAvgQ(Quality const& quality);
53
56 bool
57 isConst() const
58 {
59 return quality_.has_value();
60 }
61
63 quality() const
64 {
65 return quality_;
66 }
67};
68
69template <typename TIn, typename TOut>
71{
72 if (amounts.in <= beast::zero || amounts.out <= beast::zero)
73 Throw<std::runtime_error>("QualityFunction amounts are 0.");
74 Number const cfee = feeMult(tfee);
75 m_ = -cfee / amounts.in;
76 b_ = amounts.out * cfee / amounts.in;
77}
78
79} // namespace xrpl
Number is a floating point type that can represent a wide range of values.
Definition Number.h:207
Average quality of a path as a function of out: q(out) = m * out + b, where m = -1 / poolGets,...
std::optional< Quality > const & quality() const
QualityFunction(Quality const &quality, CLOBLikeTag)
void combine(QualityFunction const &qf)
Combines QF with the next step QF.
std::optional< Quality > quality_
std::optional< Number > outFromAvgQ(Quality const &quality)
Find output to produce the requested average quality.
bool isConst() const
Return true if the quality function is constant.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Number feeMult(std::uint16_t tfee)
Get fee multiplier (1 - tfee) @tfee trading fee in basis points.
Definition AMMCore.h:84
T has_value(T... args)