Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Dec 9, 2024
1 parent 5771e20 commit 86faeee
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 108 deletions.
27 changes: 0 additions & 27 deletions include/xrpl/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ class Asset
friend constexpr bool
operator==(Asset const& lhs, Asset const& rhs);

friend constexpr bool
operator!=(Asset const& lhs, Asset const& rhs);

friend constexpr bool
operator<(Asset const& lhs, Asset const& rhs);

friend constexpr std::weak_ordering
operator<=>(Asset const& lhs, Asset const& rhs);

Expand Down Expand Up @@ -160,27 +154,6 @@ operator==(Asset const& lhs, Asset const& rhs)
rhs.issue_);
}

constexpr bool
operator!=(Asset const& lhs, Asset const& rhs)
{
return !(lhs == rhs);
}

constexpr bool
operator<(Asset const& lhs, Asset const& rhs)
{
return std::visit(
[&]<typename TLhs, typename TRhs>(
TLhs const& issLhs, TRhs const& issRhs) {
if constexpr (std::is_same_v<TLhs, TRhs>)
return issLhs < issRhs;
else
return false;
},
lhs.issue_,
rhs.issue_);
}

constexpr bool
operator==(Currency const& lhs, Asset const& rhs)
{
Expand Down
25 changes: 1 addition & 24 deletions include/xrpl/protocol/MPTIssue.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,16 @@ class MPTIssue
void
setJson(Json::Value& jv) const;

auto
constexpr std::weak_ordering
operator<=>(MPTIssue const&) const = default;

bool
native() const
{
return false;
}

friend constexpr std::weak_ordering
operator<=>(MPTIssue const& lhs, MPTIssue const& rhs);
};

constexpr bool
operator==(MPTIssue const& lhs, MPTIssue const& rhs)
{
return lhs.mptID_ == rhs.mptID_;
}

constexpr bool
operator!=(MPTIssue const& lhs, MPTIssue const& rhs)
{
return !(lhs == rhs);
}

constexpr std::weak_ordering
operator<=>(MPTIssue const& lhs, MPTIssue const& rhs)
{
if (auto const c{lhs.mptID_ <=> rhs.mptID_}; c != 0)
return c;
return lhs.mptID_ <=> rhs.mptID_;
}

