1#include <test/jtx/AMMTest.h>
3#include <test/jtx/AMM.h>
4#include <test/jtx/Account.h>
5#include <test/jtx/CaptureLogs.h>
6#include <test/jtx/Env.h>
7#include <test/jtx/amount.h>
8#include <test/jtx/envconfig.h>
9#include <test/jtx/mpt.h>
10#include <test/jtx/pay.h>
11#include <test/jtx/ter.h>
13#include <xrpld/core/Config.h>
15#include <xrpl/basics/Number.h>
16#include <xrpl/beast/unit_test/suite.h>
17#include <xrpl/protocol/Feature.h>
18#include <xrpl/protocol/Issue.h>
19#include <xrpl/protocol/MPTIssue.h>
20#include <xrpl/protocol/STAmount.h>
21#include <xrpl/protocol/UintTypes.h>
22#include <xrpl/protocol/XRPAmount.h>
33[[maybe_unused]] std::vector<STAmount>
41 return fund(env, gw, accounts,
XRP(30000), amts, how);
53 for (
auto const& account : accounts)
57 env.
fund(xrp, account);
63 for (
auto const& account : accounts)
66 for (
auto const& amt : amts)
69 if (amtsOut.
size() == amts.size())
73 if (amt.holds<
MPTIssue>() && mptIssuer)
75 MPTTester const mpt({.env = env, .issuer = *mptIssuer, .holders = accounts});
76 return STAmount{mpt.issuanceID(), amt.mpt().value()};
80 if (amount.holds<
Issue>())
81 env.
trust(amount + amount, account);
82 if (amtsOut.
size() != amts.size())
84 env(
pay(amount.getIssuer(), account, amount));
103 return fund(env, accounts, xrp, amts, how, gw);
127 testAMM(cb,
TestAMMArg{.pool = pool, .tfee = tfee, .ter = ter, .features = vfeatures});
137 for (
auto const& features :
arg.features)
146 features - featureSingleAssetVault - featureLendingProtocol,
153 auto const defXRP =
XRP(30000);
156 return a +
XRP(1000);
158 auto defAmt =
STAmount{a.asset(), 30000};
161 return a +
STAmount{a.asset(), 1000};
163 auto const toFund1 = toFund(asset1);
164 auto const toFund2 = toFund(asset2);
165 BEAST_EXPECT(asset1 <= toFund1 && asset2 <= toFund2);
172 if (!asset1.native() && !asset2.native())
176 else if (asset1.native())
181 else if (asset2.native())
187 auto const pool1 =
STAmount{funded[0].asset(),
static_cast<Number>(asset1)};
188 auto const pool2 =
STAmount{funded[1].asset(),
static_cast<Number>(asset2)};
192 if (BEAST_EXPECT(ammAlice.expectBalances(pool1, pool2, ammAlice.tokens())))
200 return env.
current()->fees().accountReserve(count);
206 return env.
current()->fees().increment;
216 cfg->pathSearchOld = 7;
218 cfg->pathSearchMax = 10;
std::string const & arg() const
Return the argument associated with the runner.
A currency issued by an account.
Sets the new scale and restores the old scale when it leaves scope.
Number is a floating point type that can represent a wide range of values.
jtx::Account const alice_
void testAMM(std::function< void(jtx::AMM &, jtx::Env &)> const &cb, std::optional< std::pair< STAmount, STAmount > > const &pool=std::nullopt, std::uint16_t tfee=0, std::optional< jtx::Ter > const &ter=std::nullopt, std::vector< FeatureBitset > const &features={testableAmendments()})
testAMM() funds 30,000XRP and 30,000IOU for each non-XRP asset to Alice and Carol
jtx::Account const carol_
static XRPAmount reserve(jtx::Env &env, std::uint32_t count)
static XRPAmount ammCrtFee(jtx::Env &env)
Convenience class to test AMM functionality.
Immutable cryptographic account descriptor.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Converts to IOU Issue or STAmount.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
std::vector< STAmount > fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
XrpT const XRP
Converts to XRP Issue or STAmount.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
constexpr XRPAmount
Convert XRP to drops (integral types).
Currency const & badCurrency()
We deliberately disallow the currency that looks like "XRP" because too many people were using it ins...