1#ifndef XRPL_APP_BOOK_OFFER_H_INCLUDED
2#define XRPL_APP_BOOK_OFFER_H_INCLUDED
4#include <xrpl/basics/Log.h>
5#include <xrpl/basics/contract.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/Quality.h>
8#include <xrpl/protocol/Rules.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/STLedgerEntry.h>
16template <
class TIn,
class TOut>
31template <
class TIn = STAmount,
class TOut = STAmount>
73 TAmounts<TIn, TOut>
const&
95 Throw<std::logic_error>(
"can't consume more than is available.");
98 Throw<std::logic_error>(
"can't produce more than is available.");
124 TAmounts<TIn, TOut>
const& offrAmt,
129 limitIn(TAmounts<TIn, TOut>
const& offrAmt, TIn
const& limit,
bool roundUp)
132 template <
typename... Args>
147 return {ofrInRate, ofrOutRate};
163 <<
"AMMOffer::checkInvariant failed: consumed "
178template <
class TIn,
class TOut>
182 , m_account(m_entry->getAccountID(sfAccount))
184 auto const tp =
m_entry->getFieldAmount(sfTakerPays);
185 auto const tg =
m_entry->getFieldAmount(sfTakerGets);
188 this->
issIn_ = tp.issue();
198 , m_account(m_entry->getAccountID(sfAccount))
200 m_entry->getFieldAmount(sfTakerPays),
201 m_entry->getFieldAmount(sfTakerGets))
205template <
class TIn,
class TOut>
211 UNREACHABLE(
"ripple::TOffer::setFieldAmounts : must be specialized");
213 static_assert(
sizeof(TOut) == -1,
"Must be specialized");
218template <
class TIn,
class TOut>
221 TAmounts<TIn, TOut>
const& offrAmt,
227 return quality().ceil_out_strict(offrAmt, limit, roundUp);
230template <
class TIn,
class TOut>
233 TAmounts<TIn, TOut>
const& offrAmt,
238 rules && rules->enabled(fixReducedOffersV2))
243 return quality().ceil_in_strict(offrAmt, limit, roundUp);
244 return m_quality.ceil_in(offrAmt, limit);
247template <
class TIn,
class TOut>
248template <
typename... Args>
259 m_entry->setFieldAmount(sfTakerPays, m_amounts.in);
260 m_entry->setFieldAmount(sfTakerGets, m_amounts.out);
267 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
268 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
275 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
276 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out));
283 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in));
284 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
287template <
class TIn,
class TOut>
298 return m_amounts.in.issue();
301template <
class TIn,
class TOut>
305 return this->issOut_;
312 return m_amounts.out.issue();
315template <
class TIn,
class TOut>
319 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()