Skip to content

feat(#1382): Add accrual index logic - #1579

Open
T-kesh wants to merge 1 commit into
LabsCrypt:mainfrom
T-kesh:fix-issue-1382
Open

feat(#1382): Add accrual index logic#1579
T-kesh wants to merge 1 commit into
LabsCrypt:mainfrom
T-kesh:fix-issue-1382

Conversation

@T-kesh

@T-kesh T-kesh commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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).

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. wire the module into lib.rs and resolve the LoanError collision (extend the existing enum rather than redefining it).
  2. 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.
  3. the StaleIndex check is a commented-out TODO; implement it.
  4. integrate index_at_origination into the Loan struct and the actual accrual call path.
  5. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cross-Layer] Fixed-point cumulative interest index to eliminate per-ledger truncation drift in loan accrual

2 participants