rippled
AMMWithdraw.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2023 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_TX_AMMWITHDRAW_H_INCLUDED
21 #define RIPPLE_TX_AMMWITHDRAW_H_INCLUDED
22 
23 #include <ripple/app/tx/impl/Transactor.h>
24 
25 namespace ripple {
26 
27 class Sandbox;
28 
65 class AMMWithdraw : public Transactor
66 {
67 public:
69 
70  explicit AMMWithdraw(ApplyContext& ctx) : Transactor(ctx)
71  {
72  }
73 
74  static NotTEC
75  preflight(PreflightContext const& ctx);
76 
77  static TER
78  preclaim(PreclaimContext const& ctx);
79 
80  TER
81  doApply() override;
82 
83 private:
86 
100  withdraw(
101  Sandbox& view,
102  AccountID const& ammAccount,
103  STAmount const& amountWithdraw,
104  STAmount const& amountBalance,
105  std::optional<STAmount> const& amount2Withdraw,
106  STAmount const& lpTokensAMMBalance,
107  STAmount const& lpTokensWithdraw,
108  std::uint16_t tfee);
109 
125  Sandbox& view,
126  AccountID const& ammAccount,
127  STAmount const& amountBalance,
128  STAmount const& amount2Balance,
129  STAmount const& lptAMMBalance,
130  STAmount const& lpTokens,
131  STAmount const& lpTokensWithdraw,
132  std::uint16_t tfee);
133 
149  Sandbox& view,
150  AccountID const& ammAccount,
151  STAmount const& amountBalance,
152  STAmount const& amount2Balance,
153  STAmount const& lptAMMBalance,
154  STAmount const& amount,
155  STAmount const& amount2,
156  std::uint16_t tfee);
157 
170  Sandbox& view,
171  AccountID const& ammAccount,
172  STAmount const& amountBalance,
173  STAmount const& lptAMMBalance,
174  STAmount const& amount,
175  std::uint16_t tfee);
176 
190  Sandbox& view,
191  AccountID const& ammAccount,
192  STAmount const& amountBalance,
193  STAmount const& lptAMMBalance,
194  STAmount const& amount,
195  STAmount const& lpTokensWithdraw,
196  std::uint16_t tfee);
197 
211  Sandbox& view,
212  AccountID const& ammAccount,
213  STAmount const& amountBalance,
214  STAmount const& lptAMMBalance,
215  STAmount const& amount,
216  STAmount const& ePrice,
217  std::uint16_t tfee);
218 
224  TER
226 };
227 
228 } // namespace ripple
229 
230 #endif // RIPPLE_TX_AMMWITHDRAW_H_INCLUDED
ripple::AMMWithdraw::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: AMMWithdraw.h:68
ripple::Transactor
Definition: Transactor.h:85
std::pair
ripple::AMMWithdraw::doApply
TER doApply() override
Definition: AMMWithdraw.cpp:391
ripple::AMMWithdraw::applyGuts
std::pair< TER, bool > applyGuts(Sandbox &view)
Definition: AMMWithdraw.cpp:295
ripple::ammAccountID
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
Definition: AMMCore.cpp:30
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::AMMWithdraw::singleWithdrawEPrice
std::pair< TER, STAmount > singleWithdrawEPrice(Sandbox &view, 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.
Definition: AMMWithdraw.cpp:773
ripple::Transactor::ConsequencesFactoryType
ConsequencesFactoryType
Definition: Transactor.h:101
ripple::AMMWithdraw::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: AMMWithdraw.cpp:37
ripple::AMMWithdraw::equalWithdrawTokens
std::pair< TER, STAmount > equalWithdrawTokens(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount2Balance, STAmount const &lptAMMBalance, STAmount const &lpTokens, STAmount const &lpTokensWithdraw, std::uint16_t tfee)
Equal-asset withdrawal (LPTokens) of some AMM instance pools shares represented by the number of LPTo...
Definition: AMMWithdraw.cpp:574
ripple::TERSubset
Definition: TER.h:347
ripple::AMMWithdraw::singleWithdraw
std::pair< TER, STAmount > singleWithdraw(Sandbox &view, 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.
Definition: AMMWithdraw.cpp:696
ripple::Sandbox
Discardable, editable view to a ledger.
Definition: Sandbox.h:34
ripple::STAmount
Definition: STAmount.h:45
ripple::AMMWithdraw
AMMWithdraw implements AMM withdraw Transactor.
Definition: AMMWithdraw.h:65
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
std::uint16_t
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:52
ripple::AMMWithdraw::singleWithdrawTokens
std::pair< TER, STAmount > singleWithdrawTokens(Sandbox &view, 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.
Definition: AMMWithdraw.cpp:729
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Transactor::view
ApplyView & view()
Definition: Transactor.h:107
ripple::Transactor::Normal
@ Normal
Definition: Transactor.h:101
ripple::AMMWithdraw::withdraw
std::pair< TER, STAmount > withdraw(Sandbox &view, AccountID const &ammAccount, STAmount const &amountWithdraw, STAmount const &amountBalance, std::optional< STAmount > const &amount2Withdraw, STAmount const &lpTokensAMMBalance, STAmount const &lpTokensWithdraw, std::uint16_t tfee)
Withdraw requested assets and token from AMM into LP account.
Definition: AMMWithdraw.cpp:423
std::optional< STAmount >
ripple::AMMWithdraw::deleteAccount
TER deleteAccount(Sandbox &view, AccountID const &ammAccountID)
Delete AMM account.
Definition: AMMWithdraw.cpp:405
ripple::AMMWithdraw::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: AMMWithdraw.cpp:173
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:31
ripple::AMMWithdraw::equalWithdrawLimit
std::pair< TER, STAmount > equalWithdrawLimit(Sandbox &view, 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 ...
Definition: AMMWithdraw.cpp:654
ripple::AMMWithdraw::AMMWithdraw
AMMWithdraw(ApplyContext &ctx)
Definition: AMMWithdraw.h:70