rippled
Loading...
Searching...
No Matches
AMMLiquidity.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2023 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_TX_AMMLIQUIDITY_H_INCLUDED
21#define RIPPLE_APP_TX_AMMLIQUIDITY_H_INCLUDED
22
23#include <xrpld/app/misc/AMMHelpers.h>
24#include <xrpld/app/misc/AMMUtils.h>
25#include <xrpld/app/paths/AMMContext.h>
26#include <xrpld/ledger/ReadView.h>
27#include <xrpld/ledger/View.h>
28
29#include <xrpl/basics/Log.h>
30#include <xrpl/protocol/Quality.h>
31
32namespace ripple {
33
34template <typename TIn, typename TOut>
35class AMMOffer;
36
51template <typename TIn, typename TOut>
53{
54private:
55 inline static Number const InitialFibSeqPct = Number(5) / 20000;
61 // Initial AMM pool balances
62 TAmounts<TIn, TOut> const initialBalances_;
64
65public:
67 ReadView const& view,
68 AccountID const& ammAccountID,
70 Issue const& in,
71 Issue const& out,
72 AMMContext& ammContext,
74 ~AMMLiquidity() = default;
75 AMMLiquidity(AMMLiquidity const&) = delete;
77 operator=(AMMLiquidity const&) = delete;
78
85 getOffer(ReadView const& view, std::optional<Quality> const& clobQuality)
86 const;
87
88 AccountID const&
89 ammAccount() const
90 {
91 return ammAccountID_;
92 }
93
94 bool
95 multiPath() const
96 {
97 return ammContext_.multiPath();
98 }
99
102 {
103 return tradingFee_;
104 }
105
107 context() const
108 {
109 return ammContext_;
110 }
111
112 Issue const&
113 issueIn() const
114 {
115 return issueIn_;
116 }
117
118 Issue const&
119 issueOut() const
120 {
121 return issueOut_;
122 }
123
124private:
127 TAmounts<TIn, TOut>
128 fetchBalances(ReadView const& view) const;
129
137 TAmounts<TIn, TOut>
138 generateFibSeqOffer(TAmounts<TIn, TOut> const& balances) const;
139
150 maxOffer(TAmounts<TIn, TOut> const& balances, Rules const& rules) const;
151};
152
153} // namespace ripple
154
155#endif // RIPPLE_APP_TX_AMMLIQUIDITY_H_INCLUDED
A generic endpoint for log messages.
Definition: Journal.h:60
Maintains AMM info per overall payment engine execution and individual iteration.
Definition: AMMContext.h:36
bool multiPath() const
Definition: AMMContext.h:64
AMMLiquidity class provides AMM offers to BookStep class.
Definition: AMMLiquidity.h:53
AMMLiquidity(AMMLiquidity const &)=delete
AMMContext & context() const
Definition: AMMLiquidity.h:107
Issue const & issueOut() const
Definition: AMMLiquidity.h:119
static Number const InitialFibSeqPct
Definition: AMMLiquidity.h:55
AccountID const ammAccountID_
Definition: AMMLiquidity.h:57
std::uint32_t tradingFee() const
Definition: AMMLiquidity.h:101
bool multiPath() const
Definition: AMMLiquidity.h:95
Issue const & issueIn() const
Definition: AMMLiquidity.h:113
Issue const issueIn_
Definition: AMMLiquidity.h:59
std::optional< AMMOffer< TIn, TOut > > getOffer(ReadView const &view, std::optional< Quality > const &clobQuality) const
Generate AMM offer.
beast::Journal const j_
Definition: AMMLiquidity.h:63
TAmounts< TIn, TOut > fetchBalances(ReadView const &view) const
Fetches current AMM balances.
AccountID const & ammAccount() const
Definition: AMMLiquidity.h:89
AMMLiquidity & operator=(AMMLiquidity const &)=delete
AMMContext & ammContext_
Definition: AMMLiquidity.h:56
std::optional< AMMOffer< TIn, TOut > > maxOffer(TAmounts< TIn, TOut > const &balances, Rules const &rules) const
Generate max offer.
TAmounts< TIn, TOut > const initialBalances_
Definition: AMMLiquidity.h:62
Issue const issueOut_
Definition: AMMLiquidity.h:60
std::uint32_t const tradingFee_
Definition: AMMLiquidity.h:58
TAmounts< TIn, TOut > generateFibSeqOffer(TAmounts< TIn, TOut > const &balances) const
Generate AMM offers with the offer size based on Fibonacci sequence.
A currency issued by an account.
Definition: Issue.h:36
A view into a ledger.
Definition: ReadView.h:52
Rules controlling protocol behavior.
Definition: Rules.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26