From 7793b5f10bb2ab9b66ae166ff654edbe156eaf2d Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 8 Apr 2026 13:38:33 -0400 Subject: [PATCH] refactor: Combine `AMMHelpers` and `AMMUtils` (#6733) --- include/xrpl/ledger/helpers/AMMHelpers.h | 96 ++++ include/xrpl/ledger/helpers/AMMUtils.h | 108 ---- include/xrpl/tx/paths/AMMLiquidity.h | 1 - src/libxrpl/ledger/helpers/AMMHelpers.cpp | 533 +++++++++++++++++ src/libxrpl/ledger/helpers/AMMUtils.cpp | 542 ------------------ src/libxrpl/tx/invariants/AMMInvariant.cpp | 1 - src/libxrpl/tx/paths/BookStep.cpp | 2 +- src/libxrpl/tx/transactors/dex/AMMBid.cpp | 1 - .../tx/transactors/dex/AMMClawback.cpp | 1 - src/libxrpl/tx/transactors/dex/AMMCreate.cpp | 1 - src/libxrpl/tx/transactors/dex/AMMDelete.cpp | 2 +- src/libxrpl/tx/transactors/dex/AMMDeposit.cpp | 1 - src/libxrpl/tx/transactors/dex/AMMVote.cpp | 2 +- .../tx/transactors/dex/AMMWithdraw.cpp | 1 - src/test/app/AMMClawbackMPT_test.cpp | 2 +- src/test/app/AMMClawback_test.cpp | 2 +- src/test/app/AMMExtended_test.cpp | 2 +- src/test/app/AMMMPT_test.cpp | 1 - src/test/app/AMM_test.cpp | 1 - src/test/jtx/impl/AMM.cpp | 1 - src/xrpld/app/ledger/OrderBookDBImpl.cpp | 2 +- src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp | 2 +- 22 files changed, 637 insertions(+), 668 deletions(-) delete mode 100644 include/xrpl/ledger/helpers/AMMUtils.h delete mode 100644 src/libxrpl/ledger/helpers/AMMUtils.cpp diff --git a/include/xrpl/ledger/helpers/AMMHelpers.h b/include/xrpl/ledger/helpers/AMMHelpers.h index 173b4924ae..34597b3cb5 100644 --- a/include/xrpl/ledger/helpers/AMMHelpers.h +++ b/include/xrpl/ledger/helpers/AMMHelpers.h @@ -1,8 +1,13 @@ #pragma once +#include #include #include #include +#include +#include +#include +#include #include #include #include @@ -11,6 +16,7 @@ #include #include #include +#include namespace xrpl { @@ -713,4 +719,94 @@ adjustFracByTokens( STAmount const& tokens, Number const& frac); +/** Get AMM pool balances. + */ +std::pair +ammPoolHolds( + ReadView const& view, + AccountID const& ammAccountID, + Asset const& asset1, + Asset const& asset2, + FreezeHandling freezeHandling, + AuthHandling authHandling, + beast::Journal const j); + +/** Get AMM pool and LP token balances. If both optIssue are + * provided then they are used as the AMM token pair issues. + * Otherwise the missing issues are fetched from ammSle. + */ +Expected, TER> +ammHolds( + ReadView const& view, + SLE const& ammSle, + std::optional const& optAsset1, + std::optional const& optAsset2, + FreezeHandling freezeHandling, + AuthHandling authHandling, + beast::Journal const j); + +/** Get the balance of LP tokens. + */ +STAmount +ammLPHolds( + ReadView const& view, + Asset const& asset1, + Asset const& asset2, + AccountID const& ammAccount, + AccountID const& lpAccount, + beast::Journal const j); + +STAmount +ammLPHolds( + ReadView const& view, + SLE const& ammSle, + AccountID const& lpAccount, + beast::Journal const j); + +/** Get AMM trading fee for the given account. The fee is discounted + * if the account is the auction slot owner or one of the slot's authorized + * accounts. + */ +std::uint16_t +getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account); + +/** Returns total amount held by AMM for the given token. + */ +STAmount +ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Asset const& asset); + +/** Delete trustlines to AMM. If all trustlines are deleted then + * AMM object and account are deleted. Otherwise tecINCOMPLETE is returned. + */ +TER +deleteAMMAccount(Sandbox& view, Asset const& asset, Asset const& asset2, beast::Journal j); + +/** Initialize Auction and Voting slots and set the trading/discounted fee. + */ +void +initializeFeeAuctionVote( + ApplyView& view, + std::shared_ptr& ammSle, + AccountID const& account, + Asset const& lptAsset, + std::uint16_t tfee); + +/** Return true if the Liquidity Provider is the only AMM provider, false + * otherwise. Return tecINTERNAL if encountered an unexpected condition, + * for instance Liquidity Provider has more than one LPToken trustline. + */ +Expected +isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount); + +/** Due to rounding, the LPTokenBalance of the last LP might + * not match the LP's trustline balance. If it's within the tolerance, + * update LPTokenBalance to match the LP's trustline balance. + */ +Expected +verifyAndAdjustLPTokenBalance( + Sandbox& sb, + STAmount const& lpTokens, + std::shared_ptr& ammSle, + AccountID const& account); + } // namespace xrpl diff --git a/include/xrpl/ledger/helpers/AMMUtils.h b/include/xrpl/ledger/helpers/AMMUtils.h deleted file mode 100644 index a9e9c9344a..0000000000 --- a/include/xrpl/ledger/helpers/AMMUtils.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace xrpl { - -class ReadView; -class ApplyView; -class Sandbox; -class NetClock; - -/** Get AMM pool balances. - */ -std::pair -ammPoolHolds( - ReadView const& view, - AccountID const& ammAccountID, - Asset const& asset1, - Asset const& asset2, - FreezeHandling freezeHandling, - AuthHandling authHandling, - beast::Journal const j); - -/** Get AMM pool and LP token balances. If both optIssue are - * provided then they are used as the AMM token pair issues. - * Otherwise the missing issues are fetched from ammSle. - */ -Expected, TER> -ammHolds( - ReadView const& view, - SLE const& ammSle, - std::optional const& optAsset1, - std::optional const& optAsset2, - FreezeHandling freezeHandling, - AuthHandling authHandling, - beast::Journal const j); - -/** Get the balance of LP tokens. - */ -STAmount -ammLPHolds( - ReadView const& view, - Asset const& asset1, - Asset const& asset2, - AccountID const& ammAccount, - AccountID const& lpAccount, - beast::Journal const j); - -STAmount -ammLPHolds( - ReadView const& view, - SLE const& ammSle, - AccountID const& lpAccount, - beast::Journal const j); - -/** Get AMM trading fee for the given account. The fee is discounted - * if the account is the auction slot owner or one of the slot's authorized - * accounts. - */ -std::uint16_t -getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account); - -/** Returns total amount held by AMM for the given token. - */ -STAmount -ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Asset const& asset); - -/** Delete trustlines to AMM. If all trustlines are deleted then - * AMM object and account are deleted. Otherwise tecIMPCOMPLETE is returned. - */ -TER -deleteAMMAccount(Sandbox& view, Asset const& asset, Asset const& asset2, beast::Journal j); - -/** Initialize Auction and Voting slots and set the trading/discounted fee. - */ -void -initializeFeeAuctionVote( - ApplyView& view, - std::shared_ptr& ammSle, - AccountID const& account, - Asset const& lptAsset, - std::uint16_t tfee); - -/** Return true if the Liquidity Provider is the only AMM provider, false - * otherwise. Return tecINTERNAL if encountered an unexpected condition, - * for instance Liquidity Provider has more than one LPToken trustline. - */ -Expected -isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount); - -/** Due to rounding, the LPTokenBalance of the last LP might - * not match the LP's trustline balance. If it's within the tolerance, - * update LPTokenBalance to match the LP's trustline balance. - */ -Expected -verifyAndAdjustLPTokenBalance( - Sandbox& sb, - STAmount const& lpTokens, - std::shared_ptr& ammSle, - AccountID const& account); - -} // namespace xrpl diff --git a/include/xrpl/tx/paths/AMMLiquidity.h b/include/xrpl/tx/paths/AMMLiquidity.h index 5716ea531d..128052f851 100644 --- a/include/xrpl/tx/paths/AMMLiquidity.h +++ b/include/xrpl/tx/paths/AMMLiquidity.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libxrpl/ledger/helpers/AMMHelpers.cpp b/src/libxrpl/ledger/helpers/AMMHelpers.cpp index 4c161bd135..631e4d0774 100644 --- a/src/libxrpl/ledger/helpers/AMMHelpers.cpp +++ b/src/libxrpl/ledger/helpers/AMMHelpers.cpp @@ -1,4 +1,6 @@ #include +// +#include namespace xrpl { @@ -376,4 +378,535 @@ adjustFracByTokens( return tokens / lptAMMBalance; } +std::pair +ammPoolHolds( + ReadView const& view, + AccountID const& ammAccountID, + Asset const& asset1, + Asset const& asset2, + FreezeHandling freezeHandling, + AuthHandling authHandling, + beast::Journal const j) +{ + auto const assetInBalance = + accountHolds(view, ammAccountID, asset1, freezeHandling, authHandling, j); + auto const assetOutBalance = + accountHolds(view, ammAccountID, asset2, freezeHandling, authHandling, j); + return std::make_pair(assetInBalance, assetOutBalance); +} + +Expected, TER> +ammHolds( + ReadView const& view, + SLE const& ammSle, + std::optional const& optAsset1, + std::optional const& optAsset2, + FreezeHandling freezeHandling, + AuthHandling authHandling, + beast::Journal const j) +{ + auto const assets = [&]() -> std::optional> { + auto const asset1 = ammSle[sfAsset]; + auto const asset2 = ammSle[sfAsset2]; + if (optAsset1 && optAsset2) + { + if (invalidAMMAssetPair( + *optAsset1, *optAsset2, std::make_optional(std::make_pair(asset1, asset2)))) + { + // This error can only be hit if the AMM is corrupted + // LCOV_EXCL_START + JLOG(j.debug()) << "ammHolds: Invalid optAsset1 or optAsset2 " << *optAsset1 << " " + << *optAsset2; + return std::nullopt; + // LCOV_EXCL_STOP + } + return std::make_optional(std::make_pair(*optAsset1, *optAsset2)); + } + auto const singleAsset = [&asset1, &asset2, &j]( + Asset checkIssue, + char const* label) -> std::optional> { + if (checkIssue == asset1) + { + return std::make_optional(std::make_pair(asset1, asset2)); + } + if (checkIssue == asset2) + { + return std::make_optional(std::make_pair(asset2, asset1)); + } + // Unreachable unless AMM corrupted. + // LCOV_EXCL_START + JLOG(j.debug()) << "ammHolds: Invalid " << label << " " << checkIssue; + return std::nullopt; + // LCOV_EXCL_STOP + }; + if (optAsset1) + { + return singleAsset(*optAsset1, "optAsset1"); + } + if (optAsset2) + { + // Cannot have Amount2 without Amount. + return singleAsset(*optAsset2, "optAsset2"); // LCOV_EXCL_LINE + } + return std::make_optional(std::make_pair(asset1, asset2)); + }(); + if (!assets) + return Unexpected(tecAMM_INVALID_TOKENS); + auto const [amount1, amount2] = ammPoolHolds( + view, + ammSle.getAccountID(sfAccount), + assets->first, + assets->second, + freezeHandling, + authHandling, + j); + return std::make_tuple(amount1, amount2, ammSle[sfLPTokenBalance]); +} + +STAmount +ammLPHolds( + ReadView const& view, + Asset const& asset1, + Asset const& asset2, + AccountID const& ammAccount, + AccountID const& lpAccount, + beast::Journal const j) +{ + // This function looks similar to `accountHolds`. However, it only checks if + // a LPToken holder has enough balance. On the other hand, `accountHolds` + // checks if the underlying assets of LPToken are frozen with the + // fixFrozenLPTokenTransfer amendment + + auto const currency = ammLPTCurrency(asset1, asset2); + STAmount amount; + + auto const sle = view.read(keylet::line(lpAccount, ammAccount, currency)); + if (!sle) + { + amount.clear(Issue{currency, ammAccount}); + JLOG(j.trace()) << "ammLPHolds: no SLE " + << " lpAccount=" << to_string(lpAccount) + << " amount=" << amount.getFullText(); + } + else if (isFrozen(view, lpAccount, currency, ammAccount)) + { + amount.clear(Issue{currency, ammAccount}); + JLOG(j.trace()) << "ammLPHolds: frozen currency " + << " lpAccount=" << to_string(lpAccount) + << " amount=" << amount.getFullText(); + } + else + { + amount = sle->getFieldAmount(sfBalance); + if (lpAccount > ammAccount) + { + // Put balance in account terms. + amount.negate(); + } + amount.get().account = ammAccount; + + JLOG(j.trace()) << "ammLPHolds:" + << " lpAccount=" << to_string(lpAccount) + << " amount=" << amount.getFullText(); + } + + return view.balanceHookIOU(lpAccount, ammAccount, amount); +} + +STAmount +ammLPHolds( + ReadView const& view, + SLE const& ammSle, + AccountID const& lpAccount, + beast::Journal const j) +{ + return ammLPHolds(view, ammSle[sfAsset], ammSle[sfAsset2], ammSle[sfAccount], lpAccount, j); +} + +std::uint16_t +getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account) +{ + using namespace std::chrono; + XRPL_ASSERT( + !view.rules().enabled(fixInnerObjTemplate) || ammSle.isFieldPresent(sfAuctionSlot), + "xrpl::getTradingFee : auction present"); + if (ammSle.isFieldPresent(sfAuctionSlot)) + { + auto const& auctionSlot = safe_downcast(ammSle.peekAtField(sfAuctionSlot)); + // Not expired + if (auto const expiration = auctionSlot[~sfExpiration]; + duration_cast(view.header().parentCloseTime.time_since_epoch()).count() < + expiration) + { + if (auctionSlot[~sfAccount] == account) + return auctionSlot[sfDiscountedFee]; + if (auctionSlot.isFieldPresent(sfAuthAccounts)) + { + for (auto const& acct : auctionSlot.getFieldArray(sfAuthAccounts)) + { + if (acct[~sfAccount] == account) + return auctionSlot[sfDiscountedFee]; + } + } + } + } + return ammSle[sfTradingFee]; +} + +STAmount +ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Asset const& asset) +{ + // Get the actual AMM balance without factoring in the balance hook + return asset.visit( + [&](MPTIssue const& issue) { + if (auto const sle = view.read(keylet::mptoken(issue, ammAccountID)); + sle && !isFrozen(view, ammAccountID, issue)) + return STAmount{issue, (*sle)[sfMPTAmount]}; + return STAmount{asset}; + }, + [&](Issue const& issue) { + if (isXRP(issue)) + { + if (auto const sle = view.read(keylet::account(ammAccountID))) + return (*sle)[sfBalance]; + } + else if ( + auto const sle = + view.read(keylet::line(ammAccountID, issue.account, issue.currency)); + sle && !isFrozen(view, ammAccountID, issue.currency, issue.account)) + { + STAmount amount = (*sle)[sfBalance]; + if (ammAccountID > issue.account) + amount.negate(); + amount.get().account = issue.account; + return amount; + } + return STAmount{asset}; + }); +} + +static TER +deleteAMMTrustLines( + Sandbox& sb, + AccountID const& ammAccountID, + std::uint16_t maxTrustlinesToDelete, + beast::Journal j) +{ + return cleanupOnAccountDelete( + sb, + keylet::ownerDir(ammAccountID), + [&](LedgerEntryType nodeType, + uint256 const&, + std::shared_ptr& sleItem) -> std::pair { + // Skip AMM and MPToken + if (nodeType == ltAMM || nodeType == ltMPTOKEN) + return {tesSUCCESS, SkipEntry::Yes}; + + if (nodeType == ltRIPPLE_STATE) + { + // Trustlines must have zero balance + if (sleItem->getFieldAmount(sfBalance) != beast::zero) + { + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMObjects: deleting trustline with " + "non-zero balance."; + return {tecINTERNAL, SkipEntry::No}; + // LCOV_EXCL_STOP + } + + return {deleteAMMTrustLine(sb, sleItem, ammAccountID, j), SkipEntry::No}; + } + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMObjects: deleting non-trustline or non-MPT " << nodeType; + return {tecINTERNAL, SkipEntry::No}; + // LCOV_EXCL_STOP + }, + j, + maxTrustlinesToDelete); +} + +static TER +deleteAMMMPTokens(Sandbox& sb, AccountID const& ammAccountID, beast::Journal j) +{ + return cleanupOnAccountDelete( + sb, + keylet::ownerDir(ammAccountID), + [&](LedgerEntryType nodeType, + uint256 const&, + std::shared_ptr& sleItem) -> std::pair { + // Skip AMM + if (nodeType == ltAMM) + return {tesSUCCESS, SkipEntry::Yes}; + + if (nodeType == ltMPTOKEN) + { + // MPT must have zero balance + if (sleItem->getFieldU64(sfMPTAmount) != 0 || + (*sleItem)[~sfLockedAmount].value_or(0) != 0) + { + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMObjects: deleting MPT with " + "non-zero balance."; + return {tecINTERNAL, SkipEntry::No}; + // LCOV_EXCL_STOP + } + + return {deleteAMMMPToken(sb, sleItem, ammAccountID, j), SkipEntry::No}; + } + if (nodeType == ltRIPPLE_STATE) + { + // Trustlines should have been deleted + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMObjects: trustlines should have been deleted"; + return {tecINTERNAL, SkipEntry::No}; + // LCOV_EXCL_STOP + } + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMObjects: deleting non-trustline or non-MPT " << nodeType; + return {tecINTERNAL, SkipEntry::No}; + // LCOV_EXCL_STOP + }, + j, + 3); // At most two MPToken plus AMM object +} + +TER +deleteAMMAccount(Sandbox& sb, Asset const& asset, Asset const& asset2, beast::Journal j) +{ + auto ammSle = sb.peek(keylet::amm(asset, asset2)); + if (!ammSle) + { + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMAccount: AMM object does not exist " << asset << " " << asset2; + return tecINTERNAL; + // LCOV_EXCL_STOP + } + + auto const ammAccountID = (*ammSle)[sfAccount]; + auto sleAMMRoot = sb.peek(keylet::account(ammAccountID)); + if (!sleAMMRoot) + { + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMAccount: AMM account does not exist " + << to_string(ammAccountID); + return tecINTERNAL; + // LCOV_EXCL_STOP + } + + if (auto const ter = deleteAMMTrustLines(sb, ammAccountID, maxDeletableAMMTrustLines, j); + !isTesSuccess(ter)) + return ter; + + // Delete AMM's MPTokens only if all trustlines are deleted. If trustlines + // are not deleted then AMM can be re-created with Deposit and + // AMM's MPToken(s) must exist. + if (auto const ter = deleteAMMMPTokens(sb, ammAccountID, j); !isTesSuccess(ter)) + return ter; + + auto const ownerDirKeylet = keylet::ownerDir(ammAccountID); + if (!sb.dirRemove(ownerDirKeylet, (*ammSle)[sfOwnerNode], ammSle->key(), false)) + { + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMAccount: failed to remove dir link"; + return tecINTERNAL; + // LCOV_EXCL_STOP + } + if (sb.exists(ownerDirKeylet) && !sb.emptyDirDelete(ownerDirKeylet)) + { + // LCOV_EXCL_START + JLOG(j.error()) << "deleteAMMAccount: cannot delete root dir node of " + << toBase58(ammAccountID); + return tecINTERNAL; + // LCOV_EXCL_STOP + } + + sb.erase(ammSle); + sb.erase(sleAMMRoot); + + return tesSUCCESS; +} + +void +initializeFeeAuctionVote( + ApplyView& view, + std::shared_ptr& ammSle, + AccountID const& account, + Asset const& lptAsset, + std::uint16_t tfee) +{ + auto const& rules = view.rules(); + // AMM creator gets the voting slot. + STArray voteSlots; + STObject voteEntry = STObject::makeInnerObject(sfVoteEntry); + if (tfee != 0) + voteEntry.setFieldU16(sfTradingFee, tfee); + voteEntry.setFieldU32(sfVoteWeight, VOTE_WEIGHT_SCALE_FACTOR); + voteEntry.setAccountID(sfAccount, account); + voteSlots.push_back(voteEntry); + ammSle->setFieldArray(sfVoteSlots, voteSlots); + // AMM creator gets the auction slot for free. + // AuctionSlot is created on AMMCreate and updated on AMMDeposit + // when AMM is in an empty state + if (rules.enabled(fixInnerObjTemplate) && !ammSle->isFieldPresent(sfAuctionSlot)) + { + STObject auctionSlot = STObject::makeInnerObject(sfAuctionSlot); + ammSle->set(std::move(auctionSlot)); + } + STObject& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot); + auctionSlot.setAccountID(sfAccount, account); + // current + sec in 24h + auto const expiration = std::chrono::duration_cast( + view.header().parentCloseTime.time_since_epoch()) + .count() + + TOTAL_TIME_SLOT_SECS; + auctionSlot.setFieldU32(sfExpiration, expiration); + auctionSlot.setFieldAmount(sfPrice, STAmount{lptAsset, 0}); + // Set the fee + if (tfee != 0) + { + ammSle->setFieldU16(sfTradingFee, tfee); + } + else if (ammSle->isFieldPresent(sfTradingFee)) + { + ammSle->makeFieldAbsent(sfTradingFee); // LCOV_EXCL_LINE + } + if (auto const dfee = tfee / AUCTION_SLOT_DISCOUNTED_FEE_FRACTION) + { + auctionSlot.setFieldU16(sfDiscountedFee, dfee); + } + else if (auctionSlot.isFieldPresent(sfDiscountedFee)) + { + auctionSlot.makeFieldAbsent(sfDiscountedFee); // LCOV_EXCL_LINE + } +} + +Expected +isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount) +{ + // Liquidity Provider (LP) must have one LPToken trustline + std::uint8_t nLPTokenTrustLines = 0; + // AMM account has at most two IOU (pool tokens, not LPToken) trustlines. + // One or both trustlines could be to the LP if LP is the issuer, + // or a different account if LP is not an issuer. For instance, + // if AMM has two tokens USD and EUR and LP is not the issuer of the tokens + // then the trustlines are between AMM account and the issuer. + // There is one LPToken trustline for each LP. Only remaining LP has + // exactly one LPToken trustlines and at most two IOU trustline for each + // pool token. One or both tokens could be MPT. + std::uint8_t nIOUTrustLines = 0; + // There are at most two MPT objects, one for each side of the pool. + std::uint8_t nMPT = 0; + // There is only one AMM object + bool hasAMM = false; + // AMM LP has at most three trustlines, at most two MPTs, and only one + // AMM object must exist. If there are more than four objects then + // it's either an error or there are more than one LP. Ten pages should + // be sufficient to include four objects. + std::uint8_t limit = 10; + auto const root = keylet::ownerDir(ammIssue.account); + auto currentIndex = root; + + // Iterate over AMM owner directory objects. + while (limit-- >= 1) + { + auto const ownerDir = view.read(currentIndex); + if (!ownerDir) + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + for (auto const& key : ownerDir->getFieldV256(sfIndexes)) + { + auto const sle = view.read(keylet::child(key)); + if (!sle) + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + auto const entryType = sle->getFieldU16(sfLedgerEntryType); + // Only one AMM object + if (entryType == ltAMM) + { + if (hasAMM) + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + hasAMM = true; + continue; + } + if (entryType == ltMPTOKEN) + { + ++nMPT; + continue; + } + if (entryType != ltRIPPLE_STATE) + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + auto const lowLimit = sle->getFieldAmount(sfLowLimit); + auto const highLimit = sle->getFieldAmount(sfHighLimit); + auto const isLPTrustline = + lowLimit.getIssuer() == lpAccount || highLimit.getIssuer() == lpAccount; + auto const isLPTokenTrustline = + lowLimit.asset() == ammIssue || highLimit.asset() == ammIssue; + + // Liquidity Provider trustline + if (isLPTrustline) + { + // LPToken trustline + if (isLPTokenTrustline) + { + // LP has exactly one LPToken trustline + if (++nLPTokenTrustLines > 1) + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + } + // AMM account has at most two IOU trustlines + else if (++nIOUTrustLines > 2) + { + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + } + } + // Another Liquidity Provider LPToken trustline + else if (isLPTokenTrustline) + { + return false; + } + // AMM account has at most two IOU trustlines + else if (++nIOUTrustLines > 2) + { + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + } + } + auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext); + if (uNodeNext == 0) + { + if (nLPTokenTrustLines != 1 || (nIOUTrustLines == 0 && nMPT == 0) || + (nIOUTrustLines > 2 || nMPT > 2) || (nIOUTrustLines + nMPT) > 2) + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE + return true; + } + currentIndex = keylet::page(root, uNodeNext); + } + return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE +} + +Expected +verifyAndAdjustLPTokenBalance( + Sandbox& sb, + STAmount const& lpTokens, + std::shared_ptr& ammSle, + AccountID const& account) +{ + auto const res = isOnlyLiquidityProvider(sb, lpTokens.get(), account); + if (!res.has_value()) + { + return Unexpected(res.error()); + } + + if (res.value()) + { + if (withinRelativeDistance( + lpTokens, ammSle->getFieldAmount(sfLPTokenBalance), Number{1, -3})) + { + ammSle->setFieldAmount(sfLPTokenBalance, lpTokens); + sb.update(ammSle); + } + else + { + return Unexpected(tecAMM_INVALID_TOKENS); + } + } + return true; +} + } // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/AMMUtils.cpp b/src/libxrpl/ledger/helpers/AMMUtils.cpp deleted file mode 100644 index 166e9e9494..0000000000 --- a/src/libxrpl/ledger/helpers/AMMUtils.cpp +++ /dev/null @@ -1,542 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace xrpl { - -std::pair -ammPoolHolds( - ReadView const& view, - AccountID const& ammAccountID, - Asset const& asset1, - Asset const& asset2, - FreezeHandling freezeHandling, - AuthHandling authHandling, - beast::Journal const j) -{ - auto const assetInBalance = - accountHolds(view, ammAccountID, asset1, freezeHandling, authHandling, j); - auto const assetOutBalance = - accountHolds(view, ammAccountID, asset2, freezeHandling, authHandling, j); - return std::make_pair(assetInBalance, assetOutBalance); -} - -Expected, TER> -ammHolds( - ReadView const& view, - SLE const& ammSle, - std::optional const& optAsset1, - std::optional const& optAsset2, - FreezeHandling freezeHandling, - AuthHandling authHandling, - beast::Journal const j) -{ - auto const assets = [&]() -> std::optional> { - auto const asset1 = ammSle[sfAsset]; - auto const asset2 = ammSle[sfAsset2]; - if (optAsset1 && optAsset2) - { - if (invalidAMMAssetPair( - *optAsset1, *optAsset2, std::make_optional(std::make_pair(asset1, asset2)))) - { - // This error can only be hit if the AMM is corrupted - // LCOV_EXCL_START - JLOG(j.debug()) << "ammHolds: Invalid optAsset1 or optAsset2 " << *optAsset1 << " " - << *optAsset2; - return std::nullopt; - // LCOV_EXCL_STOP - } - return std::make_optional(std::make_pair(*optAsset1, *optAsset2)); - } - auto const singleAsset = [&asset1, &asset2, &j]( - Asset checkIssue, - char const* label) -> std::optional> { - if (checkIssue == asset1) - { - return std::make_optional(std::make_pair(asset1, asset2)); - } - if (checkIssue == asset2) - { - return std::make_optional(std::make_pair(asset2, asset1)); - } - // Unreachable unless AMM corrupted. - // LCOV_EXCL_START - JLOG(j.debug()) << "ammHolds: Invalid " << label << " " << checkIssue; - return std::nullopt; - // LCOV_EXCL_STOP - }; - if (optAsset1) - { - return singleAsset(*optAsset1, "optAsset1"); - } - if (optAsset2) - { - // Cannot have Amount2 without Amount. - return singleAsset(*optAsset2, "optAsset2"); // LCOV_EXCL_LINE - } - return std::make_optional(std::make_pair(asset1, asset2)); - }(); - if (!assets) - return Unexpected(tecAMM_INVALID_TOKENS); - auto const [amount1, amount2] = ammPoolHolds( - view, - ammSle.getAccountID(sfAccount), - assets->first, - assets->second, - freezeHandling, - authHandling, - j); - return std::make_tuple(amount1, amount2, ammSle[sfLPTokenBalance]); -} - -STAmount -ammLPHolds( - ReadView const& view, - Asset const& asset1, - Asset const& asset2, - AccountID const& ammAccount, - AccountID const& lpAccount, - beast::Journal const j) -{ - // This function looks similar to `accountHolds`. However, it only checks if - // a LPToken holder has enough balance. On the other hand, `accountHolds` - // checks if the underlying assets of LPToken are frozen with the - // fixFrozenLPTokenTransfer amendment - - auto const currency = ammLPTCurrency(asset1, asset2); - STAmount amount; - - auto const sle = view.read(keylet::line(lpAccount, ammAccount, currency)); - if (!sle) - { - amount.clear(Issue{currency, ammAccount}); - JLOG(j.trace()) << "ammLPHolds: no SLE " - << " lpAccount=" << to_string(lpAccount) - << " amount=" << amount.getFullText(); - } - else if (isFrozen(view, lpAccount, currency, ammAccount)) - { - amount.clear(Issue{currency, ammAccount}); - JLOG(j.trace()) << "ammLPHolds: frozen currency " - << " lpAccount=" << to_string(lpAccount) - << " amount=" << amount.getFullText(); - } - else - { - amount = sle->getFieldAmount(sfBalance); - if (lpAccount > ammAccount) - { - // Put balance in account terms. - amount.negate(); - } - amount.get().account = ammAccount; - - JLOG(j.trace()) << "ammLPHolds:" - << " lpAccount=" << to_string(lpAccount) - << " amount=" << amount.getFullText(); - } - - return view.balanceHookIOU(lpAccount, ammAccount, amount); -} - -STAmount -ammLPHolds( - ReadView const& view, - SLE const& ammSle, - AccountID const& lpAccount, - beast::Journal const j) -{ - return ammLPHolds(view, ammSle[sfAsset], ammSle[sfAsset2], ammSle[sfAccount], lpAccount, j); -} - -std::uint16_t -getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account) -{ - using namespace std::chrono; - XRPL_ASSERT( - !view.rules().enabled(fixInnerObjTemplate) || ammSle.isFieldPresent(sfAuctionSlot), - "xrpl::getTradingFee : auction present"); - if (ammSle.isFieldPresent(sfAuctionSlot)) - { - auto const& auctionSlot = safe_downcast(ammSle.peekAtField(sfAuctionSlot)); - // Not expired - if (auto const expiration = auctionSlot[~sfExpiration]; - duration_cast(view.header().parentCloseTime.time_since_epoch()).count() < - expiration) - { - if (auctionSlot[~sfAccount] == account) - return auctionSlot[sfDiscountedFee]; - if (auctionSlot.isFieldPresent(sfAuthAccounts)) - { - for (auto const& acct : auctionSlot.getFieldArray(sfAuthAccounts)) - { - if (acct[~sfAccount] == account) - return auctionSlot[sfDiscountedFee]; - } - } - } - } - return ammSle[sfTradingFee]; -} - -STAmount -ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Asset const& asset) -{ - // Get the actual AMM balance without factoring in the balance hook - return asset.visit( - [&](MPTIssue const& issue) { - if (auto const sle = view.read(keylet::mptoken(issue, ammAccountID)); - sle && !isFrozen(view, ammAccountID, issue)) - return STAmount{issue, (*sle)[sfMPTAmount]}; - return STAmount{asset}; - }, - [&](Issue const& issue) { - if (isXRP(issue)) - { - if (auto const sle = view.read(keylet::account(ammAccountID))) - return (*sle)[sfBalance]; - } - else if ( - auto const sle = - view.read(keylet::line(ammAccountID, issue.account, issue.currency)); - sle && !isFrozen(view, ammAccountID, issue.currency, issue.account)) - { - STAmount amount = (*sle)[sfBalance]; - if (ammAccountID > issue.account) - amount.negate(); - amount.get().account = issue.account; - return amount; - } - return STAmount{asset}; - }); -} - -static TER -deleteAMMTrustLines( - Sandbox& sb, - AccountID const& ammAccountID, - std::uint16_t maxTrustlinesToDelete, - beast::Journal j) -{ - return cleanupOnAccountDelete( - sb, - keylet::ownerDir(ammAccountID), - [&](LedgerEntryType nodeType, - uint256 const&, - std::shared_ptr& sleItem) -> std::pair { - // Skip AMM and MPToken - if (nodeType == ltAMM || nodeType == ltMPTOKEN) - return {tesSUCCESS, SkipEntry::Yes}; - - if (nodeType == ltRIPPLE_STATE) - { - // Trustlines must have zero balance - if (sleItem->getFieldAmount(sfBalance) != beast::zero) - { - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMObjects: deleting trustline with " - "non-zero balance."; - return {tecINTERNAL, SkipEntry::No}; - // LCOV_EXCL_STOP - } - - return {deleteAMMTrustLine(sb, sleItem, ammAccountID, j), SkipEntry::No}; - } - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMObjects: deleting non-trustline or non-MPT " << nodeType; - return {tecINTERNAL, SkipEntry::No}; - // LCOV_EXCL_STOP - }, - j, - maxTrustlinesToDelete); -} - -static TER -deleteAMMMPTokens(Sandbox& sb, AccountID const& ammAccountID, beast::Journal j) -{ - return cleanupOnAccountDelete( - sb, - keylet::ownerDir(ammAccountID), - [&](LedgerEntryType nodeType, - uint256 const&, - std::shared_ptr& sleItem) -> std::pair { - // Skip AMM - if (nodeType == ltAMM) - return {tesSUCCESS, SkipEntry::Yes}; - - if (nodeType == ltMPTOKEN) - { - // MPT must have zero balance - if (sleItem->getFieldU64(sfMPTAmount) != 0 || - (*sleItem)[~sfLockedAmount].value_or(0) != 0) - { - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMObjects: deleting MPT with " - "non-zero balance."; - return {tecINTERNAL, SkipEntry::No}; - // LCOV_EXCL_STOP - } - - return {deleteAMMMPToken(sb, sleItem, ammAccountID, j), SkipEntry::No}; - } - if (nodeType == ltRIPPLE_STATE) - { - // Trustlines should have been deleted - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMObjects: trustlines should have been deleted"; - return {tecINTERNAL, SkipEntry::No}; - // LCOV_EXCL_STOP - } - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMObjects: deleting non-trustline or non-MPT " << nodeType; - return {tecINTERNAL, SkipEntry::No}; - // LCOV_EXCL_STOP - }, - j, - 3); // At most two MPToken plus AMM object -} - -TER -deleteAMMAccount(Sandbox& sb, Asset const& asset, Asset const& asset2, beast::Journal j) -{ - auto ammSle = sb.peek(keylet::amm(asset, asset2)); - if (!ammSle) - { - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMAccount: AMM object does not exist " << asset << " " << asset2; - return tecINTERNAL; - // LCOV_EXCL_STOP - } - - auto const ammAccountID = (*ammSle)[sfAccount]; - auto sleAMMRoot = sb.peek(keylet::account(ammAccountID)); - if (!sleAMMRoot) - { - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMAccount: AMM account does not exist " - << to_string(ammAccountID); - return tecINTERNAL; - // LCOV_EXCL_STOP - } - - if (auto const ter = deleteAMMTrustLines(sb, ammAccountID, maxDeletableAMMTrustLines, j); - !isTesSuccess(ter)) - return ter; - - // Delete AMM's MPTokens only if all trustlines are deleted. If trustlines - // are not deleted then AMM can be re-created with Deposit and - // AMM's MPToken(s) must exist. - if (auto const ter = deleteAMMMPTokens(sb, ammAccountID, j); !isTesSuccess(ter)) - return ter; - - auto const ownerDirKeylet = keylet::ownerDir(ammAccountID); - if (!sb.dirRemove(ownerDirKeylet, (*ammSle)[sfOwnerNode], ammSle->key(), false)) - { - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMAccount: failed to remove dir link"; - return tecINTERNAL; - // LCOV_EXCL_STOP - } - if (sb.exists(ownerDirKeylet) && !sb.emptyDirDelete(ownerDirKeylet)) - { - // LCOV_EXCL_START - JLOG(j.error()) << "deleteAMMAccount: cannot delete root dir node of " - << toBase58(ammAccountID); - return tecINTERNAL; - // LCOV_EXCL_STOP - } - - sb.erase(ammSle); - sb.erase(sleAMMRoot); - - return tesSUCCESS; -} - -void -initializeFeeAuctionVote( - ApplyView& view, - std::shared_ptr& ammSle, - AccountID const& account, - Asset const& lptAsset, - std::uint16_t tfee) -{ - auto const& rules = view.rules(); - // AMM creator gets the voting slot. - STArray voteSlots; - STObject voteEntry = STObject::makeInnerObject(sfVoteEntry); - if (tfee != 0) - voteEntry.setFieldU16(sfTradingFee, tfee); - voteEntry.setFieldU32(sfVoteWeight, VOTE_WEIGHT_SCALE_FACTOR); - voteEntry.setAccountID(sfAccount, account); - voteSlots.push_back(voteEntry); - ammSle->setFieldArray(sfVoteSlots, voteSlots); - // AMM creator gets the auction slot for free. - // AuctionSlot is created on AMMCreate and updated on AMMDeposit - // when AMM is in an empty state - if (rules.enabled(fixInnerObjTemplate) && !ammSle->isFieldPresent(sfAuctionSlot)) - { - STObject auctionSlot = STObject::makeInnerObject(sfAuctionSlot); - ammSle->set(std::move(auctionSlot)); - } - STObject& auctionSlot = ammSle->peekFieldObject(sfAuctionSlot); - auctionSlot.setAccountID(sfAccount, account); - // current + sec in 24h - auto const expiration = std::chrono::duration_cast( - view.header().parentCloseTime.time_since_epoch()) - .count() + - TOTAL_TIME_SLOT_SECS; - auctionSlot.setFieldU32(sfExpiration, expiration); - auctionSlot.setFieldAmount(sfPrice, STAmount{lptAsset, 0}); - // Set the fee - if (tfee != 0) - { - ammSle->setFieldU16(sfTradingFee, tfee); - } - else if (ammSle->isFieldPresent(sfTradingFee)) - { - ammSle->makeFieldAbsent(sfTradingFee); // LCOV_EXCL_LINE - } - if (auto const dfee = tfee / AUCTION_SLOT_DISCOUNTED_FEE_FRACTION) - { - auctionSlot.setFieldU16(sfDiscountedFee, dfee); - } - else if (auctionSlot.isFieldPresent(sfDiscountedFee)) - { - auctionSlot.makeFieldAbsent(sfDiscountedFee); // LCOV_EXCL_LINE - } -} - -Expected -isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount) -{ - // Liquidity Provider (LP) must have one LPToken trustline - std::uint8_t nLPTokenTrustLines = 0; - // AMM account has at most two IOU (pool tokens, not LPToken) trustlines. - // One or both trustlines could be to the LP if LP is the issuer, - // or a different account if LP is not an issuer. For instance, - // if AMM has two tokens USD and EUR and LP is not the issuer of the tokens - // then the trustlines are between AMM account and the issuer. - // There is one LPToken trustline for each LP. Only remaining LP has - // exactly one LPToken trustlines and at most two IOU trustline for each - // pool token. One or both tokens could be MPT. - std::uint8_t nIOUTrustLines = 0; - // There are at most two MPT objects, one for each side of the pool. - std::uint8_t nMPT = 0; - // There is only one AMM object - bool hasAMM = false; - // AMM LP has at most three trustlines, at most two MPTs, and only one - // AMM object must exist. If there are more than four objects then - // it's either an error or there are more than one LP. Ten pages should - // be sufficient to include four objects. - std::uint8_t limit = 10; - auto const root = keylet::ownerDir(ammIssue.account); - auto currentIndex = root; - - // Iterate over AMM owner directory objects. - while (limit-- >= 1) - { - auto const ownerDir = view.read(currentIndex); - if (!ownerDir) - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - for (auto const& key : ownerDir->getFieldV256(sfIndexes)) - { - auto const sle = view.read(keylet::child(key)); - if (!sle) - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - auto const entryType = sle->getFieldU16(sfLedgerEntryType); - // Only one AMM object - if (entryType == ltAMM) - { - if (hasAMM) - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - hasAMM = true; - continue; - } - if (entryType == ltMPTOKEN) - { - ++nMPT; - continue; - } - if (entryType != ltRIPPLE_STATE) - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - auto const lowLimit = sle->getFieldAmount(sfLowLimit); - auto const highLimit = sle->getFieldAmount(sfHighLimit); - auto const isLPTrustline = - lowLimit.getIssuer() == lpAccount || highLimit.getIssuer() == lpAccount; - auto const isLPTokenTrustline = - lowLimit.asset() == ammIssue || highLimit.asset() == ammIssue; - - // Liquidity Provider trustline - if (isLPTrustline) - { - // LPToken trustline - if (isLPTokenTrustline) - { - // LP has exactly one LPToken trustline - if (++nLPTokenTrustLines > 1) - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - } - // AMM account has at most two IOU trustlines - else if (++nIOUTrustLines > 2) - { - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - } - } - // Another Liquidity Provider LPToken trustline - else if (isLPTokenTrustline) - { - return false; - } - // AMM account has at most two IOU trustlines - else if (++nIOUTrustLines > 2) - { - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - } - } - auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext); - if (uNodeNext == 0) - { - if (nLPTokenTrustLines != 1 || (nIOUTrustLines == 0 && nMPT == 0) || - (nIOUTrustLines > 2 || nMPT > 2) || (nIOUTrustLines + nMPT) > 2) - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE - return true; - } - currentIndex = keylet::page(root, uNodeNext); - } - return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE -} - -Expected -verifyAndAdjustLPTokenBalance( - Sandbox& sb, - STAmount const& lpTokens, - std::shared_ptr& ammSle, - AccountID const& account) -{ - auto const res = isOnlyLiquidityProvider(sb, lpTokens.get(), account); - if (!res.has_value()) - { - return Unexpected(res.error()); - } - - if (res.value()) - { - if (withinRelativeDistance( - lpTokens, ammSle->getFieldAmount(sfLPTokenBalance), Number{1, -3})) - { - ammSle->setFieldAmount(sfLPTokenBalance, lpTokens); - sb.update(ammSle); - } - else - { - return Unexpected(tecAMM_INVALID_TOKENS); - } - } - return true; -} - -} // namespace xrpl diff --git a/src/libxrpl/tx/invariants/AMMInvariant.cpp b/src/libxrpl/tx/invariants/AMMInvariant.cpp index 03eb4c1d4a..35fd356918 100644 --- a/src/libxrpl/tx/invariants/AMMInvariant.cpp +++ b/src/libxrpl/tx/invariants/AMMInvariant.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include namespace xrpl { diff --git a/src/libxrpl/tx/paths/BookStep.cpp b/src/libxrpl/tx/paths/BookStep.cpp index 253f702114..ab2efcf39a 100644 --- a/src/libxrpl/tx/paths/BookStep.cpp +++ b/src/libxrpl/tx/paths/BookStep.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMBid.cpp b/src/libxrpl/tx/transactors/dex/AMMBid.cpp index 8efc36537a..3fed28e3c2 100644 --- a/src/libxrpl/tx/transactors/dex/AMMBid.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMBid.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMClawback.cpp b/src/libxrpl/tx/transactors/dex/AMMClawback.cpp index 4b98711c19..e437da3e70 100644 --- a/src/libxrpl/tx/transactors/dex/AMMClawback.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMClawback.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMCreate.cpp b/src/libxrpl/tx/transactors/dex/AMMCreate.cpp index 53680f360a..6f16b818e1 100644 --- a/src/libxrpl/tx/transactors/dex/AMMCreate.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMCreate.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMDelete.cpp b/src/libxrpl/tx/transactors/dex/AMMDelete.cpp index 1033f22722..f601a360d4 100644 --- a/src/libxrpl/tx/transactors/dex/AMMDelete.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMDelete.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp b/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp index 4fc2c14de8..0371388d29 100644 --- a/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMVote.cpp b/src/libxrpl/tx/transactors/dex/AMMVote.cpp index ed75cf5d90..42b339a65e 100644 --- a/src/libxrpl/tx/transactors/dex/AMMVote.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMVote.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp b/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp index f4f27309b5..29043582b1 100644 --- a/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include diff --git a/src/test/app/AMMClawbackMPT_test.cpp b/src/test/app/AMMClawbackMPT_test.cpp index 2708218df9..c1da7aab9c 100644 --- a/src/test/app/AMMClawbackMPT_test.cpp +++ b/src/test/app/AMMClawbackMPT_test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include namespace xrpl { diff --git a/src/test/app/AMMClawback_test.cpp b/src/test/app/AMMClawback_test.cpp index 3160354445..5803d1a0d3 100644 --- a/src/test/app/AMMClawback_test.cpp +++ b/src/test/app/AMMClawback_test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include namespace xrpl { diff --git a/src/test/app/AMMExtended_test.cpp b/src/test/app/AMMExtended_test.cpp index e98822266d..4b9f00bdd1 100644 --- a/src/test/app/AMMExtended_test.cpp +++ b/src/test/app/AMMExtended_test.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/test/app/AMMMPT_test.cpp b/src/test/app/AMMMPT_test.cpp index 0a2f1de234..69de309383 100644 --- a/src/test/app/AMMMPT_test.cpp +++ b/src/test/app/AMMMPT_test.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index 8a56e841d6..a434eb96c7 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/src/test/jtx/impl/AMM.cpp b/src/test/jtx/impl/AMM.cpp index dfc0849793..79f4fa222e 100644 --- a/src/test/jtx/impl/AMM.cpp +++ b/src/test/jtx/impl/AMM.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/src/xrpld/app/ledger/OrderBookDBImpl.cpp b/src/xrpld/app/ledger/OrderBookDBImpl.cpp index 67597531ab..1a764d952f 100644 --- a/src/xrpld/app/ledger/OrderBookDBImpl.cpp +++ b/src/xrpld/app/ledger/OrderBookDBImpl.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp b/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp index 425642b471..272e66018c 100644 --- a/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/orderbook/AMMInfo.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include