Add estimateFeeForAmount with bigint precision to feeEstimator - #722
Merged
Conversation
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This PR adds a new method, estimateFeeForAmount, to the feeEstimator module. The method uses bigint precision to calculate fees for arbitrary amounts, ensuring accuracy for large values that exceed JavaScript’s Number safe integer range.
Changes Introduced:
Implemented estimateFeeForAmount(amount: bigint): bigint in feeEstimator.
Leveraged bigint arithmetic for fee calculations to avoid precision loss.
Added unit tests covering:
Small amounts (within safe integer range).
Large amounts (beyond Number.MAX_SAFE_INTEGER).
Edge cases (zero, negative values, extremely large inputs).
Updated documentation (/docs/fee-estimator.md) with usage examples.
Refactored existing fee estimation logic to delegate to the new method where appropriate.
Rationale:
Current fee estimation relies on Number, which can introduce rounding errors for large values.
Using bigint ensures exact precision, critical for financial and blockchain-related calculations.
Provides developers with a safe and consistent API for fee estimation across all input sizes.
Next Steps:
Review by maintainers for API design consistency.
Rollout plan to replace legacy Number-based fee estimation in dependent modules.
Update developer guides to highlight the new bigint-based method.
Close #615