3#include <test/app/lending/LoanTestBase.h>
4#include <test/app/vault/VaultFixedPrecisionBase.h>
5#include <test/jtx/Account.h>
6#include <test/jtx/Env.h>
7#include <test/jtx/TestHelpers.h>
8#include <test/jtx/amount.h>
9#include <test/jtx/fee.h>
10#include <test/jtx/pay.h>
11#include <test/jtx/sig.h>
12#include <test/jtx/trust.h>
13#include <test/jtx/vault.h>
15#include <xrpl/basics/Number.h>
16#include <xrpl/basics/chrono.h>
17#include <xrpl/protocol/Indexes.h>
18#include <xrpl/protocol/Keylet.h>
19#include <xrpl/protocol/SField.h>
20#include <xrpl/protocol/SeqProxy.h>
21#include <xrpl/protocol/Units.h>
54 env.
fund(XRP(1'000'000), holder);
56 env(trust(holder, accounts.
asset(trustLimit)));
58 env(pay(accounts.
issuer, holder, accounts.
asset(funds)));
89 Number const& depositAmount,
97 using namespace loan_broker;
99 Vault const vault{env};
100 auto [tx, vaultKeylet, subscriptionDate] = vault.createClosedEnded({
104 .investmentWindow = investmentWindow,
107 tx[sfScale] = *
scale;
112 {.depositor = depositor, .id = vaultKeylet.key, .amount = asset(depositAmount)}));
115 vault.closePastSubscription(subscriptionDate);
117 auto const brokerKeylet =
119 env(
set(owner, vaultKeylet.key),
127 .vaultKeylet = vaultKeylet,
128 .brokerKeylet = brokerKeylet,
129 .redemptionDate = subscriptionDate + investmentWindow,
131 .depositor = depositor,
151 using namespace loan;
157 kInterestRate(interestRate),
158 kGracePeriod(gracePeriod),
159 kPaymentInterval(paymentInterval),
160 kPaymentTotal(paymentTotal),
161 Sig(sfCounterpartySignature, fixture.
owner),
162 Fee(env.
current()->fees().base * 2));
178 *
this, env, fixture.
vaultKeylet, {fixture.brokerKeylet}, loanKeylets, label);
static LendingFixture setupLendingVault(test::jtx::Env &env, test::jtx::Account const &owner, test::jtx::Account const &depositor, PrettyAsset const &asset, Number const &depositAmount, std::chrono::seconds investmentWindow=std::chrono::seconds{1 '000 '000}, std::optional< std::uint8_t > scale=std::nullopt, TenthBips32 coverRateMinimum=TenthBips32(0), TenthBips32 coverRateLiquidation=TenthBips32(0), TenthBips16 managementFeeRate=TenthBips16(0))
static void fundIouHolder(test::jtx::Env &env, test::jtx::Account const &holder, AssetAccounts const &accounts, Number const &trustLimit, Number const &funds)
void checkVaultLoanSums(test::jtx::Env &env, LendingFixture const &fixture, std::vector< Keylet > const &loanKeylets, std::string const &label={})
static Keylet openLoan(test::jtx::Env &env, LendingFixture const &fixture, Number const &principal, std::uint32_t paymentTotal, TenthBips32 interestRate=TenthBips32(0), std::uint32_t flags=0, std::uint32_t paymentInterval=120, std::uint32_t gracePeriod=60)
std::chrono::time_point< NetClock > time_point
Number is a floating point type that can represent a wide range of values.
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
test::jtx::PrettyAsset PrettyAsset
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
SLE::const_pointer le(Account const &account) const
Return an account root.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loan(UInt256 const &loanBrokerID, SeqProxy const &loanSeq) noexcept
auto const kManagementFeeRate
auto const kCoverRateMinimum
auto const kCoverRateLiquidation
void checkFixedPrecisionVaultAssetsDeployed(beast::unit_test::Suite &suite, jtx::Env &env, Keylet const &vaultKeylet, std::vector< Keylet > const &brokerKeylets, std::vector< Keylet > const &loanKeylets, std::string const &label={})
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
int scale(Number const &number, Asset const &asset)
Get the scale of a Number for a given asset.
TenthBips< std::uint32_t > TenthBips32
TenthBips< std::uint16_t > TenthBips16
A pair of SHAMap key and LedgerEntryType.
test::jtx::Account depositor
NetClock::time_point redemptionDate
test::jtx::Account issuer
test::jtx::PrettyAsset asset