Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move tfClawTwoAssets check to preflight #5201

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
XRPL_FEATURE(Credentials, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(AMMClawback, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (AMMv1_2, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
// InvariantsV1_1 will be changes to Supported::yes when all the
// invariants expected to be included under it are complete.
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo)
XRPL_FIX (NFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (InnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo)
Expand Down
6 changes: 3 additions & 3 deletions src/test/app/AMMClawback_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ class AMMClawback_test : public jtx::AMMTest
// gw creates AMM pool of XRP/USD.
AMM amm(env, gw, XRP(100), USD(100), ter(tesSUCCESS));

// Return tecNO_PERMISSION because the issuer set tfClawTwoAssets,
// Return temINVALID_FLAG because the issuer set tfClawTwoAssets,
// but the issuer only issues USD in the pool. The issuer is not
// allowed to set tfClawTwoAssets flag if he did not issue both
// assts in the pool.
// assets in the pool.
env(amm::ammClawback(gw, alice, USD, XRP, std::nullopt),
txflags(tfClawTwoAssets),
ter(tecNO_PERMISSION));
ter(temINVALID_FLAG));
}

// Test clawing back XRP is being prohibited.
Expand Down
21 changes: 11 additions & 10 deletions src/xrpld/app/tx/detail/AMMClawback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ AMMClawback::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret; // LCOV_EXCL_LINE

if (ctx.tx.getFlags() & tfAMMClawbackMask)
yinyiqian1 marked this conversation as resolved.
Show resolved Hide resolved
auto const flags = ctx.tx.getFlags();
if (flags & tfAMMClawbackMask)
return temINVALID_FLAG;

AccountID const issuer = ctx.tx[sfAccount];
Expand All @@ -57,10 +58,19 @@ AMMClawback::preflight(PreflightContext const& ctx)

std::optional<STAmount> const clawAmount = ctx.tx[~sfAmount];
auto const asset = ctx.tx[sfAsset];
auto const asset2 = ctx.tx[sfAsset2];

if (isXRP(asset))
return temMALFORMED;

if (flags & tfClawTwoAssets && asset.account != asset2.account)
{
JLOG(ctx.j.trace())
<< "AMMClawback: tfClawTwoAssets can only be enabled when two "
"assets in the AMM pool are both issued by the issuer";
return temINVALID_FLAG;
yinyiqian1 marked this conversation as resolved.
Show resolved Hide resolved
}

if (asset.account != issuer)
{
JLOG(ctx.j.trace()) << "AMMClawback: Asset's account does not "
Expand Down Expand Up @@ -108,15 +118,6 @@ AMMClawback::preclaim(PreclaimContext const& ctx)
(issuerFlagsIn & lsfNoFreeze))
return tecNO_PERMISSION;

auto const flags = ctx.tx.getFlags();
if (flags & tfClawTwoAssets && asset.account != asset2.account)
{
JLOG(ctx.j.trace())
<< "AMMClawback: tfClawTwoAssets can only be enabled when two "
"assets in the AMM pool are both issued by the issuer";
return tecNO_PERMISSION;
}

return tesSUCCESS;
}

Expand Down
Loading