xrpld
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 };
39 template <typename TIn, typename TOut>
41
44 void
45 combine(QualityFunction const& qf);
46
53
56 [[nodiscard]] bool
57 isConst() const
58 {
59 return quality_.has_value();
60 }
61
62 [[nodiscard]] std::optional<Quality> const&
63 quality() const
64 {
65 return quality_;
66 }
67};
68
69template <typename TIn, typename TOut>
71 TAmounts<TIn, TOut> const& amounts,
72 std::uint32_t tfee,
74{
75 if (amounts.in <= beast::kZero || amounts.out <= beast::kZero)
76 Throw<std::runtime_error>("QualityFunction amounts are 0.");
77 Number const cfee = feeMult(tfee);
78 m_ = -cfee / amounts.in;
79 b_ = amounts.out * cfee / amounts.in;
80}
81
82} // namespace xrpl
Number is a floating point type that can represent a wide range of values.
Definition Number.h:306
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.
Represents the logical ratio of output currency to input currency.
Definition Quality.h:91
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:87
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49
Represents a pair of input and output currencies.
Definition Quality.h:26