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.
Summary
This PR adds a new view function
getPoolReserves()to theTest_AMMContract, enabling external callers to query the current token reserves for any pool by its market ID. This enhances the contract's observability and enables better integration with off-chain systems and frontends.Changes
New Function
getPoolReserves(bytes32 marketId)marketId: Unique identifier for the prediction market/poolreserve0: Current reserve amount of tokenA in the poolreserve1: Current reserve amount of tokenB in the poolUse Cases
This function enables several important capabilities:
Price Discovery: Calculate current token ratios and implied prices
Liquidity Analysis: Determine available liquidity before executing swaps
Frontend Integration: Display real-time pool state in user interfaces
Analytics & Monitoring: Track reserve changes over time for market insights
Smart Contract Composition: Other contracts can query reserves for decision-making
Technical Details
src/onchain/TestAMMContract.soluint256valuesmarketIdToPoolmapping to retrieve pool data(0, 0)gracefullyBehavior
(reserveA, reserveB)(0, 0)(0, 0)Documentation
The function includes comprehensive NatSpec documentation:
Integration Examples
Frontend (using Wagmi)
Smart Contract
Testing Recommendations
Ensure the following test cases are covered:
(0, 0)for pool with no liquidity(0, 0)without revertingSuggested Test Structure (Foundry)
Security Considerations
Related Functions
This function complements the existing
getAllPools()function by providing: