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

chore: total inj burnt #530

Merged
merged 1 commit into from
Dec 19, 2024
Merged

chore: total inj burnt #530

merged 1 commit into from
Dec 19, 2024

Conversation

shane-moore
Copy link
Collaborator

@shane-moore shane-moore commented Dec 19, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new method fetchInjBurnt in the API, enhancing data retrieval capabilities.
    • Added a new method injBurntResponseToInjBurnt for transforming response data.
    • New type alias TotalInjBurnt added to improve type definitions.
  • Bug Fixes

    • Updated dependency version for improved functionality.
  • Tests

    • Added a new test case for the fetchInjBurnt method to ensure its reliability.

Copy link

coderabbitai bot commented Dec 19, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.spec.ts

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the config "./../../eslintrc.js" to extend from. Please check that the name of the config is correct.

The config "./../../eslintrc.js" was referenced from the config file in "/packages/sdk-ts/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces a new feature to fetch INJ (Injective) burnt tokens in the Injective SDK. The changes span multiple files in the packages/sdk-ts directory, adding a new method fetchInjBurnt to the IndexerGrpcAuctionApi class. The implementation includes a corresponding transformer method, a new type alias, and a test case to validate the new functionality. A minor dependency version update for @injectivelabs/indexer-proto-ts is also included.

Changes

File Change Summary
packages/sdk-ts/package.json Updated @injectivelabs/indexer-proto-ts dependency from 1.13.3 to 1.13.4
packages/sdk-ts/src/client/indexer/types/auction.ts Added TotalInjBurnt type alias
packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcAuctionTransformer.ts Added injBurntResponseToInjBurnt method and related imports
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts Added fetchInjBurnt async method
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.spec.ts Added new test case for fetchInjBurnt method

Sequence Diagram

sequenceDiagram
    participant Client
    participant IndexerGrpcAuctionApi
    participant GrpcClient
    participant Transformer

    Client->>IndexerGrpcAuctionApi: fetchInjBurnt()
    IndexerGrpcAuctionApi->>GrpcClient: Call InjBurntEndpoint
    GrpcClient-->>IndexerGrpcAuctionApi: Return InjBurntEndpointResponse
    IndexerGrpcAuctionApi->>Transformer: Transform response
    Transformer-->>IndexerGrpcAuctionApi: Return TotalInjBurnt
    IndexerGrpcAuctionApi-->>Client: Return total INJ burnt
Loading

Possibly Related PRs

Suggested Reviewers

  • ThomasRalee

Poem

🔥 Burning tokens, a rabbit's delight,
INJ goes poof in the blockchain's light!
A method so neat, a feature so bright,
SDK grows stronger with each coding might! 🐰✨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

🧹 Nitpick comments (2)
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.spec.ts (1)

51-68: Enhance test coverage with edge cases

While the basic happy path is covered, consider adding test cases for:

  1. Error scenarios (e.g., network errors)
  2. Response validation (e.g., negative values)
  3. Zero value responses
test('fetchInjBurnt handles errors', async () => {
  // Mock client to throw error
  const error = new Error('Network error');
  jest.spyOn(indexerGrpcAuctionApi.client, 'InjBurntEndpoint').mockRejectedValue(error);
  
  await expect(indexerGrpcAuctionApi.fetchInjBurnt()).rejects.toThrow();
});

test('fetchInjBurnt handles zero value', async () => {
  // Test with zero burnt tokens
  const response = { totalInjBurnt: '0' };
  jest.spyOn(indexerGrpcAuctionApi.client, 'InjBurntEndpoint').mockResolvedValue(response);
  
  const result = await indexerGrpcAuctionApi.fetchInjBurnt();
  expect(result).toBe(0);
});
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts (1)

87-112: LGTM: Implementation follows established patterns

The implementation correctly follows the existing patterns for error handling and retry mechanism. A few minor suggestions:

  1. Consider using InjectiveAuctionRpc.InjBurntEndpointRequest.create() for consistency with other methods
  2. Add JSDoc comments to document the method's purpose and return type
