8000 refactor: move AcrossApi types into separate file by shoom3301 · Pull Request #292 · cowprotocol/cow-sdk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: move AcrossApi types into separate file #292

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

Merged
merged 1 commit into from
Apr 23, 2025

Conversation

shoom3301
Copy link
Contributor
@shoom3301 shoom3301 commented Apr 23, 2025

Just moved types from AcrossApi.ts into a separate file.
Also fixed one test.

Summary by CodeRabbit

  • Refactor
    • Improved code organization by moving type definitions related to bridging and fee suggestions into a dedicated module. This change does not affect user-facing features or functionality.

@shoom3301 shoom3301 requested a review from a team April 23, 2025 12:17
@shoom3301 shoom3301 self-assigned this Apr 23, 2025
Copy link
Contributor
coderabbitai bot commented Apr 23, 2025

Walkthrough

This change refactors the Across bridging provider codebase by extracting several TypeScript interface definitions from the main implementation files into a new dedicated types.ts module. All relevant imports across the provider, utility, and test files are updated to reference these shared types from the new module. The refactor does not alter any logic, method signatures, or test behaviors; it is limited to code organization and type import paths.

Changes

File(s) Change Summary
src/bridging/providers/across/types.ts New file: Introduces shared TypeScript interfaces for bridging requests, routes, fee limits, fee responses, and percentage fee modeling.
src/bridging/providers/across/AcrossApi.ts Removes all inline interface declarations; imports all types from ./types instead.
src/bridging/providers/across/AcrossBridgeProvider.ts Updates import of SuggestedFeesResponse to come from ./types instead of ./AcrossApi.
src/bridging/providers/across/util.ts Updates import of SuggestedFeesResponse to come from ./types instead of ./AcrossApi.
src/bridging/providers/across/AcrossApi.test.ts, src/bridging/providers/across/util.test.ts Updates test imports to reference types from ./types instead of ./AcrossApi.
src/bridging/providers/across/AcrossBridgeProvider.test.ts Updates test imports to use types from ./types; minor test argument and type usage adjustments.

Suggested reviewers

  • alfetopito

Poem

In the land of bridges, types now roam free,
Gathered in one meadow, clear as can be.
With imports now tidy, and logic untouched,
Our code hops along, robust and unclutched.
From many small burrows, one warren is made—
The rabbit applauds this organizational upgrade!
🐇✨

✨ 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.
    • 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.
  • @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
Contributor
@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 (1)
src/bridging/providers/across/types.ts (1)

21-22: Consider cleaning up commented code

There are commented-out fields for inputToken and outputToken. If these are no longer needed, consider removing them completely rather than keeping them commented.

- // inputToken: string
- // outputToken: string
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e4bb752 and bf94bb5.

📒 Files selected for processing (7)
  • src/bridging/providers/across/AcrossApi.test.ts (1 hunks)
  • src/bridging/providers/across/AcrossApi.ts (1 hunks)
  • src/bridging/providers/across/AcrossBridgeProvider.test.ts (3 hunks)
  • src/bridging/providers/across/AcrossBridgeProvider.ts (1 hunks)
  • src/bridging/providers/across/types.ts (1 hunks)
  • src/bridging/providers/across/util.test.ts (1 hunks)
  • src/bridging/providers/across/util.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
src/bridging/providers/across/AcrossApi.ts (1)
Learnt from: anxolin
PR: cowprotocol/cow-sdk#251
File: src/bridging/providers/across/AcrossApi.ts:5-10
Timestamp: 2025-03-21T15:14:59.767Z
Learning: In AcrossApi.ts, interfaces like AvailableRoutesRequest and Route use string types for chain IDs (originChainId, destinationChainId) because they're mapping to an external API contract from Across, which expects chain IDs as strings, rather than using internal enum types like TargetChainId.
src/bridging/providers/across/AcrossBridgeProvider.test.ts (1)
Learnt from: anxolin
PR: cowprotocol/cow-sdk#267
File: src/bridging/BridgingSdk/getCrossChainOrder.ts:44-46
Timestamp: 2025-04-14T20:37:56.543Z
Learning: The decoding of bridge appData (using provider.decodeBridgeHook) in the getCrossChainOrder function was intentionally left as a TODO comment for implementation in a future PR.
src/bridging/providers/across/types.ts (1)
Learnt from: anxolin
PR: cowprotocol/cow-sdk#251
File: src/bridging/providers/across/AcrossApi.ts:5-10
Timestamp: 2025-03-21T15:14:59.767Z
Learning: In AcrossApi.ts, interfaces like AvailableRoutesRequest and Route use string types for chain IDs (originChainId, destinationChainId) because they're mapping to an external API contract from Across, which expects chain IDs as strings, rather than using internal enum types like TargetChainId.
🧬 Code Graph Analysis (2)
src/bridging/providers/across/AcrossBridgeProvider.test.ts (1)
src/chains/types.ts (1)
  • TargetChainId (31-31)
