Add configurable interest rate models#407
Open
TUPM96 wants to merge 1 commit into
Open
Conversation
|
@TUPM96 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for selectable, prebuilt interest-rate models (linear/kink/jump/exponential) and exposes endpoints to query/switch the active model, along with tests, benchmarks, and docs.
Changes:
- Introduces
InterestRateModelKindand model-specific borrow-rate calculations with shared clamping logic. - Adds contract APIs + tests to query/update the active interest rate model.
- Extends benchmark suite and adds documentation for the available models.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| stellar-lend/contracts/lending/src/lib.rs | Exposes interest-rate model types and adds contract entrypoints for model querying/updating. |
| stellar-lend/contracts/lending/src/interest_rate.rs | Implements multiple interest-rate model formulas, config updates, and event publication. |
| stellar-lend/contracts/lending/src/interest_rate_test.rs | Updates event assertions and adds coverage for switching between models. |
| stellar-lend/contracts/lending/src/borrow.rs | Updates config update construction to include the new model field. |
| stellar-lend/contracts/lending/interest_rate_models.md | Documents supported rate models, behavior, migration notes, and benchmarks. |
| stellar-lend/contracts/hello-world/src/lib.rs | Adds APIs to read/switch the active interest-rate model. |
| stellar-lend/contracts/hello-world/src/interest_rate.rs | Adds model enum and model-based rate calculation + admin model switching. |
| stellar-lend/benchmarks/src/lending_benchmarks.rs | Adds benchmarks for switching interest-rate models. |
| stellar-lend/benchmarks/src/framework.rs | Adds budget entries for the new interest-rate model benchmarks. |
Comments suppressed due to low confidence (1)
stellar-lend/contracts/lending/src/interest_rate.rs:76
- Using
Option<u32>formodelmakes the API less type-safe and forces callers to cast enum variants (and allows accidental invalid codes). Preferpub model: Option<InterestRateModelKind>inInterestRateConfigUpdateand accept/serialize the enum directly; this removes the need forfrom_codeat the boundary and reduces invalid-input surface area.
pub struct InterestRateConfigUpdate {
pub model: Option<u32>,
pub base_rate_bps: Option<i128>,
pub kink_utilization_bps: Option<i128>,
pub slope_bps: Option<i128>,
pub jump_slope_bps: Option<i128>,
pub rate_floor_bps: Option<i128>,
pub rate_ceiling_bps: Option<i128>,
pub spread_bps: Option<i128>,
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+14
| | Model | Behavior | | ||
| | --- | --- | | ||
| | `Linear` | `base + utilization * slope` | | ||
| | `Kink` | Piecewise linear. Uses `slope` below `kink_utilization_bps` and `jump_slope` above it. | | ||
| | `Jump` | Linear slope across all utilization plus an additional jump slope above the kink. | | ||
| | `Exponential` | Quadratic/cubic integer approximation for markets that need sharper high-utilization pricing. | |
Comment on lines
262
to
274
| pub fn supply_rate_bps(env: &Env) -> Result<i128, InterestRateError> { | ||
| let cfg = get_config(env); | ||
| let borrow = borrow_rate_bps(env)?; | ||
| let supply = borrow | ||
| .checked_sub(cfg.spread_bps) | ||
| .ok_or(InterestRateError::Overflow)?; | ||
| let supply = if borrow <= cfg.spread_bps { | ||
| 0 | ||
| } else { | ||
| borrow | ||
| .checked_sub(cfg.spread_bps) | ||
| .ok_or(InterestRateError::Overflow)? | ||
| }; | ||
|
|
||
| Ok(supply.max(cfg.rate_floor_bps)) | ||
| } |
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.
Closes #357
Summary
InterestRateConfigand adds a governance update API throughupdate_interest_rate_model.Validation
cargo check --manifest-path stellar-lend/contracts/lending/Cargo.toml --libcargo test --manifest-path stellar-lend/contracts/lending/Cargo.toml interest_rate --no-run(still blocked by pre-existingborrow_test/math_safety_testharness errors unrelated to this change)cargo check -p stellarlend-benchmarks(still blocked by pre-existinghello-worldduplicate definitions/stale tests)git diff --cached --checkNotes
stable_rate_bpssnapshot; new stable borrows use the active model.