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