Skip to content
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

feat: added token info endpoint #8

Merged
merged 2 commits into from
May 9, 2024
Merged

feat: added token info endpoint #8

merged 2 commits into from
May 9, 2024

Conversation

yevhen-burkovskyi
Copy link
Contributor

No description provided.

Copy link

coderabbitai bot commented May 9, 2024

Walkthrough

The recent updates across various modules primarily involve code reformatting for improved readability and minor functionality enhancements. Key changes include adding new models and endpoints for market cap and token data, adjusting enum and method indentations, and modifying data types in configurations. The alterations enhance maintainability and clarity without significantly altering the existing logic or functionality.

Changes

Files Change Summary
eslint.config.mjs, src/.../query-param.enum.ts, src/.../supply-endpoints.enum.ts Adjusted indentation and added new rules or values in enums and ESLint configuration.
prisma/schema.prisma, prisma/migrations/.../migration.sql Introduced HistoricalMcap model and corresponding SQL migration script for database table creation.
src/.../config.dto.ts, src/.../config.ts Modified CacheConfig type and parsing method for userStackingTtl.
src/.../routes.enum.ts, src/modules/app.module.ts Updated routing enums and module imports, replacing PriceModule with TokenModule.
src/.../osmosis/enums/endpoints.enum.ts, src/.../osmosis/osmosis.service.ts, src/.../osmosis/responses/... Added new endpoints and methods in Osmosis service for token and market cap information, along with corresponding response interfaces.
src/.../okp4/okp4.service.ts No changes in exported entities, maintaining existing service methods.
src/.../stacking/..., src/.../supply/... Major reformatting across Stacking and Supply modules for better readability and alignment, affecting controllers, services, and DTOs.
src/main.ts Enabled CORS in the main application setup.

This table summarizes the scope and nature of changes, focusing on improvements in code structure and the introduction of new data handling features.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Out of diff range and nitpick comments (1)
src/modules/token/services/token.jobs.ts (1)

[!TIP]
Codebase Verification

The cron job setup in TokenJobs and SupplyJobs shows overlapping schedules that could potentially lead to performance issues if these jobs are resource-intensive. Here are the specific overlaps:

  • Both have jobs scheduled to run every 2 hours.
  • Both have jobs scheduled to run every 6 hours.
  • Both have jobs scheduled to run daily.
  • Both have jobs scheduled to run yearly.

It would be advisable to review these overlaps and consider adjusting the schedules to prevent potential performance bottlenecks.

Analysis chain

Line range hint 1-54: Cron job setup in TokenJobs is well-defined for regular token data updates.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the cron expressions in TokenJobs.

# Test: Check for correct cron expressions and non-overlapping schedules in TokenJobs.
grep -R "Cron" src/ | grep -v "token.jobs.ts"