+  /**
+   * Fetches the total amount of INJ tokens that have been burnt
+   * @returns {Promise<TotalInjBurnt>} The total amount of burnt INJ tokens
+   */
   async fetchInjBurnt() {
-    const request: InjectiveAuctionRpc.InjBurntEndpointRequest = {}
+    const request = InjectiveAuctionRpc.InjBurntEndpointRequest.create()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2a01a5 and 159f844.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • packages/sdk-ts/package.json (1 hunks)
  • packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.spec.ts (1 hunks)
  • packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts (1 hunks)
  • packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcAuctionTransformer.ts (2 hunks)
  • packages/sdk-ts/src/client/indexer/types/auction.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/sdk-ts/src/client/indexer/types/auction.ts
🔇 Additional comments (3)
packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcAuctionTransformer.ts (1)

5-8: LGTM: Import statements are properly organized

The new type imports are correctly added and organized with related types.

packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts (1)

87-112: Verify endpoint usage and error handling

Let's verify the implementation across the codebase:

✅ Verification successful

Let me gather more information about the implementation and its usage.


Let me check the test implementation to ensure proper test coverage.


Implementation verified and properly integrated

The fetchInjBurnt implementation is correctly integrated within the codebase with:

  • Proper error handling and consistent with other endpoints in the module
  • Complete type definitions (TotalInjBurnt)
  • Transformer implementation for response handling
  • Test coverage in place
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any other usages of InjBurntEndpoint
rg -l "InjBurntEndpoint"

# Check for similar implementations in other modules
ast-grep --pattern 'class $_ extends BaseGrpcConsumer {
  $$$
  async fetch$_() {
    $$$
  }
}'

Length of output: 269


Script:

#!/bin/bash
# Check the transformer implementation
cat packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcAuctionTransformer.ts

# Check for any tests related to this endpoint
rg -l "fetchInjBurnt"

# Look for any interface definitions or types related to this endpoint
rg "InjBurntEndpoint" -A 3 -B 3

Length of output: 5380


Script:

#!/bin/bash
# Check the test implementation
cat packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.spec.ts

# Check for any type definitions
rg "TotalInjBurnt" -A 3 -B 3

Length of output: 4058

packages/sdk-ts/package.json (1)

130-130: Verify the dependency version update.

The update of @injectivelabs/indexer-proto-ts to version 1.13.4 aligns with the PR objectives for implementing INJ burnt token functionality.

Let's verify the version and check for any security concerns:

✅ Verification successful

Dependency update to @injectivelabs/[email protected] is safe and up-to-date

The verification confirms:

  • The version 1.13.4 is the latest available version on npm registry
  • No security vulnerabilities were found for this package
  • The patch version bump is appropriate for the feature addition
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the dependency version and check for security advisories.

# Check if this is the latest version
curl -s "https://registry.npmjs.org/@injectivelabs%2Findexer-proto-ts" | jq -r '."dist-tags".latest'

# Check for any security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "@injectivelabs/indexer-proto-ts") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

# Check for compatibility with other @injectivelabs dependencies
rg '"@injectivelabs/[^"]+": "[^"]+"' package.json

Length of output: 523

Comment on lines +66 to +70
static injBurntResponseToInjBurnt(
response: InjectiveAuctionRpc.InjBurntEndpointResponse,
): TotalInjBurnt {
return Number(response.totalInjBurnt)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using BigNumber for safe number conversion

The current implementation uses Number() for converting the total burnt amount. Since this could be a large value representing token amounts, consider using BigNumber to avoid potential precision loss or overflow issues.

-  static injBurntResponseToInjBurnt(
-    response: InjectiveAuctionRpc.InjBurntEndpointResponse,
-  ): TotalInjBurnt {
-    return Number(response.totalInjBurnt)
-  }
+  static injBurntResponseToInjBurnt(
+    response: InjectiveAuctionRpc.InjBurntEndpointResponse,
+  ): TotalInjBurnt {
+    return new BigNumber(response.totalInjBurnt).toNumber()
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static injBurntResponseToInjBurnt(
response: InjectiveAuctionRpc.InjBurntEndpointResponse,
): TotalInjBurnt {
return Number(response.totalInjBurnt)
}
static injBurntResponseToInjBurnt(
response: InjectiveAuctionRpc.InjBurntEndpointResponse,
): TotalInjBurnt {
return new BigNumber(response.totalInjBurnt).toNumber()
}

@ThomasRalee ThomasRalee merged commit 1920820 into dev Dec 19, 2024
3 checks passed
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