-
Notifications
You must be signed in to change notification settings - Fork 0
feat(bcl): enhance BclPluginSyncService with transaction decoding and… #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Historical Prices Always Use Latest Rates
The getPriceData method uses the class property this.latestRates instead of the local variable latestRates when checking for null and calculating prices. When a date parameter is provided, historical rates are fetched into the local variable but then ignored, causing all calculations to use the class property instead of the historically-appropriate rates.
src/ae-pricing/ae-pricing.service.ts#L74-L81
superhero-api/src/ae-pricing/ae-pricing.service.ts
Lines 74 to 81 in 0b8b4ef
| if (!this.latestRates) { | |
| return prices as any; | |
| } | |
| CURRENCIES.forEach(({ code }) => { | |
| try { | |
| prices[code] = price.multipliedBy(this.latestRates.rates![code]) as any; |
| const priceChangeData = pluginLogs.data?.find( | ||
| (data) => data.name === 'PriceChange', | ||
| ); | ||
| const _unit_price = _amount.div(volume); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Division by Zero: Price Calculation Breakdown
Division by zero occurs when calculating _unit_price as _amount.div(volume). For create_community transactions without a PriceChange log, volume remains zero, causing BigNumber division by zero which produces Infinity or NaN, breaking subsequent price calculations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Historical Prices: Wrong Rates Applied.
The method uses the instance variable this.latestRates instead of the local variable latestRates that was just fetched. When calling getPriceData with a historical date, latestRates contains the correct historical price data, but the calculations use this.latestRates which may contain different (current) rates or be null, causing incorrect price conversions for historical transactions.
src/ae-pricing/ae-pricing.service.ts#L74-L81
superhero-api/src/ae-pricing/ae-pricing.service.ts
Lines 74 to 81 in 06c6ead
| if (!this.latestRates) { | |
| return prices as any; | |
| } | |
| CURRENCIES.forEach(({ code }) => { | |
| try { | |
| prices[code] = price.multipliedBy(this.latestRates.rates![code]) as any; |
06c6ead to
6f7d09e
Compare
17e23ca to
f5c3c92
Compare
| address: transferLogs?.contract?.address, | ||
| factory_address: createCommunityLogs?.contract?.address, | ||
| dao_address: createCommunityLogs.args[1], | ||
| sale_address: createCommunityLogs.args[2], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Potential null access on createCommunityLogs
When tx.function is create_community, the code accesses createCommunityLogs.args[0] and other properties without checking if createCommunityLogs is defined. If the CreateCommunity log isn't found in the decoded logs, this causes a runtime error. Line 203 uses optional chaining but lines 200, 204, and 205 don't.
aa6fa36 to
9a878ec
Compare
… price data retrieval - Updated BclPluginSyncService to include a new decodeData method for processing transaction logs and extracting relevant data. - Integrated AePricingService to fetch price data for various transaction parameters, improving financial calculations within the service. - Added a new contract address to BCL_CONTRACT configuration for enhanced functionality.
…nd service - Added BclTransactionsController to handle requests for retrieving paginated BCL transactions. - Introduced BclTransactionsService for managing transaction data retrieval and pagination. - Created BclTransactionDto to standardize the data structure for BCL transactions. - Implemented BclTransaction view entity to facilitate querying transaction data from the database. - Updated BclPluginModule to include new services and controllers for enhanced BCL functionality.
…Number conversion - Added an optional parameter 'asBigNumber' to the getPriceData method to allow for price data to be returned as a number or BigNumber. - Updated price calculations to respect the new parameter, improving flexibility in handling price data formats.
…ving logic - Introduced an onUpdateComplete method in BasePluginSyncService to handle post-update actions. - Updated transaction saving in BasePlugin to use upsert for improved conflict resolution and efficiency.
…zed view refresh logic - Added onUpdateComplete method in BclPluginSyncService to refresh the materialized view for BCL transactions upon update completion. - Updated transaction processing logic to conditionally refresh the view based on sync direction. - Modified BclTransaction view entity to be materialized and adjusted query logic to include 'create_community' function for better transaction management.
…ution time - Updated BclTransactionsController and TransactionsController to return the time taken for query execution in the pagination response. - Modified BclTransactionsService and TransactionsService to calculate and include the queryMs property in the returned pagination results, improving performance insights for API consumers.
…e, and DTO - Added BclTokensController to handle requests for retrieving paginated BCL tokens. - Implemented BclTokensService for managing token data retrieval and pagination. - Created BclTokenDto to standardize the data structure for BCL tokens. - Introduced BclToken view entity for querying token data from the database. - Enhanced BclPluginModule to include new services and controllers for improved BCL functionality. - Updated BclPluginSyncService to refresh materialized views for tokens during transaction processing.
…d data handling - Added logic to identify duplicate sale addresses in BclPluginSyncService, improving error handling during materialized view refresh. - Updated transaction processing to include sell price calculations and collection data in BclPluginSyncService. - Modified BclToken view to ensure proper casting of price and sell price fields, enhancing data integrity in queries.
9a878ec to
e8b4e29
Compare
…ndling - Introduced a new sync direction 'Upgrade' in SyncDirectionEnum for enhanced transaction processing. - Updated BclPluginSyncService to utilize the new Upgrade direction during transaction processing. - Removed materialized view refresh logic from BclPluginSyncService, transitioning to direct BCL transaction saving. - Implemented BclTransactionPersistenceService for managing BCL transaction records, including verification and price calculations.
…dling - Created a new BclTransaction entity for improved transaction data management. - Updated imports in BclPluginModule and related services to reference the new BclTransaction entity. - Added logic in BclPluginSyncService to handle community creation transactions, enhancing transaction processing capabilities.
- Introduced BclToken entity for improved token data management. - Added BclTokenPersistenceService to handle saving BCL token records during community creation transactions. - Updated BclPluginSyncService to save BCL tokens directly, removing the need for materialized view refresh. - Modified BclTokensController and BclTokensService to utilize the new BclToken entity and view for better data handling. - Renamed and refactored methods in BclTokensController for clarity and consistency.
…oller, and DTO - Introduced BclTokenStats entity and materialized view for tracking token statistics. - Added BclTokenStatsService for retrieving and managing token stats data. - Implemented BclTokenStatsRefreshService for automatic and manual refresh of the materialized view. - Created BclTokenStatsController to handle API requests for token stats, including pagination and specific token queries. - Defined BclTokenStatsDto to standardize the response structure for token stats API endpoints.
…hance validation - Consolidated order_by and order_direction query parameters for clarity. - Added validation for sort fields to prevent SQL injection vulnerabilities. - Updated BclToken view to utilize COALESCE for trending_score and adjusted related SQL queries for improved data integrity.
- Introduced BclTokenPerformanceView for efficient querying of token performance data. - Added BclTokenPerformanceController to handle API requests for token performance metrics. - Created BclTokenPerformanceRefreshService to automate the refresh of the materialized view. - Updated BclTokenDto and BclTokenView to include performance metrics for various time periods. - Enhanced BclPluginModule to integrate new services and controllers for improved BCL functionality.
…manceController - Added DeprecatedApisModule to encapsulate deprecated API functionalities. - Implemented TokenPerformanceController to handle token performance requests, marking endpoints as deprecated. - Updated BclPluginModule to export BclTokensService for broader access. - Removed TokenPerformanceController from TokensModule to streamline token management.
- Added BclTokenView import to post.module.ts for enhanced token data handling. - Updated posts.controller.ts to replace Token with BclTokenView in query joins, streamlining token retrieval and improving data integrity.
…n endpoints - Introduced DeprecatedTokensController to handle legacy token queries, marking endpoints as deprecated. - Updated DeprecatedApisModule to include the new controller, enhancing the management of deprecated API functionalities. - Removed token listing and retrieval methods from TokensController to streamline the API structure.
…lity - Introduced BclTokenRankingsController to provide an API endpoint for retrieving token rankings based on market cap. - Updated BclPluginModule to include the new controller, enhancing the BCL plugin's capabilities. - Removed deprecated token ranking methods from TokensController to streamline the API structure.
…tion - Added CacheInterceptor and CacheTTL for improved caching of token data. - Integrated InjectQueue for managing token holder synchronization tasks. - Removed deprecated methods and streamlined the controller for better maintainability.
…d price - Updated sorting logic to use addOrderBy for handling NULL values in market cap and price fields. - Ensured proper order direction handling by converting input to uppercase. - Streamlined query building for better data integrity and performance.
…ty function - Implemented a utility function `isSelfTransferTx` to identify self-transfer transactions. - Updated `LiveIndexerService` to ignore self-transfer transactions during live transaction handling. - Cleaned up code formatting for improved readability.
…nchronization - Integrated the `isSelfTransferTx` utility function to filter out self-transfer transactions during block synchronization. - Enhanced transaction processing logic to improve data handling and integrity.
- Changed view dependencies in BclTokenPerformanceView, BclTokenStats, and BclTokensView to use class references instead of strings for improved TypeORM view creation order. - Updated backup file path in db-restore.sh to point to the latest backup file.
| total_supply = new BigNumber( | ||
| toAe(pluginLogs.data.find((data) => data.name === 'Buy').args[2]), | ||
| ).plus(volume); | ||
| dao_balance = pluginLogs.data.find((data) => data.name === 'Buy').args[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null checks cause crashes on log access
In the decodeData method, .find() results are accessed without null checks. For example, pluginLogs.data.find((data) => data.name === 'Buy').args[0] at line 136 will throw a TypeError if no Buy log exists. Similarly, mints[0].args[1] at lines 133/146 will crash if the mints array is empty. The same pattern affects Sell and Burn log access in the sell block at lines 159-166.
Additional Locations (1)
|
|
||
| await this.dataSource.query( | ||
| `REFRESH MATERIALIZED VIEW CONCURRENTLY bcl_token_stats`, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-materialized view cannot be refreshed as materialized
The bcl_token_stats view is defined with materialized: false, making it a regular view. However, BclTokenStatsRefreshService attempts to execute REFRESH MATERIALIZED VIEW CONCURRENTLY bcl_token_stats, which will fail at runtime because PostgreSQL cannot refresh a regular view as a materialized view. The comment in the view definition contradicts the actual setting.
Additional Locations (1)
| try { | ||
| // Try concurrent refresh first (requires unique index) | ||
| await this.dataSource.query( | ||
| 'REFRESH MATERIALIZED VIEW CONCURRENTLY token_performance_view', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-materialized view cannot be refreshed as materialized
The bcl_token_performance_view view is defined with materialized: false, making it a regular view. However, BclTokenPerformanceRefreshService attempts to execute REFRESH MATERIALIZED VIEW CONCURRENTLY bcl_token_performance_view, which will fail at runtime because PostgreSQL cannot refresh a regular view as a materialized view.
… price data retrieval
Note
BclToken,BclTransactionentities plusbcl_tokens_view,bcl_token_performance_view,bcl_token_statsfor efficient reads; implement services to decode/save BCL txs/tokens and compute sell/market values usingAePricingService.bcl/fortokens(listing, by address, rankings),transactions(paginated),token-stats(list/top/by token, manual refresh), andtokens/:address/performance./tokenslist/find and/tokens/:address/performanceto@deprecated-apiswith deprecation notices; remove oldTokenPerformanceView; updatePostsControllerto joinBclTokenView.Upgradesync direction; safer plugin sync-state initialization via upsert; base plugin upserts tx updates and exposesonUpdateComplete.synchronizeand runsynchronizeWithErrorHandlingon startup; extendAePricingServiceto support historical/number outputs; add cron refreshers for BCL views.queryMs) in transactions list responses.Written by Cursor Bugbot for commit a4605f8. This will update automatically on new commits. Configure here.