Skip to content

feat: add new Avalanche and Polygon networks#143

Merged
cowdan merged 5 commits intomainfrom
feat/add-new-networks
Jun 9, 2025
Merged

feat: add new Avalanche and Polygon networks#143
cowdan merged 5 commits intomainfrom
feat/add-new-networks

Conversation

@cowdan
Copy link
Copy Markdown
Contributor

@cowdan cowdan commented Jun 9, 2025

Description

  • added Avalanche and Polygon networks
  • import SupportedChainId from cow-sdk
  • updated unit tests

Summary by CodeRabbit

  • New Features

    • Added support for Polygon and Avalanche networks across multiple services and configurations.
    • Expanded environment configuration examples with RPC and API endpoints for Polygon, Avalanche, and Sepolia.
  • Bug Fixes

    • Improved network mappings and token configurations for accurate chain identification.
  • Documentation

    • Updated example environment variables to include new blockchain networks.
  • Chores

    • Upgraded to a newer version of the blockchain SDK.
    • Refactored internal references to supported chain IDs for better consistency.
  • Tests

    • Added tests verifying behavior with Polygon and Avalanche networks.

- import `SupportedChainId` from `cow-sdk`
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 9, 2025

Walkthrough

This change migrates the definition and usage of the SupportedChainId enum from a local module to the external @cowprotocol/cow-sdk package throughout the codebase. It also adds support for the Polygon and Avalanche networks across environment examples, type definitions, token mappings, and network configuration constants, updating related tests and documentation accordingly.

Changes

