Skip to content

Commit

Permalink
Use tfee as 0 since it is a two asset withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Sep 24, 2024
1 parent 3be6878 commit 8a8553d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/xrpld/app/tx/detail/AMMClawback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ AMMClawback::applyGuts(Sandbox& sb)
if (holdLPtokens == beast::zero)
return tecINTERNAL;

auto const tfee = getTradingFee(ctx_.view(), *ammSle, holder);
if (!clawAmount)
{
// Because we are doing a two-asset withdrawal,
// tfee is actually not used, so pass tfee as 0.
std::tie(result, newLPTokenBalance, amountWithdraw, amount2Withdraw) =
AMMWithdraw::equalWithdrawTokens(
sb,
Expand All @@ -186,7 +187,7 @@ AMMClawback::applyGuts(Sandbox& sb)
lptAMMBalance,
holdLPtokens,
holdLPtokens,
tfee,
0,
ctx_.journal,
ctx_.tx,
true);
Expand All @@ -201,8 +202,7 @@ AMMClawback::applyGuts(Sandbox& sb)
amountBalance,
amount2Balance,
lptAMMBalance,
*clawAmount,
tfee);
*clawAmount);

if (result != tesSUCCESS)
return result; // LCOV_EXCL_LINE
Expand Down Expand Up @@ -242,8 +242,7 @@ AMMClawback::equalWithdrawMatchingOneAmount(
STAmount const& amountBalance,
STAmount const& amount2Balance,
STAmount const& lptAMMBalance,
STAmount const& amount,
std::uint16_t tfee)
STAmount const& amount)
{
auto frac = Number{amount} / amountBalance;
auto const amount2Withdraw = amount2Balance * frac;
Expand All @@ -253,7 +252,8 @@ AMMClawback::equalWithdrawMatchingOneAmount(
auto const holdLPtokens = ammLPHolds(sb, ammSle, holder, j_);
if (lpTokensWithdraw > holdLPtokens)
// if lptoken balance less than what the issuer intended to clawback,
// clawback all the tokens
// clawback all the tokens. Because we are doing a two-asset withdrawal,
// tfee is actually not used, so pass tfee as 0.
return AMMWithdraw::equalWithdrawTokens(
sb,
ammSle,
Expand All @@ -264,11 +264,13 @@ AMMClawback::equalWithdrawMatchingOneAmount(
lptAMMBalance,
holdLPtokens,
holdLPtokens,
tfee,
0,
ctx_.journal,
ctx_.tx,
true);

// Because we are doing a two-asset withdrawal,
// tfee is actually not used, so pass tfee as 0.
return withdraw(
sb,
ammAccount,
Expand All @@ -279,7 +281,7 @@ AMMClawback::equalWithdrawMatchingOneAmount(
toSTAmount(amount2Balance.issue(), amount2Withdraw),
lptAMMBalance,
toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac),
tfee,
0,
ctx_.journal,
ctx_.tx,
false);
Expand Down
5 changes: 2 additions & 3 deletions src/xrpld/app/tx/detail/AMMClawback.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class AMMClawback : public Transactor

/** Withdraw both assets by providing maximum amount of asset1,
* asset2's amount will be calculated according to the current proportion.
* Since it is two-asset withdrawal, tfee is omitted.
* @param view
* @param ammAccount current AMM account
* @param amountBalance current AMM asset1 balance
* @param amount2Balance current AMM asset2 balance
* @param lptAMMBalance current AMM LPT balance
* @param amount asset1 withdraw amount
* @param tfee trading fee in basis points
* @return
*/
std::tuple<TER, STAmount, STAmount, std::optional<STAmount>>
Expand All @@ -66,8 +66,7 @@ class AMMClawback : public Transactor
STAmount const& amountBalance,
STAmount const& amount2Balance,
STAmount const& lptAMMBalance,
STAmount const& amount,
std::uint16_t tfee);
STAmount const& amount);
};

} // namespace ripple
Expand Down

0 comments on commit 8a8553d

Please sign in to comment.