20 #include <ripple/app/tx/impl/AMMVote.h>
22 #include <ripple/app/misc/AMMHelpers.h>
23 #include <ripple/app/misc/AMMUtils.h>
24 #include <ripple/ledger/Sandbox.h>
25 #include <ripple/protocol/AMMCore.h>
26 #include <ripple/protocol/Feature.h>
27 #include <ripple/protocol/STAccount.h>
28 #include <ripple/protocol/TxFlags.h>
43 JLOG(ctx.
j.
debug()) <<
"AMM Vote: invalid asset pair.";
49 JLOG(ctx.
j.
debug()) <<
"AMM Vote: invalid flags.";
55 JLOG(ctx.
j.
debug()) <<
"AMM Vote: invalid trading fee.";
65 if (
auto const ammSle =
69 JLOG(ctx.
j.
debug()) <<
"AMM Vote: Invalid asset pair.";
74 else if (
auto const lpTokensNew =
76 lpTokensNew == beast::zero)
78 JLOG(ctx.
j.
debug()) <<
"AMM Vote: account is not LP.";
106 bool foundAccount =
false;
111 for (
auto const& entry : ammSle->getFieldArray(
sfVoteSlots))
115 if (lpTokens == beast::zero)
118 <<
"AMMVote::applyVote, account " << account <<
" is not LP";
124 if (account == account_)
126 lpTokens = lpTokensNew;
131 num += feeVal * lpTokens;
133 newEntry.setAccountID(
sfAccount, account);
136 newEntry.setFieldU32(
144 (lpTokens < *minTokens ||
145 (lpTokens == *minTokens &&
146 (feeVal < minFee || (feeVal == minFee && account < minAccount)))))
148 minTokens = lpTokens;
149 minPos = updatedVoteSlots.
size();
150 minAccount = account;
153 updatedVoteSlots.
push_back(std::move(newEntry));
164 newEntry.setFieldU32(
169 newEntry.setAccountID(
sfAccount, account_);
170 num += feeNew * lpTokensNew;
173 *(updatedVoteSlots.
begin() + *minPos) = std::move(newEntry);
175 updatedVoteSlots.
push_back(std::move(newEntry));
184 lpTokensNew > *minTokens ||
185 (lpTokensNew == *minTokens && feeNew > minFee))
187 auto const entry = updatedVoteSlots.
begin() + minPos;
197 JLOG(j_.
debug()) <<
"AMMVote::applyVote, insufficient tokens to "
198 "override other votes";
203 ammSle->setFieldArray(
sfVoteSlots, updatedVoteSlots);
204 if (
auto const fee =
static_cast<std::int64_t>(num / den))
210 if (
auto const discountedFee =
static std::pair< TER, bool > applyVote(ApplyContext &ctx_, Sandbox &sb, AccountID const &account_, beast::Journal j_)
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
const SF_UINT16 sfDiscountedFee
constexpr std::uint16_t VOTE_MAX_SLOTS
constexpr std::uint32_t VOTE_WEIGHT_SCALE_FACTOR
const SF_AMOUNT sfLPTokenBalance
constexpr std::uint32_t AUCTION_SLOT_DISCOUNTED_FEE_FRACTION
static TER preclaim(PreclaimContext const &ctx)
bool ammEnabled(Rules const &)
Return true if required AMM amendments are enabled.
Keylet amm(Issue const &issue1, Issue const &issue2) noexcept
AMM entry.
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
void push_back(STObject const &object)
const beast::Journal journal
const SF_UINT32 sfVoteWeight
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
const SF_UINT16 sfTradingFee
Integers of any length that is a multiple of 32-bits.
static NotTEC preflight(PreflightContext const &ctx)
Discardable, editable view to a ledger.
TERSubset< CanCvtToTER > TER
std::uint32_t getFlags() const
State information when applying a tx.
A generic endpoint for log messages.
NotTEC invalidAMMAssetPair(Issue const &issue1, Issue const &issue2, std::optional< std::pair< Issue, Issue >> const &pair=std::nullopt)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
State information when determining if a tx is likely to claim a fee.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint16_t TRADING_FEE_THRESHOLD
STAmount ammLPHolds(ReadView const &view, Currency const &cur1, Currency const &cur2, AccountID const &ammAccount, AccountID const &lpAccount, beast::Journal const j)
Get the balance of LP tokens.
const SF_ACCOUNT sfAccount
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
State information when preflighting a tx.
constexpr std::uint32_t tfUniversalMask
const SField sfAuctionSlot
TERSubset< CanCvtToNotTEC > NotTEC