Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(RewardsStreamerMP): use Math.mulDiv to reduce likelyhood of #92

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

0x-r4bbit
Copy link
Collaborator

precision loss

Closes #85

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Added natspec comments?
  • Ran pnpm adorno?
  • Ran pnpm verify?

return amount * lockMultiplier / SCALE_FACTOR;
return Math.mulDiv(
Math.mulDiv(amount * lockPeriod, MAX_MULTIPLIER * SCALE_FACTOR, MAX_LOCKUP_PERIOD), 1, SCALE_FACTOR
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be changed to

uint256 intermediate = Math.mulDiv(amount * lockPeriod, MAX_MULTIPLIER * SCALE_FACTOR, MAX_LOCKUP_PERIOD);
return intermediate / SCALE_FACTOR;

3esmit
3esmit previously requested changes Dec 5, 2024
@@ -444,7 +447,7 @@ contract RewardsStreamerMP is
return 0;
}

uint256 accruedMP = (timeDiff * account.stakedBalance * MP_RATE_PER_YEAR) / (365 days * SCALE_FACTOR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove scale factor if using math.muldiv

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

@0x-r4bbit
Copy link
Collaborator Author

@3esmit this is now green on CI. I'm dismissing your "change requested" as all the requested changes have landed and it keeps us blocked from merging this.

@0x-r4bbit 0x-r4bbit dismissed 3esmit’s stale review December 6, 2024 07:02

We agreed on merging this once green on CI

@0x-r4bbit 0x-r4bbit merged commit 106ec98 into main Dec 6, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Precision loss in division
2 participants