src/bridging/providers/across/types.ts (1)
src/chains/types.ts (1)
  • TargetChainId (31-31)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: Build Package
  • GitHub Check: eslint
🔇 Additional comments (17)
src/bridging/providers/across/types.ts (6)

3-8: LGTM: Well-defined interface for route requests!

The AvailableRoutesRequest interface is properly defined with clear field names for origin and destination chain IDs and tokens.


10-17: LGTM: Consistent with request interface

The Route interface appropriately extends the request fields with additional token symbol information.


19-67: Note the type difference between chain ID fields

I notice that while AvailableRoutesRequest and Route use string for chain IDs, SuggestedFeesRequest uses TargetChainId. This difference is intentional as the route interfaces map to an external API contract from Across that expects string chain IDs, whereas SuggestedFeesRequest is using internal types.


69-111: LGTM: Well-documented deposit limits

The SuggestedFeesLimits interface is thoroughly documented with clear explanations for each limit type and detailed comments explaining timing expectations per chain.


113-187: LGTM: Comprehensive response interface

The SuggestedFeesResponse interface provides a detailed structure for fee breakdowns with appropriate documentation for each field.


189-198: LGTM: Clear percentage fee representation

The PctFee interface clearly defines how percentage fees are represented, with helpful comments explaining the fixed-point format.

src/bridging/providers/across/util.test.ts (1)

6-6: LGTM: Correct import path updated

The import path for SuggestedFeesResponse has been correctly updated to use the new types file.

src/bridging/providers/across/util.ts (1)

7-7: LGTM: Correct import path updated

The import path for SuggestedFeesResponse has been correctly updated to use the new types file.

src/bridging/providers/across/AcrossBridgeProvider.ts (1)

27-33: LGTM: Proper separation of imports

The imports have been correctly organized to separate the API class imports from the type imports. AcrossApi and AcrossApiOptions are still imported from the original file, while SuggestedFeesResponse now comes from the new types module.

src/bridging/providers/across/AcrossApi.test.ts (1)

1-3: Imports correctly updated to reflect the type refactoring.

The import statements have been properly adjusted to reflect the type definitions being moved to a dedicated types.ts file. The AcrossApi class is now imported separately from the types SuggestedFeesRequest and SuggestedFeesResponse.

src/bridging/providers/across/AcrossBridgeProvider.test.ts (3)

4-8: Import statements correctly restructured for better type organization.

The imports have been properly reorganized:

  • Types like BridgeQuoteResult and QuoteBridgeRequest are now imported from '../../types'
  • SuggestedFeesResponse is imported from the new dedicated './types' file
  • Added latestAppData from '@cowprotocol/app-data/dist/generatedTypes' to support the updated type usage in the decodeBridgeHook test

This aligns with the overall refactoring to improve type organization.


81-81: Simplified argument for unsupported chain test.

The argument for testing unsupported chains has been simplified from an object with a targetChainId property to directly using a numeric value with a type assertion. This makes the test more concise while maintaining type safety.


173-175: Updated type casting in decodeBridgeHook test.

The test now properly uses latestAppData.CoWHook for type casting instead of BridgeHook. This change aligns with the note in the retrieved learnings that mentions the implementation of decodeBridgeHook was intentionally left as a TODO for a future PR.

src/bridging/providers/across/AcrossApi.ts (4)

1-9: Types correctly extracted to dedicated file.

The type definitions have been properly moved from inline declarations to imports from the new './types' module. This includes:

  • AvailableRoutesRequest
  • PctFee
  • Route
  • SuggestedFeesLimits
  • SuggestedFeesRequest
  • SuggestedFeesResponse

This refactoring improves code organization by separating type declarations from implementation logic, making the codebase more maintainable.


51-71: Implementation of getSuggestedFees remains unchanged.

The implementation logic continues to work correctly with the imported types. The method correctly handles the request parameters and makes the API call to retrieve fee suggestions from the Across API.

Note: I see there's a TODO comment (lines 66-67) mentioning a potential discrepancy between documented API parameters and actual implementation. This is unrelated to the current refactoring but might be worth addressing in a future PR.


119-142: Validation function continues to work with imported types.

The isValidSuggestedFeesResponse function correctly uses the imported SuggestedFeesResponse and PctFee types. The validation logic remains unchanged and will continue to work as expected.


144-187: Helper validation functions properly reference imported types.

The helper functions isValidPctFee, isValidSuggestedFeeLimits, isValidRoutes, and isValidRoute correctly use the imported types. These functions remain unchanged in logic and will continue to validate the API responses properly.

@coveralls
Copy link
Collaborator
coveralls commented Apr 23, 2025

Coverage Status

coverage: 75.501%. remained the same
when pulling bf94bb5 on feat/bridge-details
into e4bb752 on main.

@shoom3301 shoom3301 merged commit 1de4320 into main Apr 23, 2025
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2025
Copy link
Contributor
@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

👍

@alfetopito alfetopito deleted the feat/bridge-details branch April 24, 2025 13:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0