Skip to content

fix(milestones): track unspent contribution remainder to prevent late contributor subsidization - #638

Open
dwaddle wants to merge 1 commit into
MergeFi:mainfrom
dwaddle:fix/milestones-refund-accounting-531
Open

dwaddle wants to merge 1 commit into
MergeFi:mainfrom
dwaddle:fix/milestones-refund-accounting-531

Conversation

@dwaddle

@dwaddle dwaddle commented Oct 14, 2026

Copy link
Copy Markdown

Summary

Tracks unspent contribution remainders per sponsor in mergefi-milestones so that late contributors do not subsidize milestone releases that occurred before they joined.

Related issues

Closes #531

Changes

  • Contribution Model: Added unspent: i128 to Contribution in contracts/milestones/src/types.rs, initialized on milestone creation and append.
  • Release Deduction: In release_issue, deduct released amounts pro-rata across currently active unspent contributions (deduct_release_from_contributions), with largest-remainder dust distribution.
  • Unspent Refund Accounting: In refund_remaining_budget, calculate proportional refunds using actual unspent balances instead of total_budget, returning each sponsor's true unconsumed funds without subsidizing prior releases.
  • Contract Interface: Exported contract::* to ensure MilestonesContract and MilestonesContractClient are accessible in the crate root.
  • Tests: Added regression tests (test_late_contributor_does_not_subsidize_earlier_releases and test_late_contributor_with_subsequent_release_shares_costs_pro_rata).

Test plan

  • Existing tests pass (cargo test -p mergefi-milestones)
  • New tests added for changed behaviour (test_late_contributor_does_not_subsidize_earlier_releases)
  • Verified zero flakiness across 5x test runs

Checklist

  • Branch is up to date with main
  • No debug / dead code left in
  • cargo fmt and cargo clippy are clean

… contributor subsidization

- Add unspent field to Contribution to track unspent balances per sponsor
- In release_issue, deduct released amounts pro-rata across active unspent contributions
- In refund_remaining_budget, calculate proportional refunds using unspent balances instead of total_budget
- Fix late contributors subsidizing earlier spent releases on milestone cancellation
- Add unit tests for late contributor refund accounting and subsequent releases

Closes MergeFi#531
@dwaddle
dwaddle requested a review from chonilius as a code owner October 14, 2026 18:03
@vercel

vercel Bot commented Oct 14, 2026

Copy link
Copy Markdown

@dwaddle is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

milestones refund is pro-rata to lifetime contributions, so late contributors subsidise budget already spent from earlier sponsors

1 participant