rippled
Loading...
Searching...
No Matches
AMMWithdraw.h
1#pragma once
2
3#include <xrpld/app/tx/detail/Transactor.h>
4
5#include <xrpl/ledger/View.h>
6
7namespace xrpl {
8
9class Sandbox;
10
48enum class WithdrawAll : bool { No = false, Yes };
49
50class AMMWithdraw : public Transactor
51{
52public:
54
55 explicit AMMWithdraw(ApplyContext& ctx) : Transactor(ctx)
56 {
57 }
58
59 static bool
61
62 static std::uint32_t
64
65 static NotTEC
66 preflight(PreflightContext const& ctx);
67
68 static TER
69 preclaim(PreclaimContext const& ctx);
70
71 TER
72 doApply() override;
73
92 SLE const& ammSle,
93 AccountID const account,
94 AccountID const& ammAccount,
95 STAmount const& amountBalance,
96 STAmount const& amount2Balance,
97 STAmount const& lptAMMBalance,
98 STAmount const& lpTokens,
99 STAmount const& lpTokensWithdraw,
100 std::uint16_t tfee,
101 FreezeHandling freezeHanding,
102 WithdrawAll withdrawAll,
103 XRPAmount const& priorBalance,
104 beast::Journal const& journal);
105
123 withdraw(
124 Sandbox& view,
125 SLE const& ammSle,
126 AccountID const& ammAccount,
127 AccountID const& account,
128 STAmount const& amountBalance,
129 STAmount const& amountWithdraw,
130 std::optional<STAmount> const& amount2Withdraw,
131 STAmount const& lpTokensAMMBalance,
132 STAmount const& lpTokensWithdraw,
133 std::uint16_t tfee,
134 FreezeHandling freezeHandling,
135 WithdrawAll withdrawAll,
136 XRPAmount const& priorBalance,
137 beast::Journal const& journal);
138
141 Sandbox& sb,
142 std::shared_ptr<SLE> const ammSle,
143 STAmount const& lpTokenBalance,
144 Issue const& issue1,
145 Issue const& issue2,
146 beast::Journal const& journal);
147
148private:
151
165 withdraw(
166 Sandbox& view,
167 SLE const& ammSle,
168 AccountID const& ammAccount,
169 STAmount const& amountBalance,
170 STAmount const& amountWithdraw,
171 std::optional<STAmount> const& amount2Withdraw,
172 STAmount const& lpTokensAMMBalance,
173 STAmount const& lpTokensWithdraw,
174 std::uint16_t tfee);
175
191 Sandbox& view,
192 SLE const& ammSle,
193 AccountID const& ammAccount,
194 STAmount const& amountBalance,
195 STAmount const& amount2Balance,
196 STAmount const& lptAMMBalance,
197 STAmount const& lpTokens,
198 STAmount const& lpTokensWithdraw,
199 std::uint16_t tfee);
200
216 Sandbox& view,
217 SLE const& ammSle,
218 AccountID const& ammAccount,
219 STAmount const& amountBalance,
220 STAmount const& amount2Balance,
221 STAmount const& lptAMMBalance,
222 STAmount const& amount,
223 STAmount const& amount2,
224 std::uint16_t tfee);
225
238 Sandbox& view,
239 SLE const& ammSle,
240 AccountID const& ammAccount,
241 STAmount const& amountBalance,
242 STAmount const& lptAMMBalance,
243 STAmount const& amount,
244 std::uint16_t tfee);
245
259 Sandbox& view,
260 SLE const& ammSle,
261 AccountID const& ammAccount,
262 STAmount const& amountBalance,
263 STAmount const& lptAMMBalance,
264 STAmount const& amount,
265 STAmount const& lpTokensWithdraw,
266 std::uint16_t tfee);
267
281 Sandbox& view,
282 SLE const& ammSle,
283 AccountID const& ammAccount,
284 STAmount const& amountBalance,
285 STAmount const& lptAMMBalance,
286 STAmount const& amount,
287 STAmount const& ePrice,
288 std::uint16_t tfee);
289
291 static WithdrawAll
292 isWithdrawAll(STTx const& tx);
293};
294
295} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
static WithdrawAll isWithdrawAll(STTx const &tx)
Check from the flags if it's withdraw all.
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...
static NotTEC preflight(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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
AMMWithdraw(ApplyContext &ctx)
Definition AMMWithdraw.h:55
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition AMMWithdraw.h:53
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::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)
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.
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 bool checkExtraFeatures(PreflightContext const &ctx)
std::pair< TER, bool > applyGuts(Sandbox &view)
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.
State information when applying a tx.
A currency issued by an account.
Definition Issue.h:13
Discardable, editable view to a ledger.
Definition Sandbox.h:15
ApplyView & view()
Definition Transactor.h:128
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
FreezeHandling
Controls the treatment of frozen account balances.
Definition View.h:58
WithdrawAll
AMMWithdraw implements AMM withdraw Transactor.
Definition AMMWithdraw.h:48
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:53
State information when preflighting a tx.
Definition Transactor.h:15