1#include <xrpld/app/misc/AMMUtils.h>
2#include <xrpld/app/paths/AMMLiquidity.h>
3#include <xrpld/app/paths/AMMOffer.h>
4#include <xrpld/app/paths/detail/FlatSets.h>
5#include <xrpld/app/paths/detail/Steps.h>
6#include <xrpld/app/tx/detail/OfferStream.h>
8#include <xrpl/basics/Log.h>
9#include <xrpl/basics/contract.h>
10#include <xrpl/beast/utility/instrumentation.h>
11#include <xrpl/ledger/PaymentSandbox.h>
12#include <xrpl/protocol/Book.h>
13#include <xrpl/protocol/Feature.h>
14#include <xrpl/protocol/IOUAmount.h>
15#include <xrpl/protocol/Quality.h>
16#include <xrpl/protocol/XRPAmount.h>
18#include <boost/container/flat_set.hpp>
25template <
class TIn,
class TOut,
class TDerived>
26class BookStep :
public StepImp<TIn, TOut, BookStep<TIn, TOut, TDerived>>
59 Cache(TIn
const& in_, TOut
const& out_) :
in(in_),
out(out_)
76 ammSle && ammSle->getFieldAmount(sfLPTokenBalance) != beast::zero)
170 return !(lhs == rhs);
181 template <
class Callback>
186 template <
template <
typename,
typename>
typename Offer>
191 TAmounts<TIn, TOut>
const& ofrAmt,
192 TAmounts<TIn, TOut>
const& stepAmt,
193 TOut
const& ownerGives)
const;
225template <
class TIn,
class TOut>
236 template <
template <
typename,
typename>
typename Offer>
317template <
class TIn,
class TOut>
330 XRPL_ASSERT(limitQuality,
"xrpl::BookOfferCrossingStep::getQuality : nonzero quality");
332 Throw<FlowException>(
tefINTERNAL,
"Offer requires quality.");
333 return *limitQuality;
344 template <
template <
typename,
typename>
typename Offer>
352 bool const offerAttempted)
const
384 strandDst == offer.owner())
387 if (
auto const key = offer.
key())
388 offers.permRmOffer(*key);
434 return owner == srcAcct
457 Rules const& rules)
const
469 if (!rules.
enabled(fixAMMv1_1))
501template <
class TIn,
class TOut,
class TDerived>
506 return book_ == bs->book_;
510template <
class TIn,
class TOut,
class TDerived>
522 Quality
const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
527template <
class TIn,
class TOut,
class TDerived>
541 auto const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
551 Quality
const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
556template <
class TIn,
class TOut,
class TDerived>
564template <
class TIn,
class TOut,
class Offer>
568 TAmounts<TIn, TOut>& ofrAmt,
569 TAmounts<TIn, TOut>& stpAmt,
575 if (limit < stpAmt.in)
578 auto const inLmt =
mulRatio(stpAmt.in, QUALITY_ONE, transferRateIn,
false);
586 ofrAmt = offer.limitIn(ofrAmt, inLmt,
false);
587 stpAmt.out = ofrAmt.out;
588 ownerGives =
mulRatio(ofrAmt.out, transferRateOut, QUALITY_ONE,
false);
593template <
class TIn,
class TOut,
class Offer>
597 TAmounts<TIn, TOut>& ofrAmt,
598 TAmounts<TIn, TOut>& stpAmt,
604 if (limit < stpAmt.out)
607 ownerGives =
mulRatio(stpAmt.out, transferRateOut, QUALITY_ONE,
false);
608 ofrAmt = offer.limitOut(
612 stpAmt.in =
mulRatio(ofrAmt.in, transferRateIn, QUALITY_ONE,
true);
616template <
class TIn,
class TOut,
class TDerived>
617template <
class Callback>
623 Callback& callback)
const
631 if (
isXRP(
id) ||
id == this->strandDst_)
638 std::uint32_t const trOut = ownerPaysTransferFee_ ? rate(book_.out.account) : QUALITY_ONE;
644 bool offerAttempted =
false;
646 auto execOffer = [&](
auto& offer) {
650 ofrQ = offer.quality();
651 else if (*ofrQ != offer.quality())
654 if (
static_cast<TDerived const*
>(
this)->limitSelfCrossQuality(
655 strandSrc_, strandDst_, offer, ofrQ, offers, offerAttempted))
660 if (!
isXRP(offer.issueIn().currency) && offer.owner() != offer.issueIn().account)
662 auto const& issuerID = offer.issueIn().account;
667 auto const& ownerID = offer.owner();
670 auto const line = afView.
read(
keylet::line(ownerID, issuerID, offer.issueIn().currency));
672 if (!line || (((*line)[sfFlags] & authFlag) == 0))
676 if (
auto const key = offer.
key())
677 offers.permRmOffer(*key);
687 if (!
static_cast<TDerived const*
>(
this)->checkQualityThreshold(offer.quality()))
690 auto const [ofrInRate, ofrOutRate] = offer.adjustRates(
691 static_cast<TDerived const*
>(
this)->getOfrInRate(prevStep_, offer.owner(), trIn),
692 static_cast<TDerived const*
>(
this)->getOfrOutRate(prevStep_, offer.owner(), strandDst_, trOut));
694 auto ofrAmt = offer.amount();
695 TAmounts stpAmt{
mulRatio(ofrAmt.in, ofrInRate, QUALITY_ONE,
true), ofrAmt.out};
698 auto ownerGives =
mulRatio(ofrAmt.out, ofrOutRate, QUALITY_ONE,
false);
700 auto const funds = offer.isFunded() ? ownerGives
701 : offers.ownerFunds();
704 if (funds < ownerGives)
708 stpAmt.out =
mulRatio(ownerGives, QUALITY_ONE, ofrOutRate,
false);
713 ofrAmt = offer.limitOut(ofrAmt, stpAmt.out,
false);
715 stpAmt.in =
mulRatio(ofrAmt.in, ofrInRate, QUALITY_ONE,
true);
718 offerAttempted =
true;
719 return callback(offer, ofrAmt, stpAmt, ownerGives, ofrInRate, ofrOutRate);
732 return static_cast<TDerived const*
>(
this)->qualityThreshold(*lobQuality);
735 auto ammOffer = getAMMOffer(sb, qualityThreshold);
736 return !ammOffer || execOffer(*ammOffer);
741 if (tryAMM(offers.tip().quality()))
745 if (!execOffer(offers.tip()))
747 }
while (offers.step());
756 return {offers.permToRemove(), counter.
count()};
759template <
class TIn,
class TOut,
class TDerived>
760template <
template <
typename,
typename>
typename Offer>
765 TAmounts<TIn, TOut>
const& ofrAmt,
766 TAmounts<TIn, TOut>
const& stepAmt,
767 TOut
const& ownerGives)
const
769 if (!offer.checkInvariant(ofrAmt, j_))
782 auto const dr = offer.send(sb, book_.in.account, offer.owner(),
toSTAmount(ofrAmt.in, book_.in), j_);
784 Throw<FlowException>(dr);
790 auto const cr = offer.send(sb, offer.owner(), book_.out.account,
toSTAmount(ownerGives, book_.out), j_);
792 Throw<FlowException>(cr);
795 offer.consume(sb, ofrAmt);
798template <
class TIn,
class TOut,
class TDerived>
803 return ammLiquidity_->getOffer(view, clobQuality);
807template <
class TIn,
class TOut,
class TDerived>
834 return static_cast<TDerived const*
>(
this)->qualityThreshold(*lobQuality);
838 if (
auto const ammOffer = getAMMOffer(view, qualityThreshold);
839 ammOffer && ((lobQuality && ammOffer->quality() > lobQuality) || !lobQuality))
845template <
class TIn,
class TOut,
class TDerived>
850 if (
auto const res = tip(view); !res)
858template <
class TIn,
class TOut,
class TDerived>
862 if (
auto const res = tip(view); !res)
870template <
class TCollection>
872sum(TCollection
const& col)
876 return TResult{beast::zero};
880template <
class TIn,
class TOut,
class TDerived>
885 boost::container::flat_set<uint256>& ofrsToRm,
890 TAmounts<TIn, TOut> result(beast::zero, beast::zero);
892 auto remainingOut =
out;
894 boost::container::flat_multiset<TIn> savedIns;
895 savedIns.reserve(64);
896 boost::container::flat_multiset<TOut> savedOuts;
897 savedOuts.reserve(64);
903 auto eachOffer = [&](
auto& offer,
904 TAmounts<TIn, TOut>
const& ofrAmt,
905 TAmounts<TIn, TOut>
const& stpAmt,
906 TOut
const& ownerGives,
909 if (remainingOut <= beast::zero)
912 if (stpAmt.out <= remainingOut)
914 savedIns.insert(stpAmt.in);
915 savedOuts.insert(stpAmt.out);
916 result = TAmounts<TIn, TOut>(
sum(savedIns),
sum(savedOuts));
917 remainingOut =
out - result.out;
918 this->consumeOffer(sb, offer, ofrAmt, stpAmt, ownerGives);
925 auto ofrAdjAmt = ofrAmt;
926 auto stpAdjAmt = stpAmt;
927 auto ownerGivesAdj = ownerGives;
928 limitStepOut(offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj, transferRateIn, transferRateOut, remainingOut);
929 remainingOut = beast::zero;
930 savedIns.insert(stpAdjAmt.in);
931 savedOuts.insert(remainingOut);
932 result.in =
sum(savedIns);
934 this->consumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
941 return offer.fully_consumed();
946 auto const prevStepDebtDir = [&] {
951 auto const r = forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
952 boost::container::flat_set<uint256> toRm = std::move(
std::get<0>(r));
954 offersUsed_ = offersConsumed;
958 if (offersConsumed >= MaxOffersToConsume)
964 switch (remainingOut.signum())
969 JLOG(j_.error()) <<
"BookStep remainingOut < 0 " <<
to_string(remainingOut);
970 UNREACHABLE(
"xrpl::BookStep::revImp : remaining less than zero");
971 cache_.emplace(beast::zero, beast::zero);
972 return {beast::zero, beast::zero};
982 cache_.emplace(result.in, result.out);
983 return {result.in, result.out};
986template <
class TIn,
class TOut,
class TDerived>
991 boost::container::flat_set<uint256>& ofrsToRm,
994 XRPL_ASSERT(cache_,
"xrpl::BookStep::fwdImp : cache is set");
996 TAmounts<TIn, TOut> result(beast::zero, beast::zero);
998 auto remainingIn =
in;
1000 boost::container::flat_multiset<TIn> savedIns;
1001 savedIns.reserve(64);
1002 boost::container::flat_multiset<TOut> savedOuts;
1003 savedOuts.reserve(64);
1007 auto eachOffer = [&](
auto& offer,
1008 TAmounts<TIn, TOut>
const& ofrAmt,
1009 TAmounts<TIn, TOut>
const& stpAmt,
1010 TOut
const& ownerGives,
1013 XRPL_ASSERT(cache_,
"xrpl::BookStep::fwdImp::eachOffer : cache is set");
1015 if (remainingIn <= beast::zero)
1018 bool processMore =
true;
1019 auto ofrAdjAmt = ofrAmt;
1020 auto stpAdjAmt = stpAmt;
1021 auto ownerGivesAdj = ownerGives;
1023 typename boost::container::flat_multiset<TOut>::const_iterator lastOut;
1024 if (stpAmt.in <= remainingIn)
1026 savedIns.insert(stpAmt.in);
1027 lastOut = savedOuts.insert(stpAmt.out);
1028 result = TAmounts<TIn, TOut>(
sum(savedIns),
sum(savedOuts));
1034 limitStepIn(offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj, transferRateIn, transferRateOut, remainingIn);
1035 savedIns.insert(remainingIn);
1036 lastOut = savedOuts.insert(stpAdjAmt.out);
1037 result.out =
sum(savedOuts);
1040 processMore =
false;
1043 if (result.out > cache_->out && result.in <= cache_->in)
1052 auto const lastOutAmt = *lastOut;
1053 savedOuts.erase(lastOut);
1054 auto const remainingOut = cache_->out -
sum(savedOuts);
1055 auto ofrAdjAmtRev = ofrAmt;
1056 auto stpAdjAmtRev = stpAmt;
1057 auto ownerGivesAdjRev = ownerGives;
1059 offer, ofrAdjAmtRev, stpAdjAmtRev, ownerGivesAdjRev, transferRateIn, transferRateOut, remainingOut);
1061 if (stpAdjAmtRev.in == remainingIn)
1064 result.out = cache_->out;
1067 savedIns.insert(result.in);
1069 savedOuts.insert(result.out);
1071 ofrAdjAmt = ofrAdjAmtRev;
1072 stpAdjAmt.in = remainingIn;
1073 stpAdjAmt.out = remainingOut;
1074 ownerGivesAdj = ownerGivesAdjRev;
1080 savedOuts.insert(lastOutAmt);
1084 remainingIn =
in - result.in;
1085 this->consumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1091 return processMore || offer.fully_consumed();
1095 auto const prevStepDebtDir = [&] {
1100 auto const r = forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1101 boost::container::flat_set<uint256> toRm = std::move(
std::get<0>(r));
1103 offersUsed_ = offersConsumed;
1107 if (offersConsumed >= MaxOffersToConsume)
1113 switch (remainingIn.signum())
1118 JLOG(j_.error()) <<
"BookStep remainingIn < 0 " <<
to_string(remainingIn);
1119 UNREACHABLE(
"xrpl::BookStep::fwdImp : remaining less than zero");
1120 cache_.emplace(beast::zero, beast::zero);
1121 return {beast::zero, beast::zero};
1131 cache_.emplace(result.in, result.out);
1132 return {result.in, result.out};
1135template <
class TIn,
class TOut,
class TDerived>
1141 JLOG(j_.trace()) <<
"Expected valid cache in validFwd";
1145 auto const savCache = *cache_;
1149 boost::container::flat_set<uint256> dummy;
1150 fwdImp(sb, afView, dummy, get<TIn>(
in));
1152 catch (FlowException
const&)
1159 JLOG(j_.warn()) <<
"Strand re-execute check failed."
1160 <<
" ExpectedIn: " <<
to_string(savCache.in) <<
" CachedIn: " <<
to_string(cache_->in)
1161 <<
" ExpectedOut: " <<
to_string(savCache.out) <<
" CachedOut: " <<
to_string(cache_->out);
1167template <
class TIn,
class TOut,
class TDerived>
1171 if (book_.in == book_.out)
1173 JLOG(j_.debug()) <<
"BookStep: Book with same in and out issuer " << *
this;
1178 JLOG(j_.debug()) <<
"Book: currency is inconsistent with issuer." << *
this;
1186 JLOG(j_.debug()) <<
"BookStep: loop detected: " << *
this;
1192 JLOG(j_.debug()) <<
"BookStep: loop detected: " << *
this;
1196 auto issuerExists = [](
ReadView const& view,
Issue const& iss) ->
bool {
1200 if (!issuerExists(ctx.
view, book_.in) || !issuerExists(ctx.
view, book_.out))
1202 JLOG(j_.debug()) <<
"BookStep: deleted issuer detected: " << *
this;
1210 auto const& view = ctx.
view;
1211 auto const& cur = book_.in.account;
1229template <
class TIn,
class TOut,
class TDerived>
1234 return book == bs->book();
1243 if (inXRP && outXRP)
1246 UNREACHABLE(
"xrpl::test::bookStepEqual : no XRP to XRP book step");
1250 if (inXRP && !outXRP)
1251 return equalHelper<XRPAmount, IOUAmount, BookPaymentStep<XRPAmount, IOUAmount>>(step, book);
1252 if (!inXRP && outXRP)
1253 return equalHelper<IOUAmount, XRPAmount, BookPaymentStep<IOUAmount, XRPAmount>>(step, book);
1254 if (!inXRP && !outXRP)
1255 return equalHelper<IOUAmount, IOUAmount, BookPaymentStep<IOUAmount, IOUAmount>>(step, book);
1262template <
class TIn,
class TOut>
1271 ter = offerCrossingStep->check(ctx);
1272 r = std::move(offerCrossingStep);
1277 ter = paymentStep->check(ctx);
1278 r = std::move(paymentStep);
1281 return {ter,
nullptr};
1289 return make_BookStepHelper<IOUAmount, IOUAmount>(ctx,
in,
out);
1295 return make_BookStepHelper<IOUAmount, XRPAmount>(ctx,
in,
xrpIssue());
1301 return make_BookStepHelper<XRPAmount, IOUAmount>(ctx,
xrpIssue(),
out);
A generic endpoint for log messages.
AccountID account() const
Represents synthetic AMM offer in BookStep.
Quality quality() const noexcept
Writeable view to a ledger, for applying a transaction.
std::uint32_t getOfrInRate(Step const *prevStep, AccountID const &owner, std::uint32_t trIn) const
std::string logString() const override
bool checkQualityThreshold(Quality const &quality) const
Quality adjustQualityWithFees(ReadView const &v, Quality const &ofrQ, DebtDirection prevStepDir, WaiveTransferFee waiveFee, OfferType offerType, Rules const &rules) const
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
BookOfferCrossingStep(StrandContext const &ctx, Issue const &in, Issue const &out)
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
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, Rules const &) 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::pair< boost::container::flat_set< uint256 >, std::uint32_t > forEachOffer(PaymentSandbox &sb, ApplyView &afView, DebtDirection prevStepDebtDir, Callback &callback) const
std::optional< Book > bookStepBook() const override
std::optional< std::variant< Quality, AMMOffer< TIn, TOut > > > tip(ReadView const &view) const
std::optional< QualityFunction > tipOfferQualityF(ReadView const &view) const
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
void consumeOffer(PaymentSandbox &sb, Offer< TIn, TOut > &offer, TAmounts< TIn, TOut > const &ofrAmt, TAmounts< TIn, TOut > const &stepAmt, TOut const &ownerGives) const
std::pair< TIn, TOut > fwdImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, TIn const &in)
bool equal(Step const &rhs) const override
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::optional< EitherAmount > cachedOut() const override
std::pair< TIn, TOut > revImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, TOut const &out)
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
BookStep(StrandContext const &ctx, Issue const &in, Issue const &out)
std::optional< AMMLiquidity< TIn, TOut > > ammLiquidity_
Book const & book() const
std::optional< std::pair< Quality, OfferType > > tipOfferQuality(ReadView const &view) const
static constexpr uint32_t MaxOffersToConsume
std::string logStringImpl(char const *name) 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.
A currency issued by an account.
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,...
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 std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
static std::uint64_t const uRateOne
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
Rules const & rules() const override
Returns the tx processing rules.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet account(AccountID const &id) noexcept
AccountID root.
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.
bool isConsistent(Book const &book)
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
static auto sum(TCollection const &col)
bool isXRP(AccountID const &c)
Quality composed_quality(Quality const &lhs, Quality const &rhs)
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)
std::string to_string(base_uint< Bits, Tag > const &a)
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
std::pair< TER, std::unique_ptr< Step > > make_BookStepXI(StrandContext const &ctx, 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)
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.
static bool isDefaultPath(STPath const &path)
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.
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
std::pair< TER, std::unique_ptr< Step > > make_BookStepIX(StrandContext const &ctx, Issue const &in)
bool checkNear(IOUAmount const &expected, IOUAmount const &actual)
std::pair< TER, std::unique_ptr< Step > > make_BookStepII(StrandContext const &ctx, Issue const &in, Issue const &out)
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
static std::pair< TER, std::unique_ptr< Step > > make_BookStepHelper(StrandContext const &ctx, Issue const &in, Issue const &out)
Cache(TIn const &in_, TOut const &out_)
Context needed to build Strand Steps and for error checking.
boost::container::flat_set< Issue > & seenBookOuts
A strand may not include an offer that output the same issue more than once.
ReadView const & view
Current ReadView.
std::array< boost::container::flat_set< Issue >, 2 > & seenDirectIssues
A strand may not include the same account node more than once in the same currency.
Step const *const prevStep
The previous step in the strand.
OfferCrossing const offerCrossing
Yes/Sell if offer crossing, not payment.