rippled
AMMUtils.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 #ifndef RIPPLE_APP_MISC_AMMUTILS_H_INLCUDED
20 #define RIPPLE_APP_MISC_AMMUTILS_H_INLCUDED
21 
22 #include <ripple/basics/Expected.h>
23 #include <ripple/beast/utility/Journal.h>
24 #include <ripple/ledger/View.h>
25 #include <ripple/protocol/STAmount.h>
26 #include <ripple/protocol/STLedgerEntry.h>
27 #include <ripple/protocol/TER.h>
28 
29 namespace ripple {
30 
31 class ReadView;
32 class ApplyView;
33 class Sandbox;
34 class NetClock;
35 
40  ReadView const& view,
41  AccountID const& ammAccountID,
42  Issue const& issue1,
43  Issue const& issue2,
44  FreezeHandling freezeHandling,
45  beast::Journal const j);
46 
51 Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
52 ammHolds(
53  ReadView const& view,
54  SLE const& ammSle,
55  std::optional<Issue> const& optIssue1,
56  std::optional<Issue> const& optIssue2,
57  FreezeHandling freezeHandling,
58  beast::Journal const j);
59 
62 STAmount
64  ReadView const& view,
65  Currency const& cur1,
66  Currency const& cur2,
67  AccountID const& ammAccount,
68  AccountID const& lpAccount,
69  beast::Journal const j);
70 
71 STAmount
73  ReadView const& view,
74  SLE const& ammSle,
75  AccountID const& lpAccount,
76  beast::Journal const j);
77 
84  ReadView const& view,
85  SLE const& ammSle,
86  AccountID const& account);
87 
90 STAmount
92  ReadView const& view,
93  AccountID const& ammAccountID,
94  Issue const& issue);
95 
99 TER
101  Sandbox& view,
102  Issue const& asset,
103  Issue const& asset2,
104  beast::Journal j);
105 
108 void
110  ApplyView& view,
111  std::shared_ptr<SLE>& ammSle,
112  AccountID const& account,
113  Issue const& lptIssue,
114  std::uint16_t tfee);
115 
116 } // namespace ripple
117 
118 #endif // RIPPLE_APP_MISC_AMMUTILS_H_INLCUDED
ripple::initializeFeeAuctionVote
void initializeFeeAuctionVote(ApplyView &view, std::shared_ptr< SLE > &ammSle, AccountID const &account, Issue const &lptIssue, std::uint16_t tfee)
Initialize Auction and Voting slots and set the trading/discounted fee.
Definition: AMMUtils.cpp:283
std::shared_ptr
STL class.
ripple::ammHolds
Expected< std::tuple< STAmount, STAmount, STAmount >, TER > ammHolds(ReadView const &view, SLE const &ammSle, std::optional< Issue > const &optIssue1, std::optional< Issue > const &optIssue2, FreezeHandling freezeHandling, beast::Journal const j)
Get AMM pool and LP token balances.
Definition: AMMUtils.cpp:45
std::pair
ripple::SLE
STLedgerEntry SLE
Definition: Application.h:66
ripple::FreezeHandling
FreezeHandling
Controls the treatment of frozen account balances.
Definition: View.h:79
ripple::ammAccountID
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
Definition: AMMCore.cpp:30
ripple::ammPoolHolds
std::pair< STAmount, STAmount > ammPoolHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue1, Issue const &issue2, FreezeHandling freezeHandling, beast::Journal const j)
Get AMM pool balances.
Definition: AMMUtils.cpp:29
ripple::getTradingFee
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Definition: AMMUtils.cpp:138
ripple::TER
TERSubset< CanCvtToTER > TER
Definition: TER.h:608
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint16_t
ripple::Currency
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::deleteAMMAccount
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition: AMMUtils.cpp:234
ripple::ammLPHolds
STAmount ammLPHolds(ReadView const &view, Currency const &cur1, Currency const &cur2, AccountID const &ammAccount, AccountID const &lpAccount, beast::Journal const j)
Get the balance of LP tokens.
Definition: AMMUtils.cpp:104
std::optional
ripple::ammAccountHolds
STAmount ammAccountHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue)
Returns total amount held by AMM for the given token.
Definition: AMMUtils.cpp:166
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49