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