rippled
Loading...
Searching...
No Matches
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 <xrpld/ledger/View.h>
23#include <xrpl/basics/Expected.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/protocol/STAmount.h>
26#include <xrpl/protocol/STLedgerEntry.h>
27#include <xrpl/protocol/TER.h>
28
29namespace ripple {
30
31class ReadView;
32class ApplyView;
33class Sandbox;
34class NetClock;
35
40 ReadView const& view,
42 Issue const& issue1,
43 Issue const& issue2,
44 FreezeHandling freezeHandling,
45 beast::Journal const j);
46
51Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
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
62STAmount
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
71STAmount
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
90STAmount
92 ReadView const& view,
94 Issue const& issue);
95
99TER
101 Sandbox& view,
102 Issue const& asset,
103 Issue const& asset2,
105
108void
110 ApplyView& view,
111 std::shared_ptr<SLE>& ammSle,
112 AccountID const& account,
113 Issue const& lptIssue,
114 std::uint16_t tfee);
115
120Expected<bool, TER>
122 ReadView const& view,
123 Issue const& ammIssue,
124 AccountID const& lpAccount);
125
126} // namespace ripple
127
128#endif // RIPPLE_APP_MISC_AMMUTILS_H_INLCUDED
A generic endpoint for log messages.
Definition: Journal.h:59
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
FreezeHandling
Controls the treatment of frozen account balances.
Definition: View.h:80
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Definition: AMMUtils.cpp:177
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition: AMMUtils.cpp:281
Expected< bool, TER > isOnlyLiquidityProvider(ReadView const &view, Issue const &ammIssue, AccountID const &lpAccount)
Return true if the Liquidity Provider is the only AMM provider, false otherwise.
Definition: AMMUtils.cpp:385
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
Definition: AMMCore.cpp:30
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:338
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:111
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition: UintTypes.h:56
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
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
STLedgerEntry SLE
Definition: STLedgerEntry.h:97
STAmount ammAccountHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue)
Returns total amount held by AMM for the given token.
Definition: AMMUtils.cpp:209
TERSubset< CanCvtToTER > TER
Definition: TER.h:627