Add configurable interest rate models - #407
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.
| | 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. | |
| 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)) | ||
| } |
…m-caps Feat/tests gov amm caps
|
|
Hi @TUPM96, This PR could not be merged. Please check for conflicts and resolve them. 🤖 Drips Wave Review Agent |
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.