20#ifndef RIPPLE_APP_BOOK_OFFER_H_INCLUDED
21#define RIPPLE_APP_BOOK_OFFER_H_INCLUDED
23#include <xrpl/basics/Log.h>
24#include <xrpl/basics/contract.h>
25#include <xrpl/ledger/View.h>
26#include <xrpl/protocol/Quality.h>
27#include <xrpl/protocol/Rules.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/STLedgerEntry.h>
35template <
class TIn,
class TOut>
50template <
class TIn = STAmount,
class TOut = STAmount>
92 TAmounts<TIn, TOut>
const&
114 Throw<std::logic_error>(
"can't consume more than is available.");
117 Throw<std::logic_error>(
"can't produce more than is available.");
143 TAmounts<TIn, TOut>
const& offrAmt,
148 limitIn(TAmounts<TIn, TOut>
const& offrAmt, TIn
const& limit,
bool roundUp)
151 template <
typename... Args>
166 return {ofrInRate, ofrOutRate};
182 <<
"AMMOffer::checkInvariant failed: consumed "
197template <
class TIn,
class TOut>
201 , m_account(m_entry->getAccountID(sfAccount))
203 auto const tp =
m_entry->getFieldAmount(sfTakerPays);
204 auto const tg =
m_entry->getFieldAmount(sfTakerGets);
207 this->
issIn_ = tp.issue();
217 , m_account(m_entry->getAccountID(sfAccount))
219 m_entry->getFieldAmount(sfTakerPays),
220 m_entry->getFieldAmount(sfTakerGets))
224template <
class TIn,
class TOut>
229 UNREACHABLE(
"ripple::TOffer::setFieldAmounts : must be specialized");
231 static_assert(
sizeof(TOut) == -1,
"Must be specialized");
235template <
class TIn,
class TOut>
238 TAmounts<TIn, TOut>
const& offrAmt,
243 rules && rules->enabled(fixReducedOffersV1))
248 return quality().ceil_out_strict(offrAmt, limit, roundUp);
249 return m_quality.ceil_out(offrAmt, limit);
252template <
class TIn,
class TOut>
255 TAmounts<TIn, TOut>
const& offrAmt,
260 rules && rules->enabled(fixReducedOffersV2))
265 return quality().ceil_in_strict(offrAmt, limit, roundUp);
266 return m_quality.ceil_in(offrAmt, limit);
269template <
class TIn,
class TOut>
270template <
typename... Args>
281 m_entry->setFieldAmount(sfTakerPays, m_amounts.in);
282 m_entry->setFieldAmount(sfTakerGets, m_amounts.out);
289 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
290 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
297 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
298 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out));
305 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in));
306 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
309template <
class TIn,
class TOut>
320 return m_amounts.in.issue();
323template <
class TIn,
class TOut>
327 return this->issOut_;
334 return m_amounts.out.issue();
337template <
class TIn,
class TOut>
341 return os << offer.id();
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
A currency issued by an account.
bool fully_consumed() const
Returns true if no more funds can flow through this offer.
Issue const & issueIn() const
TOffer(SLE::pointer const &entry, Quality quality)
Issue const & issueOut() const
Quality quality() const noexcept
Returns the quality of the offer.
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offrAmt, TIn const &limit, bool roundUp) const
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offrAmt, TOut const &limit, bool roundUp) const
AccountID const & owner() const
Returns the account id of the offer's owner.
bool checkInvariant(TAmounts< TIn, TOut > const &consumed, beast::Journal j) const
Check any required invariant.
TAmounts< TIn, TOut > const & amount() const
Returns the in and out amounts.
std::optional< uint256 > key() const
static std::pair< std::uint32_t, std::uint32_t > adjustRates(std::uint32_t ofrInRate, std::uint32_t ofrOutRate)
static TER send(Args &&... args)
TAmounts< TIn, TOut > m_amounts
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
Adjusts the offer to indicate that we consumed some (or all) of it.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isFeatureEnabled(uint256 const &feature)
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
std::string to_string(base_uint< Bits, Tag > const &a)
std::optional< Rules > const & getCurrentTransactionRules()