-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: incorporate era length which may be less than a day for some chains while calc a validators APY #1659
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes involve modifications to the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
packages/extension-polkagate/src/hooks/useValidatorApy.ts (1)
40-42
: LGTM! Consider extracting magic numbers as named constants.The era length calculations correctly incorporate the block time for dynamic era depth calculation. However, consider extracting magic numbers:
+const SECONDS_PER_HOUR = 3600; +const HOURS_PER_DAY = 24; -const eraLengthInHrs = eraLength.toNumber() * AVG_SECONDS_PER_BLOCK / 3600; -const eraPerDay = 24 / eraLengthInHrs; +const eraLengthInHrs = eraLength.toNumber() * AVG_SECONDS_PER_BLOCK / SECONDS_PER_HOUR; +const eraPerDay = HOURS_PER_DAY / eraLengthInHrs;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/extension-polkagate/src/hooks/useValidatorApy.ts
(4 hunks)
🔇 Additional comments (4)
packages/extension-polkagate/src/hooks/useValidatorApy.ts (4)
14-14
: Type change from BN to number looks good.
The change from BN
to number
for netReward
aligns with the goal of using native JavaScript number operations for better performance and readability.
101-102
: LGTM! Consistent type handling.
The accumulation of rewards and stakes maintains consistency in type conversions while simplifying the calculations.
109-111
: LGTM! Correct APY calculation with proper validation.
The APY calculation:
- Correctly incorporates era length variations
- Properly handles daily reward calculations
- Includes validation for infinite/NaN results
70-70
: Verify precision requirements for reward calculations.
Converting BN to number using toNumber()
could potentially lose precision for very large values. Ensure that your chain's reward values will not exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53 - 1).
#!/bin/bash
# Check for potentially large reward values
rg -A 2 "erasValidatorReward|validatorReward|reward" --type typescript
This reverts commit c35cd59.
## [0.30.1](v0.30.0...v0.30.1) (2024-11-17) ### Bug Fixes * incorporate era length which may be less than a day for some chains while calc a validators APY ([#1659](#1659)) ([b700e65](b700e65))
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation