19#include <xrpld/app/ledger/LedgerMaster.h>
20#include <xrpld/app/misc/AMMUtils.h>
21#include <xrpld/ledger/ReadView.h>
22#include <xrpld/rpc/Context.h>
23#include <xrpld/rpc/detail/RPCHelpers.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/protocol/AMMCore.h>
26#include <xrpl/protocol/Issue.h>
27#include <xrpl/protocol/RPCErr.h>
28#include <grpcpp/support/status.h>
40 for (
auto it = jv.begin(); it != jv.end(); ++it)
41 result[it.memberName()] = (*it);
48Expected<Issue, error_code_i>
57 JLOG(j.
debug()) <<
"getIssue " << ex.
what();
68 "%Y-%Om-%dT%H:%M:%OS%z",
69 date::sys_time<system_clock::duration>(
76 auto const& params(context.
params);
84 struct ValuesFromContextParams
92 auto getValuesFromContextParams =
100 return (params.isMember(jss::asset) !=
101 params.isMember(jss::asset2)) ||
102 (params.isMember(jss::asset) ==
103 params.isMember(jss::amm_account));
110 if (params.isMember(jss::asset))
112 if (
auto const i =
getIssue(params[jss::asset], context.
j))
118 if (params.isMember(jss::asset2))
120 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
126 if (params.isMember(jss::amm_account))
128 auto const id =
getAccount(params[jss::amm_account], result);
134 ammID = sle->getFieldH256(sfAMMID);
139 if (params.isMember(jss::account))
141 accountID =
getAccount(params[jss::account], result);
153 "ripple::doAMMInfo : issue1 and issue2 do match");
155 auto const ammKeylet = [&]() {
156 if (issue1 && issue2)
158 XRPL_ASSERT(ammID,
"ripple::doAMMInfo::ammKeylet : ammID is set");
161 auto const amm = ledger->read(ammKeylet);
164 if (!issue1 && !issue2)
166 issue1 = (*amm)[sfAsset].get<
Issue>();
167 issue2 = (*amm)[sfAsset2].get<
Issue>();
170 return ValuesFromContextParams{
171 accountID, *issue1, *issue2, std::move(amm)};
174 auto const r = getValuesFromContextParams();
181 auto const& [accountID, issue1, issue2, amm] = *r;
186 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
193 auto const lptAMMBalance = accountID
195 : (*amm)[sfLPTokenBalance];
198 asset1Balance.setJson(ammResult[jss::amount]);
199 asset2Balance.setJson(ammResult[jss::amount2]);
200 lptAMMBalance.setJson(ammResult[jss::lp_token]);
201 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
204 if (amm->isFieldPresent(sfVoteSlots))
206 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
209 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
210 vote[jss::trading_fee] = voteEntry[sfTradingFee];
211 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
212 voteSlots.
append(std::move(vote));
215 if (voteSlots.
size() > 0)
216 ammResult[jss::vote_slots] = std::move(voteSlots);
218 !ledger->rules().enabled(fixInnerObjTemplate) ||
219 amm->isFieldPresent(sfAuctionSlot),
220 "ripple::doAMMInfo : auction slot is set");
221 if (amm->isFieldPresent(sfAuctionSlot))
223 auto const& auctionSlot =
224 static_cast<STObject const&
>(amm->peekAtField(sfAuctionSlot));
225 if (auctionSlot.isFieldPresent(sfAccount))
229 ledger->info().parentCloseTime.time_since_epoch().count(),
231 auction[jss::time_interval] =
233 auctionSlot[sfPrice].setJson(auction[jss::price]);
234 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
235 auction[jss::account] =
236 to_string(auctionSlot.getAccountID(sfAccount));
239 if (auctionSlot.isFieldPresent(sfAuthAccounts))
242 for (
auto const& acct :
243 auctionSlot.getFieldArray(sfAuthAccounts))
246 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
249 auction[jss::auth_accounts] = auth;
251 ammResult[jss::auction_slot] = std::move(auction);
255 if (!
isXRP(asset1Balance))
256 ammResult[jss::asset_frozen] =
258 if (!
isXRP(asset2Balance))
259 ammResult[jss::asset2_frozen] =
262 result[jss::amm] = std::move(ammResult);
263 if (!result.
isMember(jss::ledger_index) &&
265 result[jss::ledger_current_index] = ledger->info().seq;
UInt size() const
Number of values in array or object.
Value & append(const Value &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
A currency issued by an account.
bool isValidated(ReadView const &ledger)
@ arrayValue
array value (ordered list)
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isXRP(AccountID const &c)
std::uint16_t constexpr AUCTION_SLOT_TIME_INTERVALS
std::optional< std::uint8_t > ammAuctionTimeSlot(std::uint64_t current, STObject const &auctionSlot)
Get time slot of the auction slot.
Issue getIssue(T const &amt)
std::optional< AccountID > getAccount(Json::Value const &v, Json::Value &result)
Json::Value doAMMInfo(RPC::JsonContext &context)
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
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.
Issue issueFromJson(Json::Value const &v)
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.
@ invalid
Timely, but invalid signature.
static constexpr std::chrono::seconds epoch_offset
Clock for measuring the network time.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string to_iso8601(NetClock::time_point tp)
LedgerMaster & ledgerMaster
T time_since_epoch(T... args)