mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25:51 +00:00
test: verify the rounding behavior of equal-asset AMM deposits (#4982)
* Specifically, test using tfLPToken flag
This commit is contained in:
committed by
GitHub
parent
24a275ba25
commit
df3aa84523
@@ -1244,6 +1244,62 @@ private:
|
||||
expectLedgerEntryRoot(env, carol, XRPAmount{28'999'999'990}));
|
||||
});
|
||||
|
||||
// equal asset deposit: unit test to exercise the rounding-down of
|
||||
// LPTokens in the AMMHelpers.cpp: adjustLPTokens calculations
|
||||
// The LPTokens need to have 16 significant digits and a fractional part
|
||||
for (const Number deltaLPTokens :
|
||||
{Number{UINT64_C(100000'0000000009), -10},
|
||||
Number{UINT64_C(100000'0000000001), -10}})
|
||||
{
|
||||
testAMM([&](AMM& ammAlice, Env& env) {
|
||||
// initial LPToken balance
|
||||
IOUAmount const initLPToken = ammAlice.getLPTokensBalance();
|
||||
const IOUAmount newLPTokens{
|
||||
deltaLPTokens.mantissa(), deltaLPTokens.exponent()};
|
||||
|
||||
// carol performs a two-asset deposit
|
||||
ammAlice.deposit(
|
||||
DepositArg{.account = carol, .tokens = newLPTokens});
|
||||
|
||||
IOUAmount const finalLPToken = ammAlice.getLPTokensBalance();
|
||||
|
||||
// Change in behavior due to rounding down of LPTokens:
|
||||
// there is a decrease in the observed return of LPTokens --
|
||||
// Inputs Number{UINT64_C(100000'0000000001), -10} and
|
||||
// Number{UINT64_C(100000'0000000009), -10} are both rounded
|
||||
// down to 1e5
|
||||
BEAST_EXPECT((finalLPToken - initLPToken == IOUAmount{1, 5}));
|
||||
BEAST_EXPECT(finalLPToken - initLPToken < deltaLPTokens);
|
||||
|
||||
// fraction of newLPTokens/(existing LPToken balance). The
|
||||
// existing LPToken balance is 1e7
|
||||
const Number fr = deltaLPTokens / 1e7;
|
||||
|
||||
// The below equations are based on Equation 1, 2 from XLS-30d
|
||||
// specification, Section: 2.3.1.2
|
||||
const Number deltaXRP = fr * 1e10;
|
||||
const Number deltaUSD = fr * 1e4;
|
||||
|
||||
const STAmount depositUSD =
|
||||
STAmount{USD, deltaUSD.mantissa(), deltaUSD.exponent()};
|
||||
|
||||
const STAmount depositXRP =
|
||||
STAmount{XRP, deltaXRP.mantissa(), deltaXRP.exponent()};
|
||||
|
||||
// initial LPTokens (1e7) + newLPTokens
|
||||
BEAST_EXPECT(ammAlice.expectBalances(
|
||||
XRP(10'000) + depositXRP,
|
||||
USD(10'000) + depositUSD,
|
||||
IOUAmount{1, 7} + newLPTokens));
|
||||
|
||||
// 30,000 less deposited depositUSD
|
||||
BEAST_EXPECT(expectLine(env, carol, USD(30'000) - depositUSD));
|
||||
// 30,000 less deposited depositXRP and 10 drops tx fee
|
||||
BEAST_EXPECT(expectLedgerEntryRoot(
|
||||
env, carol, XRP(30'000) - depositXRP - txfee(env, 1)));
|
||||
});
|
||||
}
|
||||
|
||||
// Equal limit deposit: deposit USD100 and XRP proportionally
|
||||
// to the pool composition not to exceed 100XRP. If the amount
|
||||
// exceeds 100XRP then deposit 100XRP and USD proportionally
|
||||
|
||||
Reference in New Issue
Block a user