1#include <xrpl/basics/Log.h>
2#include <xrpl/basics/base_uint.h>
3#include <xrpl/basics/contract.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/PaymentSandbox.h>
9#include <xrpl/ledger/Sandbox.h>
10#include <xrpl/ledger/helpers/AMMHelpers.h>
11#include <xrpl/ledger/helpers/AccountRootHelpers.h>
12#include <xrpl/ledger/helpers/MPTokenHelpers.h>
13#include <xrpl/ledger/helpers/TokenHelpers.h>
14#include <xrpl/protocol/AccountID.h>
15#include <xrpl/protocol/Asset.h>
16#include <xrpl/protocol/Book.h>
17#include <xrpl/protocol/Concepts.h>
18#include <xrpl/protocol/Feature.h>
19#include <xrpl/protocol/IOUAmount.h>
20#include <xrpl/protocol/Indexes.h>
21#include <xrpl/protocol/Issue.h>
22#include <xrpl/protocol/LedgerFormats.h>
23#include <xrpl/protocol/MPTAmount.h>
24#include <xrpl/protocol/MPTIssue.h>
25#include <xrpl/protocol/Quality.h>
26#include <xrpl/protocol/Rate.h>
27#include <xrpl/protocol/SField.h>
28#include <xrpl/protocol/STAmount.h>
29#include <xrpl/protocol/TER.h>
30#include <xrpl/protocol/XRPAmount.h>
31#include <xrpl/tx/paths/AMMLiquidity.h>
32#include <xrpl/tx/paths/AMMOffer.h>
33#include <xrpl/tx/paths/BookTip.h>
34#include <xrpl/tx/paths/OfferStream.h>
35#include <xrpl/tx/paths/detail/EitherAmount.h>
36#include <xrpl/tx/paths/detail/FlatSets.h>
37#include <xrpl/tx/paths/detail/Steps.h>
39#include <boost/container/flat_set.hpp>
55template <
class TIn,
class TOut,
class TDerived>
56class BookStep :
public StepImp<TIn, TOut, BookStep<TIn, TOut, TDerived>>
105 :
book_(in, out, ctx.domainID)
120 ammSle && ammSle->getFieldAmount(sfLPTokenBalance) !=
beast::kZero)
122 ammLiquidity_.emplace(
124 (*ammSle)[sfAccount],
125 getTradingFee(ctx.view, *ammSle, ctx.ammContext.account()),
134 [[nodiscard]]
Book const&
181 boost::container::flat_set<UInt256>& ofrsToRm,
188 boost::container::flat_set<UInt256>& ofrsToRm,
210 <<
"\ninIss: " <<
book_.in.getIssuer() <<
"\noutIss: " <<
book_.out.getIssuer()
228 return !(lhs == rhs);
239 template <
class Callback>
245 Callback& callback)
const;
248 template <
template <
typename,
typename>
typename Offer>
255 TOut
const& ownerGives)
const;
257 template <
template <
typename,
typename>
typename Offer>
264 TOut
const& ownerGives)
const;
303template <
class TIn,
class TOut>
318 template <
template <
typename,
typename>
typename Offer>
378 ? this->
rate(v, this->
book_.out, this->strandDst_)
393template <
class TIn,
class TOut>
406 XRPL_ASSERT(limitQuality,
"xrpl::BookOfferCrossingStep::getQuality : nonzero quality");
409 return *limitQuality;
420 template <
template <
typename,
typename>
typename Offer>
428 bool const offerAttempted)
const
460 strandDst == offer.owner())
463 if (
auto const key = offer.
key())
509 auto const srcAcct = (prevStep !=
nullptr) ? prevStep->
directStepSrcAcct() : std::nullopt;
511 return owner == srcAcct
519 Step const* prevStep,
549 if (offerType == OfferType::Clob ||
577template <
class TIn,
class TOut,
class TDerived>
582 return book_ == bs->book_;
586template <
class TIn,
class TOut,
class TDerived>
594 return {std::nullopt, dir};
599 Quality const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
600 v, std::get<Quality>(*res), prevStepDir, waiveFee, std::get<OfferType>(*res));
604template <
class TIn,
class TOut,
class TDerived>
612 return {std::nullopt, dir};
618 auto const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
628 Quality const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
638template <
class TIn,
class TOut,
class TDerived>
647template <
class TIn,
class TOut,
class Offer>
664 ofrAmt = offer.limitIn(ofrAmt, inLmt,
false);
678template <
class TIn,
class TOut,
class Offer>
689 if (limit < stpAmt.
in)
692 auto const inLmt =
mulRatio(stpAmt.
in, QUALITY_ONE, transferRateIn,
false);
693 limitOfferIn(offer, ofrAmt, stpAmt, ownerGives, transferRateOut, inLmt);
698template <
class TIn,
class TOut,
class Offer>
709 if (limit < stpAmt.
out)
717 ofrAmt = offer.limitOut(
721 stpAmt.
in =
mulRatio(ofrAmt.
in, transferRateIn, QUALITY_ONE,
true);
725template <
class TIn,
class TOut,
class TDerived>
726template <
class Callback>
732 Callback& callback)
const
740 redeems(prevStepDir) ?
rate(sb,
book_.in, this->strandDst_).value : QUALITY_ONE;
749 bool offerAttempted =
false;
751 auto execOffer = [&](
auto& offer) {
756 ofrQ = offer.quality();
758 else if (*ofrQ != offer.quality())
763 if (
static_cast<TDerived const*
>(
this)->limitSelfCrossQuality(
767 Asset const& assetIn = offer.assetIn();
769 auto const& owner = offer.owner();
772 auto const key = offer.
key();
773 if (!logMessage.
empty())
775 JLOG(
j_.trace()) << logMessage << (key ?
" " +
to_string(*key) :
"");
788 auto const& applyView = sb.
rules().
enabled(featureMPTokensV2) ? sb : afView;
805 if (!
static_cast<TDerived const*
>(
this)->checkQualityThreshold(offer.quality()))
808 auto const [ofrInRate, ofrOutRate] = offer.adjustRates(
812 auto ofrAmt = offer.amount();
813 TAmounts stpAmt{ofrAmt.in, ofrAmt.out};
814 auto ownerGives = ofrAmt.
out;
819 auto const amtIn = [&](TIn
const& in) {
return capInMPT && *
maxIn_ < in ? *
maxIn_ : in; };
827 stpAmt.
in =
mulRatio(amtIn(ofrAmt.in), ofrInRate, QUALITY_ONE,
true);
836 grossOut =
tryMulRatio(ofrAmt.out, ofrOutRate, QUALITY_ONE,
true);
840 grossOut =
mulRatio(ofrAmt.out, ofrOutRate, QUALITY_ONE,
false);
843 ownerGives = *grossOut;
845 auto const funds = offer.isFunded()
851 if (!grossOut || funds < ownerGives)
856 stpAmt.
out =
mulRatio(ownerGives, QUALITY_ONE, ofrOutRate,
false);
861 ofrAmt = offer.limitOut(ofrAmt, stpAmt.
out,
false);
863 stpAmt.
in =
mulRatio(amtIn(ofrAmt.in), ofrInRate, QUALITY_ONE,
true);
874 "Removing offer whose fee-clipped amount rounds to "
886 ownerGives =
mulRatio(stpAmt.
out, ofrOutRate, QUALITY_ONE,
true);
892 bool inLimited =
false;
894 auto const& issuer = assetIn.
getIssuer();
895 if (isAssetInMPT && offer.owner() != issuer)
915 if (stpAmt.
in > available)
931 limitStepIn(offer, ofrAmt, stpAmt, ownerGives, ofrInRate, ofrOutRate, *limitIn);
937 !capInMPT || ofrAmt.in <= *
maxIn_,
938 "xrpl::BookStep::forEachOffer : capped offer input is limited");
940 offerAttempted =
true;
941 return callback(offer, ofrAmt, stpAmt, ownerGives, ofrInRate, ofrOutRate, inLimited);
949 "BookStep::forEachOffer removed MPT offer after "
950 "overflow during crossing");
951 removeOffer(
"Removing offer with overflowing amount calculation");
970 return static_cast<TDerived const*
>(
this)->qualityThreshold(*lobQuality);
974 return !ammOffer || execOffer(*ammOffer);
979 if (tryAMM(offers.
tip().quality()))
983 if (!execOffer(offers.
tip()))
985 }
while (offers.
step());
991 tryAMM(std::nullopt);
997template <
class TIn,
class TOut,
class TDerived>
998template <
template <
typename,
typename>
typename Offer>
1005 TOut
const& ownerGives)
const
1023template <
class TIn,
class TOut,
class TDerived>
1024template <
template <
typename,
typename>
typename Offer>
1031 TOut
const& ownerGives)
const
1033 if (!offer.checkInvariant(ofrAmt,
j_))
1059 auto const dr = offer.send(
1068 auto const& issuer =
book_.out.getIssuer();
1075 if (offer.owner() == issuer)
1080 offer.consume(sb, ofrAmt);
1083template <
class TIn,
class TOut,
class TDerived>
1093 return std::nullopt;
1096 return std::nullopt;
1099template <
class TIn,
class TOut,
class TDerived>
1126 return static_cast<TDerived const*
>(
this)->qualityThreshold(*lobQuality);
1127 return std::nullopt;
1130 if (
auto const ammOffer =
getAMMOffer(view, qualityThreshold);
1131 ammOffer && ((lobQuality && ammOffer->quality() > lobQuality) || !lobQuality))
1137template <
class TIn,
class TOut,
class TDerived>
1142 auto const res =
tip(view);
1145 return std::nullopt;
1155template <
class TIn,
class TOut,
class TDerived>
1159 auto const res =
tip(view);
1162 return std::nullopt;
1169 return std::get<AMMOffer<TIn, TOut>>(*res).getQualityFunc();
1172template <
class TCollection>
1180 col.begin() + 1, col.end(), *col.begin(), [](TResult
const& a, TResult
const& b) {
1181 return checkedStepAdd(a, b);
1185template <
class TIn,
class TOut,
class TDerived>
1190 boost::container::flat_set<UInt256>& ofrsToRm,
1197 auto remainingOut = out;
1199 boost::container::flat_multiset<TIn> savedIns;
1200 savedIns.reserve(64);
1201 boost::container::flat_multiset<TOut> savedOuts;
1202 savedOuts.reserve(64);
1208 auto eachOffer = [&](
auto& offer,
1211 TOut
const& ownerGives,
1214 bool inLimited)
mutable ->
bool {
1218 if (stpAmt.out <= remainingOut)
1220 savedIns.insert(stpAmt.in);
1221 savedOuts.insert(stpAmt.out);
1223 remainingOut = out - result.
out;
1233 auto ofrAdjAmt = ofrAmt;
1234 auto stpAdjAmt = stpAmt;
1235 auto ownerGivesAdj = ownerGives;
1252 savedIns.insert(stpAdjAmt.in);
1253 savedOuts.insert(remainingOut);
1254 result.
in =
sum(savedIns);
1256 this->
tryConsumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1263 return offer.fullyConsumed();
1267 auto const prevStepDebtDir = [&] {
1272 auto const r =
forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1273 boost::container::flat_set<UInt256>
const toRm = std::move(std::get<0>(r));
1285 switch (remainingOut.signum())
1290 JLOG(
j_.error()) <<
"BookStep remainingOut < 0 " <<
to_string(remainingOut);
1291 UNREACHABLE(
"xrpl::BookStep::revImp : remaining less than zero");
1304 return {result.
in, result.
out};
1307template <
class TIn,
class TOut,
class TDerived>
1312 boost::container::flat_set<UInt256>& ofrsToRm,
1315 XRPL_ASSERT(
cache_,
"xrpl::BookStep::fwdImp : cache is set");
1319 auto remainingIn = in;
1321 boost::container::flat_multiset<TIn> savedIns;
1322 savedIns.reserve(64);
1323 boost::container::flat_multiset<TOut> savedOuts;
1324 savedOuts.reserve(64);
1328 auto eachOffer = [&](
auto& offer,
1331 TOut
const& ownerGives,
1334 bool inLimited)
mutable ->
bool {
1335 XRPL_ASSERT(
cache_,
"xrpl::BookStep::fwdImp::eachOffer : cache is set");
1340 bool processMore =
true;
1341 auto ofrAdjAmt = ofrAmt;
1342 auto stpAdjAmt = stpAmt;
1343 auto ownerGivesAdj = ownerGives;
1354 auto savedInsAdj = savedIns;
1355 auto savedOutsAdj = savedOuts;
1356 auto resultAdj = result;
1357 typename boost::container::flat_multiset<TOut>::const_iterator lastOut;
1359 if (stpAmt.in <= remainingIn)
1361 savedInsAdj.insert(stpAmt.in);
1362 lastOut = savedOutsAdj.insert(stpAmt.out);
1367 processMore = !inLimited;
1379 savedInsAdj.insert(remainingIn);
1380 lastOut = savedOutsAdj.insert(stpAdjAmt.out);
1381 resultAdj.out =
sum(savedOutsAdj);
1384 processMore =
false;
1387 if (resultAdj.out >
cache_->out && resultAdj.in <=
cache_->in)
1396 auto const lastOutAmt = *lastOut;
1397 savedOutsAdj.erase(lastOut);
1398 auto const remainingOut =
cache_->out -
sum(savedOutsAdj);
1399 auto ofrAdjAmtRev = ofrAmt;
1400 auto stpAdjAmtRev = stpAmt;
1401 auto ownerGivesAdjRev = ownerGives;
1411 if (stpAdjAmtRev.in == remainingIn)
1414 resultAdj.out =
cache_->out;
1416 savedInsAdj.clear();
1417 savedInsAdj.insert(resultAdj.in);
1418 savedOutsAdj.clear();
1419 savedOutsAdj.insert(resultAdj.out);
1421 ofrAdjAmt = ofrAdjAmtRev;
1422 stpAdjAmt.in = remainingIn;
1423 stpAdjAmt.out = remainingOut;
1424 ownerGivesAdj = ownerGivesAdjRev;
1430 savedOutsAdj.insert(lastOutAmt);
1436 savedIns = std::move(savedInsAdj);
1437 savedOuts = std::move(savedOutsAdj);
1439 remainingIn = in - result.
in;
1440 this->
tryConsumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1446 return processMore || offer.fullyConsumed();
1450 auto const prevStepDebtDir = [&] {
1455 auto const r =
forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1456 boost::container::flat_set<UInt256>
const toRm = std::move(std::get<0>(r));
1468 switch (remainingIn.signum())
1473 JLOG(
j_.error()) <<
"BookStep remainingIn < 0 " <<
to_string(remainingIn);
1474 UNREACHABLE(
"xrpl::BookStep::fwdImp : remaining less than zero");
1487 return {result.
in, result.
out};
1490template <
class TIn,
class TOut,
class TDerived>
1499 JLOG(
j_.trace()) <<
"Expected valid cache in validFwd";
1503 auto const savCache = *
cache_;
1507 boost::container::flat_set<UInt256> dummy;
1510 catch (FlowException
const&)
1518 JLOG(
j_.warn()) <<
"Strand re-execute check failed."
1519 <<
" ExpectedIn: " <<
to_string(savCache.in)
1521 <<
" ExpectedOut: " <<
to_string(savCache.out)
1529template <
class TIn,
class TOut,
class TDerived>
1535 JLOG(
j_.debug()) <<
"BookStep: Book with same in and out issuer " << *
this;
1540 JLOG(
j_.debug()) <<
"Book: currency is inconsistent with issuer." << *
this;
1561 JLOG(
j_.debug()) <<
"BookStep: loop detected: " << *
this;
1567 JLOG(
j_.debug()) <<
"BookStep: loop detected: " << *
this;
1571 auto const issuerExists = [](
ReadView const& view,
Asset const& iss) ->
bool {
1577 JLOG(
j_.debug()) <<
"BookStep: deleted issuer detected: " << *
this;
1585 auto const& view = ctx.
view;
1586 auto const& cur =
book_.in.getIssuer();
1588 auto const err =
book_.in.visit(
1593 if (sle->isFlag((cur > *prev) ? lsfHighNoRipple : lsfLowNoRipple))
1595 return std::nullopt;
1612template <
class TIn,
class TOut,
class TDerived>
1631 if (asset ==
strandDeliver_ && mptIssue.getIssuer() == dstAccount)
1637template <
class TIn,
class TOut,
class TDerived>
1653 auto const ret = [&] {
1654 auto const& asset =
book_.in;
1659 if (asset.getIssuer() == owner)
1675 auto const& asset =
book_.out;
1680 if (asset.getIssuer() == owner)
1695template <
class TIn,
class TOut,
class TDerived>
1700 return book == bs->book();
1708 [&]<
typename TIn,
typename TOut>(TIn
const&, TOut
const&) {
1709 using TInAmount = TIn::Amount;
1710 using TOutAmount = TOut::Amount;
1720 UNREACHABLE(
"xrpl::bookStepEqual : invalid book step");
1725 book.in.getAmountType(),
1726 book.out.getAmountType());
1732template <
class TIn,
class TOut>
1741 ter = offerCrossingStep->check(ctx);
1742 r = std::move(offerCrossingStep);
1747 ter = paymentStep->check(ctx);
1748 r = std::move(paymentStep);
1751 return {ter,
nullptr};
A generic endpoint for log messages.
Represents synthetic AMM offer in BookStep.
Quality quality() const noexcept
Writeable view to a ledger, for applying a transaction.
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
constexpr TIss const & get() const
AccountID const & getIssuer() const
constexpr bool holds() const
std::uint32_t getOfrInRate(Step const *prevStep, AccountID const &owner, std::uint32_t trIn) const
std::string logString() const override
Quality adjustQualityWithFees(ReadView const &v, Quality const &ofrQ, DebtDirection prevStepDir, WaiveTransferFee waiveFee, OfferType offerType) const
bool checkQualityThreshold(Quality const &quality) const
BookOfferCrossingStep(StrandContext const &ctx, Asset const &in, Asset const &out)
bool limitSelfCrossQuality(AccountID const &strandSrc, AccountID const &strandDst, Offer< TIn, TOut > const &offer, std::optional< Quality > &ofrQ, FlowOfferStream< TIn, TOut > &offers, bool const offerAttempted) const
static Quality getQuality(std::optional< Quality > const &limitQuality)
std::optional< Quality > qualityThreshold(Quality const &lobQuality) const
Quality const qualityThreshold_
std::uint32_t getOfrOutRate(Step const *prevStep, AccountID const &owner, AccountID const &strandDst, std::uint32_t trOut) const
BookPaymentStep(StrandContext const &ctx, Asset const &in, Asset const &out)
std::optional< Quality > qualityThreshold(Quality const &lobQuality) const
bool limitSelfCrossQuality(AccountID const &, AccountID const &, Offer< TIn, TOut > const &offer, std::optional< Quality > &, FlowOfferStream< TIn, TOut > &, bool) const
Quality adjustQualityWithFees(ReadView const &v, Quality const &ofrQ, DebtDirection prevStepDir, WaiveTransferFee waiveFee, OfferType) const
std::uint32_t getOfrInRate(Step const *, AccountID const &, std::uint32_t trIn) const
std::uint32_t getOfrOutRate(Step const *, AccountID const &, AccountID const &, std::uint32_t trOut) const
std::string logString() const override
BookPaymentStep()=default
bool checkQualityThreshold(Quality const &quality) const
TER check(StrandContext const &ctx) const
Step const *const prevStep_
friend bool operator==(BookStep const &lhs, BookStep const &rhs)
std::optional< Book > bookStepBook() const override
std::optional< std::variant< Quality, AMMOffer< TIn, TOut > > > tip(ReadView const &view) const
void tryConsumeOffer(PaymentSandbox &sb, Offer< TIn, TOut > &offer, TAmounts< TIn, TOut > const &ofrAmt, TAmounts< TIn, TOut > const &stepAmt, TOut const &ownerGives) const
std::optional< QualityFunction > tipOfferQualityF(ReadView const &view) const
Asset const strandDeliver_
std::optional< EitherAmount > cachedIn() const override
std::optional< AMMOffer< TIn, TOut > > getAMMOffer(ReadView const &view, std::optional< Quality > const &clobQuality) const
bool const ownerPaysTransferFee_
DebtDirection debtDirection(ReadView const &sb, StrandDirection dir) const override
BookStep(StrandContext const &ctx, Asset const &in, Asset const &out)
void consumeOffer(PaymentSandbox &sb, Offer< TIn, TOut > &offer, TAmounts< TIn, TOut > const &ofrAmt, TAmounts< TIn, TOut > const &stepAmt, TOut const &ownerGives) const
bool equal(Step const &rhs) const override
std::optional< TIn > maxIn_
std::optional< Cache > cache_
std::uint32_t offersUsed_
Number of offers consumed or partially consumed the last time the step ran, including expired and unf...
std::pair< boost::container::flat_set< UInt256 >, std::uint32_t > forEachOffer(PaymentSandbox &sb, ApplyView &afView, DebtDirection prevStepDebtDir, Callback &callback) const
std::optional< EitherAmount > cachedOut() const override
std::pair< std::optional< Quality >, DebtDirection > qualityUpperBound(ReadView const &v, DebtDirection prevStepDir) const override
bool inactive() const override
friend bool operator!=(BookStep const &lhs, BookStep const &rhs)
std::uint32_t offersUsed() const override
std::pair< std::optional< QualityFunction >, DebtDirection > getQualityFunc(ReadView const &v, DebtDirection prevStepDir) const override
std::pair< TIn, TOut > fwdImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< UInt256 > &ofrsToRm, TIn const &in)
std::optional< AMMLiquidity< TIn, TOut > > ammLiquidity_
Rate rate(ReadView const &view, Asset const &asset, AccountID const &dstAccount) const
std::pair< TIn, TOut > revImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< UInt256 > &ofrsToRm, TOut const &out)
Book const & book() const
static constexpr uint32_t kMaxOffersToConsume
std::optional< std::pair< Quality, OfferType > > tipOfferQuality(ReadView const &view) const
std::string logStringImpl(char const *name) const
bool checkMPTDEX(ReadView const &view, AccountID const &owner) const
std::pair< bool, EitherAmount > validFwd(PaymentSandbox &sb, ApplyView &afView, EitherAmount const &in) override
Iterates and consumes raw offers in an order book.
bool step(beast::Journal j)
Erases the current offer and advance to the next offer.
Quality const & quality() const noexcept
Presents and consumes the offers in an order book.
boost::container::flat_set< UInt256 > const & permToRemove() const
void permRmOffer(UInt256 const &offerIndex) override
A currency issued by an account.
constexpr MPTID const & getMptID() const
A wrapper which makes credits unavailable to balances.
Average quality of a path as a function of out: q(out) = m * out + b, where m = -1 / poolGets,...
void combine(QualityFunction const &qf)
Combines QF with the next step QF.
Represents the logical ratio of output currency to input currency.
virtual Rules const & rules() const =0
Returns the tx processing rules.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
static std::uint64_t const kURateOne
Discardable, editable view to a ledger.
A step in a payment path.
virtual std::optional< AccountID > directStepSrcAcct() const
If this step is DirectStepI (IOU->IOU direct step), return the src account.
virtual std::optional< Book > bookStepBook() const
If this step is a BookStep, return the book.
std::uint32_t count() const
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
bool step()
Advance to the next valid offer.
Rules const & rules() const override
Returns the tx processing rules.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
bool bookStepEqual(Step const &step, xrpl::Book const &book)
static bool equalHelper(Step const &step, xrpl::Book const &book)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static void limitOfferIn(Offer const &offer, TAmounts< TIn, TOut > &ofrAmt, TAmounts< TIn, TOut > &stpAmt, TOut &ownerGives, std::uint32_t transferRateOut, TIn const &inLmt)
std::int64_t maxMPTAmount(SLE const &sleIssuance)
MaximumAmount doesn't exceed 2**63-1.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
static auto sum(TCollection const &col)
std::pair< TER, std::unique_ptr< Step > > makeBookStepIi(StrandContext const &ctx, Issue const &in, Issue const &out)
TER checkCreateMPT(xrpl::ApplyView &view, xrpl::MPTIssue const &mptIssue, xrpl::AccountID const &holder, SLE::Ref sponsorSle, std::uint32_t flags, beast::Journal j)
bool isXRP(AccountID const &c)
static void limitStepOut(Offer const &offer, TAmounts< TIn, TOut > &ofrAmt, TAmounts< TIn, TOut > &stpAmt, TOut &ownerGives, std::uint32_t transferRateIn, std::uint32_t transferRateOut, TOut const &limit)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::pair< TER, std::unique_ptr< Step > > makeBookStepMx(StrandContext const &ctx, MPTIssue const &in)
void setUnion(boost::container::flat_set< T > &dst, boost::container::flat_set< T > const &src)
Given two flat sets dst and src, compute dst = dst union src.
std::pair< TER, std::unique_ptr< Step > > makeBookStepMi(StrandContext const &ctx, MPTIssue const &in, Issue const &out)
static void limitStepIn(Offer const &offer, TAmounts< TIn, TOut > &ofrAmt, TAmounts< TIn, TOut > &stpAmt, TOut &ownerGives, std::uint32_t transferRateIn, std::uint32_t transferRateOut, TIn const &limit)
TER canTransfer(ReadView const &view, MPTIssue const &mptIssue, AccountID const &from, AccountID const &to, WaiveMPTCanTransfer waive=WaiveMPTCanTransfer::No, std::uint8_t depth=0)
Check whether to may receive the given MPT from from.
std::pair< TER, std::unique_ptr< Step > > makeBookStepIx(StrandContext const &ctx, Issue const &in)
std::string to_string(BaseUInt< Bits, Tag > const &a)
TER canTrade(ReadView const &view, Asset const &asset, std::uint8_t depth=0)
Check whether asset may be traded on the DEX.
T toAmount(STAmount const &amt)=delete
std::optional< MPTAmount > tryMulRatio(MPTAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
static bool isDefaultPath(STPath const &path)
std::pair< TER, std::unique_ptr< Step > > makeBookStepXm(StrandContext const &ctx, MPTIssue const &out)
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
std::pair< TER, std::unique_ptr< Step > > makeBookStepXi(StrandContext const &ctx, Issue const &out)
bool checkNear(IOUAmount const &expected, IOUAmount const &actual)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
std::pair< TER, std::unique_ptr< Step > > makeBookStepIm(StrandContext const &ctx, Issue const &in, MPTIssue const &out)
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
bool isConsistent(Asset const &asset)
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
void issuerSelfDebitHookMPT(ApplyView &view, MPTIssue const &issue, std::uint64_t amount)
Facilitate tracking of MPT sold by an issuer owning MPT sell offer.
bool redeems(DebtDirection dir)
static std::pair< TER, std::unique_ptr< Step > > makeBookStepHelper(StrandContext const &ctx, Asset const &in, Asset const &out)
std::pair< TER, std::unique_ptr< Step > > makeBookStepMm(StrandContext const &ctx, MPTIssue const &in, MPTIssue const &out)
Quality composedQuality(Quality const &lhs, Quality const &rhs)
Calculate the quality of a two-hop path given the two hops.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
STAmount toSTAmount(IOUAmount const &iou, Asset const &asset)
Cache(TIn const &in, TOut const &out)
Represents a transfer rate.
Context needed to build Strand Steps and for error checking.
ReadView const & view
Current ReadView.
bool const isFirst
true if Step is first in Strand
std::array< boost::container::flat_set< Asset >, 2 > & seenDirectAssets
A strand may not include the same account node more than once in the same currency.
AccountID const strandSrc
Strand source account.
boost::container::flat_set< Asset > & seenBookOuts
A strand may not include an offer that output the same issue more than once.
Step const *const prevStep
The previous step in the strand.
OfferCrossing const offerCrossing
Yes/Sell if offer crossing, not payment.
Represents a pair of input and output currencies.