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#include <xrpld/ledger/View.h>
25
26namespace ripple {
27
28class Sandbox;
29
67enum class WithdrawAll : bool { No = false, Yes };
68
69class AMMWithdraw : public Transactor
70{
71public:
73
74 explicit AMMWithdraw(ApplyContext& ctx) : Transactor(ctx)
75 {
76 }
77
78 static NotTEC
79 preflight(PreflightContext const& ctx);
80
81 static TER
82 preclaim(PreclaimContext const& ctx);
83
84 TER
85 doApply() override;
86
104 Sandbox& view,
105 SLE const& ammSle,
106 AccountID const account,
107 AccountID const& ammAccount,
108 STAmount const& amountBalance,
109 STAmount const& amount2Balance,
110 STAmount const& lptAMMBalance,
111 STAmount const& lpTokens,
112 STAmount const& lpTokensWithdraw,
113 std::uint16_t tfee,
114 FreezeHandling freezeHanding,
115 WithdrawAll withdrawAll,
116 XRPAmount const& priorBalance,
117 beast::Journal const& journal);
118
136 withdraw(
137 Sandbox& view,
138 SLE const& ammSle,
139 AccountID const& ammAccount,
140 AccountID const& account,
141 STAmount const& amountBalance,
142 STAmount const& amountWithdraw,
143 std::optional<STAmount> const& amount2Withdraw,
144 STAmount const& lpTokensAMMBalance,
145 STAmount const& lpTokensWithdraw,
146 std::uint16_t tfee,
147 FreezeHandling freezeHandling,
148 WithdrawAll withdrawAll,
149 XRPAmount const& priorBalance,
150 beast::Journal const& journal);
151
154 Sandbox& sb,
155 std::shared_ptr<SLE> const ammSle,
156 STAmount const& lpTokenBalance,
157 Issue const& issue1,
158 Issue const& issue2,
159 beast::Journal const& journal);
160
161private:
164
178 withdraw(
179 Sandbox& view,
180 SLE const& ammSle,
181 AccountID const& ammAccount,
182 STAmount const& amountBalance,
183 STAmount const& amountWithdraw,
184 std::optional<STAmount> const& amount2Withdraw,
185 STAmount const& lpTokensAMMBalance,
186 STAmount const& lpTokensWithdraw,
187 std::uint16_t tfee);
188
204 Sandbox& view,
205 SLE const& ammSle,
206 AccountID const& ammAccount,
207 STAmount const& amountBalance,
208 STAmount const& amount2Balance,
209 STAmount const& lptAMMBalance,
210 STAmount const& lpTokens,
211 STAmount const& lpTokensWithdraw,
212 std::uint16_t tfee);
213
229 Sandbox& view,
230 SLE const& ammSle,
231 AccountID const& ammAccount,
232 STAmount const& amountBalance,
233 STAmount const& amount2Balance,
234 STAmount const& lptAMMBalance,
235 STAmount const& amount,
236 STAmount const& amount2,
237 std::uint16_t tfee);
238
251 Sandbox& view,
252 SLE const& ammSle,
253 AccountID const& ammAccount,
254 STAmount const& amountBalance,
255 STAmount const& lptAMMBalance,
256 STAmount const& amount,
257 std::uint16_t tfee);
258
272 Sandbox& view,
273 SLE const& ammSle,
274 AccountID const& ammAccount,
275 STAmount const& amountBalance,
276 STAmount const& lptAMMBalance,
277 STAmount const& amount,
278 STAmount const& lpTokensWithdraw,
279 std::uint16_t tfee);
280
294 Sandbox& view,
295 SLE const& ammSle,
296 AccountID const& ammAccount,
297 STAmount const& amountBalance,
298 STAmount const& lptAMMBalance,
299 STAmount const& amount,
300 STAmount const& ePrice,
301 std::uint16_t tfee);
302
304 static WithdrawAll
305 isWithdrawAll(STTx const& tx);
306};
307
308} // namespace ripple
309
310#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:74
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:72
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)
Definition: AMMWithdraw.cpp:32
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.
Definition: ApplyContext.h:37
A currency issued by an account.
Definition: Issue.h:36
Discardable, editable view to a ledger.
Definition: Sandbox.h:35
ApplyView & view()
Definition: Transactor.h:159
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
WithdrawAll
AMMWithdraw implements AMM withdraw Transactor.
Definition: AMMWithdraw.h:67
FreezeHandling
Controls the treatment of frozen account balances.
Definition: View.h:78
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:79
State information when preflighting a tx.
Definition: Transactor.h:34