Number scale helper function#6384
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## tapanito/lending-vault-invariant #6384 +/- ##
================================================================
Coverage 79.8% 79.8%
================================================================
Files 846 846
Lines 67825 67825
Branches 7556 7557 +1
================================================================
Hits 54130 54130
Misses 13695 13695
🚀 New features to boost your workflow:
|
… into ximinez/number-scale2 * XRPLF/tapanito/lending-vault-invariant: adds missing includes refactor: Modularize app/tx (6228) refactor: Decouple app/tx from `Application` and `Config` (6227)
- Rename `numberScale` to `scale`. - Remove the `AssetType` template parameter - just use class Asset.
There was a problem hiding this comment.
Pull request overview
Refactors “Number scale” computation by replacing the recently added Number::scale member template with a simpler free helper function, and updates vault/lending call sites to use it.
Changes:
- Add
scale(Number const&, Asset const&)helper inSTAmount.h. - Remove
Number::scale(and its supporting concept) fromNumber.h. - Update invariant checks and lending/vault-related code/tests to call the new helper (plus minor formatting-only changes).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/test/app/Vault_test.cpp | Formatting-only adjustment to lambda parameter layout. |
| src/test/app/Invariants_test.cpp | Switches vault min-scale test helper to scale(number, asset). |
| src/libxrpl/tx/transactors/Lending/LoanBrokerCoverWithdraw.cpp | Uses new scale(...) helper when rounding minimum cover. |
| src/libxrpl/tx/InvariantCheck.cpp | Uses new scale(...) helper for vault delta scale computations. |
| include/xrpl/tx/transactors/Lending/LendingHelpers.h | Uses new scale(...) helper to compute stored assets-total scale. |
| include/xrpl/protocol/STAmount.h | Adds the new scale(Number, Asset) helper and minor formatting of operators. |
| include/xrpl/basics/Number.h | Removes Number::scale member template and related concept. |
Comments suppressed due to low confidence (2)
include/xrpl/protocol/STAmount.h:726
- The new doc comment for
scale(Number, Asset)has very long lines and a slightly awkward sentence (“different rules and mantissa ranges for determining the exponent than Number”). Please wrap to match the surrounding style and tweak the wording for clarity/grammar.
/** Get the scale of a Number for a given asset.
*
* "scale" is similar to "exponent", but from the perspective of STAmount, which has different rules and mantissa ranges
* for determining the exponent than Number.
src/libxrpl/tx/InvariantCheck.cpp:3012
- The
std::max(scale(...), scale(...))initializer is now formatted on a single long line, while the adjacentavailableDeltauses a wrapped style. Consider wrapping this call too for consistency/readability (and to avoid line-length issues).
afterVault.assetsTotal - beforeVault.assetsTotal,
std::max(
scale(afterVault.assetsTotal, vaultAsset), scale(beforeVault.assetsTotal, vaultAsset))};
DeltaInfo availableDelta{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }); | ||
|
|
||
| #if LOANTODO | ||
| #if LOAN_TODO |
There was a problem hiding this comment.
Out of scope for this PR, but do we still need these blocks? Can we clean them up?
There was a problem hiding this comment.
Out of scope for this PR, but do we still need these blocks? Can we clean them up?
That #if block is wrapped around test cases that I started or copy/pasted, but wasn't able to fully integrate and get working - not Loan problems, but just problems with the way the test was written or the scenario was set up. I think it would be worthwhile to come back to them eventually. I could stick them in a branch, but they're likely to be even more forgotten than they are now.
I only renamed the label because cspell complained about it, and I want a green build.
…number-scale2 * commit '25cca465538a56cce501477f9e5e2c1c7ea2d84c': chore: Set clang-format width to 100 in config file (6387) chore: Set cmake-format width to 100 (6386) ci: Add clang tidy workflow to ci (6369)
* commit '2c1fad1023': chore: Apply clang-format width 100 (6387)
… into ximinez/number-scale2 * XRPLF/tapanito/lending-vault-invariant: chore: Add nix development environment (6314) ci: [DEPENDABOT] bump actions/upload-artifact from 4.6.2 to 6.0.0 (6396) ci: [DEPENDABOT] bump actions/checkout from 4.3.0 to 6.0.2 (6397) ci: [DEPENDABOT] bump actions/setup-python from 5.6.0 to 6.2.0 (6395) ci: [DEPENDABOT] bump tj-actions/changed-files from 46.0.5 to 47.0.4 (6394) ci: [DEPENDABOT] bump codecov/codecov-action from 5.4.3 to 5.5.2 (6398) ci: Build docs in PRs and in private repos (6400) ci: Add dependabot config (6379) Fix tautological assertion (6393)
11864ff
into
tapanito/lending-vault-invariant
High Level Overview of Change
After looking again at #6246 changes, I realized there could be a simpler function call.
Questions:
numberScalea good name?Number::scaleentirely and inlining it intonumberScale?Context of Change
Type of Change