rippled
AMMDeposit.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_AMMDEPOSIT_H_INCLUDED
21 #define RIPPLE_TX_AMMDEPOSIT_H_INCLUDED
22 
23 #include <ripple/app/tx/impl/Transactor.h>
24 
25 namespace ripple {
26 
27 class Sandbox;
28 
62 class AMMDeposit : public Transactor
63 {
64 public:
66 
67  explicit AMMDeposit(ApplyContext& ctx) : Transactor(ctx)
68  {
69  }
70 
71  static NotTEC
72  preflight(PreflightContext const& ctx);
73 
74  static TER
75  preclaim(PreclaimContext const& ctx);
76 
77  TER
78  doApply() override;
79 
80 private:
83 
100  deposit(
101  Sandbox& view,
102  AccountID const& ammAccount,
103  STAmount const& amountBalance,
104  STAmount const& amountDeposit,
105  std::optional<STAmount> const& amount2Deposit,
106  STAmount const& lptAMMBalance,
107  STAmount const& lpTokensDeposit,
108  std::optional<STAmount> const& depositMin,
109  std::optional<STAmount> const& deposit2Min,
110  std::optional<STAmount> const& lpTokensDepositMin,
111  std::uint16_t tfee);
112 
128  Sandbox& view,
129  AccountID const& ammAccount,
130  STAmount const& amountBalance,
131  STAmount const& amount2Balance,
132  STAmount const& lptAMMBalance,
133  STAmount const& lpTokensDeposit,
134  std::optional<STAmount> const& depositMin,
135  std::optional<STAmount> const& deposit2Min,
136  std::uint16_t tfee);
137 
154  Sandbox& view,
155  AccountID const& ammAccount,
156  STAmount const& amountBalance,
157  STAmount const& amount2Balance,
158  STAmount const& lptAMMBalance,
159  STAmount const& amount,
160  STAmount const& amount2,
161  std::optional<STAmount> const& lpTokensDepositMin,
162  std::uint16_t tfee);
163 
177  Sandbox& view,
178  AccountID const& ammAccount,
179  STAmount const& amountBalance,
180  STAmount const& lptAMMBalance,
181  STAmount const& amount,
182  std::optional<STAmount> const& lpTokensDepositMin,
183  std::uint16_t tfee);
184 
198  Sandbox& view,
199  AccountID const& ammAccount,
200  STAmount const& amountBalance,
201  STAmount const& amount,
202  STAmount const& lptAMMBalance,
203  STAmount const& lpTokensDeposit,
204  std::uint16_t tfee);
205 
219  Sandbox& view,
220  AccountID const& ammAccount,
221  STAmount const& amountBalance,
222  STAmount const& amount,
223  STAmount const& lptAMMBalance,
224  STAmount const& ePrice,
225  std::uint16_t tfee);
226 
237  Sandbox& view,
238  AccountID const& ammAccount,
239  STAmount const& amount,
240  STAmount const& amount2,
241  Issue const& lptIssue,
242  std::uint16_t tfee);
243 };
244 
245 } // namespace ripple
246 
247 #endif // RIPPLE_TX_AMMDEPOSIT_H_INCLUDED
ripple::AMMDeposit
AMMDeposit implements AMM deposit Transactor.
Definition: AMMDeposit.h:62
ripple::AMMDeposit::singleDepositTokens
std::pair< TER, STAmount > singleDepositTokens(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount, STAmount const &lptAMMBalance, STAmount const &lpTokensDeposit, std::uint16_t tfee)
Single asset deposit (Asset1In, LPTokens) by the tokens.
Definition: AMMDeposit.cpp:752
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
ripple::AMMDeposit::doApply
TER doApply() override
Definition: AMMDeposit.cpp:445
ripple::Transactor
Definition: Transactor.h:85
std::pair
ripple::AMMDeposit::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: AMMDeposit.h:65
ripple::AMMDeposit::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: AMMDeposit.cpp:169
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::Transactor::ConsequencesFactoryType
ConsequencesFactoryType
Definition: Transactor.h:101
ripple::TERSubset
Definition: TER.h:352
ripple::Sandbox
Discardable, editable view to a ledger.
Definition: Sandbox.h:34
ripple::AMMDeposit::AMMDeposit
AMMDeposit(ApplyContext &ctx)
Definition: AMMDeposit.h:67
ripple::STAmount
Definition: STAmount.h:45
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
std::uint16_t
ripple::AMMDeposit::singleDepositEPrice
std::pair< TER, STAmount > singleDepositEPrice(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount, STAmount const &lptAMMBalance, STAmount const &ePrice, std::uint16_t tfee)
Single asset deposit (Asset1In, EPrice) with two constraints.
Definition: AMMDeposit.cpp:805
ripple::AMMDeposit::equalDepositLimit
std::pair< TER, STAmount > equalDepositLimit(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount2Balance, STAmount const &lptAMMBalance, STAmount const &amount, STAmount const &amount2, std::optional< STAmount > const &lpTokensDepositMin, std::uint16_t tfee)
Equal asset deposit (Asset1In, Asset2In) with the constraint on the maximum amount of both assets tha...
Definition: AMMDeposit.cpp:659
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:52
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::AMMDeposit::applyGuts
std::pair< TER, bool > applyGuts(Sandbox &view)
Definition: AMMDeposit.cpp:334
ripple::AMMDeposit::equalDepositTokens
std::pair< TER, STAmount > equalDepositTokens(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amount2Balance, STAmount const &lptAMMBalance, STAmount const &lpTokensDeposit, std::optional< STAmount > const &depositMin, std::optional< STAmount > const &deposit2Min, std::uint16_t tfee)
Equal asset deposit (LPTokens) for the specified share of the AMM instance pools.
Definition: AMMDeposit.cpp:594
ripple::Transactor::view
ApplyView & view()
Definition: Transactor.h:107
ripple::Transactor::Normal
@ Normal
Definition: Transactor.h:101
ripple::AMMDeposit::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: AMMDeposit.cpp:36
ripple::AMMDeposit::singleDeposit
std::pair< TER, STAmount > singleDeposit(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &lptAMMBalance, STAmount const &amount, std::optional< STAmount > const &lpTokensDepositMin, std::uint16_t tfee)
Single asset deposit (Asset1In) by the amount.
Definition: AMMDeposit.cpp:718
std::optional< STAmount >
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:31
ripple::AMMDeposit::deposit
std::pair< TER, STAmount > deposit(Sandbox &view, AccountID const &ammAccount, STAmount const &amountBalance, STAmount const &amountDeposit, std::optional< STAmount > const &amount2Deposit, STAmount const &lptAMMBalance, STAmount const &lpTokensDeposit, std::optional< STAmount > const &depositMin, std::optional< STAmount > const &deposit2Min, std::optional< STAmount > const &lpTokensDepositMin, std::uint16_t tfee)
Deposit requested assets and token amount into LP account.
Definition: AMMDeposit.cpp:459
ripple::AMMDeposit::equalDepositInEmptyState
std::pair< TER, STAmount > equalDepositInEmptyState(Sandbox &view, AccountID const &ammAccount, STAmount const &amount, STAmount const &amount2, Issue const &lptIssue, std::uint16_t tfee)
Equal deposit in empty AMM state (LP tokens balance is 0)
Definition: AMMDeposit.cpp:882