/** MPT is a non-native token.
*/
inline bool
Expand Down
24 changes: 12 additions & 12 deletions include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ TRANSACTION(ttCLAWBACK, 30, Clawback, ({
/** This transaction claws back tokens from an AMM pool. */
TRANSACTION(ttAMM_CLAWBACK, 31, AMMClawback, ({
{sfHolder, soeREQUIRED},
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfAsset, soeREQUIRED, soeMPTSupported},
{sfAsset2, soeREQUIRED, soeMPTSupported},
{sfAmount, soeOPTIONAL, soeMPTSupported},
}))

Expand All @@ -250,8 +250,8 @@ TRANSACTION(ttAMM_CREATE, 35, AMMCreate, ({

/** This transaction type deposits into an AMM instance */
TRANSACTION(ttAMM_DEPOSIT, 36, AMMDeposit, ({
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfAsset, soeREQUIRED, soeMPTSupported},
{sfAsset2, soeREQUIRED, soeMPTSupported},
{sfAmount, soeOPTIONAL, soeMPTSupported},
{sfAmount2, soeOPTIONAL, soeMPTSupported},
{sfEPrice, soeOPTIONAL},
Expand All @@ -261,8 +261,8 @@ TRANSACTION(ttAMM_DEPOSIT, 36, AMMDeposit, ({

/** This transaction type withdraws from an AMM instance */
TRANSACTION(ttAMM_WITHDRAW, 37, AMMWithdraw, ({
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfAsset, soeREQUIRED, soeMPTSupported},
{sfAsset2, soeREQUIRED, soeMPTSupported},
{sfAmount, soeOPTIONAL, soeMPTSupported},
{sfAmount2, soeOPTIONAL, soeMPTSupported},
{sfEPrice, soeOPTIONAL},
Expand All @@ -271,24 +271,24 @@ TRANSACTION(ttAMM_WITHDRAW, 37, AMMWithdraw, ({

/** This transaction type votes for the trading fee */
TRANSACTION(ttAMM_VOTE, 38, AMMVote, ({
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfAsset, soeREQUIRED, soeMPTSupported},
{sfAsset2, soeREQUIRED, soeMPTSupported},
{sfTradingFee, soeREQUIRED},
}))

/** This transaction type bids for the auction slot */
TRANSACTION(ttAMM_BID, 39, AMMBid, ({
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfAsset, soeREQUIRED, soeMPTSupported},
{sfAsset2, soeREQUIRED, soeMPTSupported},
{sfBidMin, soeOPTIONAL},
{sfBidMax, soeOPTIONAL},
{sfAuthAccounts, soeOPTIONAL},
}))

/** This transaction type deletes AMM in the empty state */
TRANSACTION(ttAMM_DELETE, 40, AMMDelete, ({
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfAsset, soeREQUIRED, soeMPTSupported},
{sfAsset2, soeREQUIRED, soeMPTSupported},
}))

/** This transactions creates a crosschain sequence number */
Expand Down
1 change: 1 addition & 0 deletions src/libxrpl/protocol/MPTIssue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//==============================================================================

#include <xrpl/json/json_errors.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/jss.h>

Expand Down
27 changes: 18 additions & 9 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,9 +1544,6 @@ class MPToken_test : public beast::unit_test::suite
jrr = env.rpc("json", "sign", to_string(jv1));
BEAST_EXPECT(jrr[jss::result][jss::error] == "invalidParams");
};
auto toSFieldRef = [](SField const& field) {
return std::ref(field);
};
auto setMPTFields = [&](SField const& field,
Json::Value& jv,
bool withAmount = true) {
Expand Down Expand Up @@ -3130,16 +3127,28 @@ class MPToken_test : public beast::unit_test::suite
auto const USD = gw["USD"];
Env env(*this, features);
fund(env, gw, {alice}, XRP(1'000), {USD(1'000)});
MPTTester mpt(env, gw, {.holders = {alice}, .fund = false});
mpt.create(
{.ownerCount = 1,
.holderCount = 0,
.flags = tfMPTCanTransfer | tfMPTCanTrade});
MPTTester mpt(env, gw, {.fund = false});
mpt.create({.flags = tfMPTCanTransfer | tfMPTCanTrade});
auto const MPT = mpt["MPT"];
AMM amm(env, gw, MPT(100), XRP(100));
amm.deposit(DepositArg{.account = alice, .asset1In = XRP(10)});
amm::ammClawback(
gw, alice, MPTIssue(mpt.issuanceID()), xrpIssue(), MPT(10));
}

{
Account const gw{"gw"};
Account const alice{"alice"};
auto const USD = gw["USD"];
Env env(*this, features);
fund(env, gw, {alice}, XRP(1'000), {USD(1'000)});
MPTTester mpt(env, gw, {.fund = false});
mpt.create({.flags = tfMPTCanTransfer | tfMPTCanTrade});
mpt.authorize({.account = alice});
mpt.pay(gw, alice, 1'000);
auto const MPT = mpt["MPT"];
AMM amm(env, gw, MPT(100), XRP(100));
amm.deposit(DepositArg{.account = alice, .tokens = 100});
amm.deposit(DepositArg{.account = alice, .tokens = 10'000});
amm::ammClawback(
gw, alice, MPTIssue(mpt.issuanceID()), xrpIssue(), MPT(10));
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/paths/detail/MPTEndpointStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <xrpld/app/paths/detail/Steps.h>
#include <xrpld/ledger/PaymentSandbox.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/MPTAmount.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/MPTAmount.h>
#include <xrpl/protocol/Quality.h>

#include <boost/container/flat_set.hpp>
Expand Down
3 changes: 1 addition & 2 deletions src/xrpld/app/tx/detail/AMMBid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ AMMBid::preflight(PreflightContext const& ctx)
return temINVALID_FLAG;
}

if (auto const res = invalidAMMAssetPair(
ctx.tx[sfAsset].get<Issue>(), ctx.tx[sfAsset2].get<Issue>()))
if (auto const res = invalidAMMAssetPair(ctx.tx[sfAsset], ctx.tx[sfAsset2]))
{
JLOG(ctx.j.debug()) << "AMM Bid: Invalid asset pair.";
return res;
Expand Down
10 changes: 5 additions & 5 deletions src/xrpld/app/tx/detail/AMMClawback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ AMMClawback::preflight(PreflightContext const& ctx)
return temMALFORMED;
}

auto const asset = ctx.tx[sfAsset].get<Issue>();
auto const asset2 = ctx.tx[sfAsset2].get<Issue>();
auto const asset = ctx.tx[sfAsset];
auto const asset2 = ctx.tx[sfAsset2];

if (isXRP(asset))
return temMALFORMED;
Expand All @@ -82,7 +82,7 @@ AMMClawback::preflight(PreflightContext const& ctx)
return temMALFORMED;
}

if (clawAmount && clawAmount->get<Issue>() != asset)
if (clawAmount && clawAmount->issue() != asset)
{
JLOG(ctx.j.trace()) << "AMMClawback: Amount's issuer/currency subfield "
"does not match Asset field";
Expand All @@ -98,8 +98,8 @@ AMMClawback::preflight(PreflightContext const& ctx)
TER
AMMClawback::preclaim(PreclaimContext const& ctx)
{
auto const asset = ctx.tx[sfAsset].get<Issue>();
auto const asset2 = ctx.tx[sfAsset2].get<Issue>();
auto const asset = ctx.tx[sfAsset];
auto const asset2 = ctx.tx[sfAsset2];
auto const sleIssuer = ctx.view.read(keylet::account(ctx.tx[sfAccount]));
if (!sleIssuer)
return terNO_ACCOUNT; // LCOV_EXCL_LINE
Expand Down
12 changes: 9 additions & 3 deletions src/xrpld/app/tx/detail/AMMCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,14 @@ applyCreate(
// Authorize MPT
if (amount.holds<MPTIssue>())
{
auto const mptokenKey =
keylet::mptoken(amount.get<MPTIssue>().getMptID(), *ammAccount);
auto const& mptIssue = amount.get<MPTIssue>();
if (auto const err = requireAuth(
ctx_.view(), mptIssue, account_, MPTAuthType::WeakAuth);
err != tesSUCCESS)
return err;

auto const& mptID = mptIssue.getMptID();
auto const mptokenKey = keylet::mptoken(mptID, *ammAccount);

auto const ownerNode = sb.dirInsert(
keylet::ownerDir(*ammAccount),
Expand All @@ -358,7 +364,7 @@ applyCreate(

auto mptoken = std::make_shared<SLE>(mptokenKey);
(*mptoken)[sfAccount] = *ammAccount;
(*mptoken)[sfMPTokenIssuanceID] = amount.get<MPTIssue>().getMptID();
(*mptoken)[sfMPTokenIssuanceID] = mptID;
(*mptoken)[sfFlags] = 0;
(*mptoken)[sfOwnerNode] = *ownerNode;
sb.insert(mptoken);
Expand Down
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/AMMDelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ AMMDelete::doApply()
// as we go on processing transactions.
Sandbox sb(&ctx_.view());

auto const ter = deleteAMMAccount(
sb, ctx_.tx[sfAsset].get<Issue>(), ctx_.tx[sfAsset2].get<Issue>(), j_);
auto const ter =
deleteAMMAccount(sb, ctx_.tx[sfAsset], ctx_.tx[sfAsset2], j_);
if (ter == tesSUCCESS || ter == tecINCOMPLETE)
sb.apply(ctx_.rawView());

Expand Down
11 changes: 6 additions & 5 deletions src/xrpld/app/tx/detail/AMMDeposit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ AMMDeposit::preflight(PreflightContext const& ctx)
return temMALFORMED;
}

auto const asset = ctx.tx[sfAsset].get<Issue>();
auto const asset2 = ctx.tx[sfAsset2].get<Issue>();
auto const asset = ctx.tx[sfAsset];
auto const asset2 = ctx.tx[sfAsset2];
if (auto const res = invalidAMMAssetPair(asset, asset2))
{
JLOG(ctx.j.debug()) << "AMM Deposit: invalid asset pair.";
Expand Down Expand Up @@ -259,7 +259,8 @@ AMMDeposit::preclaim(PreclaimContext const& ctx)
// Check if either of the assets is frozen, AMMDeposit is not allowed
// if either asset is frozen
auto checkAsset = [&](Asset const& asset) -> TER {
if (auto const ter = requireAuth(ctx.view, asset, accountID))
if (auto const ter = requireAuth(
ctx.view, asset, accountID, MPTAuthType::WeakAuth))
{
JLOG(ctx.j.debug())
<< "AMM Deposit: account is not authorized, " << asset;
Expand All @@ -278,10 +279,10 @@ AMMDeposit::preclaim(PreclaimContext const& ctx)
return tesSUCCESS;
};

if (auto const ter = checkAsset(ctx.tx[sfAsset].get<Issue>()))
if (auto const ter = checkAsset(ctx.tx[sfAsset]))
return ter;

if (auto const ter = checkAsset(ctx.tx[sfAsset2].get<Issue>()))
if (auto const ter = checkAsset(ctx.tx[sfAsset2]))
return ter;
}

Expand Down
3 changes: 1 addition & 2 deletions src/xrpld/app/tx/detail/AMMVote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ AMMVote::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

if (auto const res = invalidAMMAssetPair(
ctx.tx[sfAsset].get<Issue>(), ctx.tx[sfAsset2].get<Issue>()))
if (auto const res = invalidAMMAssetPair(ctx.tx[sfAsset], ctx.tx[sfAsset2]))
{
JLOG(ctx.j.debug()) << "AMM Vote: invalid asset pair.";
return res;
Expand Down
Loading

0 comments on commit 86faeee

Please sign in to comment.