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
Summary
accrue()inpackages/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, returnsResult<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 returnResult<(), 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. whatdefindex-adapter/vaultalready use), and update call sites accordingly.Scope
Acceptance Criteria
accrue()returnsResult<(), ContractError>instead of panicking.expect()/.unwrap()remain on checked-math results inblend-adapter/src/lib.rsaccrue_*tests updated to assert on theResultwhere relevantcargo clippy --all-targets -- -D warningsandcargo testpass inpackages/contracts