@@ -51,49 +51,58 @@ AMMWithdraw::preflight(PreflightContext const& ctx)
51
51
JLOG (ctx.j .debug ()) << " AMM Withdraw: invalid flags." ;
52
52
return temINVALID_FLAG;
53
53
}
54
- bool const withdrawAll = flags & tfWithdrawAll;
55
54
56
55
auto const amount = ctx.tx [~sfAmount];
57
56
auto const amount2 = ctx.tx [~sfAmount2];
58
57
auto const ePrice = ctx.tx [~sfEPrice];
59
58
auto const lpTokens = ctx.tx [~sfLPTokenIn];
60
59
// Valid combinations are:
61
- // LPTokens|tfWithdrawAll
60
+ // LPTokens
61
+ // tfWithdrawAll
62
62
// Amount
63
+ // tfOneAssetWithdrawAll & Amount
63
64
// Amount and Amount2
64
- // AssetLPToken and [ LPTokens|tfWithdrawAll]
65
+ // Amount and LPTokens
65
66
// Amount and EPrice
66
- if (auto const subTxType = std::bitset<32 >(flags & tfSubTx );
67
+ if (auto const subTxType = std::bitset<32 >(flags & tfWithdrawSubTx );
67
68
subTxType.none () || subTxType.count () > 1 )
68
69
{
69
70
JLOG (ctx.j .debug ()) << " AMM Withdraw: invalid flags." ;
70
- return temINVALID_FLAG ;
71
+ return temBAD_AMM_OPTIONS ;
71
72
}
72
73
else if (flags & tfLPToken)
73
74
{
74
- if ((!lpTokens && !withdrawAll) || (lpTokens && withdrawAll) ||
75
- amount || amount2 || ePrice)
75
+ if (!lpTokens || amount || amount2 || ePrice)
76
+ return temBAD_AMM_OPTIONS;
77
+ }
78
+ else if (flags & tfWithdrawAll)
79
+ {
80
+ if (lpTokens || amount || amount2 || ePrice)
81
+ return temBAD_AMM_OPTIONS;
82
+ }
83
+ else if (flags & tfOneAssetWithdrawAll)
84
+ {
85
+ if (!amount || lpTokens || amount2 || ePrice)
76
86
return temBAD_AMM_OPTIONS;
77
87
}
78
88
else if (flags & tfSingleAsset)
79
89
{
80
- if (!amount || lpTokens || withdrawAll || amount2 || ePrice)
90
+ if (!amount || lpTokens || amount2 || ePrice)
81
91
return temBAD_AMM_OPTIONS;
82
92
}
83
93
else if (flags & tfTwoAsset)
84
94
{
85
- if (!amount || !amount2 || lpTokens || withdrawAll || ePrice)
95
+ if (!amount || !amount2 || lpTokens || ePrice)
86
96
return temBAD_AMM_OPTIONS;
87
97
}
88
98
else if (flags & tfOneAssetLPToken)
89
99
{
90
- if (!amount || (!lpTokens && !withdrawAll) ||
91
- (lpTokens && withdrawAll) || amount2 || ePrice)
100
+ if (!amount || !lpTokens || amount2 || ePrice)
92
101
return temBAD_AMM_OPTIONS;
93
102
}
94
103
else if (flags & tfLimitLPToken)
95
104
{
96
- if (!amount || !ePrice || lpTokens || withdrawAll || amount2)
105
+ if (!amount || !ePrice || lpTokens || amount2)
97
106
return temBAD_AMM_OPTIONS;
98
107
}
99
108
@@ -119,7 +128,9 @@ AMMWithdraw::preflight(PreflightContext const& ctx)
119
128
}
120
129
121
130
if (auto const res = invalidAMMAmount (
122
- amount, {{asset, asset2}}, withdrawAll || lpTokens || ePrice))
131
+ amount,
132
+ {{asset, asset2}},
133
+ (flags & (tfOneAssetWithdrawAll | tfOneAssetLPToken)) || ePrice))
123
134
{
124
135
JLOG (ctx.j .debug ()) << " AMM Withdraw: invalid Asset1Out" ;
125
136
return res;
@@ -214,7 +225,8 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx)
214
225
215
226
auto const lptBalance =
216
227
ammLPHolds (ctx.view , **ammSle, ctx.tx [sfAccount], ctx.j );
217
- auto const lpTokens = (ctx.tx .getFlags () & tfWithdrawAll)
228
+ auto const lpTokens =
229
+ (ctx.tx .getFlags () & (tfWithdrawAll | tfOneAssetWithdrawAll))
218
230
? std::optional<STAmount>(lptBalance)
219
231
: ctx.tx [~sfLPTokenIn];
220
232
@@ -258,7 +270,8 @@ AMMWithdraw::applyGuts(Sandbox& sb)
258
270
auto const ammAccountID = (**ammSle)[sfAMMAccount];
259
271
auto const lpTokens =
260
272
ammLPHolds (ctx_.view (), **ammSle, ctx_.tx [sfAccount], ctx_.journal );
261
- auto const lpTokensWithdraw = (ctx_.tx .getFlags () & tfWithdrawAll)
273
+ auto const lpTokensWithdraw =
274
+ (ctx_.tx .getFlags () & (tfWithdrawAll | tfOneAssetWithdrawAll))
262
275
? std::optional<STAmount>(lpTokens)
263
276
: ctx_.tx [~sfLPTokenIn];
264
277
@@ -274,7 +287,7 @@ AMMWithdraw::applyGuts(Sandbox& sb)
274
287
return {expected.error (), false };
275
288
auto const [amountBalance, amount2Balance, lptAMMBalance] = *expected;
276
289
277
- auto const subTxType = ctx_.tx .getFlags () & tfSubTx ;
290
+ auto const subTxType = ctx_.tx .getFlags () & tfWithdrawSubTx ;
278
291
279
292
auto const [result, withdrawnTokens] =
280
293
[&,
@@ -290,7 +303,8 @@ AMMWithdraw::applyGuts(Sandbox& sb)
290
303
lptAMMBalance,
291
304
*amount,
292
305
*amount2);
293
- if (subTxType == tfOneAssetLPToken)
306
+ if (subTxType == tfOneAssetLPToken ||
307
+ subTxType == tfOneAssetWithdrawAll)
294
308
return singleWithdrawTokens (
295
309
sb,
296
310
ammAccountID,
@@ -311,7 +325,7 @@ AMMWithdraw::applyGuts(Sandbox& sb)
311
325
if (subTxType == tfSingleAsset)
312
326
return singleWithdraw (
313
327
sb, ammAccountID, amountBalance, lptAMMBalance, *amount, tfee);
314
- if (subTxType == tfLPToken)
328
+ if (subTxType == tfLPToken || subTxType == tfWithdrawAll )
315
329
return equalWithdrawTokens (
316
330
sb,
317
331
ammAccountID,
0 commit comments