xrpld
Loading...
Searching...
No Matches
Rate.h
1#pragma once
2
3#include <xrpl/protocol/Asset.h>
4#include <xrpl/protocol/STAmount.h>
5
6#include <boost/operators.hpp>
7
8#include <cstdint>
9#include <ostream>
10
11namespace xrpl {
12
20struct Rate : private boost::totally_ordered<Rate>
21{
23
24 Rate() = delete;
25
26 explicit Rate(std::uint32_t rate) : value(rate)
27 {
28 }
29};
30
31inline bool
32operator==(Rate const& lhs, Rate const& rhs) noexcept
33{
34 return lhs.value == rhs.value;
35}
36
37inline bool
38operator<(Rate const& lhs, Rate const& rhs) noexcept
39{
40 return lhs.value < rhs.value;
41}
42
44operator<<(std::ostream& os, Rate const& rate)
45{
46 os << rate.value;
47 return os;
48}
49
50STAmount
51multiply(STAmount const& amount, Rate const& rate);
52
53STAmount
54multiplyRound(STAmount const& amount, Rate const& rate, bool roundUp);
55
56STAmount
57multiplyRound(STAmount const& amount, Rate const& rate, Asset const& asset, bool roundUp);
58
59STAmount
60divide(STAmount const& amount, Rate const& rate);
61
62STAmount
63divideRound(STAmount const& amount, Rate const& rate, bool roundUp);
64
65STAmount
66divideRound(STAmount const& amount, Rate const& rate, Asset const& asset, bool roundUp);
67
68namespace nft {
72Rate
74
75} // namespace nft
76
80extern Rate const kParityRate;
81
82} // namespace xrpl
Rate transferFeeAsRate(std::uint16_t fee)
Given a transfer fee (in basis points) convert it to a transfer rate.
Definition Rate2.cpp:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
STAmount divide(STAmount const &amount, Rate const &rate)
Definition Rate2.cpp:69
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:212
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
Definition base_uint.h:606
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
Definition base_uint.h:666
STAmount multiplyRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition Rate2.cpp:45
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition Rate2.cpp:80
Represents a transfer rate.
Definition Rate.h:21
std::uint32_t value
Definition Rate.h:22
Rate()=delete
Rate(std::uint32_t rate)
Definition Rate.h:26