Skip to content

Conversation

@vignesha22
Copy link
Contributor

@vignesha22 vignesha22 commented Apr 29, 2025

Description

Types of changes

What types of changes does your code introduce?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Further comments (optional)

  • it's only testable on mainnet hence doing a release and will test it

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of metadata fetching when a Paymaster address is missing, preventing errors and ensuring robust responses.
    • Updated sponsor balance retrieval to handle errors gracefully and normalize addresses for consistency.
    • Fixed whitelist logic to correctly bypass checks for specific entry point versions.
  • Chores

    • Updated changelog and version number to 4.0.2.
    • Added a comprehensive mapping for oracle decimals to enhance multi-chain support.

@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

Walkthrough

This update introduces new constants for Chainlink oracle decimals to the backend, updates the version to 4.0.2, and enhances robustness in metadata and paymaster route handlers. The OracleDecimals constant provides a mapping of oracle addresses and their decimal precision for multiple chains, reducing reliance on live RPC calls. The paymaster logic now uses this mapping for price fetching, with a fallback to contract calls. Metadata routes now handle missing paymaster addresses and contract call failures gracefully, and whitelist checks are refined to account for differences in entry point versions.

Changes

File(s) Change Summary
backend/CHANGELOG.md, backend/package.json Added changelog entry for 4.0.2 and updated package version.
backend/src/constants/MultitokenPaymaster.ts Introduced OracleDecimals constant mapping chain IDs and oracle addresses to their decimal precision.
backend/src/paymaster/index.ts Added getChainlinkOracleDecimals method to use the new decimals mapping with fallback; updated price fetching logic to use this method.
backend/src/routes/metadata-routes.ts Improved sponsor balance retrieval: added address normalization, error handling, and conditional logic for missing paymaster addresses in metadata endpoints.
backend/src/routes/paymaster-routes.ts Modified whitelist check: skips database whitelist for EPV_06 entry point version, maintaining old on-chain logic for verifyingPaymaster addresses.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MetadataRoute
    participant PaymasterContract
    participant Logger

    Client->>MetadataRoute: GET /metadata
    MetadataRoute->>MetadataRoute: Normalize paymaster address (if present)
    alt Paymaster address exists
        MetadataRoute->>PaymasterContract: getDeposit()
        alt Success
            PaymasterContract-->>MetadataRoute: Sponsor balance
        else Failure
            MetadataRoute->>Logger: Log error
            MetadataRoute-->>Client: sponsorBalance = 0
        end
    else
        MetadataRoute-->>Client: sponsorBalance = 0
    end
    MetadataRoute-->>Client: Respond with metadata (including sponsorBalance)
Loading
sequenceDiagram
    participant Paymaster
    participant OracleDecimals
    participant ChainlinkContract

    Paymaster->>OracleDecimals: Lookup decimals for (chainId, oracleAddress)
    alt Found in mapping
        OracleDecimals-->>Paymaster: Return decimals
    else Not found
        Paymaster->>ChainlinkContract: decimals()
        ChainlinkContract-->>Paymaster: Return decimals
    end
    Paymaster-->>Paymaster: Use decimals for price calculation
Loading

