Skip to content

Commit b54d85d

Browse files
intelliotyinyiqian1
andcommitted
refactor(AMMClawback): move tfClawTwoAssets check (#5201)
Move tfClawTwoAssets check to preflight and return error temINVALID_FLAG --------- Co-authored-by: yinyiqian1 <yqian@ripple.com>
1 parent f419c18 commit b54d85d

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

include/xrpl/protocol/detail/features.macro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
XRPL_FEATURE(Credentials, Supported::yes, VoteBehavior::DefaultNo)
3333
XRPL_FEATURE(AMMClawback, Supported::yes, VoteBehavior::DefaultNo)
3434
XRPL_FIX (AMMv1_2, Supported::yes, VoteBehavior::DefaultNo)
35+
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
3536
// InvariantsV1_1 will be changes to Supported::yes when all the
3637
// invariants expected to be included under it are complete.
37-
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
3838
XRPL_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo)
3939
XRPL_FIX (NFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo)
4040
XRPL_FIX (InnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo)

src/test/app/AMMClawback_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ class AMMClawback_test : public jtx::AMMTest
303303
// gw creates AMM pool of XRP/USD.
304304
AMM amm(env, gw, XRP(100), USD(100), ter(tesSUCCESS));
305305

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

315315
// Test clawing back XRP is being prohibited.

src/xrpld/app/tx/detail/AMMClawback.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ AMMClawback::preflight(PreflightContext const& ctx)
4242
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
4343
return ret; // LCOV_EXCL_LINE
4444

45-
if (ctx.tx.getFlags() & tfAMMClawbackMask)
45+
auto const flags = ctx.tx.getFlags();
46+
if (flags & tfAMMClawbackMask)
4647
return temINVALID_FLAG;
4748

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

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

6163
if (isXRP(asset))
6264
return temMALFORMED;
6365

66+
if (flags & tfClawTwoAssets && asset.account != asset2.account)
67+
{
68+
JLOG(ctx.j.trace())
69+
<< "AMMClawback: tfClawTwoAssets can only be enabled when two "
70+
"assets in the AMM pool are both issued by the issuer";
71+
return temINVALID_FLAG;
72+
}
73+
6474
if (asset.account != issuer)
6575
{
6676
JLOG(ctx.j.trace()) << "AMMClawback: Asset's account does not "
@@ -108,15 +118,6 @@ AMMClawback::preclaim(PreclaimContext const& ctx)
108118
(issuerFlagsIn & lsfNoFreeze))
109119
return tecNO_PERMISSION;
110120

111-
auto const flags = ctx.tx.getFlags();
112-
if (flags & tfClawTwoAssets && asset.account != asset2.account)
113-
{
114-
JLOG(ctx.j.trace())
115-
<< "AMMClawback: tfClawTwoAssets can only be enabled when two "
116-
"assets in the AMM pool are both issued by the issuer";
117-
return tecNO_PERMISSION;
118-
}
119-
120121
return tesSUCCESS;
121122
}
122123

0 commit comments

Comments
 (0)