Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions include/xrpl/ledger/helpers/AMMHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/Sandbox.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AMMCore.h>
#include <xrpl/protocol/AccountID.h>
Expand Down Expand Up @@ -744,7 +745,7 @@ checkAMMPrecisionLoss(
std::expected<std::tuple<STAmount, STAmount, STAmount>, TER>
ammHolds(
ReadView const& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
std::optional<Asset> const& optAsset1,
std::optional<Asset> const& optAsset2,
FreezeHandling freezeHandling,
Expand All @@ -766,7 +767,7 @@ ammLPHolds(
STAmount
ammLPHolds(
ReadView const& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& lpAccount,
beast::Journal const j);

Expand All @@ -776,7 +777,7 @@ ammLPHolds(
* accounts.
*/
std::uint16_t
getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account);
getTradingFee(ReadView const& view, AMMEntryR const& ammSle, AccountID const& account);

/**
* Returns total amount held by AMM for the given token.
Expand All @@ -797,7 +798,7 @@ deleteAMMAccount(Sandbox& view, Asset const& asset, Asset const& asset2, beast::
void
initializeFeeAuctionVote(
ApplyView const& view,
SLE::pointer const& ammSle,
AMMEntryW& ammSle,
AccountID const& account,
Asset const& lptAsset,
std::uint16_t tfee);
Expand All @@ -817,9 +818,9 @@ isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID c
*/
std::expected<bool, TER>
verifyAndAdjustLPTokenBalance(
Sandbox& sb,
Sandbox const& sb,
STAmount const& lpTokens,
SLE::pointer const& ammSle,
AMMEntryW& ammSle,
AccountID const& account);

} // namespace xrpl
3 changes: 2 additions & 1 deletion include/xrpl/tx/paths/detail/StepChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
Expand Down Expand Up @@ -52,7 +53,7 @@ checkFreeze(
if (auto const sleDst = view.read(keylet::account(dst));
sleDst && sleDst->isFieldPresent(sfAMMID))
{
auto const sleAmm = view.read(keylet::amm((*sleDst)[sfAMMID]));
AMMEntryR const sleAmm((*sleDst)[sfAMMID], view);
if (!sleAmm)
return tecINTERNAL; // LCOV_EXCL_LINE

Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/tx/transactors/dex/AMMClawback.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STTx.h>
Expand Down Expand Up @@ -71,7 +72,7 @@ class AMMClawback : public Transactor
std::tuple<TER, STAmount, STAmount, std::optional<STAmount>>
equalWithdrawMatchingOneAmount(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& holder,
AccountID const& ammAccount,
STAmount const& amountBalance,
Expand Down
19 changes: 10 additions & 9 deletions include/xrpl/tx/transactors/dex/AMMWithdraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
Expand Down Expand Up @@ -121,7 +122,7 @@ class AMMWithdraw : public Transactor
static std::tuple<TER, STAmount, STAmount, std::optional<STAmount>>
equalWithdrawTokens(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const account,
std::optional<AccountID> const& clawbackIssuer,
AccountID const& ammAccount,
Expand Down Expand Up @@ -168,7 +169,7 @@ class AMMWithdraw : public Transactor
static std::tuple<TER, STAmount, STAmount, std::optional<STAmount>>
withdraw(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
std::optional<AccountID> const& clawbackIssuer,
AccountID const& account,
Expand All @@ -188,7 +189,7 @@ class AMMWithdraw : public Transactor
static std::pair<TER, bool>
deleteAMMAccountIfEmpty(
Sandbox& sb,
SLE::pointer const ammSle,
AMMEntryW& ammSle,
STAmount const& lpTokenBalance,
Asset const& asset1,
Asset const& asset2,
Expand Down Expand Up @@ -221,7 +222,7 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
withdraw(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& amountWithdraw,
Expand All @@ -247,7 +248,7 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
equalWithdrawTokens(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& amount2Balance,
Expand All @@ -273,7 +274,7 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
equalWithdrawLimit(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& amount2Balance,
Expand All @@ -296,7 +297,7 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
singleWithdraw(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& lptAMMBalance,
Expand All @@ -318,7 +319,7 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
singleWithdrawTokens(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& lptAMMBalance,
Expand All @@ -341,7 +342,7 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
singleWithdrawEPrice(
Sandbox& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& lptAMMBalance,
Expand Down
3 changes: 2 additions & 1 deletion src/libxrpl/ledger/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/ledger/entries/AmendmentsEntry.h>
#include <xrpl/ledger/entries/DepositPreauthEntry.h>
#include <xrpl/ledger/entries/LedgerHashesEntry.h>
Expand Down Expand Up @@ -196,7 +197,7 @@ canTransferLPToken(
if (!sleIssuer || !sleIssuer->isFieldPresent(sfAMMID))
return tesSUCCESS;

auto const sleAmm = view.read(keylet::amm((*sleIssuer)[sfAMMID]));
AMMEntryR const sleAmm((*sleIssuer)[sfAMMID], view);
if (!sleAmm)
return tecINTERNAL; // LCOV_EXCL_LINE

Expand Down
38 changes: 20 additions & 18 deletions src/libxrpl/ledger/helpers/AMMHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/Sandbox.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
#include <xrpl/ledger/helpers/RippleStateHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
Expand Down Expand Up @@ -444,16 +445,16 @@ checkAMMPrecisionLoss(
std::expected<std::tuple<STAmount, STAmount, STAmount>, TER>
ammHolds(
ReadView const& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
std::optional<Asset> const& optAsset1,
std::optional<Asset> const& optAsset2,
FreezeHandling freezeHandling,
AuthHandling authHandling,
beast::Journal const j)
{
auto const assets = [&] -> std::optional<std::pair<Asset, Asset>> {
auto const asset1 = ammSle[sfAsset];
auto const asset2 = ammSle[sfAsset2];
auto const asset1 = (*ammSle)[sfAsset];
auto const asset2 = (*ammSle)[sfAsset2];
if (optAsset1 && optAsset2)
{
if (invalidAMMAssetPair(
Expand Down Expand Up @@ -500,13 +501,13 @@ ammHolds(
return std::unexpected(tecAMM_INVALID_TOKENS);
auto const [amount1, amount2] = ammPoolHolds(
view,
ammSle.getAccountID(sfAccount),
ammSle->getAccountID(sfAccount),
assets->first,
assets->second,
freezeHandling,
authHandling,
j);
return std::make_tuple(amount1, amount2, ammSle[sfLPTokenBalance]);
return std::make_tuple(amount1, amount2, (*ammSle)[sfLPTokenBalance]);
}

STAmount
Expand Down Expand Up @@ -562,21 +563,22 @@ ammLPHolds(
STAmount
ammLPHolds(
ReadView const& view,
SLE const& ammSle,
AMMEntryR const& ammSle,
AccountID const& lpAccount,
beast::Journal const j)
{
return ammLPHolds(view, ammSle[sfAsset], ammSle[sfAsset2], ammSle[sfAccount], lpAccount, 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)
getTradingFee(ReadView const& view, AMMEntryR const& ammSle, AccountID const& account)
{
using namespace std::chrono;
XRPL_ASSERT(ammSle.isFieldPresent(sfAuctionSlot), "xrpl::getTradingFee : auction present");
if (ammSle.isFieldPresent(sfAuctionSlot))
XRPL_ASSERT(ammSle->isFieldPresent(sfAuctionSlot), "xrpl::getTradingFee : auction present");
if (ammSle->isFieldPresent(sfAuctionSlot))
{
auto const& auctionSlot = safeDowncast<STObject const&>(ammSle.peekAtField(sfAuctionSlot));
auto const& auctionSlot = safeDowncast<STObject const&>(ammSle->peekAtField(sfAuctionSlot));
// Not expired
if (auto const expiration = auctionSlot[~sfExpiration];
duration_cast<seconds>(view.header().parentCloseTime.time_since_epoch()).count() <
Expand All @@ -594,7 +596,7 @@ getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account)
}
}
}
return ammSle[sfTradingFee];
return (*ammSle)[sfTradingFee];
}

STAmount
Expand Down Expand Up @@ -717,7 +719,7 @@ deleteAMMMPTokens(Sandbox& sb, AccountID const& ammAccountID, beast::Journal j)
TER
deleteAMMAccount(Sandbox& sb, Asset const& asset, Asset const& asset2, beast::Journal j)
{
auto const ammSle = sb.peek(keylet::amm(asset, asset2));
AMMEntryW ammSle(asset, asset2, sb, j);
if (!ammSle)
{
// LCOV_EXCL_START
Expand Down Expand Up @@ -764,7 +766,7 @@ deleteAMMAccount(Sandbox& sb, Asset const& asset, Asset const& asset2, beast::Jo
// LCOV_EXCL_STOP
}

sb.erase(ammSle);
ammSle.eraseFromView();
sb.erase(sleAMMRoot);

return tesSUCCESS;
Expand All @@ -773,7 +775,7 @@ deleteAMMAccount(Sandbox& sb, Asset const& asset, Asset const& asset2, beast::Jo
void
initializeFeeAuctionVote(
ApplyView const& view,
SLE::pointer const& ammSle,
AMMEntryW& ammSle,
AccountID const& account,
Asset const& lptAsset,
std::uint16_t tfee)
Expand Down Expand Up @@ -929,9 +931,9 @@ isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID c

std::expected<bool, TER>
verifyAndAdjustLPTokenBalance(
Sandbox& sb,
Sandbox const& sb,
STAmount const& lpTokens,
SLE::pointer const& ammSle,
AMMEntryW& ammSle,
AccountID const& account)
{
auto const res = isOnlyLiquidityProvider(sb, lpTokens.get<Issue>(), account);
Expand All @@ -946,7 +948,7 @@ verifyAndAdjustLPTokenBalance(
lpTokens, ammSle->getFieldAmount(sfLPTokenBalance), Number{1, -3}))
{
ammSle->setFieldAmount(sfLPTokenBalance, lpTokens);
sb.update(ammSle);
ammSle.updateInView();
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/libxrpl/ledger/helpers/TokenHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
#include <xrpl/ledger/helpers/RippleStateHelpers.h>
Expand Down Expand Up @@ -304,7 +305,7 @@ getLineIfUsable(
}
if (sleIssuer->isFieldPresent(sfAMMID))
{
auto const sleAmm = view.read(keylet::amm((*sleIssuer)[sfAMMID]));
AMMEntryR const sleAmm((*sleIssuer)[sfAMMID], view);

if (!sleAmm ||
isLPTokenFrozen(view, account, (*sleAmm)[sfAsset], (*sleAmm)[sfAsset2]))
Expand Down
5 changes: 3 additions & 2 deletions src/libxrpl/tx/paths/BookStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/PaymentSandbox.h>
#include <xrpl/ledger/Sandbox.h>
#include <xrpl/ledger/entries/AMMEntry.h>
#include <xrpl/ledger/helpers/AMMHelpers.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
Expand Down Expand Up @@ -116,13 +117,13 @@ class BookStep : public StepImp<TIn, TOut, BookStep<TIn, TOut, TDerived>>
maxIn_.emplace(*max);
}

if (auto const ammSle = ctx.view.read(keylet::amm(in, out));
if (AMMEntryR const ammSle(in, out, ctx.view);
ammSle && ammSle->getFieldAmount(sfLPTokenBalance) != beast::kZero)
{
ammLiquidity_.emplace(
ctx.view,
(*ammSle)[sfAccount],
getTradingFee(ctx.view, *ammSle, ctx.ammContext.account()),
getTradingFee(ctx.view, ammSle, ctx.ammContext.account()),
in,
out,
ctx.ammContext,
Expand Down
Loading
Loading