Skip to content

fix: make unclaimed winnings sweep idempotent - #562

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
michaelvic123:bug/sweep-idempotency
May 27, 2026
Merged

fix: make unclaimed winnings sweep idempotent#562
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
michaelvic123:bug/sweep-idempotency

Conversation

@michaelvic123

Copy link
Copy Markdown
Contributor
  • Add winnings_swept: bool field to Market struct (types.rs); initialized to false in Market::new and all direct struct literals
  • Add SweepAlreadyDone = 411 error variant to Error enum (err.rs)
  • Guard sweep_unclaimed_winnings with early return Err(SweepAlreadyDone) if market.winnings_swept is already true, preventing any repeat treasury credit or state mutation
  • Set market.winnings_swept = true atomically with the final storage write so the flag is committed in the same operation as the claimed map updates
  • Already-claimed users continue to be excluded via the existing ClaimInfo::is_claimed() check; the swept flag is an additional layer
  • Add four tests in unclaimed_winnings_timeout_tests.rs: test_double_sweep_rejected, test_double_sweep_burn_rejected, test_claim_then_sweep_excludes_claimed_user, test_sweep_sets_winnings_swept_flag

Pull Request Description

📋 Basic Information

Type of Change

Please select the type of change this PR introduces:

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧪 Test addition/update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🎨 UI/UX improvement
  • 🚀 Deployment/Infrastructure change

Related Issues

Closes #(issue number)
Fixes #(issue number)
Related to #(issue number)

Priority Level

  • 🔴 Critical (blocking other development)
  • 🟡 High (significant impact)
  • 🟢 Medium (moderate impact)
  • 🔵 Low (minor improvement)

📝 Detailed Description

What does this PR do?

Why is this change needed?

How was this tested?

Alternative Solutions Considered


🏗️ Smart Contract Specific

Contract Changes

Please check all that apply:

  • Core contract logic modified
  • Oracle integration changes (Pyth/Reflector)
  • New functions added
  • Existing functions modified
  • Storage structure changes
  • Events added/modified
  • Error handling improved
  • Gas optimization
  • Access control changes
  • Admin functions modified
  • Fee structure changes

Oracle Integration

  • Pyth oracle integration affected
  • Reflector oracle integration affected
  • Oracle configuration changes
  • Price feed handling modified
  • Oracle fallback mechanisms
  • Price validation logic

Market Resolution Logic

  • Hybrid resolution algorithm changed
  • Dispute mechanism modified
  • Fee structure updated
  • Voting mechanism changes
  • Community weight calculation
  • Oracle weight calculation

Security Considerations

  • Access control reviewed
  • Reentrancy protection
  • Input validation
  • Overflow/underflow protection
  • Oracle manipulation protection

🧪 Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • All tests passing locally
  • Manual testing completed
  • Oracle integration tested
  • Edge cases covered
  • Error conditions tested
  • Gas usage optimized
  • Cross-contract interactions tested

Test Results

# Paste test output here
cargo test
# Expected output: X tests passed, Y tests failed

Manual Testing Steps


📚 Documentation

Documentation Updates

  • README updated
  • Code comments added/updated
  • API documentation updated
  • Examples updated
  • Deployment instructions updated
  • Contributing guidelines updated
  • Architecture documentation updated

Breaking Changes

Breaking Changes:

Migration Guide:


🔍 Code Quality

Code Review Checklist

  • Code follows Rust/Soroban best practices
  • Self-review completed
  • No unnecessary code duplication
  • Error handling is appropriate
  • Logging/monitoring added where needed
  • Security considerations addressed
  • Performance implications considered
  • Code is readable and well-commented
  • Variable names are descriptive
  • Functions are focused and small

Performance Impact

  • Gas Usage:
  • Storage Impact:
  • Computational Complexity:

Security Review

  • No obvious security vulnerabilities
  • Access controls properly implemented
  • Input validation in place
  • Oracle data properly validated
  • No sensitive data exposed

🚀 Deployment & Integration

Deployment Notes

  • Network: Testnet/Mainnet
  • Contract Address:
  • Migration Required: Yes/No
  • Special Instructions:

Integration Points

  • Frontend integration considered
  • API changes documented
  • Backward compatibility maintained
  • Third-party integrations updated

📊 Impact Assessment

User Impact

  • End Users:
  • Developers:
  • Admins:

Business Impact

  • Revenue:
  • User Experience:
  • Technical Debt:

✅ Final Checklist

Pre-Submission

  • Code follows Rust/Soroban best practices
  • All CI checks passing
  • No breaking changes (or breaking changes are documented)
  • Ready for review
  • PR description is complete and accurate
  • All required sections filled out
  • Test results included
  • Documentation updated

Review Readiness

  • Self-review completed
  • Code is clean and well-formatted
  • Commit messages are clear and descriptive
  • Branch is up to date with main
  • No merge conflicts

📸 Screenshots (if applicable)

🔗 Additional Resources

  • Design Document:
  • Technical Spec:
  • Related Discussion:
  • External Documentation:

closes #560

- Add `winnings_swept: bool` field to Market struct (types.rs); initialized
  to false in Market::new and all direct struct literals
- Add `SweepAlreadyDone = 411` error variant to Error enum (err.rs)
- Guard sweep_unclaimed_winnings with early return Err(SweepAlreadyDone)
  if market.winnings_swept is already true, preventing any repeat treasury
  credit or state mutation
- Set market.winnings_swept = true atomically with the final storage write
  so the flag is committed in the same operation as the claimed map updates
- Already-claimed users continue to be excluded via the existing
  ClaimInfo::is_claimed() check; the swept flag is an additional layer
- Add four tests in unclaimed_winnings_timeout_tests.rs:
  test_double_sweep_rejected, test_double_sweep_burn_rejected,
  test_claim_then_sweep_excludes_claimed_user, test_sweep_sets_winnings_swept_flag
@drips-wave

drips-wave Bot commented May 26, 2026

Copy link
Copy Markdown

@michaelvic123 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

The Market struct gained a winnings_swept: bool field in the sweep
idempotency fix but the direct struct literal in create_market was
missed. This caused a compile error since all struct fields must be
initialised. Set it to false (same as Market::new).
@greatest0fallt1me
greatest0fallt1me merged commit 1e2dbfd into Predictify-org:master May 27, 2026
1 check failed
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.

Add idempotency guard to sweep_unclaimed_winnings preventing double-sweep to treasury

2 participants