20#include <xrpld/app/misc/AMMUtils.h>
21#include <xrpld/app/paths/AMMLiquidity.h>
22#include <xrpld/app/paths/AMMOffer.h>
23#include <xrpld/app/paths/detail/FlatSets.h>
24#include <xrpld/app/paths/detail/Steps.h>
25#include <xrpld/app/tx/detail/OfferStream.h>
26#include <xrpld/ledger/PaymentSandbox.h>
28#include <xrpl/basics/Log.h>
29#include <xrpl/basics/contract.h>
30#include <xrpl/beast/utility/instrumentation.h>
31#include <xrpl/protocol/Book.h>
32#include <xrpl/protocol/Feature.h>
33#include <xrpl/protocol/IOUAmount.h>
34#include <xrpl/protocol/Quality.h>
35#include <xrpl/protocol/XRPAmount.h>
37#include <boost/container/flat_set.hpp>
44template <
class TIn,
class TOut,
class TDerived>
45class BookStep :
public StepImp<TIn, TOut, BookStep<TIn, TOut, TDerived>>
78 Cache(TIn
const& in_, TOut
const& out_) :
in(in_),
out(out_)
104 ammSle && ammSle->getFieldAmount(sfLPTokenBalance) != beast::zero)
107 (*ammSle)[sfAccount],
164 boost::container::flat_set<uint256>& ofrsToRm,
171 boost::container::flat_set<uint256>& ofrsToRm,
211 return !(lhs == rhs);
222 template <
class Callback>
228 Callback& callback)
const;
231 template <
template <
typename,
typename>
typename Offer>
236 TAmounts<TIn, TOut>
const& ofrAmt,
237 TAmounts<TIn, TOut>
const& stepAmt,
238 TOut
const& ownerGives)
const;
271template <
class TIn,
class TOut>
282 template <
template <
typename,
typename>
typename Offer>
369template <
class TIn,
class TOut>
371 :
public BookStep<TIn, TOut, BookOfferCrossingStep<TIn, TOut>>
387 "ripple::BookOfferCrossingStep::getQuality : nonzero quality");
389 Throw<FlowException>(
tefINTERNAL,
"Offer requires quality.");
390 return *limitQuality;
404 template <
template <
typename,
typename>
typename Offer>
412 bool const offerAttempted)
const
444 strandSrc == offer.owner() && strandDst == offer.owner())
447 if (
auto const key = offer.
key())
448 offers.permRmOffer(*key);
492 Step const* prevStep,
499 return owner == srcAcct
507 Step const* prevStep,
526 Rules const& rules)
const
538 if (!rules.
enabled(fixAMMv1_1))
541 offerType == OfferType::CLOB ||
573template <
class TIn,
class TOut,
class TDerived>
578 return book_ == bs->book_;
582template <
class TIn,
class TOut,
class TDerived>
592 return {std::nullopt, dir};
594 auto const waiveFee = (std::get<OfferType>(*res) == OfferType::AMM)
598 Quality
const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
600 std::get<Quality>(*res),
603 std::get<OfferType>(*res),
608template <
class TIn,
class TOut,
class TDerived>
618 return {std::nullopt, dir};
625 static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
640 Quality
const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
650template <
class TIn,
class TOut,
class TDerived>
658template <
class TIn,
class TOut,
class Offer>
662 TAmounts<TIn, TOut>& ofrAmt,
663 TAmounts<TIn, TOut>& stpAmt,
669 if (limit < stpAmt.in)
673 mulRatio(stpAmt.in, QUALITY_ONE, transferRateIn,
false);
681 ofrAmt = offer.limitIn(ofrAmt, inLmt,
false);
682 stpAmt.out = ofrAmt.out;
684 ofrAmt.out, transferRateOut, QUALITY_ONE,
false);
689template <
class TIn,
class TOut,
class Offer>
693 TAmounts<TIn, TOut>& ofrAmt,
694 TAmounts<TIn, TOut>& stpAmt,
700 if (limit < stpAmt.out)
704 stpAmt.out, transferRateOut, QUALITY_ONE,
false);
705 ofrAmt = offer.limitOut(
710 mulRatio(ofrAmt.in, transferRateIn, QUALITY_ONE,
true);
714template <
class TIn,
class TOut,
class TDerived>
715template <
class Callback>
721 Callback& callback)
const
729 if (
isXRP(
id) ||
id == this->strandDst_)
735 redeems(prevStepDir) ? rate(book_.in.account) : QUALITY_ONE;
738 ownerPaysTransferFee_ ? rate(book_.out.account) : QUALITY_ONE;
741 maxOffersToConsume_, j_);
746 bool const flowCross = afView.
rules().
enabled(featureFlowCross);
747 bool offerAttempted =
false;
749 auto execOffer = [&](
auto& offer) {
753 ofrQ = offer.quality();
754 else if (*ofrQ != offer.quality())
757 if (
static_cast<TDerived const*
>(
this)->limitSelfCrossQuality(
758 strandSrc_, strandDst_, offer, ofrQ, offers, offerAttempted))
763 if (flowCross && (!
isXRP(offer.issueIn().currency)) &&
764 (offer.owner() != offer.issueIn().account))
766 auto const& issuerID = offer.issueIn().account;
771 auto const& ownerID = offer.owner();
772 auto const authFlag =
775 auto const line = afView.
read(
776 keylet::line(ownerID, issuerID, offer.issueIn().currency));
778 if (!line || (((*line)[sfFlags] & authFlag) == 0))
782 if (
auto const key = offer.
key())
783 offers.permRmOffer(*key);
793 if (!
static_cast<TDerived const*
>(
this)->checkQualityThreshold(
797 auto const [ofrInRate, ofrOutRate] = offer.adjustRates(
798 static_cast<TDerived const*
>(
this)->getOfrInRate(
799 prevStep_, offer.owner(), trIn),
800 static_cast<TDerived const*
>(
this)->getOfrOutRate(
801 prevStep_, offer.owner(), strandDst_, trOut));
803 auto ofrAmt = offer.amount();
805 mulRatio(ofrAmt.in, ofrInRate, QUALITY_ONE,
true),
810 mulRatio(ofrAmt.out, ofrOutRate, QUALITY_ONE,
false);
812 auto const funds = offer.isFunded()
814 : offers.ownerFunds();
817 if (funds < ownerGives)
822 ownerGives, QUALITY_ONE, ofrOutRate,
false);
827 ofrAmt = offer.limitOut(ofrAmt, stpAmt.out,
false);
830 mulRatio(ofrAmt.in, ofrInRate, QUALITY_ONE,
true);
833 offerAttempted =
true;
835 offer, ofrAmt, stpAmt, ownerGives, ofrInRate, ofrOutRate);
848 return static_cast<TDerived const*
>(
this)->qualityThreshold(
852 auto ammOffer = getAMMOffer(sb, qualityThreshold);
853 return !ammOffer || execOffer(*ammOffer);
858 if (tryAMM(offers.tip().quality()))
862 if (!execOffer(offers.tip()))
864 }
while (offers.step());
870 tryAMM(std::nullopt);
873 return {offers.permToRemove(), counter.
count()};
876template <
class TIn,
class TOut,
class TDerived>
877template <
template <
typename,
typename>
typename Offer>
882 TAmounts<TIn, TOut>
const& ofrAmt,
883 TAmounts<TIn, TOut>
const& stepAmt,
884 TOut
const& ownerGives)
const
886 if (!offer.checkInvariant(ofrAmt, j_))
892 Throw<FlowException>(
900 auto const dr = offer.send(
907 Throw<FlowException>(dr);
913 auto const cr = offer.send(
920 Throw<FlowException>(cr);
923 offer.consume(sb, ofrAmt);
926template <
class TIn,
class TOut,
class TDerived>
933 return ammLiquidity_->getOffer(view, clobQuality);
937template <
class TIn,
class TOut,
class TDerived>
944 auto const lobQuality =
965 return static_cast<TDerived const*
>(
this)->qualityThreshold(
970 if (
auto const ammOffer = getAMMOffer(view, qualityThreshold); ammOffer &&
971 ((lobQuality && ammOffer->quality() > lobQuality) || !lobQuality))
977template <
class TIn,
class TOut,
class TDerived>
982 if (
auto const res = tip(view); !res)
984 else if (
auto const q = std::get_if<Quality>(&(*res)))
991template <
class TIn,
class TOut,
class TDerived>
995 if (
auto const res = tip(view); !res)
997 else if (
auto const q = std::get_if<Quality>(&(*res)))
1000 return std::get<AMMOffer<TIn, TOut>>(*res).getQualityFunc();
1003template <
class TCollection>
1009 return TResult{beast::zero};
1013template <
class TIn,
class TOut,
class TDerived>
1018 boost::container::flat_set<uint256>& ofrsToRm,
1023 TAmounts<TIn, TOut> result(beast::zero, beast::zero);
1025 auto remainingOut =
out;
1027 boost::container::flat_multiset<TIn> savedIns;
1028 savedIns.reserve(64);
1029 boost::container::flat_multiset<TOut> savedOuts;
1030 savedOuts.reserve(64);
1036 auto eachOffer = [&](
auto& offer,
1037 TAmounts<TIn, TOut>
const& ofrAmt,
1038 TAmounts<TIn, TOut>
const& stpAmt,
1039 TOut
const& ownerGives,
1042 if (remainingOut <= beast::zero)
1045 if (stpAmt.out <= remainingOut)
1047 savedIns.insert(stpAmt.in);
1048 savedOuts.insert(stpAmt.out);
1049 result = TAmounts<TIn, TOut>(
sum(savedIns),
sum(savedOuts));
1050 remainingOut =
out - result.out;
1051 this->consumeOffer(sb, offer, ofrAmt, stpAmt, ownerGives);
1058 auto ofrAdjAmt = ofrAmt;
1059 auto stpAdjAmt = stpAmt;
1060 auto ownerGivesAdj = ownerGives;
1069 remainingOut = beast::zero;
1070 savedIns.insert(stpAdjAmt.in);
1071 savedOuts.insert(remainingOut);
1072 result.in =
sum(savedIns);
1074 this->consumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1081 return offer.fully_consumed();
1086 auto const prevStepDebtDir = [&] {
1091 auto const r = forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1092 boost::container::flat_set<uint256> toRm = std::move(std::get<0>(r));
1094 offersUsed_ = offersConsumed;
1097 if (offersConsumed >= maxOffersToConsume_)
1103 cache_.emplace(beast::zero, beast::zero);
1104 return {beast::zero, beast::zero};
1113 switch (remainingOut.signum())
1118 <<
"BookStep remainingOut < 0 " <<
to_string(remainingOut);
1119 UNREACHABLE(
"ripple::BookStep::revImp : remaining less than zero");
1120 cache_.emplace(beast::zero, beast::zero);
1121 return {beast::zero, beast::zero};
1130 cache_.emplace(result.in, result.out);
1131 return {result.in, result.out};
1134template <
class TIn,
class TOut,
class TDerived>
1139 boost::container::flat_set<uint256>& ofrsToRm,
1142 XRPL_ASSERT(cache_,
"ripple::BookStep::fwdImp : cache is set");
1144 TAmounts<TIn, TOut> result(beast::zero, beast::zero);
1146 auto remainingIn =
in;
1148 boost::container::flat_multiset<TIn> savedIns;
1149 savedIns.reserve(64);
1150 boost::container::flat_multiset<TOut> savedOuts;
1151 savedOuts.reserve(64);
1155 auto eachOffer = [&](
auto& offer,
1156 TAmounts<TIn, TOut>
const& ofrAmt,
1157 TAmounts<TIn, TOut>
const& stpAmt,
1158 TOut
const& ownerGives,
1162 cache_,
"ripple::BookStep::fwdImp::eachOffer : cache is set");
1164 if (remainingIn <= beast::zero)
1167 bool processMore =
true;
1168 auto ofrAdjAmt = ofrAmt;
1169 auto stpAdjAmt = stpAmt;
1170 auto ownerGivesAdj = ownerGives;
1172 typename boost::container::flat_multiset<TOut>::const_iterator lastOut;
1173 if (stpAmt.in <= remainingIn)
1175 savedIns.insert(stpAmt.in);
1176 lastOut = savedOuts.insert(stpAmt.out);
1177 result = TAmounts<TIn, TOut>(
sum(savedIns),
sum(savedOuts));
1191 savedIns.insert(remainingIn);
1192 lastOut = savedOuts.insert(stpAdjAmt.out);
1193 result.out =
sum(savedOuts);
1196 processMore =
false;
1199 if (result.out > cache_->out && result.in <= cache_->in)
1208 auto const lastOutAmt = *lastOut;
1209 savedOuts.erase(lastOut);
1210 auto const remainingOut = cache_->out -
sum(savedOuts);
1211 auto ofrAdjAmtRev = ofrAmt;
1212 auto stpAdjAmtRev = stpAmt;
1213 auto ownerGivesAdjRev = ownerGives;
1223 if (stpAdjAmtRev.in == remainingIn)
1226 result.out = cache_->out;
1229 savedIns.insert(result.in);
1231 savedOuts.insert(result.out);
1233 ofrAdjAmt = ofrAdjAmtRev;
1234 stpAdjAmt.in = remainingIn;
1235 stpAdjAmt.out = remainingOut;
1236 ownerGivesAdj = ownerGivesAdjRev;
1242 savedOuts.insert(lastOutAmt);
1246 remainingIn =
in - result.in;
1247 this->consumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1253 return processMore || offer.fully_consumed();
1257 auto const prevStepDebtDir = [&] {
1262 auto const r = forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1263 boost::container::flat_set<uint256> toRm = std::move(std::get<0>(r));
1265 offersUsed_ = offersConsumed;
1268 if (offersConsumed >= maxOffersToConsume_)
1274 cache_.emplace(beast::zero, beast::zero);
1275 return {beast::zero, beast::zero};
1284 switch (remainingIn.signum())
1289 <<
"BookStep remainingIn < 0 " <<
to_string(remainingIn);
1290 UNREACHABLE(
"ripple::BookStep::fwdImp : remaining less than zero");
1291 cache_.emplace(beast::zero, beast::zero);
1292 return {beast::zero, beast::zero};
1301 cache_.emplace(result.in, result.out);
1302 return {result.in, result.out};
1305template <
class TIn,
class TOut,
class TDerived>
1314 JLOG(j_.
trace()) <<
"Expected valid cache in validFwd";
1318 auto const savCache = *cache_;
1322 boost::container::flat_set<uint256> dummy;
1323 fwdImp(sb, afView, dummy, get<TIn>(
in));
1325 catch (FlowException
const&)
1330 if (!(
checkNear(savCache.in, cache_->in) &&
1333 JLOG(j_.
warn()) <<
"Strand re-execute check failed."
1334 <<
" ExpectedIn: " <<
to_string(savCache.in)
1335 <<
" CachedIn: " <<
to_string(cache_->in)
1336 <<
" ExpectedOut: " <<
to_string(savCache.out)
1337 <<
" CachedOut: " <<
to_string(cache_->out);
1343template <
class TIn,
class TOut,
class TDerived>
1347 if (book_.in == book_.out)
1349 JLOG(j_.
debug()) <<
"BookStep: Book with same in and out issuer "
1355 JLOG(j_.
debug()) <<
"Book: currency is inconsistent with issuer."
1365 JLOG(j_.
debug()) <<
"BookStep: loop detected: " << *
this;
1371 JLOG(j_.
debug()) <<
"BookStep: loop detected: " << *
this;
1375 auto issuerExists = [](
ReadView const& view,
Issue const& iss) ->
bool {
1379 if (!issuerExists(ctx.
view, book_.in) || !issuerExists(ctx.
view, book_.out))
1381 JLOG(j_.
debug()) <<
"BookStep: deleted issuer detected: " << *
this;
1389 auto const& view = ctx.
view;
1390 auto const& cur = book_.in.account;
1395 if ((*sle)[sfFlags] &
1409template <
class TIn,
class TOut,
class TDerived>
1414 return book == bs->book();
1423 if (inXRP && outXRP)
1425 UNREACHABLE(
"ripple::test::bookStepEqual : no XRP to XRP book step");
1428 if (inXRP && !outXRP)
1433 if (!inXRP && outXRP)
1438 if (!inXRP && !outXRP)
1449template <
class TIn,
class TOut>
1457 auto offerCrossingStep =
1458 std::make_unique<BookOfferCrossingStep<TIn, TOut>>(ctx,
in,
out);
1459 ter = offerCrossingStep->check(ctx);
1460 r = std::move(offerCrossingStep);
1465 std::make_unique<BookPaymentStep<TIn, TOut>>(ctx,
in,
out);
1466 ter = paymentStep->check(ctx);
1467 r = std::move(paymentStep);
1470 return {ter,
nullptr};
1478 return make_BookStepHelper<IOUAmount, IOUAmount>(ctx,
in,
out);
1484 return make_BookStepHelper<IOUAmount, XRPAmount>(ctx,
in,
xrpIssue());
1490 return make_BookStepHelper<XRPAmount, IOUAmount>(ctx,
xrpIssue(),
out);
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
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
static Quality getQuality(std::optional< Quality > const &limitQuality)
BookOfferCrossingStep(StrandContext const &ctx, Issue const &in, Issue const &out)
bool checkQualityThreshold(Quality const &quality) const
std::string logString() const override
std::uint32_t getOfrOutRate(Step const *prevStep, AccountID const &owner, AccountID const &strandDst, std::uint32_t trOut) 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
Quality const qualityThreshold_
std::optional< Quality > qualityThreshold(Quality const &lobQuality) const
Quality adjustQualityWithFees(ReadView const &v, Quality const &ofrQ, DebtDirection prevStepDir, WaiveTransferFee waiveFee, OfferType offerType, Rules const &rules) 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 getOfrOutRate(Step const *, AccountID const &, AccountID const &, std::uint32_t trOut) const
BookPaymentStep()=default
std::uint32_t getOfrInRate(Step const *, AccountID const &, std::uint32_t trIn) const
bool checkQualityThreshold(Quality const &quality) const
std::optional< Quality > qualityThreshold(Quality const &lobQuality) const
std::string logString() const override
std::optional< AMMOffer< TIn, TOut > > getAMMOffer(ReadView const &view, std::optional< Quality > const &clobQuality) const
std::optional< AMMLiquidity< TIn, TOut > > ammLiquidity_
friend bool operator==(BookStep const &lhs, BookStep const &rhs)
std::uint32_t offersUsed() const override
std::optional< Book > bookStepBook() const override
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::optional< std::pair< Quality, OfferType > > tipOfferQuality(ReadView const &view) const
void consumeOffer(PaymentSandbox &sb, Offer< TIn, TOut > &offer, TAmounts< TIn, TOut > const &ofrAmt, TAmounts< TIn, TOut > const &stepAmt, TOut const &ownerGives) const
std::pair< std::optional< QualityFunction >, DebtDirection > getQualityFunc(ReadView const &v, DebtDirection prevStepDir) const override
TER check(StrandContext const &ctx) const
std::pair< boost::container::flat_set< uint256 >, std::uint32_t > forEachOffer(PaymentSandbox &sb, ApplyView &afView, DebtDirection prevStepDebtDir, Callback &callback) const
std::pair< bool, EitherAmount > validFwd(PaymentSandbox &sb, ApplyView &afView, EitherAmount const &in) override
Book const & book() const
std::optional< EitherAmount > cachedIn() const override
uint32_t const maxOffersToConsume_
bool equal(Step const &rhs) const override
DebtDirection debtDirection(ReadView const &sb, StrandDirection dir) const override
std::pair< TIn, TOut > revImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, TOut const &out)
Step const *const prevStep_
friend bool operator!=(BookStep const &lhs, BookStep const &rhs)
std::string logStringImpl(char const *name) const
BookStep(StrandContext const &ctx, Issue const &in, Issue const &out)
std::pair< TIn, TOut > fwdImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, TIn const &in)
std::optional< QualityFunction > tipOfferQualityF(ReadView const &view) const
bool inactive() const override
static uint32_t getMaxOffersToConsume(StrandContext const &ctx)
std::optional< std::variant< Quality, AMMOffer< TIn, TOut > > > tip(ReadView const &view) const
std::pair< std::optional< Quality >, DebtDirection > qualityUpperBound(ReadView const &v, DebtDirection prevStepDir) const override
bool const ownerPaysTransferFee_
std::optional< Cache > cache_
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.
Floating point representation of amounts with high dynamic range.
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 std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
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< Book > bookStepBook() const
If this step is a BookStep, return the book.
virtual std::optional< AccountID > directStepSrcAcct() const
If this step is DirectStepI (IOU->IOU direct step), return the src account.
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.
static bool equalHelper(Step const &step, ripple::Book const &book)
bool bookStepEqual(Step const &step, ripple::Book const &book)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
static auto sum(TCollection const &col)
bool isConsistent(Book const &book)
bool isXRP(AccountID const &c)
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)
std::uint16_t getTradingFee(ReadView const &view, SLE const &ammSle, AccountID const &account)
Get AMM trading fee for the given account.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
static bool isDefaultPath(STPath const &path)
std::uint64_t getRate(STAmount const &offerOut, STAmount const &offerIn)
Quality composed_quality(Quality const &lhs, Quality const &rhs)
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 > > make_BookStepXI(StrandContext const &ctx, Issue const &out)
std::pair< TER, std::unique_ptr< Step > > make_BookStepIX(StrandContext const &ctx, Issue const &in)
bool checkNear(IOUAmount const &expected, IOUAmount const &actual)
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)
static std::pair< TER, std::unique_ptr< Step > > make_BookStepHelper(StrandContext const &ctx, Issue const &in, Issue const &out)
std::pair< TER, std::unique_ptr< Step > > make_BookStepII(StrandContext const &ctx, Issue const &in, Issue const &out)
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
std::string to_string(base_uint< Bits, Tag > const &a)
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
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.