Length of output: 455

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8121e07 and 8a5fa2f.
Files ignored due to path filters (1)
  • package.json is excluded by !**/*.json
Files selected for processing (35)
  • eslint.config.mjs (1 hunks)
  • prisma/migrations/20240508135425_historical_mcap/migration.sql (1 hunks)
  • prisma/schema.prisma (1 hunks)
  • src/core/config/config.dto.ts (1 hunks)
  • src/core/config/config.ts (1 hunks)
  • src/core/enums/query-param.enum.ts (1 hunks)
  • src/core/enums/routes.enum.ts (1 hunks)
  • src/core/lib/okp4/okp4.service.ts (1 hunks)
  • src/core/lib/osmosis/enums/endpoints.enum.ts (1 hunks)
  • src/core/lib/osmosis/osmosis.service.ts (3 hunks)
  • src/core/lib/osmosis/responses/mcap.response.ts (1 hunks)
  • src/core/lib/osmosis/responses/token-info.response.ts (1 hunks)
  • src/main.ts (1 hunks)
  • src/modules/app.module.ts (2 hunks)
  • src/modules/stacking/enums/stacking-endpoints.enum.ts (1 hunks)
  • src/modules/stacking/services/stacking.cache.ts (1 hunks)
  • src/modules/stacking/services/stacking.service.ts (1 hunks)
  • src/modules/stacking/stacking.controller.ts (1 hunks)
  • src/modules/stacking/stacking.module.ts (1 hunks)
  • src/modules/supply/dtos/change-interval.dto.ts (1 hunks)
  • src/modules/supply/dtos/current-supply.dto.ts (1 hunks)
  • src/modules/supply/enums/query-param.enum.ts (1 hunks)
  • src/modules/supply/enums/supply-endpoints.enum.ts (1 hunks)
  • src/modules/supply/services/supply.jobs.ts (1 hunks)
  • src/modules/supply/services/supply.service.ts (1 hunks)
  • src/modules/supply/supply.controller.ts (1 hunks)
  • src/modules/supply/supply.module.ts (1 hunks)
  • src/modules/token/dtos/token-info.dto.ts (1 hunks)
  • src/modules/token/enums/token-endpoint.enum.ts (1 hunks)
  • src/modules/token/schemas/historical-price-range.schema.ts (1 hunks)
  • src/modules/token/services/token.cache.ts (2 hunks)
  • src/modules/token/services/token.jobs.ts (2 hunks)
  • src/modules/token/services/token.service.ts (1 hunks)
  • src/modules/token/token.controller.ts (1 hunks)
  • src/modules/token/token.module.ts (1 hunks)
Files skipped from review due to trivial changes (19)
  • src/core/config/config.dto.ts
  • src/core/enums/query-param.enum.ts
  • src/core/lib/okp4/okp4.service.ts
  • src/core/lib/osmosis/responses/mcap.response.ts
  • src/main.ts
  • src/modules/stacking/enums/stacking-endpoints.enum.ts
  • src/modules/stacking/services/stacking.cache.ts
  • src/modules/stacking/services/stacking.service.ts
  • src/modules/stacking/stacking.controller.ts
  • src/modules/stacking/stacking.module.ts
  • src/modules/supply/dtos/change-interval.dto.ts
  • src/modules/supply/dtos/current-supply.dto.ts
  • src/modules/supply/enums/query-param.enum.ts
  • src/modules/supply/enums/supply-endpoints.enum.ts
  • src/modules/supply/services/supply.jobs.ts
  • src/modules/supply/services/supply.service.ts
  • src/modules/supply/supply.controller.ts
  • src/modules/supply/supply.module.ts
  • src/modules/token/enums/token-endpoint.enum.ts
Additional comments not posted (14)
src/core/enums/routes.enum.ts (1)

4-4: Addition of TOKEN route is correctly implemented and aligns with the new feature set.

src/core/lib/osmosis/enums/endpoints.enum.ts (1)

3-4: Addition of TOKEN_BY_SYMBOL and MARKET_CAP endpoints is correctly implemented and aligns with the new feature set.

src/modules/token/dtos/token-info.dto.ts (1)

1-10: The TokenInfoDto and ItemWithChange interfaces are well-defined and suitable for handling token-related data.

src/modules/token/schemas/historical-price-range.schema.ts (1)

5-7: The HistoricalPriceRange schema is correctly defined, using appropriate validation rules and making the field required.

prisma/migrations/20240508135425_historical_mcap/migration.sql (1)

1-9: The SQL migration script for creating the historical_mcap table is correctly implemented with appropriate fields and constraints.

eslint.config.mjs (1)

8-8: The addition of the indentation rule in the ESLint configuration is correctly implemented and will help maintain code consistency.

src/core/lib/osmosis/responses/token-info.response.ts (1)

1-13: The TokenInfoResponse interface is well-defined, covering all necessary properties for token information with appropriate data types.

prisma/schema.prisma (1)

23-27: The HistoricalMcap model in the Prisma schema is correctly defined with appropriate fields and annotations.

src/modules/app.module.ts (1)

9-9: Addition of TokenModule aligns with the new feature set.

Verification successful

The addition of TokenModule to the application's main module has been thoroughly reviewed. The module is well-structured, importing necessary services and a controller, and does not introduce any dependency issues. It is properly integrated within the application, and there are no signs of circular dependencies or other integration problems.

  • The module correctly imports and utilizes shared services like PrismaService, HttpService, and OsmosisService.
  • It also defines its own services (TokenService, TokenCache, TokenJobs) and a controller (TokenController), which are typical for a module's functionality.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that TokenModule does not introduce any dependency issues.

# Test: Check for potential integration issues with TokenModule.
grep -R "TokenModule" src/ | grep -v "app.module.ts"

Length of output: 112



Script:

#!/bin/bash
# Description: Inspect the internal structure and dependencies of TokenModule.

# Display the contents of token.module.ts to check for imports and service registrations.
cat src/modules/token/token.module.ts

Length of output: 699

src/modules/token/token.module.ts (1)

1-24: TokenModule is well-defined with appropriate services and controllers.

Verification successful

The verification process for the TokenService within the TokenModule shows that the service is properly implemented and integrated. The service is defined in token.service.ts and is utilized in token.jobs.ts, which aligns with the expected module structure and dependencies.

  • File Locations:
    • Service Definition: src/modules/token/services/token.service.ts
    • Service Usage: src/modules/token/services/token.jobs.ts
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify completeness of service implementations in TokenModule.

# Test: Check for any missing implementations or imports in the TokenModule services.
grep -R "TokenService" src/ | grep -v "token.module.ts"

Length of output: 323

src/modules/token/token.controller.ts (1)

1-28: TokenController setup is appropriate for handling token-related operations.

Verification successful

The verification process for the endpoint configurations in the TokenController has been completed. The usage of TokenEndpoint.HISTORICAL is confined to the token.controller.ts file, and it is correctly applied in the @Get decorator. There are no indications of misconfiguration or incorrect usage based on the script outputs.

  • TokenController correctly uses TokenEndpoint.HISTORICAL for the historical price endpoint.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the endpoint configurations in TokenController.

# Test: Check for correct configuration and error handling in the TokenController endpoints.
grep -R "TokenEndpoint" src/ | grep -v "token.controller.ts"

Length of output: 133



Script:

#!/bin/bash
# Description: Further verify the usage of TokenEndpoint values in the codebase.

# Search for the usage of specific TokenEndpoint enum values across the codebase to understand their configuration in endpoints.
rg "TokenEndpoint\." src/

Length of output: 98

src/core/lib/osmosis/osmosis.service.ts (1)

Line range hint 13-63: Additions in OsmosisService enhance its functionality for token data retrieval.

Verification successful

The error handling implementation in OsmosisService appears robust. It includes a comprehensive try-catch mechanism that not only catches exceptions but also checks for failed responses, throwing a BadRequestException when necessary. This approach ensures that errors are handled gracefully and are not propagated further, which aligns with best practices in error management.

  • File: src/core/lib/osmosis/osmosis.service.ts
  • Method: errorHandleWrapper
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the robustness of error handling in OsmosisService.

# Test: Check for comprehensive error handling in the new methods of OsmosisService.
grep -R "errorHandleWrapper" src/ | grep -v "osmosis.service.ts"

Length of output: 297



Script:

#!/bin/bash
# Description: Fetch the implementation of errorHandleWrapper in osmosis.service.ts to verify its robustness.

# Display the implementation of errorHandleWrapper from osmosis.service.ts
grep -A 10 "errorHandleWrapper" src/core/lib/osmosis/osmosis.service.ts

Length of output: 642

src/modules/token/services/token.cache.ts (1)

Line range hint 1-115: Caching setup in TokenCache is robust and well-suited for handling token data.

Verification successful

The review of the createRedisKey method implementations in both stacking.cache.ts and supply.cache.ts confirms that each service uses a unique prefix (redisStackingPrefix and redisSupplyPrefix) combined with a dynamic parameter. This design effectively ensures the uniqueness of cache keys across different services by preventing key collisions, even if the dynamic parts of the keys are identical. The cache key generation strategy is both unique and efficient as required.

  • Stacking Service: Uses redisStackingPrefix combined with the user's address.
  • Supply Service: Uses redisSupplyPrefix combined with the range.

This approach aligns with best practices for cache key generation, ensuring that keys are both unique and meaningful, thereby reducing the risk of key collision and improving cache management efficiency.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the uniqueness and efficiency of cache keys in TokenCache.

# Test: Check for unique and efficient cache key generation in TokenCache.
grep -R "createRedisKey" src/ | grep -v "token.cache.ts"

Length of output: 1151



Script:

#!/bin/bash
# Description: Inspect the implementation of createRedisKey in stacking.cache.ts and supply.cache.ts to verify key uniqueness.

# Fetch the implementation of createRedisKey in stacking.cache.ts
cat src/modules/stacking/services/stacking.cache.ts | grep -A 10 "private createRedisKey"

# Fetch the implementation of createRedisKey in supply.cache.ts
cat src/modules/supply/services/supply.cache.ts | grep -A 10 "private createRedisKey"

Length of output: 378

src/modules/token/services/token.service.ts (1)

1-133: Method additions in TokenService enhance its functionality for token data management.

Verification successful

The review of the TokenService usage in token.jobs.ts and token.module.ts shows that the service is integrated into the system's scheduled jobs and module configuration appropriately. The scheduled tasks are set at varied intervals, suggesting a consideration for load management and system efficiency. No direct security concerns are evident from the usage patterns provided. However, the actual security and efficiency would depend on the implementation details of the methods within TokenService.

  • Security: Ensure that data handling within TokenService methods includes proper validation and error management.
  • Efficiency: The scheduling intervals appear to be optimized to prevent system overload, but continue to monitor system performance to adjust as necessary.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the security and efficiency of data handling in TokenService.

# Test: Check for secure and efficient data handling in the new methods of TokenService.
grep -R "TokenService" src/ | grep -v "token.service.ts"

Length of output: 371



Script:

#!/bin/bash
# Description: Inspect the usage of TokenService in token.jobs.ts and token.module.ts for security and efficiency concerns.

# Display the contents of token.jobs.ts and token.module.ts where TokenService is used.
cat src/modules/token/services/token.jobs.ts
cat src/modules/token/token.module.ts

Length of output: 1933

src/core/config/config.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8a5fa2f and 05a4e82.
Files selected for processing (1)
  • src/core/config/config.schema.ts (1 hunks)
Additional comments not posted (1)
src/core/config/config.schema.ts (1)

14-14: Change from string to number type for USER_STACKING_TTL enhances type safety and aligns with PR objectives.

@dbatarin dbatarin merged commit 0bb8086 into main May 9, 2024
6 checks passed
@dbatarin dbatarin deleted the feat/token-info branch May 9, 2024 12:15
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