From b07a37d99b97b926c1057d1eefc4b425a341743d Mon Sep 17 00:00:00 2001 From: laurentketterle-hub Date: Wed, 12 Aug 2026 23:10:37 +0200 Subject: [PATCH] refactor: remove dead storage helpers and unify interest-rate calculation (Closes #331) storage.rs exposed six accessor helpers (read/write_project, read/write_proposal, read/write_whitelist) that lib.rs never referenced, and logic::calculate_interest_rate duplicated the private compute_rate formula in lib.rs. This removes the dead storage helpers and makes compute_rate delegate to logic::calculate_interest_rate (which already includes the underflow guard the local copy lacked), unifying the rate formula into a single implementation. Signed-off-by: laurentketterle-hub --- project_registry/src/lib.rs | 6 ++--- project_registry/src/logic.rs | 3 --- project_registry/src/storage.rs | 42 ++++++--------------------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/project_registry/src/lib.rs b/project_registry/src/lib.rs index 12905686..6632ab7c 100644 --- a/project_registry/src/lib.rs +++ b/project_registry/src/lib.rs @@ -1223,9 +1223,9 @@ fn require_multisig_disabled(env: &Env) { } fn compute_rate(credit_quality: u32, green_impact: u32) -> u32 { - let avg = (credit_quality + green_impact) / 2; - let discount = avg * MAX_DISCOUNT_BPS / 100; - BASE_RATE_BPS - discount + // Single source of truth: logic::calculate_interest_rate already applies + // the underflow guard this local copy lacked. + logic::calculate_interest_rate(BASE_RATE_BPS, MAX_DISCOUNT_BPS, credit_quality, green_impact) } fn read_state_version(env: &Env) -> u32 { diff --git a/project_registry/src/logic.rs b/project_registry/src/logic.rs index 2f5de543..4d174038 100644 --- a/project_registry/src/logic.rs +++ b/project_registry/src/logic.rs @@ -1,6 +1,3 @@ -use crate::types::{CertificationStatus, ProjectData}; -use soroban_sdk::{Address, Env, String}; - /// Interest-rate calculation for green-bond projects. /// /// Heliobond uses a two-dimensional scoring model to determine each project's diff --git a/project_registry/src/storage.rs b/project_registry/src/storage.rs index 0c7c83d8..6cd8781c 100644 --- a/project_registry/src/storage.rs +++ b/project_registry/src/storage.rs @@ -1,35 +1,7 @@ -use crate::types::{DataKey, ProjectData, Proposal}; -use soroban_sdk::{Address, Env}; - -pub fn read_project(env: &Env, id: u32) -> Option { - env.storage().persistent().get(&DataKey::Project(id)) -} - -pub fn write_project(env: &Env, id: u32, project: &ProjectData) { - env.storage() - .persistent() - .set(&DataKey::Project(id), project); -} - -pub fn read_proposal(env: &Env, id: u32) -> Option { - env.storage().persistent().get(&DataKey::Proposal(id)) -} - -pub fn write_proposal(env: &Env, id: u32, proposal: &Proposal) { - env.storage() - .persistent() - .set(&DataKey::Proposal(id), proposal); -} - -pub fn read_whitelist(env: &Env, account: Address) -> bool { - env.storage() - .persistent() - .get(&DataKey::Whitelist(account)) - .unwrap_or(false) -} - -pub fn write_whitelist(env: &Env, account: Address, status: bool) { - env.storage() - .persistent() - .set(&DataKey::Whitelist(account), &status); -} +//! Storage-accessor helpers. +//! +//! Historically this module exposed read_project / write_project / +//! read_proposal / write_proposal / read_whitelist / write_whitelist wrappers +//! around env.storage(), but lib.rs inlines env.storage() calls directly and +//! never referenced them. They were removed to eliminate dead, drift-prone +//! abstractions (#331).