1#include <xrpl/basics/Number.h>
2#include <xrpl/basics/base_uint.h>
3#include <xrpl/ledger/helpers/LendingHelpers.h>
4#include <xrpl/protocol/Asset.h>
5#include <xrpl/protocol/Indexes.h>
6#include <xrpl/protocol/Issue.h>
7#include <xrpl/protocol/MPTIssue.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/STAmount.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12#include <xrpl/protocol/STNumber.h>
13#include <xrpl/protocol/STTakesAsset.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/UintTypes.h>
17#include <gtest/gtest.h>
18#include <helpers/Account.h>
19#include <protocol/VaultTestHelpers.h>
32makeBroker(
Asset const& asset,
Number const& coverAvailable)
35 broker->at(sfCoverAvailable) = coverAvailable;
40TEST(LoanBrokerCover, broker_cover_scale_and_rounding)
45 auto const broker = makeBroker(iou,
Number{9'999'999'999'999'999, -6});
54 broker->at(sfCoverAvailable) =
Number{1'000'000'000'000'001, -5};
66 broker->at(sfCoverAvailable) =
Number{1, 10};
76TEST(LoanBrokerCover, broker_cover_optional_inflow_boundaries)
82 auto const iouBroker = makeBroker(iou,
Number{9, 5});
93 auto const broker = makeBroker(asset,
Number{9, 15});
100TEST(LoanBrokerCover, broker_cover_optional_inflow_scale_mismatch)
111 auto const broker = makeBroker(iou,
Number{2, 10});
116TEST(LoanBrokerCover, credit_to_posterior_broker_cover_scale_at_to_nearest_carry_cusp)
126 Number const coverAvailable{9'999'999'999'999'999, -6};
129 auto const broker = makeBroker(iou, coverAvailable);
A currency issued by an account.
Number is a floating point type that can represent a wide range of values.
Immutable cryptographic account descriptor.
STAmount roundToPosteriorBrokerCoverScale(SLE::ConstRef vault, SLE::ConstRef broker, STAmount const &delta, Number::RoundingMode roundingMode)
Round a cover outflow delta (cover withdraw, cover clawback, the broker-side decrease of a default's ...
int getPosteriorBrokerCoverScale(SLE::ConstRef vault, SLE::ConstRef broker, Number const &delta)
Return a LoanBroker's posterior live cover exponent after applying an unrounded delta.
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
TEST(FileUtilitiesTest, get_file_contents)
std::shared_ptr< SLE > makeVault(Asset const &asset, Number const &assetsTotal, std::optional< VaultVersion > version, std::uint8_t scaleValue=kVaultDefaultIouScale, Number const &assetsDeployed=Number{0}, std::optional< Number > assetsAvailable=std::nullopt)
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
TER checkOptionalBrokerCoverInflow(SLE::ConstRef vault, SLE::ConstRef broker, STAmount const &amount)
Check whether amount is an admissible optional cover inflow.
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
STAmount creditToPosteriorBrokerCoverScale(SLE::ConstRef vault, SLE::ConstRef broker, Number const &raw, Number::RoundingMode roundingMode)
Round a cover inflow (cover deposit, LoanPay's fee redirect into cover) into CoverAvailable by floori...