Skip to content

Extract invoice funding-percentage helper into calc.rs #705

Description

@Kingsman-99

Description

Computing funded * 10_000 / total (funding completion in basis points) is repeated in multiple places (_pay, auto_resolve, get_invoice_funding_progress, etc.). Extracting it into a single funding_bps(funded: i128, total: i128) -> u32 helper in calc.rs reduces duplication and makes the clamping logic testable in isolation.

Acceptance Criteria

  • New pub fn funding_bps(funded: i128, total: i128) -> u32 added to calc.rs
  • Returns 0 when total <= 0
  • Clamps the result to [0, 10_000]
  • All existing inline computations replaced with calls to this function
  • At least three unit tests covering: funded < total, funded == total, funded > total
  • cargo test passes

Context

  • Target file: contracts/split/src/calc.rs

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programcomplexity: highComplex feature requiring deep knowledge - 200 ptsrefactorCode quality and restructuring

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions