60 auto const& params(context.
params);
68 struct ValuesFromContextParams
76 auto getValuesFromContextParams =
84 return (params.isMember(jss::asset) !=
85 params.isMember(jss::asset2)) ||
86 (params.isMember(jss::asset) ==
87 params.isMember(jss::amm_account));
94 if (params.isMember(jss::asset))
96 if (
auto const i =
getIssue(params[jss::asset], context.
j))
102 if (params.isMember(jss::asset2))
104 if (
auto const i =
getIssue(params[jss::asset2], context.
j))
110 if (params.isMember(jss::amm_account))
112 auto const id =
getAccount(params[jss::amm_account], result);
118 ammID = sle->getFieldH256(sfAMMID);
123 if (params.isMember(jss::account))
125 accountID =
getAccount(params[jss::account], result);
137 "ripple::doAMMInfo : issue1 and issue2 do match");
139 auto const ammKeylet = [&]() {
140 if (issue1 && issue2)
142 XRPL_ASSERT(ammID,
"ripple::doAMMInfo::ammKeylet : ammID is set");
145 auto const amm = ledger->read(ammKeylet);
148 if (!issue1 && !issue2)
150 issue1 = (*amm)[sfAsset].get<
Issue>();
151 issue2 = (*amm)[sfAsset2].get<
Issue>();
154 return ValuesFromContextParams{
155 accountID, *issue1, *issue2, std::move(amm)};
158 auto const r = getValuesFromContextParams();
165 auto const& [accountID, issue1, issue2, amm] = *r;
167 auto const ammAccountID = amm->getAccountID(sfAccount);
170 auto const [asset1Balance, asset2Balance] =
ammPoolHolds(
177 auto const lptAMMBalance = accountID
179 : (*amm)[sfLPTokenBalance];
182 asset1Balance.setJson(ammResult[jss::amount]);
183 asset2Balance.setJson(ammResult[jss::amount2]);
184 lptAMMBalance.setJson(ammResult[jss::lp_token]);
185 ammResult[jss::trading_fee] = (*amm)[sfTradingFee];
186 ammResult[jss::account] =
to_string(ammAccountID);
188 if (amm->isFieldPresent(sfVoteSlots))
190 for (
auto const& voteEntry : amm->getFieldArray(sfVoteSlots))
193 vote[jss::account] =
to_string(voteEntry.getAccountID(sfAccount));
194 vote[jss::trading_fee] = voteEntry[sfTradingFee];
195 vote[jss::vote_weight] = voteEntry[sfVoteWeight];
196 voteSlots.
append(std::move(vote));
199 if (voteSlots.
size() > 0)
200 ammResult[jss::vote_slots] = std::move(voteSlots);
202 !ledger->rules().enabled(fixInnerObjTemplate) ||
203 amm->isFieldPresent(sfAuctionSlot),
204 "ripple::doAMMInfo : auction slot is set");
205 if (amm->isFieldPresent(sfAuctionSlot))
207 auto const& auctionSlot =
208 static_cast<STObject const&
>(amm->peekAtField(sfAuctionSlot));
209 if (auctionSlot.isFieldPresent(sfAccount))
213 ledger->info().parentCloseTime.time_since_epoch().count(),
215 auction[jss::time_interval] =
217 auctionSlot[sfPrice].setJson(auction[jss::price]);
218 auction[jss::discounted_fee] = auctionSlot[sfDiscountedFee];
219 auction[jss::account] =
220 to_string(auctionSlot.getAccountID(sfAccount));
223 if (auctionSlot.isFieldPresent(sfAuthAccounts))
226 for (
auto const& acct :
227 auctionSlot.getFieldArray(sfAuthAccounts))
230 jv[jss::account] =
to_string(acct.getAccountID(sfAccount));
233 auction[jss::auth_accounts] = auth;
235 ammResult[jss::auction_slot] = std::move(auction);
239 if (!
isXRP(asset1Balance))
240 ammResult[jss::asset_frozen] =
241 isFrozen(*ledger, ammAccountID, issue1.currency, issue1.account);
242 if (!
isXRP(asset2Balance))
243 ammResult[jss::asset2_frozen] =
244 isFrozen(*ledger, ammAccountID, issue2.currency, issue2.account);
246 result[jss::amm] = std::move(ammResult);
247 if (!result.
isMember(jss::ledger_index) &&
249 result[jss::ledger_current_index] = ledger->info().seq;