mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-29 10:00:30 +00:00
Merge branch 'ximinez/number-round-maxrep-down' into ximinez/number-round-maxrep
This commit is contained in:
@@ -1091,10 +1091,13 @@ AMMWithdraw::singleWithdrawEPrice(
|
||||
// t = T*(T + A*E*(f - 2))/(T*f - A*E)
|
||||
Number const ae = amountBalance * ePrice;
|
||||
auto const f = getFee(tfee);
|
||||
auto tokNoRoundCb = [&] {
|
||||
return lptAMMBalance * (lptAMMBalance + ae * (f - 2)) / (lptAMMBalance * f - ae);
|
||||
};
|
||||
auto tokProdCb = [&] { return (lptAMMBalance + ae * (f - 2)) / (lptAMMBalance * f - ae); };
|
||||
auto const denom = lptAMMBalance * f - ae;
|
||||
// fixCleanup3_3_0: guard against division by zero
|
||||
// when ePrice == lptAMMBalance*f/amountBalance
|
||||
if (view.rules().enabled(fixCleanup3_3_0) && denom == beast::kZero)
|
||||
return {tecAMM_FAILED, STAmount{}};
|
||||
auto tokNoRoundCb = [&] { return lptAMMBalance * (lptAMMBalance + ae * (f - 2)) / denom; };
|
||||
auto tokProdCb = [&] { return (lptAMMBalance + ae * (f - 2)) / denom; };
|
||||
auto const tokensAdj =
|
||||
getRoundedLPTokens(view.rules(), tokNoRoundCb, lptAMMBalance, tokProdCb, IsDeposit::No);
|
||||
if (tokensAdj <= beast::kZero)
|
||||
|
||||
@@ -2229,6 +2229,31 @@ private:
|
||||
ammAlice.withdraw(alice_, XRPAmount{9'999'999'999});
|
||||
BEAST_EXPECT(ammAlice.expectBalances(XRPAmount{1}, USD(10'000), IOUAmount{100}));
|
||||
});
|
||||
|
||||
// singleWithdrawEPrice: crafted ePrice = lptAMMBalance*f/amountBalance
|
||||
// makes the denominator (T*f - A*E) exactly zero.
|
||||
// Pre-fixCleanup3_3_0: std::overflow_error escapes to the
|
||||
// transactor backstop and is returned as tefEXCEPTION.
|
||||
// Post-fixCleanup3_3_0: denominator check returns tecAMM_FAILED.
|
||||
//
|
||||
// Pool: USD(100)/EUR(100), baseFee=1000 (1%).
|
||||
// Alice is the creator so her discounted fee is 100 (0.1%), f=0.001.
|
||||
// ePrice = lptAMMBalance(100) * f(0.001) / amountBalance(100) = 0.001
|
||||
testAMM(
|
||||
[&](AMM& ammAlice, Env& env) {
|
||||
auto const err =
|
||||
env.enabled(fixCleanup3_3_0) ? Ter(tecAMM_FAILED) : Ter(tefEXCEPTION);
|
||||
ammAlice.withdraw(
|
||||
WithdrawArg{
|
||||
.account = alice_,
|
||||
.asset1Out = USD(0),
|
||||
.maxEP = IOUAmount{1, -3}, // ePrice=0.001 → denom=0
|
||||
.err = err});
|
||||
},
|
||||
{{USD(100), EUR(100)}},
|
||||
1000,
|
||||
std::nullopt,
|
||||
{all - fixCleanup3_3_0, all});
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user