19 #include <ripple/app/misc/AMMUtils.h>
20 #include <ripple/json/json_value.h>
21 #include <ripple/ledger/ReadView.h>
22 #include <ripple/net/RPCErr.h>
23 #include <ripple/protocol/AMMCore.h>
24 #include <ripple/protocol/Issue.h>
25 #include <ripple/rpc/Context.h>
26 #include <ripple/rpc/impl/RPCHelpers.h>
27 #include <grpcpp/support/status.h>
39 for (
auto it = jv.begin(); it != jv.end(); ++it)
40 result[it.memberName()] = (*it);
47 Expected<Issue, error_code_i>
56 JLOG(j.
debug()) <<
"getIssue " << ex.
what();
67 "%Y-%Om-%dT%H:%M:%OS%z",
68 date::sys_time<system_clock::duration>(
75 auto const& params(context.
params);
82 if (!params.isMember(jss::asset) || !params.isMember(jss::asset2))
88 if (
auto const i =
getIssue(params[jss::asset], context.
j); !i)
95 if (
auto const i =
getIssue(params[jss::asset2], context.
j); !i)
108 if (params.isMember(jss::account))
110 accountID =
getAccount(params[jss::account], result);
118 auto const ammKeylet =
keylet::amm(issue1, issue2);
119 auto const amm = ledger->
read(ammKeylet);
126 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
131 FreezeHandling::fhIGNORE_FREEZE,
133 auto const lptAMMBalance = accountID
138 asset1Balance.setJson(ammResult[jss::amount]);
139 asset2Balance.setJson(ammResult[jss::amount2]);
140 lptAMMBalance.setJson(ammResult[jss::lp_token]);
146 for (
auto const& voteEntry : amm->getFieldArray(
sfVoteSlots))
152 voteSlots.
append(std::move(vote));
155 if (voteSlots.
size() > 0)
156 ammResult[jss::vote_slots] = std::move(voteSlots);
159 auto const& auctionSlot =
161 if (auctionSlot.isFieldPresent(
sfAccount))
167 auction[jss::time_interval] =
169 auctionSlot[
sfPrice].setJson(auction[jss::price]);
171 auction[jss::account] =
178 for (
auto const& acct :
185 auction[jss::auth_accounts] = auth;
187 ammResult[jss::auction_slot] = std::move(auction);
191 if (!
isXRP(asset1Balance))
192 ammResult[jss::asset_frozen] =
194 if (!
isXRP(asset2Balance))
195 ammResult[jss::asset2_frozen] =
198 result[jss::amm] = std::move(ammResult);
199 if (!result.
isMember(jss::ledger_index) &&
201 result[jss::ledger_current_index] = ledger->
info().
seq;
202 result[jss::validated] =
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
const SF_UINT16 sfDiscountedFee
A currency issued by an account.
Json::Value rpcError(int iError)
constexpr std::uint16_t AUCTION_SLOT_TIME_INTERVALS
@ arrayValue
array value (ordered list)
const SF_AMOUNT sfLPTokenBalance
Keylet amm(Issue const &issue1, Issue const &issue2) noexcept
AMM entry.
Unexpected(E(&)[N]) -> Unexpected< E const * >
LedgerMaster & ledgerMaster
const SF_UINT32 sfVoteWeight
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.
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
const SF_UINT16 sfTradingFee
std::string to_iso8601(NetClock::time_point tp)
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)
Value & append(const Value &value)
Append value to array at the end.
Issue getIssue(T const &amt)
Keylet account(AccountID const &id) noexcept
AccountID root.
const SField sfAuthAccounts
UInt size() const
Number of values in array or object.
bool isXRP(AccountID const &c)
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
Issue issueFromJson(Json::Value const &v)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::optional< AccountID > getAccount(Json::Value const &v, Json::Value &result)
Json::Value doAMMInfo(RPC::JsonContext &context)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isValidated(LedgerMaster &ledgerMaster, ReadView const &ledger, Application &app)
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.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
const SField sfAuctionSlot
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
std::optional< std::uint8_t > ammAuctionTimeSlot(std::uint64_t current, STObject const &auctionSlot)
Get time slot of the auction slot.
std::string asString() const
Returns the unquoted string value.