Skip to content

[Chore] Replace .expect() with typed ContractError in blend-adapter accrue() #459

Description

@collinsezedike

Summary

accrue() in packages/contracts/blend-adapter/src/lib.rs (lines 252 and 254) uses .expect("overflow") and .expect("div zero") on the checked-math result, which panics instead of returning a typed error. Every other mutating entrypoint in this contract, and every entrypoint across the vault/router/defindex-adapter contracts, returns Result<T, ContractError> and propagates a typed variant on checked-math failure.

Motivation

This is the one inconsistency in an otherwise disciplined typed-error pattern across the contracts. A panic here is low-risk today since the inputs come from Blend's own reserve data, but it's still a silent trap for whoever touches this function next without knowing the rest of the codebase avoids .expect()/.unwrap() on fallible math.

Proposed Solution

Change accrue()'s signature to return Result<(), ContractError>, replace both .expect(...) calls with .ok_or(ContractError::Overflow)? (or the equivalent existing variant used elsewhere in this contract for div-by-zero, e.g. what defindex-adapter/vault already use), and update call sites accordingly.

Scope

Field Value
Area Contracts
Protocol affected Blend
Network testnet
Breaking change? No (internal function signature only)

Acceptance Criteria

  • accrue() returns Result<(), ContractError> instead of panicking
  • No .expect()/.unwrap() remain on checked-math results in blend-adapter/src/lib.rs
  • Existing accrue_* tests updated to assert on the Result where relevant
  • cargo clippy --all-targets -- -D warnings and cargo test pass in packages/contracts

Metadata

Metadata

Assignees

Labels

choreBuild, CI, dependency updates, or repository maintenancecontractsInvolves writing or testing Rust/Soroban contracts in packages/contractstrivialSelf-contained task, completable in < 2 hours with no deep protocol knowledge required

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions