rippled
Loading...
Searching...
No Matches
AMMOffer.h
1#ifndef XRPL_APP_AMMOFFER_H_INCLUDED
2#define XRPL_APP_AMMOFFER_H_INCLUDED
3
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/View.h>
6#include <xrpl/protocol/Quality.h>
7#include <xrpl/protocol/TER.h>
8
9namespace ripple {
10
11template <typename TIn, typename TOut>
12class AMMLiquidity;
13class QualityFunction;
14
19template <typename TIn, typename TOut>
21{
22private:
24 // Initial offer amounts. It is fibonacci seq generated for multi-path.
25 // If the offer size is set based on the competing CLOB offer then
26 // the AMM offer size is such that if the offer is consumed then
27 // the updated AMM pool SP quality is going to be equal to competing
28 // CLOB offer quality. If there is no competing CLOB offer then
29 // the initial size is set to in=cMax[Native,Value],balances.out.
30 // While this is not a "real" offer it simulates the case of
31 // the swap out of the entire side of the pool, in which case
32 // the swap in amount is infinite.
33 TAmounts<TIn, TOut> const amounts_;
34 // Current pool balances.
35 TAmounts<TIn, TOut> const balances_;
36 // The Spot Price quality if balances != amounts
37 // else the amounts quality
38 Quality const quality_;
39 // AMM offer can be consumed once at a given iteration
41
42public:
44 AMMLiquidity<TIn, TOut> const& ammLiquidity,
45 TAmounts<TIn, TOut> const& amounts,
46 TAmounts<TIn, TOut> const& balances,
47 Quality const& quality);
48
49 Quality
50 quality() const noexcept
51 {
52 return quality_;
53 }
54
55 Issue const&
56 issueIn() const;
57
58 AccountID const&
59 owner() const;
60
62 key() const
63 {
64 return std::nullopt;
65 }
66
67 TAmounts<TIn, TOut> const&
68 amount() const;
69
70 void
71 consume(ApplyView& view, TAmounts<TIn, TOut> const& consumed);
72
73 bool
75 {
76 return consumed_;
77 }
78
83 TAmounts<TIn, TOut>
85 TAmounts<TIn, TOut> const& offrAmt,
86 TOut const& limit,
87 bool roundUp) const;
88
93 TAmounts<TIn, TOut>
94 limitIn(TAmounts<TIn, TOut> const& offrAmt, TIn const& limit, bool roundUp)
95 const;
96
98 getQualityFunc() const;
99
102 template <typename... Args>
103 static TER
104 send(Args&&... args)
105 {
107 }
108
109 bool
110 isFunded() const
111 {
112 // AMM offer is fully funded by the pool
113 return true;
114 }
115
118 {
119 // AMM doesn't pay transfer fee on Payment tx
120 return {ofrInRate, QUALITY_ONE};
121 }
122
126 bool
127 checkInvariant(TAmounts<TIn, TOut> const& consumed, beast::Journal j) const;
128};
129
130} // namespace ripple
131
132#endif // XRPL_APP_AMMOFFER_H_INCLUDED
A generic endpoint for log messages.
Definition Journal.h:41
AMMLiquidity class provides AMM offers to BookStep class.
Represents synthetic AMM offer in BookStep.
Definition AMMOffer.h:21
bool isFunded() const
Definition AMMOffer.h:110
static TER send(Args &&... args)
Send funds without incurring the transfer fee.
Definition AMMOffer.h:104
Quality const quality_
Definition AMMOffer.h:38
AccountID const & owner() const
Definition AMMOffer.cpp:31
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offrAmt, TOut const &limit, bool roundUp) const
Limit out of the provided offer.
Definition AMMOffer.cpp:63
static std::pair< std::uint32_t, std::uint32_t > adjustRates(std::uint32_t ofrInRate, std::uint32_t ofrOutRate)
Definition AMMOffer.h:117
AMMLiquidity< TIn, TOut > const & ammLiquidity_
Definition AMMOffer.h:23
Quality quality() const noexcept
Definition AMMOffer.h:50
bool checkInvariant(TAmounts< TIn, TOut > const &consumed, beast::Journal j) const
Check the new pool product is greater or equal to the old pool product or if decreases then within so...
Definition AMMOffer.cpp:117
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
Definition AMMOffer.cpp:45
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offrAmt, TIn const &limit, bool roundUp) const
Limit in of the provided offer.
Definition AMMOffer.cpp:88
std::optional< uint256 > key() const
Definition AMMOffer.h:62
TAmounts< TIn, TOut > const balances_
Definition AMMOffer.h:35
TAmounts< TIn, TOut > const amounts_
Definition AMMOffer.h:33
bool fully_consumed() const
Definition AMMOffer.h:74
Issue const & issueIn() const
Definition AMMOffer.cpp:24
TAmounts< TIn, TOut > const & amount() const
Definition AMMOffer.cpp:38
QualityFunction getQualityFunc() const
Definition AMMOffer.cpp:107
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
A currency issued by an account.
Definition Issue.h:14
Average quality of a path as a function of out: q(out) = m * out + b, where m = -1 / poolGets,...
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
Definition View.cpp:2172