3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/ledger/View.h>
6#include <xrpl/protocol/Quality.h>
7#include <xrpl/protocol/Rules.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/STLedgerEntry.h>
15template <
class TIn,
class TOut>
30template <
class TIn = STAmount,
class TOut = STAmount>
72 TAmounts<TIn, TOut>
const&
94 Throw<std::logic_error>(
"can't consume more than is available.");
97 Throw<std::logic_error>(
"can't produce more than is available.");
122 limitOut(TAmounts<TIn, TOut>
const& offerAmount, TOut
const& limit,
bool roundUp)
const;
125 limitIn(TAmounts<TIn, TOut>
const& offerAmount, TIn
const& limit,
bool roundUp)
const;
127 template <
typename... Args>
142 return {ofrInRate, ofrOutRate};
157 JLOG(j.
error()) <<
"AMMOffer::checkInvariant failed: consumed " <<
to_string(consumed.in) <<
" "
171template <
class TIn,
class TOut>
173 : m_entry(entry), m_quality(quality), m_account(m_entry->getAccountID(sfAccount))
175 auto const tp =
m_entry->getFieldAmount(sfTakerPays);
176 auto const tg =
m_entry->getFieldAmount(sfTakerGets);
179 this->
issIn_ = tp.issue();
187 , m_account(m_entry->getAccountID(sfAccount))
188 , m_amounts(m_entry->getFieldAmount(sfTakerPays), m_entry->getFieldAmount(sfTakerGets))
192template <
class TIn,
class TOut>
198 UNREACHABLE(
"xrpl::TOffer::setFieldAmounts : must be specialized");
200 static_assert(
sizeof(TOut) == -1,
"Must be specialized");
205template <
class TIn,
class TOut>
211 return quality().ceil_out_strict(offerAmount, limit, roundUp);
214template <
class TIn,
class TOut>
223 return quality().ceil_in_strict(offerAmount, limit, roundUp);
224 return m_quality.ceil_in(offerAmount, limit);
227template <
class TIn,
class TOut>
228template <
typename... Args>
239 m_entry->setFieldAmount(sfTakerPays, m_amounts.in);
240 m_entry->setFieldAmount(sfTakerGets, m_amounts.out);
247 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
248 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
255 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
256 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out));
263 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in));
264 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
267template <
class TIn,
class TOut>
278 return m_amounts.in.issue();
281template <
class TIn,
class TOut>
285 return this->issOut_;
292 return m_amounts.out.issue();
295template <
class TIn,
class TOut>
299 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.
Issue const & issueOut() const
static TER send(Args &&... args)
bool fully_consumed() const
Returns true if no more funds can flow through this offer.
AccountID const & owner() const
Returns the account id of the offer's owner.
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
Adjusts the offer to indicate that we consumed some (or all) of it.
static std::pair< std::uint32_t, std::uint32_t > adjustRates(std::uint32_t ofrInRate, std::uint32_t ofrOutRate)
std::optional< uint256 > key() const
Quality quality() const noexcept
Returns the quality of the offer.
TAmounts< TIn, TOut > m_amounts
TOffer(SLE::pointer const &entry, Quality quality)
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offerAmount, TOut const &limit, bool roundUp) const
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.
Issue const & issueIn() const
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offerAmount, TIn const &limit, bool roundUp) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
std::optional< Rules > const & getCurrentTransactionRules()
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.
bool isFeatureEnabled(uint256 const &feature)