Skip to content

lending: name the interest index for what it is - #121

Merged
mikemaccana merged 1 commit into
mainfrom
claude/rename-borrow-accumulation-factor
Aug 7, 2026
Merged

lending: name the interest index for what it is#121
mikemaccana merged 1 commit into
mainfrom
claude/rename-borrow-accumulation-factor

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Why

cumulative_borrow_rate_index is 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

From To
cumulative_borrow_rate_index borrow_accumulation_factor
borrowed_amount_scaled borrowed_principal

The 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:

borrowed_principal * borrow_accumulation_factor / FIXED_POINT_SCALE

Scope

Both variants, and everything that mirrored the old vocabulary:

  • Anchor: state/reserve.rs, state/obligation.rs, the five instruction handlers, and three test files.
  • Quasar: state.rs, logic.rs, math.rs, instructions/*.rs. Its own spellings went too, accrue_index()accrue_factor() and borrowed_scaledborrowed_principal.
  • Kani proofs: grow_index()grow_factor(), proof_interest_index_monotonicproof_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.
  • Doc comments that spell the relationship out, including new_index = old_index * (...)new_factor = old_factor * (...), and the three READMEs.

Array positions keep the word. borrow_index and collateral_index in liquidate_obligation.rs and repay_obligation_liquidity.rs are positions in obligation.borrows and obligation.deposits. That is what an index is, and renaming them would have been the same mistake in reverse.

cumulative_funding is left alone. The perps venue accumulates funding additively (funding owed is size × (current − entry)), so neither "factor" nor "multiplier" would describe it. Different quantity, separate decision.

Verification

cargo check --workspace --all-targets passes on the Anchor variant and cargo check --all-targets on the Quasar one. The Kani crate's unit tests pass (4/4). cargo build-sbf and 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

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
@mikemaccana
mikemaccana merged commit 58fdf49 into main Aug 7, 2026
27 checks passed
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.

2 participants