mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Ensure vault asset cap is not exceeded (#6124)
This commit is contained in:
@@ -3590,6 +3590,26 @@ protected:
|
||||
fee(env.current()->fees().base * 5));
|
||||
},
|
||||
CaseArgs{.requireAuth = true, .authorizeBorrower = true});
|
||||
|
||||
testCase(
|
||||
[&, this](Env& env, BrokerInfo const& broker, auto&) {
|
||||
using namespace loan;
|
||||
Number const principalRequest = broker.asset(1'000).value();
|
||||
Vault vault{env};
|
||||
auto tx = vault.set({.owner = lender, .id = broker.vaultID});
|
||||
tx[sfAssetsMaximum] = BrokerParameters::defaults().vaultDeposit;
|
||||
env(tx);
|
||||
env.close();
|
||||
|
||||
testcase("Vault maximum value exceeded");
|
||||
env(set(issuer, broker.brokerID, principalRequest),
|
||||
counterparty(lender),
|
||||
interestRate(TenthBips32(10'000)),
|
||||
sig(sfCounterpartySignature, lender),
|
||||
fee(env.current()->fees().base * 5),
|
||||
ter(tecLIMIT_EXCEEDED));
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -407,6 +407,17 @@ LoanSet::doApply()
|
||||
vaultScale,
|
||||
j_);
|
||||
|
||||
LoanState const state = constructLoanState(
|
||||
properties.totalValueOutstanding,
|
||||
principalRequested,
|
||||
properties.managementFeeOwedToBroker);
|
||||
|
||||
if (vaultSle->at(sfAssetsMaximum) != 0 &&
|
||||
vaultTotalProxy + state.interestDue > vaultSle->at(sfAssetsMaximum))
|
||||
{
|
||||
JLOG(j_.warn()) << "Loan would exceed the maximum assets of the vault";
|
||||
return tecLIMIT_EXCEEDED;
|
||||
}
|
||||
// Check that relevant values won't lose precision. This is mostly only
|
||||
// relevant for IOU assets.
|
||||
{
|
||||
@@ -449,11 +460,6 @@ LoanSet::doApply()
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
LoanState const state = constructLoanState(
|
||||
properties.totalValueOutstanding,
|
||||
principalRequested,
|
||||
properties.managementFeeOwedToBroker);
|
||||
|
||||
auto const originationFee = tx[~sfLoanOriginationFee].value_or(Number{});
|
||||
|
||||
auto const loanAssetsToBorrower = principalRequested - originationFee;
|
||||
|
||||
Reference in New Issue
Block a user