Feature/statistics #3
Open
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.
POOL STATISTICS IMPLEMENTATION - SUMMARY
WHAT I IMPLEMENTED
I added comprehensive pool statistics tracking to the AMM (Automated Market Maker) to monitor pool performance and trading activity.
The implementation includes:
SMART CONTRACT CHANGES (amm4.clar)
New Fields Added to the Pool Data Structure:
total-volume-0 — Tracks cumulative trading volume for token-0
total-volume-1 — Tracks cumulative trading volume for token-1
total-fees-collected — Tracks total fees earned by liquidity providers
swap-count — Counts the number of swaps executed in the pool
Function Updates:
create-pool — Initializes all statistics fields to zero
swap — Automatically updates statistics after each swap transaction
FRONTEND CHANGES (frontend/lib/amm.ts)
Updates:
Updated TypeScript type definitions (PoolCV and Pool) to include the new statistics fields
Modified getAllPools function to parse and return statistics data from the blockchain
Added a parseUintCV helper function to safely handle potentially undefined statistics values
WHY YOU COULDN’T SEE THE CODE IN MY PREVIOUS PR
The previous pull request was already merged into the main branch, which is why you only saw a README file when you checked.
The actual code changes had already been integrated into the codebase before you reviewed it, you can see the changes in the closed pr section.
WHAT’S NEW IN THIS PR
To make the code more maintainable and understandable, I’ve added comprehensive inline documentation:
Detailed comments explaining each statistics field and its purpose
Documentation of how statistics are initialized when pools are created
Explanations of the statistics update logic in the swap function, including how swap direction affects which volumes are tracked
TypeScript documentation clarifying the data structures and helper functions