1#include <xrpl/tx/paths/AMMOffer.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/contract.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/helpers/AMMHelpers.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/Asset.h>
11#include <xrpl/protocol/Concepts.h>
12#include <xrpl/protocol/Feature.h>
13#include <xrpl/protocol/IOUAmount.h>
14#include <xrpl/protocol/MPTAmount.h>
15#include <xrpl/protocol/Quality.h>
16#include <xrpl/protocol/QualityFunction.h>
17#include <xrpl/protocol/Rules.h>
18#include <xrpl/protocol/XRPAmount.h>
19#include <xrpl/tx/paths/AMMLiquidity.h>
25template <StepAmount TIn, StepAmount TOut>
36template <StepAmount TIn, StepAmount TOut>
43template <StepAmount TIn, StepAmount TOut>
50template <StepAmount TIn, StepAmount TOut>
57template <StepAmount TIn, StepAmount TOut>
64template <StepAmount TIn, StepAmount TOut>
80template <StepAmount TIn, StepAmount TOut>
97 return quality().ceilOutStrict(offerAmount, limit, roundUp);
105template <StepAmount TIn, StepAmount TOut>
114 rules && rules->enabled(fixReducedOffersV2))
115 return quality().ceilInStrict(offerAmount, limit, roundUp);
117 return quality().ceilIn(offerAmount, limit);
122template <StepAmount TIn, StepAmount TOut>
131template <StepAmount TIn, StepAmount TOut>
137 JLOG(j.
error()) <<
"AMMOffer::checkInvariant failed: consumed " <<
to_string(consumed.
in)
145 auto const newBalances =
147 Number const newProduct = newBalances.in * newBalances.out;
155 <<
" product/newProduct " << product <<
" " << newProduct <<
" diff "
A generic endpoint for log messages.
AMMLiquidity class provides AMM offers to BookStep class.
Represents synthetic AMM offer in BookStep.
Asset const & assetOut() const
AMMOffer(AMMLiquidity< TIn, TOut > const &ammLiquidity, TAmounts< TIn, TOut > const &amounts, TAmounts< TIn, TOut > const &balances, Quality const &quality)
TAmounts< TIn, TOut > const amounts_
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
TAmounts< TIn, TOut > const & amount() const
QualityFunction getQualityFunc() const
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offerAmount, TOut const &limit, bool roundUp) const
Limit out of the provided offer.
Asset const & assetIn() const
TAmounts< TIn, TOut > const balances_
AMMLiquidity< TIn, TOut > const & ammLiquidity_
bool checkInvariant(TAmounts< TIn, TOut > const &consumed, beast::Journal j) const
Check the new pool product is greater or equal to the old pool product or if decreases then within so...
AccountID const & owner() const
Quality quality() const noexcept
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offerAmount, TIn const &limit, bool roundUp) const
Limit in of the provided offer.
Writeable view to a ledger, for applying a transaction.
Number is a floating point type that can represent a wide range of values.
Average quality of a path as a function of out: q(out) = m * out + b, where m = -1 / poolGets,...
Represents the logical ratio of output currency to input currency.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< Rules > const & getCurrentTransactionRules()
TOut swapAssetIn(TAmounts< TIn, TOut > const &pool, TIn const &assetIn, std::uint16_t tfee)
AMM pool invariant - the product (A * B) after swap in/out has to remain at least the same: (A + in) ...
std::string to_string(BaseUInt< Bits, Tag > const &a)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TIn swapAssetOut(TAmounts< TIn, TOut > const &pool, TOut const &assetOut, std::uint16_t tfee)
Swap assetOut out of the pool and swap in a proportional amount of the other asset.
bool withinRelativeDistance(Quality const &calcQuality, Quality const &reqQuality, Number const &dist)
Check if the relative distance between the qualities is within the requested distance.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Represents a pair of input and output currencies.