xrpld
Loading...
Searching...
No Matches
tx/transactors/dex/AMMWithdraw.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/core/ServiceRegistry.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/helpers/TokenHelpers.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Asset.h>
9#include <xrpl/protocol/STAmount.h>
10#include <xrpl/protocol/STTx.h>
11#include <xrpl/protocol/TER.h>
12#include <xrpl/protocol/XRPAmount.h>
13#include <xrpl/tx/ApplyContext.h>
14#include <xrpl/tx/Transactor.h>
15
16#include <cstdint>
17#include <optional>
18#include <tuple>
19#include <utility>
20
21namespace xrpl {
22
23class Sandbox;
24
62
63enum class WithdrawAll : bool { No = false, Yes };
64
65class AMMWithdraw : public Transactor
66{
67public:
69
70 explicit AMMWithdraw(ApplyContext& ctx) : Transactor(ctx)
71 {
72 }
73
74 static bool
76
77 static std::uint32_t
79
80 static NotTEC
81 preflight(PreflightContext const& ctx);
82
83 static TER
84 preclaim(PreclaimContext const& ctx);
85
86 TER
87 doApply() override;
88
89 void
90 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
91
92 [[nodiscard]] bool
94 STTx const& tx,
95 TER result,
96 XRPAmount fee,
97 ReadView const& view,
98 beast::Journal const& j) override;
99
118 Sandbox& view,
119 SLE const& ammSle,
120 AccountID const account,
121 std::optional<AccountID> const& clawbackIssuer,
122 AccountID const& ammAccount,
123 STAmount const& amountBalance,
124 STAmount const& amount2Balance,
125 STAmount const& lptAMMBalance,
126 STAmount const& lpTokens,
127 STAmount const& lpTokensWithdraw,
128 std::uint16_t tfee,
129 FreezeHandling freezeHandling,
130 AuthHandling authHandling,
131 WithdrawAll withdrawAll,
132 XRPAmount const& priorBalance,
133 beast::Journal const& journal);
134
158 withdraw(
159 Sandbox& view,
160 SLE const& ammSle,
161 AccountID const& ammAccount,
162 std::optional<AccountID> const& clawbackIssuer,
163 AccountID const& account,
164 STAmount const& amountBalance,
165 STAmount const& amountWithdraw,
166 std::optional<STAmount> const& amount2Withdraw,
167 STAmount const& lpTokensAMMBalance,
168 STAmount const& lpTokensWithdraw,
169 std::uint16_t tfee,
170 FreezeHandling freezeHandling,
171 AuthHandling authHandling,
172 WithdrawAll withdrawAll,
173 XRPAmount const& priorBalance,
174 beast::Journal const& journal);
175
178 Sandbox& sb,
179 SLE::pointer const ammSle,
180 STAmount const& lpTokenBalance,
181 Asset const& asset1,
182 Asset const& asset2,
183 beast::Journal const& journal);
184
185private:
190 [[nodiscard]] FreezeHandling
191 issuerFreezeHandling() const;
192
195
210 withdraw(
211 Sandbox& view,
212 SLE const& ammSle,
213 AccountID const& ammAccount,
214 STAmount const& amountBalance,
215 STAmount const& amountWithdraw,
216 std::optional<STAmount> const& amount2Withdraw,
217 STAmount const& lpTokensAMMBalance,
218 STAmount const& lpTokensWithdraw,
219 std::uint16_t tfee);
220
237 Sandbox& view,
238 SLE const& ammSle,
239 AccountID const& ammAccount,
240 STAmount const& amountBalance,
241 STAmount const& amount2Balance,
242 STAmount const& lptAMMBalance,
243 STAmount const& lpTokens,
244 STAmount const& lpTokensWithdraw,
245 std::uint16_t tfee);
246
263 Sandbox& view,
264 SLE const& ammSle,
265 AccountID const& ammAccount,
266 STAmount const& amountBalance,
267 STAmount const& amount2Balance,
268 STAmount const& lptAMMBalance,
269 STAmount const& amount,
270 STAmount const& amount2,
271 std::uint16_t tfee);
272
286 Sandbox& view,
287 SLE const& ammSle,
288 AccountID const& ammAccount,
289 STAmount const& amountBalance,
290 STAmount const& lptAMMBalance,
291 STAmount const& amount,
292 std::uint16_t tfee);
293
308 Sandbox& view,
309 SLE const& ammSle,
310 AccountID const& ammAccount,
311 STAmount const& amountBalance,
312 STAmount const& lptAMMBalance,
313 STAmount const& amount,
314 STAmount const& lpTokensWithdraw,
315 std::uint16_t tfee);
316
331 Sandbox& view,
332 SLE const& ammSle,
333 AccountID const& ammAccount,
334 STAmount const& amountBalance,
335 STAmount const& lptAMMBalance,
336 STAmount const& amount,
337 STAmount const& ePrice,
338 std::uint16_t tfee);
339
343 static WithdrawAll
344 isWithdrawAll(STTx const& tx);
345};
346
347} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
FreezeHandling issuerFreezeHandling() const
Returns IgnoreFreeze when the withdrawer is the issuer of a pool asset (post-fixCleanup3_3_0),...
static std::tuple< TER, STAmount, STAmount, std::optional< STAmount > > equalWithdrawTokens(Sandbox &view, SLE const &ammSle, AccountID const account, std::optional< AccountID > const &clawbackIssuer, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount2Balance, STAmount const &lptAMMBalance, STAmount const &lpTokens, STAmount const &lpTokensWithdraw, std::uint16_t tfee, FreezeHandling freezeHandling, AuthHandling authHandling, 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 std::pair< TER, bool > deleteAMMAccountIfEmpty(Sandbox &sb, SLE::pointer const ammSle, STAmount const &lpTokenBalance, Asset const &asset1, Asset const &asset2, beast::Journal const &journal)
static WithdrawAll isWithdrawAll(STTx const &tx)
Check from the flags if it's withdraw all.
static NotTEC preflight(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static constexpr auto kConsequencesFactory
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
static std::tuple< TER, STAmount, STAmount, std::optional< STAmount > > withdraw(Sandbox &view, SLE const &ammSle, AccountID const &ammAccount, std::optional< AccountID > const &clawbackIssuer, 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, AuthHandling authHandling, WithdrawAll withdrawAll, XRPAmount const &priorBalance, beast::Journal const &journal)
Withdraw requested assets and token from AMM into LP account.
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 ...
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
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 view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
Discardable, editable view to a ledger.
Definition Sandbox.h:18
ApplyView & view()
Definition Transactor.h:175
Transactor(Transactor const &)=delete
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.
WithdrawAll
AMMWithdraw implements AMM withdraw Transactor.
STLedgerEntry SLE
@ Yes
We have consensus along with the network.
@ No
We do not have consensus.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
AuthHandling
Controls the treatment of unauthorized MPT balances.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:572
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:647
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:83
State information when preflighting a tx.
Definition Transactor.h:38