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 xrpl {
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& offerAmount,
86 TOut const& limit,
87 bool roundUp) const;
88
93 TAmounts<TIn, TOut>
94 limitIn(
95 TAmounts<TIn, TOut> const& offerAmount,
96 TIn const& limit,
97 bool roundUp) const;
98
100 getQualityFunc() const;
101
104 template <typename... Args>
105 static TER
106 send(Args&&... args)
107 {
109 }
110
111 bool
112 isFunded() const
113 {
114 // AMM offer is fully funded by the pool
115 return true;
116 }
117
120 {
121 // AMM doesn't pay transfer fee on Payment tx
122 return {ofrInRate, QUALITY_ONE};
123 }
124
128 bool
129 checkInvariant(TAmounts<TIn, TOut> const& consumed, beast::Journal j) const;
130};
131
132} // namespace xrpl
133
134#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
static std::pair< std::uint32_t, std::uint32_t > adjustRates(std::uint32_t ofrInRate, std::uint32_t ofrOutRate)
Definition AMMOffer.h:119
Quality const quality_
Definition AMMOffer.h:38
TAmounts< TIn, TOut > const amounts_
Definition AMMOffer.h:33
bool fully_consumed() const
Definition AMMOffer.h:74
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
Definition AMMOffer.cpp:45
TAmounts< TIn, TOut > const & amount() const
Definition AMMOffer.cpp:38
std::optional< uint256 > key() const
Definition AMMOffer.h:62
QualityFunction getQualityFunc() const
Definition AMMOffer.cpp:107
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offerAmount, TOut const &limit, bool roundUp) const
Limit out of the provided offer.
Definition AMMOffer.cpp:63
Issue const & issueIn() const
Definition AMMOffer.cpp:24
TAmounts< TIn, TOut > const balances_
Definition AMMOffer.h:35
static TER send(Args &&... args)
Send funds without incurring the transfer fee.
Definition AMMOffer.h:106
AMMLiquidity< TIn, TOut > const & ammLiquidity_
Definition AMMOffer.h:23
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
AccountID const & owner() const
Definition AMMOffer.cpp:31
Quality quality() const noexcept
Definition AMMOffer.h:50
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offerAmount, TIn const &limit, bool roundUp) const
Limit in of the provided offer.
Definition AMMOffer.cpp:88
bool isFunded() const
Definition AMMOffer.h:112
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:2777