feat: upgrade bridge-sdk to 0.10.0#556
Conversation
WalkthroughThis 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
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
Estimated code review effort3 (~45 minutes) Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🔇 Additional comments (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
directcase to use the dedicated withdrawal route functionHowever, 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 itWould 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
⛔ Files ignored due to path filters (1)
yarn.lockis 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 (
VirtualChainsandMockedChains) 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 RecommendedI searched for direct imports of
@defuse-protocol/bridge-sdkand 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
VirtualChainsinstead of the broaderSupportedChainNameprovides 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_NETWORKfrom 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
RealChainstype 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
auroraEngineContractIdwith thegetAuroraEngineContractIdfunction 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
createVirtualChainRoutewith 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 newrouteConfigparameter, 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, andcreateVirtualChainRouteare correctly added and align with their usage in the refactoredtoRouteConfigfunction.
16-16: LGTM: Enhanced type safety with validated accessor functions.The imports of
getAuroraEngineContractIdandgetCAIP2replace 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
bridgetorouteConfigaccurately reflects that it receives aRouteConfigobject from thetoRouteConfig()function call, improving code clarity.
## [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))
|
🎉 This PR is included in version 1.0.0-beta.204 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary by CodeRabbit
New Features
Refactor
Chores
Tests