Possibly related PRs

  • added some necessary improvements (#195) #196: Both PRs address fixes related to the multiTokenPaymaster's handling of token decimals by defining them as constants rather than fetching from RPC, indicating a direct continuation or refinement of the same functionality.

Poem

A rabbit hopped through backend code,
Mapping decimals down the road.
With constants set and errors caught,
The metadata’s now robustly wrought.
Whitelists check with versioned care,
4.0.2 brings changes fair!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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
Member

@ch4r10t33r ch4r10t33r left a comment

Choose a reason for hiding this comment

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

LGTM

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d51879f and 3702df6.

📒 Files selected for processing (6)
  • backend/CHANGELOG.md (1 hunks)
  • backend/package.json (1 hunks)
  • backend/src/constants/MultitokenPaymaster.ts (1 hunks)
  • backend/src/paymaster/index.ts (3 hunks)
  • backend/src/routes/metadata-routes.ts (5 hunks)
  • backend/src/routes/paymaster-routes.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/src/paymaster/index.ts (1)
backend/src/constants/MultitokenPaymaster.ts (1)
  • OracleDecimals (206-360)
🪛 LanguageTool
backend/CHANGELOG.md

[uncategorized] ~5-~5: You might be missing the article “a” here.
Context: ...data fetching if the config doesnt have Paymaster address ## [4.0.1] - 2025-04-22 ### Fi...

(AI_EN_LECTOR_MISSING_DETERMINER_A)

🪛 markdownlint-cli2 (0.17.2)
backend/CHANGELOG.md

2-2: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Above

(MD022, blanks-around-headings)


2-2: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


3-3: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Above

(MD022, blanks-around-headings)


3-3: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


4-4: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (11)
backend/package.json (1)

3-3: Version updated appropriately for bugfix release.

The version bump from 4.0.1 to 4.0.2 correctly follows semantic versioning for a patch release with bugfixes.

backend/src/constants/MultitokenPaymaster.ts (1)

206-359: Well-structured constants added for oracle decimals.

The new OracleDecimals constant provides a comprehensive mapping of Chainlink oracle addresses and their decimal precision across multiple chains. This addition will reduce reliance on RPC calls that were causing errors with some endpoints.

backend/src/paymaster/index.ts (3)

17-17: Import updated to include new OracleDecimals constant.

The import statement now correctly includes the newly added OracleDecimals mapping.


436-441: Good optimization with cache-first approach.

This new private method follows a best practice of checking the cached constants before falling back to on-chain calls. This pattern matches the existing methods like getTokenDecimals and getTokenSymbol.


585-585: Improved error resilience by using cached oracle decimals.

Replacing the direct contract call with the new getChainlinkOracleDecimals method reduces the chances of RPC errors when fetching oracle decimals.

backend/src/routes/paymaster-routes.ts (1)

259-260: Conditional whitelist check for EPV_06 correctly accommodates on-chain whitelisting

The updated logic correctly adds an exception for EPV_06, preventing errors when the sender address is not whitelisted in the database. This is appropriate since EPV_06 uses the old paymaster which performs whitelisting on-chain for verifying paymaster addresses.

The clear comment also helps document this special case, making future maintenance easier.

backend/src/routes/metadata-routes.ts (5)

16-16: Appropriate import for address normalization

Adding the getAddress utility from ethers is a good addition that will support proper address validation and normalization throughout the metadata routes.


96-106: Improved error handling for paymaster deposit fetching

These changes properly handle potential failure cases:

  1. Initializing sponsorBalance to 0 provides a safe default
  2. Checking if paymaster address exists before attempting to use it prevents runtime errors
  3. Using getAddress to normalize the paymaster address enhances reliability
  4. Adding try-catch blocks around contract calls ensures the endpoint remains functional even if a contract call fails

This significantly improves the robustness of the API endpoint.


208-217: Enhanced robustness for deposit retrieval in v2 metadata endpoint

Similar to the main metadata endpoint, this implementation properly handles potential failure points when retrieving sponsor balances. The defensive programming approach with initialization, conditional checks, address normalization, and error handling is appropriate for integration with blockchain contracts.


240-240: Improved logic for sponsor balance reporting

This change prioritizes using the verifying paymaster deposit when available, falling back to the global paymaster deposit. This provides more accurate balance information to API consumers who are using a verifying paymaster.


320-328: Consistent error handling for v3 metadata endpoint

The implementation correctly follows the same pattern established in the other endpoints, initializing the deposit variable and adding proper error handling around the contract call. This consistency across endpoints is good practice and ensures all routes have the same level of robustness.

Comment on lines +2 to +5
## [4.0.2] - 2025-04-29
### Fixes
- Added oracle decimals as constants for multiTokenPaymaster as some rpc endpoints return error
- Fixed bug in metadata fetching if the config doesnt have Paymaster address
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Changelog entries clearly document the fixes in this release.

The changelog properly documents the two bugfixes included in this release. However, there's a small grammatical error.

- Fixed bug in metadata fetching if the config doesnt have Paymaster address
+ Fixed bug in metadata fetching if the config doesn't have a Paymaster address
📝 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
## [4.0.2] - 2025-04-29
### Fixes
- Added oracle decimals as constants for multiTokenPaymaster as some rpc endpoints return error
- Fixed bug in metadata fetching if the config doesnt have Paymaster address
## [4.0.2] - 2025-04-29
### Fixes
- Added oracle decimals as constants for multiTokenPaymaster as some rpc endpoints return error
- Fixed bug in metadata fetching if the config doesn't have a Paymaster address
🧰 Tools
🪛 LanguageTool

[uncategorized] ~5-~5: You might be missing the article “a” here.
Context: ...data fetching if the config doesnt have Paymaster address ## [4.0.1] - 2025-04-22 ### Fi...

(AI_EN_LECTOR_MISSING_DETERMINER_A)

🪛 markdownlint-cli2 (0.17.2)

2-2: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Above

(MD022, blanks-around-headings)


2-2: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


3-3: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Above

(MD022, blanks-around-headings)


3-3: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


4-4: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)

@vignesha22 vignesha22 merged commit 334de83 into master Apr 29, 2025
6 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 31, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants