rippled
Loading...
Searching...
No Matches
Rate.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2015 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_RATE_H_INCLUDED
21#define RIPPLE_PROTOCOL_RATE_H_INCLUDED
22
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/protocol/STAmount.h>
25#include <boost/operators.hpp>
26#include <cstdint>
27#include <ostream>
28
29namespace ripple {
30
37struct Rate : private boost::totally_ordered<Rate>
38{
40
41 Rate() = delete;
42
43 explicit Rate(std::uint32_t rate) : value(rate)
44 {
45 }
46};
47
48inline bool
49operator==(Rate const& lhs, Rate const& rhs) noexcept
50{
51 return lhs.value == rhs.value;
52}
53
54inline bool
55operator<(Rate const& lhs, Rate const& rhs) noexcept
56{
57 return lhs.value < rhs.value;
58}
59
61operator<<(std::ostream& os, Rate const& rate)
62{
63 os << rate.value;
64 return os;
65}
66
67STAmount
68multiply(STAmount const& amount, Rate const& rate);
69
70STAmount
71multiplyRound(STAmount const& amount, Rate const& rate, bool roundUp);
72
73STAmount
75 STAmount const& amount,
76 Rate const& rate,
77 Asset const& asset,
78 bool roundUp);
79
80STAmount
81divide(STAmount const& amount, Rate const& rate);
82
83STAmount
84divideRound(STAmount const& amount, Rate const& rate, bool roundUp);
85
86STAmount
88 STAmount const& amount,
89 Rate const& rate,
90 Asset const& asset,
91 bool roundUp);
92
93namespace nft {
95Rate
97
98} // namespace nft
99
101extern Rate const parityRate;
102
103} // namespace ripple
104
105#endif
Rate transferFeeAsRate(std::uint16_t fee)
Given a transfer fee (in basis points) convert it to a transfer rate.
Definition: Rate2.cpp:39
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
STAmount divide(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:87
STAmount multiply(STAmount const &amount, Rate const &rate)
Definition: Rate2.cpp:47
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:636
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition: Rate2.cpp:98
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition: Slice.h:222
STAmount multiplyRound(STAmount const &amount, Rate const &rate, bool roundUp)
Definition: Rate2.cpp:58
constexpr bool operator==(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition: base_uint.h:584
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
Represents a transfer rate.
Definition: Rate.h:38
Rate(std::uint32_t rate)
Definition: Rate.h:43
std::uint32_t value
Definition: Rate.h:39
Rate()=delete