-
Notifications
You must be signed in to change notification settings - Fork 1.6k
adds a check to ensure vault asset cap is not exceeded #6124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ximinez/lending-XLS-66-ongoing
Are you sure you want to change the base?
Changes from all commits
4109cb5
52948a9
bd1cea0
9570222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
Comment on lines
+415
to
+420
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to leave some extra buffer here? A late payment, for example, could increase the vault total over assets maximum. Those things are hard to predict, though, so I'm not sure what a reasonable amount would be.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's okay, a LoanPay transaction is allowed to exceed the Vault asset limit, precisely for the reason you mention: it's unpredictable. This is similar to freezing logic, where if the LoanBroker is frozen during the loan creation, the transaction fails, but if the LoanBroker is frozen during LoanPay, then we redirect the funds to the LoanBrokerCover. |
||
| // 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to have another test case where the loan has interest, and the principal request is under the limit, but the interest drives it over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This testcase is exactly what you describe.
We set the Vault max assets to 1,000,000
tx[sfAssetsMaximum] = BrokerParameters::defaults().vaultDeposit; <=== 1,000,000We request principal of 1,000, but the interest pushes the TotalValue above the limit of 1,000,000