Files/Groups Change Summary
.env.example Added commented-out environment variable examples for Polygon, Avalanche, and Sepolia RPC and API endpoints.
apps/notification-producer/..., apps/twap/... Updated import of SupportedChainId to source from @cowprotocol/cow-sdk; extended type definitions for new chains.
libs/repositories/src/const.ts Added USDC token addresses for Polygon and Avalanche. Updated SupportedChainId import source.
libs/repositories/src/datasources/* Updated SupportedChainId import; added Polygon and Avalanche to various network mappings (Coingecko, Ethplorer, GoldRush, etc.).
libs/repositories/src/repos/*, libs/repositories/src/utils/* Updated SupportedChainId import source; extended test and mock data for Polygon and Avalanche where relevant.
libs/shared/src/const.ts Added Polygon and Avalanche to network mappings and explorer/API name constants.
libs/shared/src/types.ts Removed SupportedChainId enum export; now only exports Logger type.
libs/shared/src/utils/format.ts, libs/shared/src/utils/misc.ts Updated SupportedChainId import to external package.
package.json Updated @cowprotocol/cow-sdk dependency to version 6.0.0-RC.59.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant CowSDK
    participant NetworkConfig

    App->>CowSDK: Import SupportedChainId
    App->>NetworkConfig: Use SupportedChainId for config (Polygon, Avalanche, etc.)
    NetworkConfig->>App: Provide network-specific config (tokens, endpoints)
Loading

Possibly related PRs

  • Cleanup and improvements #125: The main PR and the retrieved PR both involve refactoring and improvements related to push notification repositories and utilities, including introducing interfaces, renaming repositories, moving database connection logic, and enhancing the doForever utility; thus, their changes are directly related at the code and architectural level.
  • feat(usd-price): support unsupported chains #137: The main PR expands supported blockchain networks and updates imports of SupportedChainId to come from @cowprotocol/cow-sdk, while the retrieved PR refactors API schemas and repository methods to accept more generic chain ID or slug strings and supports unsupported chains in USD price queries; both PRs are related through their shared focus on extending chain ID support and modifying SupportedChainId usage across the codebase.

Suggested reviewers

  • alfetopito

Poem

In the warren of code, new chains appear,
Polygon and Avalanche now hop in with cheer.
Old enums are gone, CowSDK takes the lead,
With tokens and configs for every new need.
The rabbits rejoice, as networks expand—
More blockchains to explore in this digital land!
🐇✨


📜 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 5776df1 and 44f73f2.

📒 Files selected for processing (1)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: docker (apps/telegram)
  • GitHub Check: docker (apps/notification-producer)
  • GitHub Check: docker (apps/twap)
  • GitHub Check: docker (apps/api)
✨ 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.

@cowdan cowdan requested review from alfetopito and anxolin June 9, 2025 14:00
Copy link
Copy Markdown
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: 2

🧹 Nitpick comments (9)
libs/services/src/SlippageService/SlippageServiceMain.spec.ts (1)

7-7: Extend tests for new networks
Now that Polygon and Avalanche are supported via SupportedChainId, consider adding test cases using SupportedChainId.POLYGON and SupportedChainId.AVALANCHE to validate slippage logic across the new chains.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.spec.ts (1)

1-1: Consider coverage for new networks
Since Polygon and Avalanche are newly supported, you may want to add tests for SupportedChainId.POLYGON and SupportedChainId.AVALANCHE in repository specs to ensure data providers handle them correctly.

libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.test.ts (1)

1-1: Import source updated to central SDK and test coverage completeness
The SupportedChainId import was migrated to @cowprotocol/cow-sdk correctly. To ensure the new Avalanche and Polygon networks are supported, consider adding test cases for SupportedChainId.POLYGON (137) and SupportedChainId.AVALANCHE (43114) in getUsdPrice and getUsdPrices.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepository.ts (1)

2-2: Standardize import to central SDK
The SupportedChainId import has been correctly updated to @cowprotocol/cow-sdk. Consider removing the eslint-disable directive if no unused variables remain to clean up the code.

libs/repositories/src/repos/Erc20Repository/Erc20RepositoryViem.spec.ts (1)

42-43: Add clients for Polygon and Avalanche

The viemClients map now includes entries for POLYGON and AVALANCHE, extending support to the new networks. Consider adding corresponding tests to confirm these mappings.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.test.ts (1)

67-85: Consider using network-appropriate token addresses for cross-chain tests.

While the test logic is correct (expecting null since Ethplorer doesn't support these networks), using the Ethereum mainnet WETH address for Polygon and Avalanche tests may be misleading. Consider using network-specific token addresses or a more generic test approach.

However, since these tests expect null returns due to unsupported networks, the token address choice doesn't affect the test outcome. The current implementation is acceptable.

libs/repositories/src/utils/coingeckoUtils.ts (1)

34-39: Handle chain ID or slug resolution
Using COINGECKO_PLATFORMS[+chainIdOrSlug] || chainIdOrSlug is concise. Consider normalizing slug casing or adding explicit test coverage for unknown inputs.

libs/shared/src/const.ts (2)

18-20: Include wrapped native tokens for new chains
Addresses for Polygon and Avalanche native wrappers are added correctly.
Consider sourcing these mappings dynamically from the SDK to eliminate manual TODO stubs.


40-42: Update explorer slug mappings
Explorers for Polygon (matic) and Avalanche (avax) are correct.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 40d81d4 and 1c4aaeb.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (48)
  • .env.example (1 hunks)
  • apps/notification-producer/src/producers/trade/fromOrderInvalidationToNotification.ts (1 hunks)
  • apps/twap/src/app/plugins/orderbook.ts (1 hunks)
  • apps/twap/src/app/utils/getConditionalOrderId.ts (1 hunks)
  • libs/repositories/src/const.ts (2 hunks)
  • libs/repositories/src/datasources/coingecko.ts (2 hunks)
  • libs/repositories/src/datasources/cowApi.ts (1 hunks)
  • libs/repositories/src/datasources/ethplorer.ts (2 hunks)
  • libs/repositories/src/datasources/goldRush.ts (2 hunks)
  • libs/repositories/src/datasources/moralis.ts (2 hunks)
  • libs/repositories/src/datasources/viem.ts (1 hunks)
  • libs/repositories/src/repos/Erc20Repository/Erc20Repository.ts (1 hunks)
  • libs/repositories/src/repos/Erc20Repository/Erc20RepositoryCache.spec.ts (1 hunks)
  • libs/repositories/src/repos/Erc20Repository/Erc20RepositoryCache.ts (1 hunks)
  • libs/repositories/src/repos/Erc20Repository/Erc20RepositoryViem.spec.ts (2 hunks)
  • libs/repositories/src/repos/Erc20Repository/Erc20RepositoryViem.ts (1 hunks)
  • libs/repositories/src/repos/SimulationRepository/SimulationRepository.ts (1 hunks)
  • libs/repositories/src/repos/SimulationRepository/SimulationRepositoryTenderly.ts (1 hunks)
  • libs/repositories/src/repos/SimulationRepository/SimulationrepositoryTenderly.test.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepository.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryCache.spec.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryCache.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.test.ts (2 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryFallback.spec.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryFallback.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryGoldRush.test.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryGoldRush.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.spec.ts (1 hunks)
  • libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.ts (1 hunks)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.spec.ts (1 hunks)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.ts (1 hunks)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.test.ts (1 hunks)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.spec.ts (1 hunks)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.ts (1 hunks)
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.spec.ts (1 hunks)
  • libs/repositories/src/utils/coingeckoUtils.ts (2 hunks)
  • libs/services/src/SimulationService/SimulationService.ts (1 hunks)
  • libs/services/src/SlippageService/SlippageService.ts (1 hunks)
  • libs/services/src/SlippageService/SlippageServiceMain.spec.ts (1 hunks)
  • libs/services/src/SlippageService/SlippageServiceMain.test.ts (1 hunks)
  • libs/services/src/SlippageService/SlippageServiceMain.ts (1 hunks)
  • libs/services/src/TokenHolderService/TokenHolderService.ts (1 hunks)
  • libs/shared/src/const.ts (5 hunks)
  • libs/shared/src/types.ts (0 hunks)
  • libs/shared/src/utils/format.ts (1 hunks)
  • libs/shared/src/utils/misc.ts (1 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • libs/shared/src/types.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
libs/repositories/src/utils/coingeckoUtils.ts (1)
libs/repositories/src/datasources/coingecko.ts (1)
  • COINGECKO_PLATFORMS (28-228)
libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.test.ts (1)
libs/repositories/test/mock.ts (1)
  • WETH (1-1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: docker (apps/notification-producer)
  • GitHub Check: docker (apps/api)
🔇 Additional comments (56)
libs/services/src/SlippageService/SlippageServiceMain.test.ts (2)

3-3: Approve: Updated third-party import
Importing ChainNames and toSupportedChainId from @cowprotocol/shared correctly centralizes chain ID definitions.


4-4: Approve: Local import order
The SlippageServiceMain import follows the third-party imports as per our import grouping conventions (built-ins → external → local).

package.json (1)

32-32:

Details

✅ Verification successful

Confirm the dependency version
The RC version is pinned without a caret, which might prevent receiving patch updates. Please verify that 6.0.0-RC.59 exists and consider if you want to allow patch updates (e.g., ^6.0.0-RC.59).


🏁 Script executed:

#!/bin/bash
# Verify that the specified RC version exists on npm
npm view @cowprotocol/cow-sdk@6.0.0-RC.59 version

Length of output: 63


Dependency version confirmed on npm
Version 6.0.0-RC.59 is published and valid. Since you’ve pinned it exactly, no patch‐level updates will be pulled in. If you’d like to automatically receive future patch releases on the same RC line, consider changing to:

"@cowprotocol/cow-sdk": "^6.0.0-RC.59"

Otherwise, locking to the specific RC version is fine.

libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.ts (2)

1-1: Removed unused import
Good cleanup of the unused inject import from inversify.


1-1: Inconsistent AI summary
The AI summary mentions updating SupportedChainId imports in this file, but there is no such import here. Please confirm or adjust the summary.

Likely an incorrect or invalid review comment.

libs/services/src/SlippageService/SlippageServiceMain.spec.ts (1)

7-7: Import path updated correctly
Switching SupportedChainId to come from @cowprotocol/cow-sdk aligns with the centralized enum.

libs/services/src/SlippageService/SlippageServiceMain.ts (1)

11-12: Split import sources appropriately
Correctly migrating SupportedChainId to @cowprotocol/cow-sdk while retaining toTokenAddress from @cowprotocol/shared.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.spec.ts (1)

1-1: Import path updated correctly
The SupportedChainId enum now comes from @cowprotocol/cow-sdk, aligning with the centralized definitions.

libs/services/src/SlippageService/SlippageService.ts (1)

2-2: Align import to central SDK
Importing SupportedChainId from @cowprotocol/cow-sdk is now consistent across services.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.ts (1)

1-1:

Details

✅ Verification successful

Consistent import of SupportedChainId
Switched to @cowprotocol/cow-sdk, aligning with the repository-wide standard. Ensure that MORALIS_CLIENT_NETWORK_MAPPING in libs/repositories/src/datasources/moralis.ts includes entries for SupportedChainId.POLYGON and SupportedChainId.AVALANCHE to support the new networks.

Run this script to verify:


🏁 Script executed:

#!/bin/bash
# Verify MORALIS_CLIENT_NETWORK_MAPPING includes Polygon and Avalanche
grep -R "MORALIS_CLIENT_NETWORK_MAPPING" -n libs/repositories/src/datasources/moralis.ts
grep -R "SupportedChainId.POLYGON" -n libs/repositories/src/datasources/moralis.ts
grep -R "SupportedChainId.AVALANCHE" -n libs/repositories/src/datasources/moralis.ts

Length of output: 434


Consistent import verified – mappings complete
I’ve confirmed that MORALIS_CLIENT_NETWORK_MAPPING in libs/repositories/src/datasources/moralis.ts includes both:

  • SupportedChainId.POLYGON (line 12)
  • SupportedChainId.AVALANCHE (line 13)

No further changes required.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryGoldRush.ts (1)

6-6:

Details

✅ Verification successful

Update import to central SDK
The migration to @cowprotocol/cow-sdk is correct. Please verify that GOLD_RUSH_CLIENT_NETWORK_MAPPING in libs/repositories/src/datasources/goldRush.ts contains mappings for SupportedChainId.POLYGON and SupportedChainId.AVALANCHE.


🏁 Script executed:

#!/bin/bash
# Verify GOLD_RUSH_CLIENT_NETWORK_MAPPING includes Polygon and Avalanche
grep -R "GOLD_RUSH_CLIENT_NETWORK_MAPPING" -n libs/repositories/src/datasources/goldRush.ts
grep -R "SupportedChainId.POLYGON" -n libs/repositories/src/datasources/goldRush.ts
grep -R "SupportedChainId.AVALANCHE" -n libs/repositories/src/datasources/goldRush.ts

Length of output: 426


Approve migration to @cowprotocol/cow-sdk
Verified that GOLD_RUSH_CLIENT_NETWORK_MAPPING in libs/repositories/src/datasources/goldRush.ts includes both

  • SupportedChainId.POLYGON'polygon-mainnet'
  • SupportedChainId.AVALANCHE'avalanche-mainnet'

No further changes required.

libs/repositories/src/repos/Erc20Repository/Erc20RepositoryViem.ts (1)

3-3: Approve import source migration
Updated SupportedChainId import to @cowprotocol/cow-sdk to centralize chain ID definitions.

libs/repositories/src/repos/Erc20Repository/Erc20Repository.ts (1)

1-1: Approve import source migration
Switching SupportedChainId import to @cowprotocol/cow-sdk aligns with the shared enum relocation.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryFallback.spec.ts (1)

1-1: Approve import source migration
Importing SupportedChainId from @cowprotocol/cow-sdk is consistent with the rest of the codebase.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryCache.ts (1)

2-2: Approve import source migration
Updating SupportedChainId import to @cowprotocol/cow-sdk maintains consistency.

libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.spec.ts (1)

5-5: Approve import source migration
Changed SupportedChainId import to @cowprotocol/cow-sdk as expected.

apps/notification-producer/src/producers/trade/fromOrderInvalidationToNotification.ts (1)

1-3: Consistent import for SupportedChainId
Importing SupportedChainId from @cowprotocol/cow-sdk aligns with the recent centralization of chain ID definitions. No further action needed here.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryGoldRush.test.ts (1)

1-1: Update import to external SDK
Switching SupportedChainId import to @cowprotocol/cow-sdk is correct and keeps definitions consistent across tests.

libs/shared/src/utils/format.ts (1)

3-5: Ensure explorer network mapping covers new chains
You’ve replaced the local SupportedChainId import with the SDK version—nice consolidation. Please verify that EXPLORER_NETWORK_NAMES includes entries for SupportedChainId.POLYGON and SupportedChainId.AVALANCHE, so getExplorerBaseUrl resolves correctly for those networks.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.ts (1)

6-6: Align import to central SDK
Importing SupportedChainId from @cowprotocol/cow-sdk follows the standardization strategy across repos. This segment looks good.

libs/repositories/src/repos/SimulationRepository/SimulationrepositoryTenderly.test.ts (1)

3-3: Centralize chain ID import
Updating SupportedChainId to the external SDK import is consistent with other modules and tests.

libs/shared/src/utils/misc.ts (1)

8-8: Consistent import for SupportedChainId
The import of SupportedChainId has been correctly migrated to @cowprotocol/cow-sdk, centralizing the enum source.

libs/repositories/src/repos/SimulationRepository/SimulationRepository.ts (1)

1-1: Consistent import for SupportedChainId
Updated the import of SupportedChainId to @cowprotocol/cow-sdk, aligning with the rest of the codebase.

libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.spec.ts (1)

1-1: Updated import for SupportedChainId in test
The test file now imports SupportedChainId from @cowprotocol/cow-sdk, matching the production code.

libs/repositories/src/repos/Erc20Repository/Erc20RepositoryCache.spec.ts (1)

4-4: Updated import for SupportedChainId in cache spec
Aligned the test to import SupportedChainId from @cowprotocol/cow-sdk instead of the deprecated package.

libs/services/src/SimulationService/SimulationService.ts (1)

7-7: Updated import for SupportedChainId in service
Migrated the SupportedChainId import to @cowprotocol/cow-sdk for consistency across services.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryFallback.ts (1)

6-6: Unify SupportedChainId import source

The SupportedChainId type is now imported from @cowprotocol/cow-sdk, centralizing chain ID definitions across the repo.

libs/repositories/src/repos/Erc20Repository/Erc20RepositoryCache.ts (1)

4-4: Unify SupportedChainId import source

Switched the SupportedChainId import to @cowprotocol/cow-sdk, aligning with the updated central package.

libs/services/src/TokenHolderService/TokenHolderService.ts (1)

6-6: Unify SupportedChainId import source

Replaced SupportedChainId import with @cowprotocol/cow-sdk to maintain consistency in service definitions.

libs/repositories/src/repos/SimulationRepository/SimulationRepositoryTenderly.ts (1)

1-2: Add and verify imports

Line 1: Introduced SupportedChainId import from @cowprotocol/cow-sdk per the centralized type migration.
Line 2: Retains logger from @cowprotocol/shared, which remains correct.

libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.ts (1)

1-2: Add and verify imports

Line 1: Updated SupportedChainId import to @cowprotocol/cow-sdk for unified chain ID references.
Line 2: Keeps logger import from @cowprotocol/shared unchanged.

libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.spec.ts (1)

1-1: Updated import for SupportedChainId

The import source for SupportedChainId has been correctly moved to @cowprotocol/cow-sdk, centralizing chain IDs.

libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryCache.spec.ts (1)

4-4: Updated import source

SupportedChainId import has been updated to @cowprotocol/cow-sdk as part of the refactor.

libs/repositories/src/datasources/cowApi.ts (1)

5-6: Align chain ID imports

The import of SupportedChainId from @cowprotocol/cow-sdk aligns with the new centralized enum, while other constants remain from @cowprotocol/shared. Ensure that AllChainIds in @cowprotocol/shared includes the newly added Polygon and Avalanche IDs so clients are generated for those networks.

apps/twap/src/app/utils/getConditionalOrderId.ts (1)

48-49: Verify handler addresses for new networks

Entries for POLYGON and AVALANCHE use the same twapHandlerAddress with TODO flags. Please confirm these handler addresses are correct for those chains and remove or update the TODO comments.

libs/repositories/src/repos/Erc20Repository/Erc20RepositoryViem.spec.ts (1)

1-1: Import source updated

SupportedChainId is correctly imported from @cowprotocol/cow-sdk, consolidating enum definitions.

libs/repositories/src/datasources/ethplorer.ts (2)

1-1: LGTM! Import migration is consistent with the broader codebase changes.

The migration from @cowprotocol/shared to @cowprotocol/cow-sdk for SupportedChainId aligns with the PR objectives.


11-12: LGTM! Appropriate handling of unsupported networks.

Setting POLYGON and AVALANCHE to null correctly indicates that Ethplorer doesn't support these networks. This will allow the implementation to gracefully handle requests for these chains.

libs/repositories/src/datasources/viem.ts (3)

2-2: LGTM! Import migration aligns with codebase updates.

The migration from @cowprotocol/shared to @cowprotocol/cow-sdk is consistent with the broader refactoring.


10-11: LGTM! Viem chain imports added correctly.

The polygon and avalanche chain imports from viem/chains are appropriate for the new network support.


19-20:

Details

✅ Verification successful

Verify environment variables for new networks.

The network mappings are correct. Ensure that the corresponding RPC environment variables (RPC_URL_137 for Polygon and RPC_URL_43114 for Avalanche) are documented or provided in environment configuration.


🏁 Script executed:

#!/bin/bash
# Description: Check if environment variables for new networks are documented
# Expected: Find RPC_URL_137 and RPC_URL_43114 references in env examples or documentation

echo "Searching for Polygon (137) and Avalanche (43114) RPC environment variables..."
rg -i "rpc_url_137|rpc_url_43114" --type md --type env --type txt --type js --type ts

Length of output: 282


🏁 Script executed:

#!/bin/bash
# Re-run search for uppercase RPC env vars across docs, config, and example files
echo "Searching for RPC_URL_137 and RPC_URL_43114 references..."
rg -n "RPC_URL_137|RPC_URL_43114" --glob "*.md" --glob "*.json" --glob ".env*" --glob "*.ts" --glob "*.js"

Length of output: 451


Environment variables for Polygon and Avalanche are documented
The .env.example file already includes commented entries for RPC_URL_137 (Polygon) and RPC_URL_43114 (Avalanche), so no further action is needed.

  • .env.example:12 – # RPC_URL_137=...
  • .env.example:15 – # RPC_URL_43114=...
  • .env.example:26 – alternate Avalanche endpoint
libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.test.ts (1)

3-3: LGTM! Import migration is consistent.

The migration to @cowprotocol/cow-sdk aligns with the broader codebase changes.

libs/repositories/src/datasources/moralis.ts (2)

1-1: LGTM! Import migration is consistent with codebase updates.

The migration from @cowprotocol/shared to @cowprotocol/cow-sdk aligns with the broader refactoring effort.


12-13: LGTM! Moralis network mappings are correct.

The network identifiers 'polygon' and 'avalanche' are appropriate for the Moralis API and will enable proper data retrieval for these networks.

libs/repositories/src/datasources/coingecko.ts (2)

1-1: LGTM: Import migration to cow-sdk package.

The migration from @cowprotocol/shared to @cowprotocol/cow-sdk aligns with the PR objectives to centralize chain ID definitions.


19-20: LGTM: Correct CoinGecko platform mappings for new networks.

The platform ID mappings are accurate:

  • polygon-pos for Polygon (chain ID 137)
  • avalanche for Avalanche (chain ID 43114)

These match the official CoinGecko platform identifiers.

.env.example (1)

12-12: LGTM: Correct RPC URL examples for new networks.

The RPC URL examples are properly formatted and use appropriate endpoints for Polygon, Avalanche, and Sepolia networks.

Also applies to: 15-16

libs/repositories/src/datasources/goldRush.ts (2)

1-1: LGTM: Consistent import migration to cow-sdk package.

The import source change aligns with the broader migration pattern across the codebase.


14-16: LGTM: Correct GoldRush network mappings.

The network mappings are accurate for the Covalent GoldRush API:

  • polygon-mainnet for Polygon (chain ID 137)
  • avalanche-mainnet for Avalanche (chain ID 43114)
  • eth-sepolia for Sepolia testnet (chain ID 11155111)
libs/repositories/src/const.ts (2)

1-1: Import SupportedChainId from external SDK
Centralizing chain IDs to the SDK is correct.
Ensure that the project’s @cowprotocol/cow-sdk dependency is pinned to a version that already includes the new Polygon and Avalanche entries.


26-35: Add Polygon & Avalanche USDC addresses
The new token mappings align with on-chain deployments and follow the existing pattern.

libs/repositories/src/utils/coingeckoUtils.ts (2)

2-6: Update Coingecko imports and chain ID source
Swapped local SupportedChainId import for the SDK variant and realigned platform mappings.


41-51: Validate supported chain ID resolution
Implementing a reverse mapping for slug resolution is solid. Add unit tests covering the new Polygon and Avalanche slugs and numeric IDs to confirm this function returns the expected values.

libs/shared/src/const.ts (3)

2-2: Switch to SDK-provided SupportedChainId
Centralizing chain ID definitions reduces duplication. Verify this import is consistent across all shared modules.


29-31: Add human-readable names for new networks
Chain names follow the existing style. You may move these into the SDK when the TODOs are addressed.


51-53: Register new CoW API network identifiers
Mapping to polygon and avalanche matches API expectations.

Comment on lines +112 to +113
[SupportedChainId.POLYGON]: Orderbook;
[SupportedChainId.AVALANCHE]: Orderbook;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify orderbook implementation matches type definitions.

The type definitions now include POLYGON and AVALANCHE orderbook instances, but the actual implementation in fastify.decorate (lines 85-92) only creates a mainnet orderbook. This mismatch could lead to runtime errors when code attempts to access these undefined properties.


🏁 Script executed:

#!/bin/bash
# Description: Check if there are any usages of the new orderbook properties that would fail at runtime
# Expected: Find usages of orderbook[SupportedChainId.POLYGON] or orderbook[SupportedChainId.AVALANCHE]

echo "Searching for POLYGON orderbook usage..."
rg -A 3 -B 3 "orderbook.*POLYGON|orderbook\[.*137\]"

echo "Searching for AVALANCHE orderbook usage..."  
rg -A 3 -B 3 "orderbook.*AVALANCHE|orderbook\[.*43114\]"

echo "Searching for any orderbook property access patterns..."
rg -A 2 "orderbook\[SupportedChainId\."

Length of output: 462


To verify the mismatch between the type declarations and the actual decorated properties, let’s inspect the relevant sections of orderbook.ts.


🏁 Script executed:

#!/bin/bash
# Locate the orderbook plugin file
file=$(fd orderbook.ts | head -n 1)
echo "Inspecting $file"

echo -e "\n--- Interface extension section ---"
rg -n -C2 "declare module 'fastify'" "$file"

echo -e "\n--- Decorate implementation section ---"
rg -n -C3 "fastify.decorate" "$file"

Length of output: 816


🏁 Script executed:

#!/bin/bash
file=apps/twap/src/app/plugins/orderbook.ts

echo "--- Interface extension (lines 90-130) ---"
sed -n '90,130p' "$file"

Length of output: 890


Ensure POLYGON and AVALANCHE orderbooks are actually decorated

The FastifyInstance.orderbook interface now declares properties for POLYGON and AVALANCHE (apps/twap/src/app/plugins/orderbook.ts, ~lines 103–110), but the plugin’s fastify.decorate('orderbook', { … }) call only passes mainnet (lines 85–92). At runtime, accessing fastify.orderbook[SupportedChainId.POLYGON] or …[SupportedChainId.AVALANCHE] will be undefined.

Please either:

  • Instantiate and decorate those chains alongside mainnet, for example:
    const polygon = getOrderbookForChain(SupportedChainId.POLYGON);
    const avalanche = getOrderbookForChain(SupportedChainId.AVALANCHE);
    fastify.decorate('orderbook', {
      gnosis,
      mainnet,
      sepolia,
      [SupportedChainId.POLYGON]: polygon,
      [SupportedChainId.AVALANCHE]: avalanche,
    });
  • Or remove the POLYGON/AVALANCHE entries from the interface until you’re ready to support them.

Files to update:

  • apps/twap/src/app/plugins/orderbook.ts:
    • Decorate implementation (lines 85–92)
    • Interface extension (lines 103–110)
🤖 Prompt for AI Agents
In apps/twap/src/app/plugins/orderbook.ts around lines 85 to 92 and 103 to 110,
the FastifyInstance.orderbook interface declares POLYGON and AVALANCHE
properties, but the fastify.decorate call only initializes mainnet. To fix this,
instantiate orderbook instances for POLYGON and AVALANCHE chains using the
appropriate factory or getter function, then include them in the object passed
to fastify.decorate alongside mainnet and other chains. Alternatively, if these
chains are not yet supported, remove their declarations from the interface to
avoid runtime undefined errors.

[SupportedChainId.GNOSIS_CHAIN]: 'gc',
[SupportedChainId.ARBITRUM_ONE]: 'arb1',
[SupportedChainId.BASE]: 'base',
[SupportedChainId.POLYGON]: 'matic',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one should be pol. It's the CoW Explorer prefix.

@cowdan cowdan merged commit b403ff3 into main Jun 9, 2025
7 checks passed
@cowdan cowdan deleted the feat/add-new-networks branch June 9, 2025 17:02
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