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::ConstRef before, SLE::ConstRef 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
123 Sandbox& view,
124 SLE const& ammSle,
125 AccountID const account,
126 std::optional<AccountID> const& clawbackIssuer,
127 AccountID const& ammAccount,
128 STAmount const& amountBalance,
129 STAmount const& amount2Balance,
130 STAmount const& lptAMMBalance,
131 STAmount const& lpTokens,
132 STAmount const& lpTokensWithdraw,
133 std::uint16_t tfee,
134 FreezeHandling freezeHandling,
135 AuthHandling authHandling,
136 ReserveHandling reserveHandling,
137 WithdrawAll withdrawAll,
138 XRPAmount const& priorBalance,
139 beast::Journal const& journal);
140
169 withdraw(
170 Sandbox& view,
171 SLE const& ammSle,
172 AccountID const& ammAccount,
173 std::optional<AccountID> const& clawbackIssuer,
174 AccountID const& account,
175 STAmount const& amountBalance,
176 STAmount const& amountWithdraw,
177 std::optional<STAmount> const& amount2Withdraw,
178 STAmount const& lpTokensAMMBalance,
179 STAmount const& lpTokensWithdraw,
180 std::uint16_t tfee,
181 FreezeHandling freezeHandling,
182 AuthHandling authHandling,
183 ReserveHandling reserveHandling,
184 WithdrawAll withdrawAll,
185 XRPAmount const& priorBalance,
186 beast::Journal const& journal);
187
190 Sandbox& sb,
191 SLE::pointer const ammSle,
192 STAmount const& lpTokenBalance,
193 Asset const& asset1,
194 Asset const& asset2,
195 beast::Journal const& journal);
196
197private:
202 [[nodiscard]] FreezeHandling
203 issuerFreezeHandling() const;
204
207
222 withdraw(
223 Sandbox& view,
224 SLE const& ammSle,
225 AccountID const& ammAccount,
226 STAmount const& amountBalance,
227 STAmount const& amountWithdraw,
228 std::optional<STAmount> const& amount2Withdraw,
229 STAmount const& lpTokensAMMBalance,
230 STAmount const& lpTokensWithdraw,
231 std::uint16_t tfee);
232
249 Sandbox& view,
250 SLE const& ammSle,
251 AccountID const& ammAccount,
252 STAmount const& amountBalance,
253 STAmount const& amount2Balance,
254 STAmount const& lptAMMBalance,
255 STAmount const& lpTokens,
256 STAmount const& lpTokensWithdraw,
257 std::uint16_t tfee);
258
275 Sandbox& view,
276 SLE const& ammSle,
277 AccountID const& ammAccount,
278 STAmount const& amountBalance,
279 STAmount const& amount2Balance,
280 STAmount const& lptAMMBalance,
281 STAmount const& amount,
282 STAmount const& amount2,
283 std::uint16_t tfee);
284
298 Sandbox& view,
299 SLE const& ammSle,
300 AccountID const& ammAccount,
301 STAmount const& amountBalance,
302 STAmount const& lptAMMBalance,
303 STAmount const& amount,
304 std::uint16_t tfee);
305
320 Sandbox& view,
321 SLE const& ammSle,
322 AccountID const& ammAccount,
323 STAmount const& amountBalance,
324 STAmount const& lptAMMBalance,
325 STAmount const& amount,
326 STAmount const& lpTokensWithdraw,
327 std::uint16_t tfee);
328
343 Sandbox& view,
344 SLE const& ammSle,
345 AccountID const& ammAccount,
346 STAmount const& amountBalance,
347 STAmount const& lptAMMBalance,
348 STAmount const& amount,
349 STAmount const& ePrice,
350 std::uint16_t tfee);
351
355 static WithdrawAll
356 isWithdrawAll(STTx const& tx);
357};
358
359} // 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 > > 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, ReserveHandling reserveHandling, WithdrawAll withdrawAll, XRPAmount const &priorBalance, beast::Journal const &journal)
Withdraw requested assets and token from AMM into LP account.
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
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
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)
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, ReserveHandling reserveHandling, 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, 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 & ConstRef
Discardable, editable view to a ledger.
Definition Sandbox.h:18
ApplyView & view()
Definition Transactor.h:184
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.
ReserveHandling
Controls whether the recipient owner-reserve check is enforced when auto-creating a trustline or MPTo...
STLedgerEntry SLE
@ Yes
We have consensus along with the network.
@ No
We do not have consensus.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:614
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:644
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:654
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:92
State information when preflighting a tx.
Definition Transactor.h:39