19 #include <ripple/app/misc/AMMUtils.h>
20 #include <ripple/basics/Log.h>
21 #include <ripple/ledger/Sandbox.h>
22 #include <ripple/protocol/AMMCore.h>
23 #include <ripple/protocol/STAccount.h>
24 #include <ripple/protocol/STObject.h>
37 auto const assetInBalance =
39 auto const assetOutBalance =
44 Expected<std::tuple<STAmount, STAmount, STAmount>,
TER>
54 auto const issue1 = ammSle[
sfAsset];
55 auto const issue2 = ammSle[
sfAsset2];
56 if (optIssue1 && optIssue2)
63 JLOG(j.
debug()) <<
"ammHolds: Invalid optIssue1 or optIssue2 "
64 << *optIssue1 <<
" " << *optIssue2;
69 auto const singleIssue =
70 [&issue1, &issue2, &j](
73 if (checkIssue == issue1)
75 else if (checkIssue == issue2)
78 <<
"ammHolds: Invalid " << label <<
" " << checkIssue;
83 return singleIssue(*optIssue1,
"optIssue1");
87 return singleIssue(*optIssue2,
"optIssue2");
117 FreezeHandling::fhZERO_IF_FROZEN,
143 auto const& auctionSlot =
147 duration_cast<seconds>(
149 .count() < expiration)
155 for (
auto const& acct :
176 else if (
auto const sle = view.
read(
184 amount.setIssuer(issue.
account);
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
const STBase & peekAtField(SField const &field) const
bool issues(DebtDirection dir)
const SF_UINT16 sfDiscountedFee
A currency issued by an account.
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.
const SF_AMOUNT sfLPTokenBalance
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
T make_optional(T... args)
Unexpected(E(&)[N]) -> Unexpected< E const * >
FreezeHandling
Controls the treatment of frozen account balances.
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
const SF_UINT16 sfTradingFee
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.
const SF_UINT32 sfExpiration
Integers of any length that is a multiple of 32-bits.
T time_since_epoch(T... args)
Keylet account(AccountID const &id) noexcept
AccountID root.
AccountID getAccountID(SField const &field) const
const SField sfAuthAccounts
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
TERSubset< CanCvtToTER > TER
bool isXRP(AccountID const &c)
A generic endpoint for log messages.
NotTEC invalidAMMAssetPair(Issue const &issue1, Issue const &issue2, std::optional< std::pair< Issue, Issue >> const &pair=std::nullopt)
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isFieldPresent(SField const &field) const
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.
const SF_AMOUNT sfBalance
const SF_ACCOUNT sfAccount
Currency ammLPTCurrency(Currency const &cur1, Currency const &cur2)
Calculate Liquidity Provider Token (LPT) Currency.
const SField sfAuctionSlot
STAmount ammAccountHolds(ReadView const &view, AccountID const &ammAccountID, Issue const &issue)
Returns total amount held by AMM for the given token.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
NetClock::time_point parentCloseTime