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,
146 auto const& auctionSlot =
150 duration_cast<seconds>(
152 .count() < expiration)
158 for (
auto const& acct :
179 else if (
auto const sle = view.
read(
187 amount.setIssuer(issue.
account);
208 if (nodeType == LedgerEntryType::ltAMM)
211 if (nodeType != LedgerEntryType::ltRIPPLE_STATE)
214 <<
"deleteAMMTrustLines: deleting non-trustline "
223 <<
"deleteAMMTrustLines: deleting trustline with "
233 maxTrustlinesToDelete);
246 JLOG(j.
error()) <<
"deleteAMMAccount: AMM object does not exist "
247 << asset <<
" " << asset2;
255 JLOG(j.
error()) <<
"deleteAMMAccount: AMM account does not exist "
267 ownerDirKeylet, (*ammSle)[
sfOwnerNode], ammSle->key(),
false))
269 JLOG(j.
error()) <<
"deleteAMMAccount: failed to remove dir link";
274 JLOG(j.
error()) <<
"deleteAMMAccount: cannot delete root dir node of "
280 sb.
erase(sleAMMRoot);
290 Issue const& lptIssue,
293 auto const& rules = view.
rules();
310 ammSle->
set(std::move(auctionSlot));
315 auto const expiration = std::chrono::duration_cast<std::chrono::seconds>(
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
const STBase & peekAtField(SField const &field) const
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
void setAccountID(SField const &field, AccountID const &)
bool issues(DebtDirection dir)
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.
const SF_UINT16 sfDiscountedFee
void makeFieldAbsent(SField const &field)
A currency issued by an account.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
const SF_UINT64 sfOwnerNode
void setFieldU16(SField const &field, std::uint16_t)
constexpr std::uint32_t VOTE_WEIGHT_SCALE_FACTOR
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
constexpr std::uint32_t AUCTION_SLOT_DISCOUNTED_FEE_FRACTION
bool exists(Keylet const &k) const override
Determine if a state item exists.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Keylet amm(Issue const &issue1, Issue const &issue2) noexcept
AMM entry.
T make_optional(T... args)
Unexpected(E(&)[N]) -> Unexpected< E const * >
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
void push_back(STObject const &object)
constexpr std::uint16_t maxDeletableAMMTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
FreezeHandling
Controls the treatment of frozen account balances.
const SF_UINT32 sfVoteWeight
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
const SF_UINT16 sfTradingFee
Writeable view to a ledger, for applying a transaction.
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
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
Integers of any length that is a multiple of 32-bits.
T time_since_epoch(T... args)
void setFieldArray(SField const &field, STArray const &v)
static STObject makeInnerObject(SField const &name, Rules const &rules)
Keylet account(AccountID const &id) noexcept
AccountID root.
void setFieldAmount(SField const &field, STAmount const &)
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.
Discardable, editable view to a ledger.
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.
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< uint16_t > maxNodesToDelete)
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STObject & peekFieldObject(SField const &field)
constexpr std::uint32_t TOTAL_TIME_SLOT_SECS
LedgerEntryType
Identifiers for on-ledger objects.
bool emptyDirDelete(Keylet const &directory)
Remove the specified directory, if it is empty.
virtual Rules const & rules() const =0
Returns the tx processing rules.
static TER deleteAMMTrustLines(Sandbox &sb, AccountID const &ammAccountID, std::uint16_t maxTrustlinesToDelete, beast::Journal j)
bool isFieldPresent(SField const &field) const
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
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
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
Currency ammLPTCurrency(Currency const &cur1, Currency const &cur2)
Calculate Liquidity Provider Token (LPT) Currency.
const SField sfAuctionSlot
const uint256 fixInnerObjTemplate
void set(const SOTemplate &)
void setFieldU32(SField const &field, std::uint32_t)
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)
STAmount const & getFieldAmount(SField const &field) const