Skip to content

Commit

Permalink
change withdraw ammSle parameter order
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Oct 1, 2024
1 parent 2796e8d commit a1e2249
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/xrpld/app/tx/detail/AMMClawback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ AMMClawback::applyGuts(Sandbox& sb)
amountBalance,
amount2Balance,
lptAMMBalance,
holdLPtokens,
*clawAmount);

if (result != tesSUCCESS)
Expand All @@ -221,6 +222,9 @@ AMMClawback::applyGuts(Sandbox& sb)
// will claw the paired asset as well. We already checked if
// tfClawTwoAssets is enabled, the two assets have to be issued by the
// same issuer.
if (!amount2Withdraw)
return tecINTERNAL; // LCOV_EXCL_LINE

auto const flags = ctx_.tx.getFlags();
if (flags & tfClawTwoAssets)
return rippleCredit(sb, holder, issuer, *amount2Withdraw, true, j_);
Expand All @@ -237,14 +241,14 @@ AMMClawback::equalWithdrawMatchingOneAmount(
STAmount const& amountBalance,
STAmount const& amount2Balance,
STAmount const& lptAMMBalance,
STAmount const& holdLPtokens,
STAmount const& amount)
{
auto frac = Number{amount} / amountBalance;
auto const amount2Withdraw = amount2Balance * frac;

auto const lpTokensWithdraw =
toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac);
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. Because we are doing a two-asset withdrawal,
Expand All @@ -268,9 +272,9 @@ AMMClawback::equalWithdrawMatchingOneAmount(
// tfee is actually not used, so pass tfee as 0.
return AMMWithdraw::withdraw(
sb,
ammSle,
ammAccount,
holder,
ammSle,
amountBalance,
amount,
toSTAmount(amount2Balance.issue(), amount2Withdraw),
Expand Down
1 change: 1 addition & 0 deletions src/xrpld/app/tx/detail/AMMClawback.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class AMMClawback : public Transactor
STAmount const& amountBalance,
STAmount const& amount2Balance,
STAmount const& lptAMMBalance,
STAmount const& holdLPtokens,
STAmount const& amount);
};

Expand Down
20 changes: 10 additions & 10 deletions src/xrpld/app/tx/detail/AMMWithdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ AMMWithdraw::doApply()
std::pair<TER, STAmount>
AMMWithdraw::withdraw(
Sandbox& view,
AccountID const& ammAccount,
SLE const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& amountWithdraw,
std::optional<STAmount> const& amount2Withdraw,
Expand All @@ -461,9 +461,9 @@ AMMWithdraw::withdraw(
STAmount newLPTokenBalance;
std::tie(ter, newLPTokenBalance, std::ignore, std::ignore) = withdraw(
view,
ammSle,
ammAccount,
account_,
ammSle,
amountBalance,
amountWithdraw,
amount2Withdraw,
Expand All @@ -479,9 +479,9 @@ AMMWithdraw::withdraw(
std::tuple<TER, STAmount, STAmount, std::optional<STAmount>>
AMMWithdraw::withdraw(
Sandbox& view,
SLE const& ammSle,
AccountID const& ammAccount,
AccountID const& account,
SLE const& ammSle,
STAmount const& amountBalance,
STAmount const& amountWithdraw,
std::optional<STAmount> const& amount2Withdraw,
Expand Down Expand Up @@ -734,9 +734,9 @@ AMMWithdraw::equalWithdrawTokens(
{
return withdraw(
view,
ammSle,
ammAccount,
account,
ammSle,
amountBalance,
amountBalance,
amount2Balance,
Expand All @@ -762,9 +762,9 @@ AMMWithdraw::equalWithdrawTokens(

return withdraw(
view,
ammSle,
ammAccount,
account,
ammSle,
amountBalance,
withdrawAmount,
withdraw2Amount,
Expand Down Expand Up @@ -828,8 +828,8 @@ AMMWithdraw::equalWithdrawLimit(
{
return withdraw(
view,
ammAccount,
ammSle,
ammAccount,
amountBalance,
amount,
toSTAmount(amount2.issue(), amount2Withdraw),
Expand All @@ -843,8 +843,8 @@ AMMWithdraw::equalWithdrawLimit(
assert(amountWithdraw <= amount);
return withdraw(
view,
ammAccount,
ammSle,
ammAccount,
amountBalance,
toSTAmount(amount.issue(), amountWithdraw),
amount2,
Expand Down Expand Up @@ -874,8 +874,8 @@ AMMWithdraw::singleWithdraw(

return withdraw(
view,
ammAccount,
ammSle,
ammAccount,
amountBalance,
amount,
std::nullopt,
Expand Down Expand Up @@ -911,8 +911,8 @@ AMMWithdraw::singleWithdrawTokens(
{
return withdraw(
view,
ammAccount,
ammSle,
ammAccount,
amountBalance,
amountWithdraw,
std::nullopt,
Expand Down Expand Up @@ -975,8 +975,8 @@ AMMWithdraw::singleWithdrawEPrice(
{
return withdraw(
view,
ammAccount,
ammSle,
ammAccount,
amountBalance,
amountWithdraw,
std::nullopt,
Expand Down
10 changes: 6 additions & 4 deletions src/xrpld/app/tx/detail/AMMWithdraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class AMMWithdraw : public Transactor
* Return new total LPToken balance and the withdrawn amounts for both
* assets.
* @param view
* @param ammAccount
* @param ammSle AMM ledger entry
* @param ammAccount AMM account
* @param amountBalance current LP asset1 balance
* @param amountWithdraw asset1 withdraw amount
* @param amount2Withdraw asset2 withdraw amount
Expand All @@ -131,9 +132,9 @@ class AMMWithdraw : public Transactor
static std::tuple<TER, STAmount, STAmount, std::optional<STAmount>>
withdraw(
Sandbox& view,
SLE const& ammSle,
AccountID const& ammAccount,
AccountID const& account,
SLE const& ammSle,
STAmount const& amountBalance,
STAmount const& amountWithdraw,
std::optional<STAmount> const& amount2Withdraw,
Expand All @@ -160,7 +161,8 @@ class AMMWithdraw : public Transactor
/** Withdraw requested assets and token from AMM into LP account.
* Return new total LPToken balance.
* @param view
* @param ammAccount
* @param ammSle AMM ledger entry
* @param ammAccount AMM account
* @param amountBalance current LP asset1 balance
* @param amountWithdraw asset1 withdraw amount
* @param amount2Withdraw asset2 withdraw amount
Expand All @@ -171,8 +173,8 @@ class AMMWithdraw : public Transactor
std::pair<TER, STAmount>
withdraw(
Sandbox& view,
AccountID const& ammAccount,
SLE const& ammSle,
AccountID const& ammAccount,
STAmount const& amountBalance,
STAmount const& amountWithdraw,
std::optional<STAmount> const& amount2Withdraw,
Expand Down

0 comments on commit a1e2249

Please sign in to comment.