Skip to content

Conversation

FonsSicca
Copy link
Contributor

Implements:

  • Removed individual CLPool event entities (CLPool_Burn, CLPool_Collect, CLPool_CollectFees, CLPool_Flash, CLPool_Mint, CLPool_Swap) and consolidated data into LiquidityPoolAggregator and UserStatsPerPool entities

  • Business logic isolation: Extracted complex calculations into dedicated logic files (CLPoolBurnLogic, CLPoolCollectLogic, CLPoolFlashLogic, etc.) with consistent processCLPool* interfaces for improved testability and maintainability

  • Replaced specific update functions with generic updateUserStatsPerPool and enhanced updateLiquidityPoolAggregator to properly handle cumulative vs non-cumulative fields

  • Enhanced schema for CL pools: Added CL-specific fields (feeProtocol0/1, observationCardinalityNext, totalFlashLoanFees0/1/USD, totalFlashLoanVolumeUSD, numberOfFlashLoans) to pool aggregators and user stats

  • Refactored all tests with exact assertions, proper mocking, and consistent patterns to ensure reliability of the new architecture

  • Standardized all CLPool handlers to follow the same data loading → processing → updating flow for improved maintainability

@FonsSicca FonsSicca requested a review from WooSungD October 6, 2025 17:48
- event: CollectFees(address indexed recipient, uint128 amount0, uint128 amount1)
- event: Flash(address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1)
- event: IncreaseObservationCardinalityNext(uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew)
- event: Initialize(uint160 sqrtPriceX96, int24 tick)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this event didn't have any useful information afaik

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted a bunch of CLPool entities and added some fields on User and pool entities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the approach here

update functions of the user and pool entitities compute the final values: current + diff for cumulative quantities

For other quantities, just substitute current with diff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm I don't understand, was it previously assigning diff to cumulative values?

Copy link
Contributor Author

@FonsSicca FonsSicca Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. The previous code simply substituted all values (cumulative and not cumulative) of current by the values of diff.

This is right for non-cumulative variables but it was wrong for cumulative

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay so this is a bug fix rather than a refactor right?

Copy link
Contributor Author

@FonsSicca FonsSicca Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

centralised user stats updates into a single function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardized the logic flow accross all event handlers + deleted event-driven entities that aren't used now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

business logic for CLPoolBurn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaning house

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

business logic for CLPoolFlash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored this taking into account that event-driven entities no longer exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardize "diff" definition -> diff should always be only the changes derived from the event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardize "diff" definition -> diff should always be only the changes derived from the event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardize "diff" definition -> diff should always be only the changes derived from the event

@FonsSicca FonsSicca merged commit 01e66f8 into main Oct 8, 2025
1 check passed
@FonsSicca FonsSicca deleted the dan/clpool-aggregate-driven-architecture branch October 8, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants