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 <xrpl/basics/Expected.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/ledger/View.h>
26#include <xrpl/protocol/STAmount.h>
27#include <xrpl/protocol/STLedgerEntry.h>
28#include <xrpl/protocol/TER.h>
29
30namespace ripple {
31
32class ReadView;
33class ApplyView;
34class Sandbox;
35class NetClock;
36
41 ReadView const& view,
42 AccountID const& ammAccountID,
43 Issue const& issue1,
44 Issue const& issue2,
45 FreezeHandling freezeHandling,
46 beast::Journal const j);
47
52Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
54 ReadView const& view,
55 SLE const& ammSle,
56 std::optional<Issue> const& optIssue1,
57 std::optional<Issue> const& optIssue2,
58 FreezeHandling freezeHandling,
59 beast::Journal const j);
60
63STAmount
65 ReadView const& view,
66 Currency const& cur1,
67 Currency const& cur2,
68 AccountID const& ammAccount,
69 AccountID const& lpAccount,
70 beast::Journal const j);
71
72STAmount
74 ReadView const& view,
75 SLE const& ammSle,
76 AccountID const& lpAccount,
77 beast::Journal const j);
78
85 ReadView const& view,
86 SLE const& ammSle,
87 AccountID const& account);
88
91STAmount
93 ReadView const& view,
94 AccountID const& ammAccountID,
95 Issue const& issue);
96
100TER
102 Sandbox& view,
103 Issue const& asset,
104 Issue const& asset2,
106
109void
111 ApplyView& view,
112 std::shared_ptr<SLE>& ammSle,
113 AccountID const& account,
114 Issue const& lptIssue,
115 std::uint16_t tfee);
116
121Expected<bool, TER>
123 ReadView const& view,
124 Issue const& ammIssue,
125 AccountID const& lpAccount);
126
131Expected<bool, TER>
133 Sandbox& sb,
134 STAmount const& lpTokens,
135 std::shared_ptr<SLE>& ammSle,
136 AccountID const& account);
137
138} // namespace ripple
139
140#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:25
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:48
FreezeHandling
Controls the treatment of frozen account balances.
Definition View.h:77
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Definition AMMUtils.cpp:179
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition AMMUtils.cpp:283
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:387
Expected< bool, TER > verifyAndAdjustLPTokenBalance(Sandbox &sb, STAmount const &lpTokens, std::shared_ptr< SLE > &ammSle, AccountID const &account)
Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance.
Definition AMMUtils.cpp:469
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:340
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:113
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:31
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:47
STLedgerEntry SLE
STAmount ammAccountHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue)
Returns total amount held by AMM for the given token.
Definition AMMUtils.cpp:211
TERSubset< CanCvtToTER > TER
Definition TER.h:645