Add helper for computing bonding curve price at any given supply step without mutating contract state #537
Merged
Merged
Conversation
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.
PR Description
Summary
Introduces a pure helper function for calculating the bonding curve price at any specified supply step without mutating contract state. This enables off-chain price estimation, previews, and testing while preserving contract state integrity.
Changes
Added a helper function to compute the bonding curve price for any given supply value.
Implemented the calculation as a read-only operation with no state mutations.
Reused the existing bonding curve pricing logic to ensure consistency with buy/sell operations.
Added validation for edge cases, including:
Zero supply.
Initial supply.
Large supply values.
Boundary and overflow scenarios (where applicable).
Refactored pricing logic where necessary to minimize code duplication.
Why
Clients, frontends, and tests often need to estimate token prices before executing transactions. A pure helper provides deterministic pricing without requiring a state-changing contract call, improving developer experience while ensuring pricing logic remains consistent across the codebase.
Testing
Added unit tests verifying price calculations across multiple supply levels.
Confirmed the helper produces the same results as the existing contract pricing logic.
Verified that invoking the helper does not modify contract state.
Tested edge cases, including zero, initial, and high supply values.
Closed #552