59 auto const& params(context.
params);
67 struct ValuesFromContextParams
75 auto getValuesFromContextParams =
83 return (params.isMember(jss::asset) !=
84 params.isMember(jss::asset2)) ||
85 (params.isMember(jss::asset) ==
86 params.isMember(jss::amm_account));
93 if (params.isMember(jss::asset))
95 if (
auto const i =
getIssue(params[jss::asset], context.
j))
101 if (params.isMember(jss::asset2))
103 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
109 if (params.isMember(jss::amm_account))
111 auto const id =
getAccount(params[jss::amm_account], result);
117 ammID = sle->getFieldH256(sfAMMID);
122 if (params.isMember(jss::account))
124 accountID =
getAccount(params[jss::account], result);
136 "ripple::doAMMInfo : issue1 and issue2 do match");
138 auto const ammKeylet = [&]() {
139 if (issue1 && issue2)
141 XRPL_ASSERT(ammID,
"ripple::doAMMInfo::ammKeylet : ammID is set");
144 auto const amm = ledger->read(ammKeylet);
147 if (!issue1 && !issue2)
149 issue1 = (*amm)[sfAsset].get<
Issue>();
150 issue2 = (*amm)[sfAsset2].get<
Issue>();
153 return ValuesFromContextParams{
154 accountID, *issue1, *issue2, std::move(amm)};
157 auto const r = getValuesFromContextParams();
164 auto const& [accountID, issue1, issue2, amm] = *r;
166 auto const ammAccountID = amm->getAccountID(sfAccount);
169 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
176 auto const lptAMMBalance = accountID
178 : (*amm)[sfLPTokenBalance];
181 asset1Balance.setJson(ammResult[jss::amount]);
182 asset2Balance.setJson(ammResult[jss::amount2]);
183 lptAMMBalance.setJson(ammResult[jss::lp_token]);
184 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
185 ammResult[jss::account] =
to_string(ammAccountID);
187 if (amm->isFieldPresent(sfVoteSlots))
189 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
192 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
193 vote[jss::trading_fee] = voteEntry[sfTradingFee];
194 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
195 voteSlots.
append(std::move(vote));
198 if (voteSlots.
size() > 0)
199 ammResult[jss::vote_slots] = std::move(voteSlots);
201 !ledger->rules().enabled(fixInnerObjTemplate) ||
202 amm->isFieldPresent(sfAuctionSlot),
203 "ripple::doAMMInfo : auction slot is set");
204 if (amm->isFieldPresent(sfAuctionSlot))
206 auto const& auctionSlot =
207 static_cast<STObject const&
>(amm->peekAtField(sfAuctionSlot));
208 if (auctionSlot.isFieldPresent(sfAccount))
212 ledger->info().parentCloseTime.time_since_epoch().count(),
214 auction[jss::time_interval] =
216 auctionSlot[sfPrice].setJson(auction[jss::price]);
217 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
218 auction[jss::account] =
219 to_string(auctionSlot.getAccountID(sfAccount));
222 if (auctionSlot.isFieldPresent(sfAuthAccounts))
225 for (
auto const& acct :
226 auctionSlot.getFieldArray(sfAuthAccounts))
229 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
232 auction[jss::auth_accounts] = auth;
234 ammResult[jss::auction_slot] = std::move(auction);
238 if (!
isXRP(asset1Balance))
239 ammResult[jss::asset_frozen] =
240 isFrozen(*ledger, ammAccountID, issue1.currency, issue1.account);
241 if (!
isXRP(asset2Balance))
242 ammResult[jss::asset2_frozen] =
243 isFrozen(*ledger, ammAccountID, issue2.currency, issue2.account);
245 result[jss::amm] = std::move(ammResult);
246 if (!result.
isMember(jss::ledger_index) &&
248 result[jss::ledger_current_index] = ledger->info().seq;