Skip to content

Commit

Permalink
refactor(AMMClawback): move tfClawTwoAssets check (#5201)
Browse files Browse the repository at this point in the history
Move tfClawTwoAssets check to preflight and return
error temINVALID_FLAG

---------

Co-authored-by: yinyiqian1 <[email protected]>
  • Loading branch information
intelliot and yinyiqian1 committed Nov 25, 2024
1 parent f419c18 commit b54d85d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
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)
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;
}

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

0 comments on commit b54d85d

Please sign in to comment.