xrpld
Loading...
Searching...
No Matches
tx/transactors/dex/AMMWithdraw.h
1#pragma once
2
3#include <xrpl/ledger/View.h>
4#include <xrpl/ledger/helpers/RippleStateHelpers.h>
5#include <xrpl/tx/Transactor.h>
6
7namespace xrpl {
8
9class Sandbox;
10
47
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
74 void
75 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
76
77 [[nodiscard]] bool
79 STTx const& tx,
80 TER result,
81 XRPAmount fee,
82 ReadView const& view,
83 beast::Journal const& j) override;
84
102 Sandbox& view,
103 SLE const& ammSle,
104 AccountID const account,
105 AccountID const& ammAccount,
106 STAmount const& amountBalance,
107 STAmount const& amount2Balance,
108 STAmount const& lptAMMBalance,
109 STAmount const& lpTokens,
110 STAmount const& lpTokensWithdraw,
111 std::uint16_t tfee,
112 FreezeHandling freezeHandling,
113 AuthHandling authHandling,
114 WithdrawAll withdrawAll,
115 XRPAmount const& priorBalance,
116 beast::Journal const& journal);
117
135 withdraw(
136 Sandbox& view,
137 SLE const& ammSle,
138 AccountID const& ammAccount,
139 AccountID const& account,
140 STAmount const& amountBalance,
141 STAmount const& amountWithdraw,
142 std::optional<STAmount> const& amount2Withdraw,
143 STAmount const& lpTokensAMMBalance,
144 STAmount const& lpTokensWithdraw,
145 std::uint16_t tfee,
146 FreezeHandling freezeHandling,
147 AuthHandling authHandling,
148 WithdrawAll withdrawAll,
149 XRPAmount const& priorBalance,
150 beast::Journal const& journal);
151
154 Sandbox& sb,
155 SLE::pointer const ammSle,
156 STAmount const& lpTokenBalance,
157 Asset const& asset1,
158 Asset const& asset2,
159 beast::Journal const& journal);
160
161private:
164 [[nodiscard]] FreezeHandling
165 issuerFreezeHandling() const;
166
169
183 withdraw(
184 Sandbox& view,
185 SLE const& ammSle,
186 AccountID const& ammAccount,
187 STAmount const& amountBalance,
188 STAmount const& amountWithdraw,
189 std::optional<STAmount> const& amount2Withdraw,
190 STAmount const& lpTokensAMMBalance,
191 STAmount const& lpTokensWithdraw,
192 std::uint16_t tfee);
193
209 Sandbox& view,
210 SLE const& ammSle,
211 AccountID const& ammAccount,
212 STAmount const& amountBalance,
213 STAmount const& amount2Balance,
214 STAmount const& lptAMMBalance,
215 STAmount const& lpTokens,
216 STAmount const& lpTokensWithdraw,
217 std::uint16_t tfee);
218
234 Sandbox& view,
235 SLE const& ammSle,
236 AccountID const& ammAccount,
237 STAmount const& amountBalance,
238 STAmount const& amount2Balance,
239 STAmount const& lptAMMBalance,
240 STAmount const& amount,
241 STAmount const& amount2,
242 std::uint16_t tfee);
243
256 Sandbox& view,
257 SLE const& ammSle,
258 AccountID const& ammAccount,
259 STAmount const& amountBalance,
260 STAmount const& lptAMMBalance,
261 STAmount const& amount,
262 std::uint16_t tfee);
263
277 Sandbox& view,
278 SLE const& ammSle,
279 AccountID const& ammAccount,
280 STAmount const& amountBalance,
281 STAmount const& lptAMMBalance,
282 STAmount const& amount,
283 STAmount const& lpTokensWithdraw,
284 std::uint16_t tfee);
285
299 Sandbox& view,
300 SLE const& ammSle,
301 AccountID const& ammAccount,
302 STAmount const& amountBalance,
303 STAmount const& lptAMMBalance,
304 STAmount const& amount,
305 STAmount const& ePrice,
306 std::uint16_t tfee);
307
309 static WithdrawAll
310 isWithdrawAll(STTx const& tx);
311};
312
313} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
FreezeHandling issuerFreezeHandling() const
Returns IgnoreFreeze when the withdrawer is the issuer of a pool asset (post-fixCleanup3_3_0),...
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
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.
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, 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 > 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.
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 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...
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:31
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
Discardable, editable view to a ledger.
Definition Sandbox.h:15
ApplyView & view()
Definition Transactor.h:136
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
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
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:554
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
TERSubset< CanCvtToTER > TER
Definition TER.h:634
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
State information when preflighting a tx.
Definition Transactor.h:18