1#include <xrpl/basics/Log.h>
2#include <xrpl/basics/contract.h>
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/ledger/PaymentSandbox.h>
5#include <xrpl/ledger/helpers/AccountRootHelpers.h>
6#include <xrpl/protocol/Book.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/IOUAmount.h>
9#include <xrpl/protocol/Quality.h>
10#include <xrpl/protocol/XRPAmount.h>
11#include <xrpl/tx/paths/AMMLiquidity.h>
12#include <xrpl/tx/paths/AMMOffer.h>
13#include <xrpl/tx/paths/OfferStream.h>
14#include <xrpl/tx/paths/detail/FlatSets.h>
15#include <xrpl/tx/paths/detail/Steps.h>
16#include <xrpl/tx/transactors/dex/AMMUtils.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)
137 boost::container::flat_set<uint256>& ofrsToRm,
144 boost::container::flat_set<uint256>& ofrsToRm,
181 return !(lhs == rhs);
192 template <
class Callback>
198 Callback& callback)
const;
201 template <
template <
typename,
typename>
typename Offer>
206 TAmounts<TIn, TOut>
const& ofrAmt,
207 TAmounts<TIn, TOut>
const& stepAmt,
208 TOut
const& ownerGives)
const;
242template <
class TIn,
class TOut>
257 template <
template <
typename,
typename>
typename Offer>
338template <
class TIn,
class TOut>
351 XRPL_ASSERT(limitQuality,
"xrpl::BookOfferCrossingStep::getQuality : nonzero quality");
353 Throw<FlowException>(
tefINTERNAL,
"Offer requires quality.");
354 return *limitQuality;
365 template <
template <
typename,
typename>
typename Offer>
373 bool const offerAttempted)
const
405 strandDst == offer.owner())
408 if (
auto const key = offer.
key())
409 offers.permRmOffer(*key);
456 return owner == srcAcct
464 Step const* prevStep,
483 Rules const& rules)
const
495 if (!rules.
enabled(fixAMMv1_1))
499 if (offerType == OfferType::CLOB ||
532template <
class TIn,
class TOut,
class TDerived>
537 return book_ == bs->book_;
541template <
class TIn,
class TOut,
class TDerived>
554 Quality
const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
559template <
class TIn,
class TOut,
class TDerived>
573 auto const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
583 Quality
const q =
static_cast<TDerived const*
>(
this)->adjustQualityWithFees(
588template <
class TIn,
class TOut,
class TDerived>
596template <
class TIn,
class TOut,
class Offer>
600 TAmounts<TIn, TOut>& ofrAmt,
601 TAmounts<TIn, TOut>& stpAmt,
607 if (limit < stpAmt.in)
610 auto const inLmt =
mulRatio(stpAmt.in, QUALITY_ONE, transferRateIn,
false);
618 ofrAmt = offer.limitIn(ofrAmt, inLmt,
false);
619 stpAmt.out = ofrAmt.out;
620 ownerGives =
mulRatio(ofrAmt.out, transferRateOut, QUALITY_ONE,
false);
625template <
class TIn,
class TOut,
class Offer>
629 TAmounts<TIn, TOut>& ofrAmt,
630 TAmounts<TIn, TOut>& stpAmt,
636 if (limit < stpAmt.out)
639 ownerGives =
mulRatio(stpAmt.out, transferRateOut, QUALITY_ONE,
false);
640 ofrAmt = offer.limitOut(
644 stpAmt.in =
mulRatio(ofrAmt.in, transferRateIn, QUALITY_ONE,
true);
648template <
class TIn,
class TOut,
class TDerived>
649template <
class Callback>
655 Callback& callback)
const
663 if (
isXRP(
id) ||
id == this->strandDst_)
670 std::uint32_t const trOut = ownerPaysTransferFee_ ? rate(book_.out.account) : QUALITY_ONE;
676 bool offerAttempted =
false;
678 auto execOffer = [&](
auto& offer) {
683 ofrQ = offer.quality();
685 else if (*ofrQ != offer.quality())
690 if (
static_cast<TDerived const*
>(
this)->limitSelfCrossQuality(
691 strandSrc_, strandDst_, offer, ofrQ, offers, offerAttempted))
696 if (!
isXRP(offer.issueIn().currency) && offer.owner() != offer.issueIn().account)
698 auto const& issuerID = offer.issueIn().account;
700 if (issuer && ((*issuer)[sfFlags] & lsfRequireAuth))
703 auto const& ownerID = offer.owner();
704 auto const authFlag = issuerID > ownerID ? lsfHighAuth : lsfLowAuth;
709 if (!line || (((*line)[sfFlags] & authFlag) == 0))
713 if (
auto const key = offer.
key())
714 offers.permRmOffer(*key);
726 if (!
static_cast<TDerived const*
>(
this)->checkQualityThreshold(offer.quality()))
729 auto const [ofrInRate, ofrOutRate] = offer.adjustRates(
730 static_cast<TDerived const*
>(
this)->getOfrInRate(prevStep_, offer.owner(), trIn),
731 static_cast<TDerived const*
>(
this)->getOfrOutRate(
732 prevStep_, offer.owner(), strandDst_, trOut));
734 auto ofrAmt = offer.amount();
735 TAmounts stpAmt{
mulRatio(ofrAmt.in, ofrInRate, QUALITY_ONE,
true), ofrAmt.out};
738 auto ownerGives =
mulRatio(ofrAmt.out, ofrOutRate, QUALITY_ONE,
false);
740 auto const funds = offer.isFunded()
742 : offers.ownerFunds();
745 if (funds < ownerGives)
749 stpAmt.out =
mulRatio(ownerGives, QUALITY_ONE, ofrOutRate,
false);
754 ofrAmt = offer.limitOut(ofrAmt, stpAmt.out,
false);
756 stpAmt.in =
mulRatio(ofrAmt.in, ofrInRate, QUALITY_ONE,
true);
759 offerAttempted =
true;
760 return callback(offer, ofrAmt, stpAmt, ownerGives, ofrInRate, ofrOutRate);
773 return static_cast<TDerived const*
>(
this)->qualityThreshold(*lobQuality);
776 auto ammOffer = getAMMOffer(sb, qualityThreshold);
777 return !ammOffer || execOffer(*ammOffer);
782 if (tryAMM(offers.tip().quality()))
786 if (!execOffer(offers.tip()))
788 }
while (offers.step());
797 return {offers.permToRemove(), counter.
count()};
800template <
class TIn,
class TOut,
class TDerived>
801template <
template <
typename,
typename>
typename Offer>
806 TAmounts<TIn, TOut>
const& ofrAmt,
807 TAmounts<TIn, TOut>
const& stepAmt,
808 TOut
const& ownerGives)
const
810 if (!offer.checkInvariant(ofrAmt, j_))
824 offer.send(sb, book_.in.account, offer.owner(),
toSTAmount(ofrAmt.in, book_.in), j_);
826 Throw<FlowException>(dr);
833 offer.send(sb, offer.owner(), book_.out.account,
toSTAmount(ownerGives, book_.out), j_);
835 Throw<FlowException>(cr);
838 offer.consume(sb, ofrAmt);
841template <
class TIn,
class TOut,
class TDerived>
848 return ammLiquidity_->getOffer(view, clobQuality);
852template <
class TIn,
class TOut,
class TDerived>
879 return static_cast<TDerived const*
>(
this)->qualityThreshold(*lobQuality);
883 if (
auto const ammOffer = getAMMOffer(view, qualityThreshold);
884 ammOffer && ((lobQuality && ammOffer->quality() > lobQuality) || !lobQuality))
890template <
class TIn,
class TOut,
class TDerived>
895 auto const res = tip(view);
908template <
class TIn,
class TOut,
class TDerived>
912 auto const res = tip(view);
925template <
class TCollection>
927sum(TCollection
const& col)
931 return TResult{beast::zero};
935template <
class TIn,
class TOut,
class TDerived>
940 boost::container::flat_set<uint256>& ofrsToRm,
945 TAmounts<TIn, TOut> result(beast::zero, beast::zero);
947 auto remainingOut =
out;
949 boost::container::flat_multiset<TIn> savedIns;
950 savedIns.reserve(64);
951 boost::container::flat_multiset<TOut> savedOuts;
952 savedOuts.reserve(64);
958 auto eachOffer = [&](
auto& offer,
959 TAmounts<TIn, TOut>
const& ofrAmt,
960 TAmounts<TIn, TOut>
const& stpAmt,
961 TOut
const& ownerGives,
964 if (remainingOut <= beast::zero)
967 if (stpAmt.out <= remainingOut)
969 savedIns.insert(stpAmt.in);
970 savedOuts.insert(stpAmt.out);
971 result = TAmounts<TIn, TOut>(
sum(savedIns),
sum(savedOuts));
972 remainingOut =
out - result.out;
973 this->consumeOffer(sb, offer, ofrAmt, stpAmt, ownerGives);
979 auto ofrAdjAmt = ofrAmt;
980 auto stpAdjAmt = stpAmt;
981 auto ownerGivesAdj = ownerGives;
990 remainingOut = beast::zero;
991 savedIns.insert(stpAdjAmt.in);
992 savedOuts.insert(remainingOut);
993 result.in =
sum(savedIns);
995 this->consumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1002 return offer.fully_consumed();
1006 auto const prevStepDebtDir = [&] {
1011 auto const r = forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1012 boost::container::flat_set<uint256>
const toRm = std::move(
std::get<0>(r));
1014 offersUsed_ = offersConsumed;
1018 if (offersConsumed >= MaxOffersToConsume)
1024 switch (remainingOut.signum())
1029 JLOG(j_.
error()) <<
"BookStep remainingOut < 0 " <<
to_string(remainingOut);
1030 UNREACHABLE(
"xrpl::BookStep::revImp : remaining less than zero");
1031 cache_.emplace(beast::zero, beast::zero);
1032 return {beast::zero, beast::zero};
1042 cache_.emplace(result.in, result.out);
1043 return {result.in, result.out};
1046template <
class TIn,
class TOut,
class TDerived>
1051 boost::container::flat_set<uint256>& ofrsToRm,
1054 XRPL_ASSERT(cache_,
"xrpl::BookStep::fwdImp : cache is set");
1056 TAmounts<TIn, TOut> result(beast::zero, beast::zero);
1058 auto remainingIn =
in;
1060 boost::container::flat_multiset<TIn> savedIns;
1061 savedIns.reserve(64);
1062 boost::container::flat_multiset<TOut> savedOuts;
1063 savedOuts.reserve(64);
1067 auto eachOffer = [&](
auto& offer,
1068 TAmounts<TIn, TOut>
const& ofrAmt,
1069 TAmounts<TIn, TOut>
const& stpAmt,
1070 TOut
const& ownerGives,
1073 XRPL_ASSERT(cache_,
"xrpl::BookStep::fwdImp::eachOffer : cache is set");
1075 if (remainingIn <= beast::zero)
1078 bool processMore =
true;
1079 auto ofrAdjAmt = ofrAmt;
1080 auto stpAdjAmt = stpAmt;
1081 auto ownerGivesAdj = ownerGives;
1083 typename boost::container::flat_multiset<TOut>::const_iterator lastOut;
1084 if (stpAmt.in <= remainingIn)
1086 savedIns.insert(stpAmt.in);
1087 lastOut = savedOuts.insert(stpAmt.out);
1088 result = TAmounts<TIn, TOut>(
sum(savedIns),
sum(savedOuts));
1102 savedIns.insert(remainingIn);
1103 lastOut = savedOuts.insert(stpAdjAmt.out);
1104 result.out =
sum(savedOuts);
1107 processMore =
false;
1110 if (result.out > cache_->out && result.in <= cache_->in)
1119 auto const lastOutAmt = *lastOut;
1120 savedOuts.erase(lastOut);
1121 auto const remainingOut = cache_->out -
sum(savedOuts);
1122 auto ofrAdjAmtRev = ofrAmt;
1123 auto stpAdjAmtRev = stpAmt;
1124 auto ownerGivesAdjRev = ownerGives;
1134 if (stpAdjAmtRev.in == remainingIn)
1137 result.out = cache_->out;
1140 savedIns.insert(result.in);
1142 savedOuts.insert(result.out);
1144 ofrAdjAmt = ofrAdjAmtRev;
1145 stpAdjAmt.in = remainingIn;
1146 stpAdjAmt.out = remainingOut;
1147 ownerGivesAdj = ownerGivesAdjRev;
1153 savedOuts.insert(lastOutAmt);
1157 remainingIn =
in - result.in;
1158 this->consumeOffer(sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
1164 return processMore || offer.fully_consumed();
1168 auto const prevStepDebtDir = [&] {
1173 auto const r = forEachOffer(sb, afView, prevStepDebtDir, eachOffer);
1174 boost::container::flat_set<uint256>
const toRm = std::move(
std::get<0>(r));
1176 offersUsed_ = offersConsumed;
1180 if (offersConsumed >= MaxOffersToConsume)
1186 switch (remainingIn.signum())
1191 JLOG(j_.
error()) <<
"BookStep remainingIn < 0 " <<
to_string(remainingIn);
1192 UNREACHABLE(
"xrpl::BookStep::fwdImp : remaining less than zero");
1193 cache_.emplace(beast::zero, beast::zero);
1194 return {beast::zero, beast::zero};
1204 cache_.emplace(result.in, result.out);
1205 return {result.in, result.out};
1208template <
class TIn,
class TOut,
class TDerived>
1217 JLOG(j_.
trace()) <<
"Expected valid cache in validFwd";
1221 auto const savCache = *cache_;
1225 boost::container::flat_set<uint256> dummy;
1226 fwdImp(sb, afView, dummy, get<TIn>(
in));
1228 catch (FlowException
const&)
1235 JLOG(j_.
warn()) <<
"Strand re-execute check failed."
1236 <<
" ExpectedIn: " <<
to_string(savCache.in)
1237 <<
" CachedIn: " <<
to_string(cache_->in)
1238 <<
" ExpectedOut: " <<
to_string(savCache.out)
1239 <<
" CachedOut: " <<
to_string(cache_->out);
1245template <
class TIn,
class TOut,
class TDerived>
1249 if (book_.in == book_.out)
1251 JLOG(j_.
debug()) <<
"BookStep: Book with same in and out issuer " << *
this;
1256 JLOG(j_.
debug()) <<
"Book: currency is inconsistent with issuer." << *
this;
1265 JLOG(j_.
debug()) <<
"BookStep: loop detected: " << *
this;
1271 JLOG(j_.
debug()) <<
"BookStep: loop detected: " << *
this;
1275 auto issuerExists = [](
ReadView const& view,
Issue const& iss) ->
bool {
1279 if (!issuerExists(ctx.
view, book_.in) || !issuerExists(ctx.
view, book_.out))
1281 JLOG(j_.
debug()) <<
"BookStep: deleted issuer detected: " << *
this;
1289 auto const& view = ctx.
view;
1290 auto const& cur = book_.in.account;
1295 if (((*sle)[sfFlags] & ((cur > *prev) ? lsfHighNoRipple : lsfLowNoRipple)) != 0u)
1308template <
class TIn,
class TOut,
class TDerived>
1313 return book == bs->book();
1322 if (inXRP && outXRP)
1325 UNREACHABLE(
"xrpl::test::bookStepEqual : no XRP to XRP book step");
1329 if (inXRP && !outXRP)
1330 return equalHelper<XRPAmount, IOUAmount, BookPaymentStep<XRPAmount, IOUAmount>>(step, book);
1331 if (!inXRP && outXRP)
1332 return equalHelper<IOUAmount, XRPAmount, BookPaymentStep<IOUAmount, XRPAmount>>(step, book);
1333 if (!inXRP && !outXRP)
1334 return equalHelper<IOUAmount, IOUAmount, BookPaymentStep<IOUAmount, IOUAmount>>(step, book);
1341template <
class TIn,
class TOut>
1350 ter = offerCrossingStep->check(ctx);
1351 r = std::move(offerCrossingStep);
1356 ter = paymentStep->check(ctx);
1357 r = std::move(paymentStep);
1360 return {ter,
nullptr};
1368 return make_BookStepHelper<IOUAmount, IOUAmount>(ctx,
in,
out);
1374 return make_BookStepHelper<IOUAmount, XRPAmount>(ctx,
in,
xrpIssue());
1380 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
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
BookPaymentStep(StrandContext const &ctx, Issue const &in, Issue const &out)
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)
bool isTesSuccess(TER x) noexcept
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.