Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

feat: upgrade bridge-sdk to 0.10.0#556

Merged
cawabunga-bytes merged 3 commits intobetafrom
feat-upgrade-bridge-sdk
Jul 23, 2025
Merged

feat: upgrade bridge-sdk to 0.10.0#556
cawabunga-bytes merged 3 commits intobetafrom
feat-upgrade-bridge-sdk

Conversation

@cawabunga-bytes
Copy link
Collaborator

@cawabunga-bytes cawabunga-bytes commented Jul 23, 2025

Summary by CodeRabbit

  • New Features

    • Added functions for safer access to contract IDs and CAIP2 network identifiers, with improved error handling for unsupported chains.
  • Refactor

    • Streamlined withdrawal route configuration using new standardized factory functions.
    • Updated type definitions to group virtual and mocked chains for better maintainability.
    • Replaced hardcoded mappings with centralized imports for network identifiers.
  • Chores

    • Updated and added dependencies to support new route configuration utilities.
  • Tests

    • Refactored tests to mock internal utilities module for consistent control over quote method behavior.

@cawabunga-bytes cawabunga-bytes self-assigned this Jul 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

This change updates the bridge SDK dependency, introduces a new internal utilities dependency, and refactors how bridge routes and chain identifiers are handled throughout the codebase. It standardizes route configuration using new SDK factory functions, adds runtime validation for contract and chain ID retrieval, and reorganizes chain type definitions for clarity and type safety. Test files were updated to mock internal utilities differently.

Changes

File(s) Change Summary
package.json Updated @defuse-protocol/bridge-sdk version; added @defuse-protocol/internal-utils dependency.
src/constants/aurora.ts Changed type imports; added getAuroraEngineContractId for runtime validation; updated constant typings.
src/features/machines/intentStatusMachine.ts Refactored imports and logic to use new route creation functions and utility getters; renamed and updated functions.
src/services/withdrawService.ts Replaced manual bridge config with SDK route creation functions; updated imports and usage in withdrawal logic.
src/types/base.ts Refactored SupportedChainName by introducing VirtualChains and MockedChains union types for better grouping.
src/utils/caip2.ts Removed constant; added getCAIP2 function with runtime validation; narrowed supported chains to real chains only.
src/sdk/aggregatedQuote/getAggregatedQuoteExactIn.test.ts Changed from spying on solverRelay.quote to mocking @defuse-protocol/internal-utils module.
src/services/quoteService.test.ts Changed from spying on solverRelay.quote to mocking @defuse-protocol/internal-utils module.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WithdrawService
    participant BridgeSDK
    participant AuroraUtils
    participant CAIP2Utils

    User->>WithdrawService: Initiate withdrawal
    WithdrawService->>CAIP2Utils: getCAIP2(chainName)
    CAIP2Utils-->>WithdrawService: CAIP2 string (or error)
    WithdrawService->>AuroraUtils: getAuroraEngineContractId(chainName)
    AuroraUtils-->>WithdrawService: Contract ID (or error)
    WithdrawService->>BridgeSDK: create route config (via SDK factory)
    WithdrawService->>BridgeSDK: estimateFee(routeConfig)
    WithdrawService->>BridgeSDK: createWithdrawalIntents(routeConfig)
    BridgeSDK-->>WithdrawService: Result
    WithdrawService-->>User: Withdrawal processed
Loading

Estimated code review effort

3 (~45 minutes)

Possibly related PRs

Poem

In the warren where bridges connect,
We tidied the chains and checked each spec.
Factory routes now hop in line,
With CAIP2 and Aurora IDs just fine.
Type-safe tunnels, less to debug—
A happy hop from every code-loving bug! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b8121c7 and 9415873.

📒 Files selected for processing (2)
  • src/sdk/aggregatedQuote/getAggregatedQuoteExactIn.test.ts (1 hunks)
  • src/services/quoteService.test.ts (1 hunks)
🔇 Additional comments (2)
src/sdk/aggregatedQuote/getAggregatedQuoteExactIn.test.ts (1)

9-13: Improved test isolation with full module mocking.

The change from direct method spying to full module mocking of @defuse-protocol/internal-utils provides better test isolation and aligns with the new dependency structure. The mock correctly provides the expected solverRelay.quote interface that all tests rely on.

src/services/quoteService.test.ts (1)

