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
20#ifndef RIPPLE_APP_MISC_AMMUTILS_H_INCLUDED
21#define RIPPLE_APP_MISC_AMMUTILS_H_INCLUDED
22
23#include <xrpld/ledger/View.h>
24
25#include <xrpl/basics/Expected.h>
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/protocol/STAmount.h>
28#include <xrpl/protocol/STLedgerEntry.h>
29#include <xrpl/protocol/TER.h>
30
31namespace ripple {
32
33class ReadView;
34class ApplyView;
35class Sandbox;
36class NetClock;
37
42 ReadView const& view,
43 AccountID const& ammAccountID,
44 Issue const& issue1,
45 Issue const& issue2,
46 FreezeHandling freezeHandling,
47 beast::Journal const j);
48
53Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
55 ReadView const& view,
56 SLE const& ammSle,
57 std::optional<Issue> const& optIssue1,
58 std::optional<Issue> const& optIssue2,
59 FreezeHandling freezeHandling,
60 beast::Journal const j);
61
64STAmount
66 ReadView const& view,
67 Currency const& cur1,
68 Currency const& cur2,
69 AccountID const& ammAccount,
70 AccountID const& lpAccount,
71 beast::Journal const j);
72
73STAmount
75 ReadView const& view,
76 SLE const& ammSle,
77 AccountID const& lpAccount,
78 beast::Journal const j);
79
86 ReadView const& view,
87 SLE const& ammSle,
88 AccountID const& account);
89
92STAmount
94 ReadView const& view,
95 AccountID const& ammAccountID,
96 Issue const& issue);
97
101TER
103 Sandbox& view,
104 Issue const& asset,
105 Issue const& asset2,
107
110void
112 ApplyView& view,
113 std::shared_ptr<SLE>& ammSle,
114 AccountID const& account,
115 Issue const& lptIssue,
116 std::uint16_t tfee);
117
122Expected<bool, TER>
124 ReadView const& view,
125 Issue const& ammIssue,
126 AccountID const& lpAccount);
127
128} // namespace ripple
129
130#endif // RIPPLE_APP_MISC_AMMUTILS_H_INCLUDED
A generic endpoint for log messages.
Definition: Journal.h:60
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:78
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Definition: AMMUtils.cpp:178
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition: AMMUtils.cpp:282
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:386
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:339
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:112
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:30
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:46
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:210
TERSubset< CanCvtToTER > TER
Definition: TER.h:643