Skip to content

fix: reorder fee arithmetic to prevent precision loss in discounts#296

Merged
hman38705 merged 1 commit intosolutions-plug:mainfrom
Macnelson9:fix/issue-39-fee-precision
Mar 26, 2026
Merged

fix: reorder fee arithmetic to prevent precision loss in discounts#296
hman38705 merged 1 commit intosolutions-plug:mainfrom
Macnelson9:fix/issue-39-fee-precision

Conversation

@Macnelson9
Copy link
Copy Markdown
Contributor

📋 Description

Fixes precision loss in multi-tier fee math by removing early truncation and using single-pass high-precision arithmetic for tier discounts. This ensures discounted tiers are correctly reflected instead of collapsing to the same fee as Basic in low-precision edge cases.

🎯 Type of Change

  • 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
  • Performance improvement
  • Code refactoring
  • Test addition/update
  • CI/CD update

🔗 Related Issues

Closes #147

📝 Changes Made

  • Updated tiered fee math in fees.rs to multiply before dividing, using basis-point multipliers end-to-end.
  • Added overflow-safe arithmetic with saturating multiplication in fee calculations.
  • Added focused unit tests for precision behavior, including explicit 4-unit bet discount regression coverage.

🧪 Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • All tests passing locally
  • Test coverage maintained/improved

Manual Testing

  • Tested on testnet
  • Tested locally
  • Edge cases tested

Test Results:
Unit tests were added in the fee module for discount precision and ratio correctness.
Local command execution for cargo test was not available in this Copilot tool session due environment terminal provider error (ENOPRO), so full local run is pending.

📸 Screenshots (if applicable)

Not applicable (no UI changes).

✅ Checklist

Code Quality

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex code
  • No unnecessary console.log or debug code
  • No commented-out code

Documentation

  • Documentation updated (if needed)
  • API documentation updated (if applicable)
  • CHANGELOG.md updated
  • README updated (if needed)

Testing & Quality

  • All tests pass (cargo test)
  • No linting errors (cargo clippy)
  • Code formatted (cargo fmt)
  • No new warnings introduced
  • Gas benchmarks run (if applicable)

Security

  • Security implications considered
  • No sensitive data exposed
  • Input validation added
  • Authorization checks in place

Git

  • Branch is up to date with main
  • Commits are atomic and well-described
  • Commit messages follow convention
  • No merge conflicts

🔍 Reviewer Notes

Please focus review on:

  • Arithmetic ordering and precision correctness in tier discount calculations.
  • Overflow behavior and use of saturating operations.
  • Test expectations for low-amount and boundary discount scenarios.

📊 Performance Impact

  • No performance impact
  • Performance improved
  • Performance impact acceptable (explain below)

Details:
Changes are arithmetic-only and limited to fee computation paths; no additional storage or RPC overhead introduced.

🚀 Deployment Notes

No migration needed.
No configuration changes required.
Safe to deploy as a non-breaking bug fix.

📚 Additional Context

Primary fix area:

  • fees.rs

Suggested commit message:
fix: reorder fee arithmetic to prevent precision loss in discounts


By submitting this PR, I confirm that:

  • I have read and followed the CONTRIBUTING.md guidelines
  • My code follows the project's coding standards
  • I have tested my changes thoroughly
  • I am ready for code review

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

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

@hman38705 hman38705 merged commit 068648b into solutions-plug:main Mar 26, 2026
2 of 13 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.

Fix Precision Loss in Multi-Tier Fee Math

2 participants