feat(#1382): Add accrual index logic - #1579
Open
T-kesh wants to merge 1 commit into
Open
Conversation
ogazboiz
requested changes
Aug 3, 2026
ogazboiz
left a comment
Contributor
There was a problem hiding this comment.
the accrual math sketch is a reasonable starting point, but as submitted this is dead code: accrual.rs is never declared in lib.rs (no mod accrual), so nothing here compiles into the crate or changes behavior.
- wire the module into lib.rs and resolve the LoanError collision (extend the existing enum rather than redefining it).
- mul_div uses plain i128 checked_mul; issue #1382 requires 256-bit widening for the intermediate product (your own comment admits this). implement a real widened mul_div.
- the StaleIndex check is a commented-out TODO; implement it.
- integrate index_at_origination into the Loan struct and the actual accrual call path.
- add the unit tests / golden vectors from the issue's acceptance criteria.
if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description: closes #1382 (Phase 1).
The current loan accrual path recomputes each step using integer division, dropping sub-stroop remainders and causing a significant downward divergence from the true closed-form accrued value over time.
This PR introduces Phase 1 of the cross-layer fix for the Smart Contract infrastructure:
Scaffolds contracts/loan_manager/src/accrual.rs.
Implements the 128-bit fixed point mathematical operations (mul_div) for INDEX_SCALE = 1e18.
Defines persistent storage for the global BorrowIndex.
Introduces LoanError::IndexOverflow and LoanError::StaleIndex for strict numerical and temporal bounds checking.
(Note: Follow-up PRs will address the backend ingestion mirror and frontend projection hooks).