lending: name the interest index for what it is - #121
Merged
Conversation
cumulative_borrow_rate_index was wrong twice. It is not a rate, since a rate is per unit of time and this value is the accumulated product of (1 + rate_per_slot * elapsed_slots); and "index" says nothing about what the number is for. Its own doc comment already described it correctly: starts at 1.0 and only ever multiplies by factors >= 1. That is an accumulation factor. cumulative_borrow_rate_index -> borrow_accumulation_factor borrowed_amount_scaled -> borrowed_principal The second follows from the first: "scaled" only meant "scaled by the index", so once the index is a factor the name points at nothing. The pair now reads as the arithmetic it is, borrowed_principal times borrow_accumulation_factor over FIXED_POINT_SCALE. Both variants, and everything that mirrored the old vocabulary: the Quasar accrue_index() and its borrowed_scaled, the Kani proof's grow_index() and proof_interest_index_monotonic, the doc comments spelling out new_index = old_index * (...), and the three READMEs. Array positions keep the word index: borrow_index and collateral_index in liquidate_obligation and repay_obligation_liquidity are positions in obligation.borrows and obligation.deposits, which is what an index is. The perpetual futures venue's cumulative_funding is left alone. It accumulates additively, funding owed being size times the change since entry, so neither "factor" nor "multiplier" would describe it. cargo check passes on both variants with --all-targets, and the Kani crate's unit tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ABFpszmPxRorwWtWGR2jXj
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.
Why
cumulative_borrow_rate_indexis inaccurate twice over.It is not a rate. A rate is per unit of time; this value is the accumulated product of
1 + rate_per_slot × elapsed_slots. And "index" says nothing about what the number is for, while colliding with the word's ordinary meaning of a position in a list.The field's own doc comment already described it correctly: "Starts at FIXED_POINT_SCALE (1.0) and only ever multiplies by factors >= 1." That is an accumulation factor, which is the standard term for the factor by which one unit of principal grows over a period.
The renames
cumulative_borrow_rate_indexborrow_accumulation_factorborrowed_amount_scaledborrowed_principalThe second follows from the first. "Scaled" only ever meant "scaled by the index", so once the index is a factor the name points at nothing. The pair now reads as the arithmetic it is:
Scope
Both variants, and everything that mirrored the old vocabulary:
state/reserve.rs,state/obligation.rs, the five instruction handlers, and three test files.state.rs,logic.rs,math.rs,instructions/*.rs. Its own spellings went too,accrue_index()→accrue_factor()andborrowed_scaled→borrowed_principal.grow_index()→grow_factor(),proof_interest_index_monotonic→proof_accumulation_factor_monotonic. I had assumed these were untouched because they do not reference the field names; they mirror the arithmetic under their own, so they needed it.new_index = old_index * (...)→new_factor = old_factor * (...), and the three READMEs.Array positions keep the word.
borrow_indexandcollateral_indexinliquidate_obligation.rsandrepay_obligation_liquidity.rsare positions inobligation.borrowsandobligation.deposits. That is what an index is, and renaming them would have been the same mistake in reverse.cumulative_fundingis left alone. The perps venue accumulates funding additively (funding owed issize × (current − entry)), so neither "factor" nor "multiplier" would describe it. Different quantity, separate decision.Verification
cargo check --workspace --all-targetspasses on the Anchor variant andcargo check --all-targetson the Quasar one. The Kani crate's unit tests pass (4/4).cargo build-sbfand the LiteSVM suites need platform-tools, whose download is blocked by this environment's egress policy, so CI is the signal for those.A repo-wide grep for the old vocabulary (
cumulative_borrow_rate_index,borrowed_amount_scaled,borrowed_scaled,interest index,grow_index,accrue_index) returns zero hits.Follow-up
The book describes this field in four places and will be updated to match once this merges, so no prose ever names a field that does not exist.
Generated by Claude Code