7-11: Consistent mocking strategy across test files.

The module mocking approach is identical to the one used in getAggregatedQuoteExactIn.test.ts, which ensures consistency across the test suite. This systematic approach to handling the new @defuse-protocol/internal-utils dependency maintains test reliability while improving isolation.

✨ 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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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

@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

🧹 Nitpick comments (3)
src/constants/aurora.ts (1)

28-36: Consider improving the type assertion in the getter function.

The function provides good runtime validation, but the type assertion could be avoided with better parameter typing.

-export function getAuroraEngineContractId(chainName: string) {
+export function getAuroraEngineContractId(chainName: string): string {
   if (!(chainName in auroraEngineContractId)) {
     throw new Error(`Unsupported virtual chain = ${chainName}`)
   }

-  return auroraEngineContractId[
-    chainName as keyof typeof auroraEngineContractId
-  ]
+  return auroraEngineContractId[chainName as VirtualChains]
}
src/services/withdrawService.ts (1)

194-196: Address the TODO comment for virtual chain route configuration.

The TODO comment indicates that the second parameter (currently null) needs a proper value. This should be addressed to ensure complete route configuration.

Do you want me to help determine what value should be provided for the second parameter of createVirtualChainRoute, or should I open an issue to track this?

src/features/machines/intentStatusMachine.ts (1)

256-283: Excellent refactor to align with new SDK patterns, but address the TODO.

The function refactor successfully:

  • Uses standardized SDK factory functions (createVirtualChainRoute, createNearWithdrawalRoute)
  • Replaces hardcoded values with validated functions (getCAIP2, getAuroraEngineContractId)
  • Maintains proper error handling with exhaustive switch checking
  • Correctly separates the direct case to use the dedicated withdrawal route function

However, the TODO comment on line 264 indicates incomplete implementation for the Aurora Engine case.

-        null // TODO: provide the correct value once you know it
+        null // TODO: provide the correct value once you know it

Would you like me to help investigate what the correct second parameter should be for createVirtualChainRoute, or would you prefer to create an issue to track this TODO?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad4827 and b8121c7.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • package.json (1 hunks)
  • src/constants/aurora.ts (1 hunks)
  • src/features/machines/intentStatusMachine.ts (5 hunks)
  • src/services/withdrawService.ts (6 hunks)
  • src/types/base.ts (1 hunks)
  • src/utils/caip2.ts (1 hunks)
🧬 Code Graph Analysis (4)
src/utils/caip2.ts (1)
src/types/base.ts (3)
  • SupportedChainName (1-23)
  • VirtualChains (25-31)
  • MockedChains (33-33)
src/constants/aurora.ts (1)
src/types/base.ts (1)
  • VirtualChains (25-31)
src/services/withdrawService.ts (2)
src/utils/blockchain.ts (1)
  • isAuroraVirtualChain (18-28)
src/constants/aurora.ts (1)
  • getAuroraEngineContractId (28-36)
src/features/machines/intentStatusMachine.ts (3)
src/types/base.ts (2)
  • SupportedBridge (35-35)
  • SupportedChainName (1-23)
src/constants/aurora.ts (1)
  • getAuroraEngineContractId (28-36)
src/utils/caip2.ts (1)
  • getCAIP2 (33-38)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/utils/caip2.ts (1)
src/types/base.ts (3)
  • SupportedChainName (1-23)
  • VirtualChains (25-31)
  • MockedChains (33-33)
src/constants/aurora.ts (1)
src/types/base.ts (1)
  • VirtualChains (25-31)
src/services/withdrawService.ts (2)
src/utils/blockchain.ts (1)
  • isAuroraVirtualChain (18-28)
src/constants/aurora.ts (1)
  • getAuroraEngineContractId (28-36)
src/features/machines/intentStatusMachine.ts (3)
src/types/base.ts (2)
  • SupportedBridge (35-35)
  • SupportedChainName (1-23)
src/constants/aurora.ts (1)
  • getAuroraEngineContractId (28-36)
src/utils/caip2.ts (1)
  • getCAIP2 (33-38)
🔇 Additional comments (15)
src/types/base.ts (1)

22-33: Well-structured type reorganization for improved maintainability.

The refactoring from inline chain name literals to organized union types (VirtualChains and MockedChains) enhances code organization and type safety. This hierarchical approach makes it easier to distinguish between different chain categories and supports the specialized handling seen in other files.

package.json (1)

51-52: Bridge SDK Version Pin—Manual Audit Recommended

I searched for direct imports of @defuse-protocol/bridge-sdk and legacy patterns (BridgeConfig|bridgeConfig) across TypeScript/JavaScript files and found no matches, suggesting the SDK isn’t referenced directly in the codebase. However, given the major version jump and switch to a fixed version, please manually verify:

  • Any dynamic import() calls or runtime loads of the SDK
  • References in tests, build scripts, or CI configurations
  • Indirect usage via route configs, plugins, or generated code

If the SDK is truly unused, this bump is harmless. Otherwise, ensure any breaking changes in v0.10.0 are addressed.

src/constants/aurora.ts (2)

1-1: Improved type specificity with VirtualChains.

Using VirtualChains instead of the broader SupportedChainName provides better type safety and aligns with the chain categorization introduced in the base types.


6-13: Explicit typing enhances type safety.

The explicit Record<VirtualChains, string> typing on both constants improves type safety and removes the need for type assertions. This ensures only valid virtual chain names can be used as keys.

Also applies to: 19-26

src/utils/caip2.ts (4)

1-6: Good centralization of CAIP2 definitions.

Importing CAIP2_NETWORK from the bridge SDK centralizes chain identifier definitions and reduces duplication. The type imports align well with the new chain categorization.


8-8: Excellent type design for real chains.

The RealChains type correctly excludes virtual and mocked chains, which appropriately don't have CAIP2 identifiers. This prevents attempting to get CAIP2 values for chains that shouldn't have them.


10-31: Comprehensive CAIP2 mapping with proper typing.

The mapping covers all real chains with appropriate CAIP2 values from the standardized constants. The explicit typing ensures type safety.


33-38: Well-implemented getter function with validation.

The function provides proper runtime validation and clear error messages. The pattern is consistent with other getter functions in the codebase.

src/services/withdrawService.ts (4)

4-9: Good adoption of standardized route configuration.

The import of new route creation functions (RouteConfig, createDefaultRoute, etc.) aligns with the bridge SDK upgrade and promotes standardized route configuration patterns.


12-12: Proper use of validated getter function.

Replacing direct access to auroraEngineContractId with the getAuroraEngineContractId function adds runtime validation and follows the new pattern established in the constants file.


190-199: Well-structured route configuration logic.

The conditional logic correctly selects appropriate route creation functions based on chain type:

  • Virtual chains use createVirtualChainRoute with contract ID
  • NEAR uses createNearWithdrawalRoute
  • Others use createDefaultRoute

205-205: Consistent migration to RouteConfig pattern.

All function calls (estimateFee, createWithdrawalIntents) have been properly updated to use the new routeConfig parameter, maintaining consistency throughout the withdrawal flow.

Also applies to: 241-241, 366-366, 380-380, 572-572

src/features/machines/intentStatusMachine.ts (3)

1-5: LGTM: Import updates align with SDK upgrade.

The new imports for RouteConfig, createNearWithdrawalRoute, and createVirtualChainRoute are correctly added and align with their usage in the refactored toRouteConfig function.


16-16: LGTM: Enhanced type safety with validated accessor functions.

The imports of getAuroraEngineContractId and getCAIP2 replace hardcoded constants with functions that provide runtime validation and throw descriptive errors for unsupported inputs, improving robustness.

Also applies to: 27-27


106-106: LGTM: Parameter name better reflects its type and purpose.

Renaming the parameter from bridge to routeConfig accurately reflects that it receives a RouteConfig object from the toRouteConfig() function call, improving code clarity.

@cawabunga-bytes cawabunga-bytes merged commit 9050042 into beta Jul 23, 2025
2 of 3 checks passed
@cawabunga-bytes cawabunga-bytes deleted the feat-upgrade-bridge-sdk branch July 23, 2025 15:28
amdefuse pushed a commit that referenced this pull request Jul 23, 2025
## [1.0.0-beta.204](v1.0.0-beta.203...v1.0.0-beta.204) (2025-07-23)

### Features

* upgrade bridge-sdk to 0.10.0 ([#556](#556)) ([9050042](9050042))
@amdefuse
Copy link
Contributor

🎉 This PR is included in version 1.0.0-beta.204 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants