rippled
Loading...
Searching...
No Matches
AMMWithdraw.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_TX_AMMWITHDRAW_H_INCLUDED
21#define RIPPLE_TX_AMMWITHDRAW_H_INCLUDED
22
23#include <xrpld/app/tx/detail/Transactor.h>
24
25#include <xrpl/ledger/View.h>
26
27namespace ripple {
28
29class Sandbox;
30
68enum class WithdrawAll : bool { No = false, Yes };
69
70class AMMWithdraw : public Transactor
71{
72public:
74
75 explicit AMMWithdraw(ApplyContext& ctx) : Transactor(ctx)
76 {
77 }
78
79 static bool
81
82 static std::uint32_t
84
85 static NotTEC
86 preflight(PreflightContext const& ctx);
87
88 static TER
89 preclaim(PreclaimContext const& ctx);
90
91 TER
92 doApply() override;
93
111 Sandbox& view,
112 SLE const& ammSle,
113 AccountID const account,
114 AccountID const& ammAccount,
115 STAmount const& amountBalance,
116 STAmount const& amount2Balance,
117 STAmount const& lptAMMBalance,
118 STAmount const& lpTokens,
119 STAmount const& lpTokensWithdraw,
120 std::uint16_t tfee,
121 FreezeHandling freezeHanding,
122 WithdrawAll withdrawAll,
123 XRPAmount const& priorBalance,
124 beast::Journal const& journal);
125
143 withdraw(
144 Sandbox& view,
145 SLE const& ammSle,
146 AccountID const& ammAccount,
147 AccountID const& account,
148 STAmount const& amountBalance,
149 STAmount const& amountWithdraw,
150 std::optional<STAmount> const& amount2Withdraw,
151 STAmount const& lpTokensAMMBalance,
152 STAmount const& lpTokensWithdraw,
153 std::uint16_t tfee,
154 FreezeHandling freezeHandling,
155 WithdrawAll withdrawAll,
156 XRPAmount const& priorBalance,
157 beast::Journal const& journal);
158
161 Sandbox& sb,
162 std::shared_ptr<SLE> const ammSle,
163 STAmount const& lpTokenBalance,
164 Issue const& issue1,
165 Issue const& issue2,
166 beast::Journal const& journal);
167
168private:
171
185 withdraw(
186 Sandbox& view,
187 SLE const& ammSle,
188 AccountID const& ammAccount,
189 STAmount const& amountBalance,
190 STAmount const& amountWithdraw,
191 std::optional<STAmount> const& amount2Withdraw,
192 STAmount const& lpTokensAMMBalance,
193 STAmount const& lpTokensWithdraw,
194 std::uint16_t tfee);
195
211 Sandbox& view,
212 SLE const& ammSle,
213 AccountID const& ammAccount,
214 STAmount const& amountBalance,
215 STAmount const& amount2Balance,
216 STAmount const& lptAMMBalance,
217 STAmount const& lpTokens,
218 STAmount const& lpTokensWithdraw,
219 std::uint16_t tfee);
220
236 Sandbox& view,
237 SLE const& ammSle,
238 AccountID const& ammAccount,
239 STAmount const& amountBalance,
240 STAmount const& amount2Balance,
241 STAmount const& lptAMMBalance,
242 STAmount const& amount,
243 STAmount const& amount2,
244 std::uint16_t tfee);
245
258 Sandbox& view,
259 SLE const& ammSle,
260 AccountID const& ammAccount,
261 STAmount const& amountBalance,
262 STAmount const& lptAMMBalance,
263 STAmount const& amount,
264 std::uint16_t tfee);
265
279 Sandbox& view,
280 SLE const& ammSle,
281 AccountID const& ammAccount,
282 STAmount const& amountBalance,
283 STAmount const& lptAMMBalance,
284 STAmount const& amount,
285 STAmount const& lpTokensWithdraw,
286 std::uint16_t tfee);
287
301 Sandbox& view,
302 SLE const& ammSle,
303 AccountID const& ammAccount,
304 STAmount const& amountBalance,
305 STAmount const& lptAMMBalance,
306 STAmount const& amount,
307 STAmount const& ePrice,
308 std::uint16_t tfee);
309
311 static WithdrawAll
312 isWithdrawAll(STTx const& tx);
313};
314
315} // namespace ripple
316
317#endif // RIPPLE_TX_AMMWITHDRAW_H_INCLUDED
A generic endpoint for log messages.
Definition Journal.h:60
static WithdrawAll isWithdrawAll(STTx const &tx)
Check from the flags if it's withdraw all.
static bool checkExtraFeatures(PreflightContext const &ctx)
AMMWithdraw(ApplyContext &ctx)
Definition AMMWithdraw.h:75
std::pair< TER, STAmount > singleWithdrawEPrice(Sandbox &view, SLE const &ammSle, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &lptAMMBalance, STAmount const &amount, STAmount const &ePrice, std::uint16_t tfee)
Withdraw single asset (Asset1Out, EPrice) with two constraints.
std::pair< TER, STAmount > equalWithdrawLimit(Sandbox &view, SLE const &ammSle, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount2Balance, STAmount const &lptAMMBalance, STAmount const &amount, STAmount const &amount2, std::uint16_t tfee)
Withdraw both assets (Asset1Out, Asset2Out) with the constraints on the maximum amount of each asset ...
static std::tuple< TER, STAmount, STAmount, std::optional< STAmount > > equalWithdrawTokens(Sandbox &view, SLE const &ammSle, AccountID const account, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount2Balance, STAmount const &lptAMMBalance, STAmount const &lpTokens, STAmount const &lpTokensWithdraw, std::uint16_t tfee, FreezeHandling freezeHanding, WithdrawAll withdrawAll, XRPAmount const &priorBalance, beast::Journal const &journal)
Equal-asset withdrawal (LPTokens) of some AMM instance pools shares represented by the number of LPTo...
std::pair< TER, bool > applyGuts(Sandbox &view)
std::pair< TER, STAmount > singleWithdraw(Sandbox &view, SLE const &ammSle, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &lptAMMBalance, STAmount const &amount, std::uint16_t tfee)
Single asset withdrawal (Asset1Out) equivalent to the amount specified in Asset1Out.
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition AMMWithdraw.h:73
static std::pair< TER, bool > deleteAMMAccountIfEmpty(Sandbox &sb, std::shared_ptr< SLE > const ammSle, STAmount const &lpTokenBalance, Issue const &issue1, Issue const &issue2, beast::Journal const &journal)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static std::tuple< TER, STAmount, STAmount, std::optional< STAmount > > withdraw(Sandbox &view, SLE const &ammSle, AccountID const &ammAccount, AccountID const &account, STAmount const &amountBalance, STAmount const &amountWithdraw, std::optional< STAmount > const &amount2Withdraw, STAmount const &lpTokensAMMBalance, STAmount const &lpTokensWithdraw, std::uint16_t tfee, FreezeHandling freezeHandling, WithdrawAll withdrawAll, XRPAmount const &priorBalance, beast::Journal const &journal)
Withdraw requested assets and token from AMM into LP account.
TER doApply() override
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
std::pair< TER, STAmount > singleWithdrawTokens(Sandbox &view, SLE const &ammSle, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &lptAMMBalance, STAmount const &amount, STAmount const &lpTokensWithdraw, std::uint16_t tfee)
Single asset withdrawal (Asset1Out, LPTokens) proportional to the share specified by tokens.
State information when applying a tx.
A currency issued by an account.
Definition Issue.h:33
Discardable, editable view to a ledger.
Definition Sandbox.h:35
ApplyView & view()
Definition Transactor.h:163
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
WithdrawAll
AMMWithdraw implements AMM withdraw Transactor.
Definition AMMWithdraw.h:68
FreezeHandling
Controls the treatment of frozen account balances.
Definition View.h:77
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
State information when preflighting a tx.
Definition Transactor.h:35