20#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/misc/AMMUtils.h>
22#include <xrpld/ledger/ReadView.h>
23#include <xrpld/rpc/Context.h>
24#include <xrpld/rpc/detail/RPCHelpers.h>
26#include <xrpl/json/json_value.h>
27#include <xrpl/protocol/AMMCore.h>
28#include <xrpl/protocol/Issue.h>
30#include <grpcpp/support/status.h>
42 for (
auto it = jv.begin(); it != jv.end(); ++it)
43 result[it.memberName()] = (*it);
50Expected<Issue, error_code_i>
59 JLOG(j.
debug()) <<
"getIssue " << ex.
what();
70 "%Y-%Om-%dT%H:%M:%OS%z",
71 date::sys_time<system_clock::duration>(
78 auto const& params(context.
params);
86 struct ValuesFromContextParams
94 auto getValuesFromContextParams =
102 return (params.isMember(jss::asset) !=
103 params.isMember(jss::asset2)) ||
104 (params.isMember(jss::asset) ==
105 params.isMember(jss::amm_account));
112 if (params.isMember(jss::asset))
114 if (
auto const i =
getIssue(params[jss::asset], context.
j))
120 if (params.isMember(jss::asset2))
122 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
128 if (params.isMember(jss::amm_account))
130 auto const id =
getAccount(params[jss::amm_account], result);
136 ammID = sle->getFieldH256(sfAMMID);
141 if (params.isMember(jss::account))
143 accountID =
getAccount(params[jss::account], result);
155 "ripple::doAMMInfo : issue1 and issue2 do match");
157 auto const ammKeylet = [&]() {
158 if (issue1 && issue2)
160 XRPL_ASSERT(ammID,
"ripple::doAMMInfo::ammKeylet : ammID is set");
163 auto const amm = ledger->read(ammKeylet);
166 if (!issue1 && !issue2)
168 issue1 = (*amm)[sfAsset].get<
Issue>();
169 issue2 = (*amm)[sfAsset2].get<
Issue>();
172 return ValuesFromContextParams{
173 accountID, *issue1, *issue2, std::move(amm)};
176 auto const r = getValuesFromContextParams();
183 auto const& [accountID, issue1, issue2, amm] = *r;
188 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
195 auto const lptAMMBalance = accountID
197 : (*amm)[sfLPTokenBalance];
200 asset1Balance.setJson(ammResult[jss::amount]);
201 asset2Balance.setJson(ammResult[jss::amount2]);
202 lptAMMBalance.setJson(ammResult[jss::lp_token]);
203 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
206 if (amm->isFieldPresent(sfVoteSlots))
208 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
211 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
212 vote[jss::trading_fee] = voteEntry[sfTradingFee];
213 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
214 voteSlots.
append(std::move(vote));
217 if (voteSlots.
size() > 0)
218 ammResult[jss::vote_slots] = std::move(voteSlots);
220 !ledger->rules().enabled(fixInnerObjTemplate) ||
221 amm->isFieldPresent(sfAuctionSlot),
222 "ripple::doAMMInfo : auction slot is set");
223 if (amm->isFieldPresent(sfAuctionSlot))
225 auto const& auctionSlot =
226 static_cast<STObject const&
>(amm->peekAtField(sfAuctionSlot));
227 if (auctionSlot.isFieldPresent(sfAccount))
231 ledger->info().parentCloseTime.time_since_epoch().count(),
233 auction[jss::time_interval] =
235 auctionSlot[sfPrice].setJson(auction[jss::price]);
236 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
237 auction[jss::account] =
238 to_string(auctionSlot.getAccountID(sfAccount));
241 if (auctionSlot.isFieldPresent(sfAuthAccounts))
244 for (
auto const& acct :
245 auctionSlot.getFieldArray(sfAuthAccounts))
248 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
251 auction[jss::auth_accounts] = auth;
253 ammResult[jss::auction_slot] = std::move(auction);
257 if (!
isXRP(asset1Balance))
258 ammResult[jss::asset_frozen] =
260 if (!
isXRP(asset2Balance))
261 ammResult[jss::asset2_frozen] =
264 result[jss::amm] = std::move(ammResult);
265 if (!result.
isMember(jss::ledger_index) &&
267 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)