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 NotTEC
80 preflight(PreflightContext const& ctx);
81
82 static TER
83 preclaim(PreclaimContext const& ctx);
84
85 TER
86 doApply() override;
87
105 Sandbox& view,
106 SLE const& ammSle,
107 AccountID const account,
108 AccountID const& ammAccount,
109 STAmount const& amountBalance,
110 STAmount const& amount2Balance,
111 STAmount const& lptAMMBalance,
112 STAmount const& lpTokens,
113 STAmount const& lpTokensWithdraw,
114 std::uint16_t tfee,
115 FreezeHandling freezeHanding,
116 WithdrawAll withdrawAll,
117 XRPAmount const& priorBalance,
118 beast::Journal const& journal);
119
137 withdraw(
138 Sandbox& view,
139 SLE const& ammSle,
140 AccountID const& ammAccount,
141 AccountID const& account,
142 STAmount const& amountBalance,
143 STAmount const& amountWithdraw,
144 std::optional<STAmount> const& amount2Withdraw,
145 STAmount const& lpTokensAMMBalance,
146 STAmount const& lpTokensWithdraw,
147 std::uint16_t tfee,
148 FreezeHandling freezeHandling,
149 WithdrawAll withdrawAll,
150 XRPAmount const& priorBalance,
151 beast::Journal const& journal);
152
155 Sandbox& sb,
156 std::shared_ptr<SLE> const ammSle,
157 STAmount const& lpTokenBalance,
158 Issue const& issue1,
159 Issue const& issue2,
160 beast::Journal const& journal);
161
162private:
165
179 withdraw(
180 Sandbox& view,
181 SLE const& ammSle,
182 AccountID const& ammAccount,
183 STAmount const& amountBalance,
184 STAmount const& amountWithdraw,
185 std::optional<STAmount> const& amount2Withdraw,
186 STAmount const& lpTokensAMMBalance,
187 STAmount const& lpTokensWithdraw,
188 std::uint16_t tfee);
189
205 Sandbox& view,
206 SLE const& ammSle,
207 AccountID const& ammAccount,
208 STAmount const& amountBalance,
209 STAmount const& amount2Balance,
210 STAmount const& lptAMMBalance,
211 STAmount const& lpTokens,
212 STAmount const& lpTokensWithdraw,
213 std::uint16_t tfee);
214
230 Sandbox& view,
231 SLE const& ammSle,
232 AccountID const& ammAccount,
233 STAmount const& amountBalance,
234 STAmount const& amount2Balance,
235 STAmount const& lptAMMBalance,
236 STAmount const& amount,
237 STAmount const& amount2,
238 std::uint16_t tfee);
239
252 Sandbox& view,
253 SLE const& ammSle,
254 AccountID const& ammAccount,
255 STAmount const& amountBalance,
256 STAmount const& lptAMMBalance,
257 STAmount const& amount,
258 std::uint16_t tfee);
259
273 Sandbox& view,
274 SLE const& ammSle,
275 AccountID const& ammAccount,
276 STAmount const& amountBalance,
277 STAmount const& lptAMMBalance,
278 STAmount const& amount,
279 STAmount const& lpTokensWithdraw,
280 std::uint16_t tfee);
281
295 Sandbox& view,
296 SLE const& ammSle,
297 AccountID const& ammAccount,
298 STAmount const& amountBalance,
299 STAmount const& lptAMMBalance,
300 STAmount const& amount,
301 STAmount const& ePrice,
302 std::uint16_t tfee);
303
305 static WithdrawAll
306 isWithdrawAll(STTx const& tx);
307};
308
309} // namespace ripple
310
311#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.
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
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:161
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