Skip to content

feat(invoice): add split rounding auditor with largest-remainder corr… - #603

Merged
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
gracepeterfejokwu:feat/split-rounding-auditor-590
Jul 30, 2026
Merged

feat(invoice): add split rounding auditor with largest-remainder corr…#603
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
gracepeterfejokwu:feat/split-rounding-auditor-590

Conversation

@gracepeterfejokwu

Copy link
Copy Markdown
Contributor

…ection

  • Add SplitLine, RoundingAdjustment, and AuditedSplitResult interfaces to src/types.ts
  • Implement auditSplitRounding() in src/invoice/rounding.ts:
    • Computes per-recipient floor amounts from bigint total × float ratio
    • Applies largest-remainder method to distribute stroop remainder deterministically (highest fractional part wins, stable tie-break)
    • Records every +/-1 stroop adjustment in AuditedSplitResult.adjustments
    • Throws RoundingOverflowError when total adjustment exceeds ceil(splits.length / 2) stroops
  • Add src/invoice/calculator.ts with calculateSplitAmounts() and computeAmounts() wrappers integrating the auditor
  • Add 20 tests in test/roundingAuditor.test.ts covering:
    • Exact division (no correction needed)
    • 3-way uneven split requiring +1 stroop correction
    • 1-stroop invoice split across 3 recipients
    • Largest-remainder ordering is deterministic
    • RoundingOverflowError when ratios deviate too far from 1.0
    • Sum invariant across a range of totals and ratios
    • calculator.ts integration

Closes #590

…ection

- Add SplitLine, RoundingAdjustment, and AuditedSplitResult interfaces
  to src/types.ts
- Implement auditSplitRounding() in src/invoice/rounding.ts:
  - Computes per-recipient floor amounts from bigint total × float ratio
  - Applies largest-remainder method to distribute stroop remainder
    deterministically (highest fractional part wins, stable tie-break)
  - Records every +/-1 stroop adjustment in AuditedSplitResult.adjustments
  - Throws RoundingOverflowError when total adjustment exceeds
    ceil(splits.length / 2) stroops
- Add src/invoice/calculator.ts with calculateSplitAmounts() and
  computeAmounts() wrappers integrating the auditor
- Add 20 tests in test/roundingAuditor.test.ts covering:
  - Exact division (no correction needed)
  - 3-way uneven split requiring +1 stroop correction
  - 1-stroop invoice split across 3 recipients
  - Largest-remainder ordering is deterministic
  - RoundingOverflowError when ratios deviate too far from 1.0
  - Sum invariant across a range of totals and ratios
  - calculator.ts integration

Closes Stellar-split#590
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@gracepeterfejokwu Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Kingsman-99
Kingsman-99 merged commit 7ac31f2 into Stellar-split:main Jul 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Payment Split Fractional Rounding Auditor

2 participants