rippled
AMMCore.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2023 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_AMMCORE_H_INCLUDED
21 #define RIPPLE_PROTOCOL_AMMCORE_H_INCLUDED
22 
23 #include <ripple/basics/Number.h>
24 #include <ripple/protocol/AccountID.h>
25 #include <ripple/protocol/Issue.h>
26 #include <ripple/protocol/TER.h>
27 #include <ripple/protocol/UintTypes.h>
28 
29 namespace ripple {
30 
31 std::uint16_t constexpr TRADING_FEE_THRESHOLD = 1000; // 1%
32 
33 // Auction slot
34 std::uint32_t constexpr TOTAL_TIME_SLOT_SECS = 24 * 3600;
42 
43 // Votes
46 
47 class STObject;
48 class STAmount;
49 class Rules;
50 
55  std::uint16_t prefix,
56  uint256 const& parentHash,
57  uint256 const& ammID);
58 
62 ammLPTCurrency(Currency const& cur1, Currency const& cur2);
63 
66 Issue
68  Currency const& cur1,
69  Currency const& cur2,
70  AccountID const& ammAccountID);
71 
77 NotTEC
79  STAmount const& amount,
80  std::optional<std::pair<Issue, Issue>> const& pair = std::nullopt,
81  bool validZero = false);
82 
83 NotTEC
85  Issue const& issue,
86  std::optional<std::pair<Issue, Issue>> const& pair = std::nullopt);
87 
88 NotTEC
90  Issue const& issue1,
91  Issue const& issue2,
92  std::optional<std::pair<Issue, Issue>> const& pair = std::nullopt);
93 
97 ammAuctionTimeSlot(std::uint64_t current, STObject const& auctionSlot);
98 
101 bool
102 ammEnabled(Rules const&);
103 
108 inline Number
110 {
111  return Number{tfee} / AUCTION_SLOT_FEE_SCALE_FACTOR;
112 }
113 
117 inline Number
119 {
120  return 1 - getFee(tfee);
121 }
122 
126 inline Number
128 {
129  return 1 - getFee(tfee) / 2;
130 }
131 
132 } // namespace ripple
133 
134 #endif // RIPPLE_PROTOCOL_AMMCORE_H_INCLUDED
ripple::AUCTION_SLOT_FEE_SCALE_FACTOR
constexpr std::uint32_t AUCTION_SLOT_FEE_SCALE_FACTOR
Definition: AMMCore.h:37
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
ripple::VOTE_MAX_SLOTS
constexpr std::uint16_t VOTE_MAX_SLOTS
Definition: AMMCore.h:44
ripple::VOTE_WEIGHT_SCALE_FACTOR
constexpr std::uint32_t VOTE_WEIGHT_SCALE_FACTOR
Definition: AMMCore.h:45
ripple::AUCTION_SLOT_TIME_INTERVALS
constexpr std::uint16_t AUCTION_SLOT_TIME_INTERVALS
Definition: AMMCore.h:35
ripple::ammLPTIssue
Issue ammLPTIssue(Currency const &cur1, Currency const &cur2, AccountID const &ammAccountID)
Calculate LPT Issue from AMM asset pair.
Definition: AMMCore.cpp:56
std::pair
ripple::AUCTION_SLOT_DISCOUNTED_FEE_FRACTION
constexpr std::uint32_t AUCTION_SLOT_DISCOUNTED_FEE_FRACTION
Definition: AMMCore.h:38
ripple::feeMult
Number feeMult(std::uint16_t tfee)
Get fee multiplier (1 - tfee) @tfee trading fee in basis points.
Definition: AMMCore.h:118
ripple::ammEnabled
bool ammEnabled(Rules const &)
Return true if required AMM amendments are enabled.
Definition: AMMCore.cpp:126
ripple::getFee
Number getFee(std::uint16_t tfee)
Convert to the fee from the basis points.
Definition: AMMCore.h:109
ripple::ammAccountID
AccountID ammAccountID(std::uint16_t prefix, uint256 const &parentHash, uint256 const &ammID)
Calculate AMM account ID.
Definition: AMMCore.cpp:30
ripple::invalidAMMAmount
NotTEC invalidAMMAmount(STAmount const &amount, std::optional< std::pair< Issue, Issue >> const &pair=std::nullopt, bool validZero=false)
Validate the amount.
Definition: AMMCore.cpp:94
ripple::AUCTION_SLOT_MIN_FEE_FRACTION
constexpr std::uint32_t AUCTION_SLOT_MIN_FEE_FRACTION
Definition: AMMCore.h:39
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::Number
Definition: Number.h:36
ripple::TERSubset
Definition: TER.h:352
ripple::STAmount
Definition: STAmount.h:45
std::uint16_t
ripple::invalidAMMAssetPair
NotTEC invalidAMMAssetPair(Issue const &issue1, Issue const &issue2, std::optional< std::pair< Issue, Issue >> const &pair=std::nullopt)
Definition: AMMCore.cpp:79
ripple::STObject
Definition: STObject.h:52
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::TRADING_FEE_THRESHOLD
constexpr std::uint16_t TRADING_FEE_THRESHOLD
Definition: AMMCore.h:31
ripple::TOTAL_TIME_SLOT_SECS
constexpr std::uint32_t TOTAL_TIME_SLOT_SECS
Definition: AMMCore.h:34
ripple::AUCTION_SLOT_INTERVAL_DURATION
constexpr std::uint32_t AUCTION_SLOT_INTERVAL_DURATION
Definition: AMMCore.h:40
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
ripple::invalidAMMAsset
NotTEC invalidAMMAsset(Issue const &issue, std::optional< std::pair< Issue, Issue >> const &pair=std::nullopt)
Definition: AMMCore.cpp:65
std::optional
ripple::AUCTION_SLOT_MAX_AUTH_ACCOUNTS
constexpr std::uint16_t AUCTION_SLOT_MAX_AUTH_ACCOUNTS
Definition: AMMCore.h:36
ripple::ammLPTCurrency
Currency ammLPTCurrency(Currency const &cur1, Currency const &cur2)
Calculate Liquidity Provider Token (LPT) Currency.
Definition: AMMCore.cpp:42
ripple::feeMultHalf
Number feeMultHalf(std::uint16_t tfee)
Get fee multiplier (1 - tfee / 2) @tfee trading fee in basis points.
Definition: AMMCore.h:127
ripple::ammAuctionTimeSlot
std::optional< std::uint8_t > ammAuctionTimeSlot(std::uint64_t current, STObject const &auctionSlot)
Get time slot of the auction slot.
Definition: AMMCore.cpp:107