feat: add new Avalanche and Polygon networks#143
Conversation
- import `SupportedChainId` from `cow-sdk`
WalkthroughThis change migrates the definition and usage of the Changes
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)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
✨ 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 (
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (9)
libs/services/src/SlippageService/SlippageServiceMain.spec.ts (1)
7-7: Extend tests for new networks
Now thatPolygonandAvalancheare supported viaSupportedChainId, consider adding test cases usingSupportedChainId.POLYGONandSupportedChainId.AVALANCHEto validate slippage logic across the new chains.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.spec.ts (1)
1-1: Consider coverage for new networks
SincePolygonandAvalancheare newly supported, you may want to add tests forSupportedChainId.POLYGONandSupportedChainId.AVALANCHEin 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
TheSupportedChainIdimport was migrated to@cowprotocol/cow-sdkcorrectly. To ensure the new Avalanche and Polygon networks are supported, consider adding test cases forSupportedChainId.POLYGON(137) andSupportedChainId.AVALANCHE(43114) ingetUsdPriceandgetUsdPrices.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepository.ts (1)
2-2: Standardize import to central SDK
TheSupportedChainIdimport has been correctly updated to@cowprotocol/cow-sdk. Consider removing theeslint-disabledirective 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 AvalancheThe
viemClientsmap now includes entries forPOLYGONandAVALANCHE, 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
nullsince 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
nullreturns 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
UsingCOINGECKO_PLATFORMS[+chainIdOrSlug] || chainIdOrSlugis 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
⛔ Files ignored due to path filters (1)
yarn.lockis 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
ImportingChainNamesandtoSupportedChainIdfrom@cowprotocol/sharedcorrectly centralizes chain ID definitions.
4-4: Approve: Local import order
TheSlippageServiceMainimport 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 that6.0.0-RC.59exists 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 versionLength of output: 63
Dependency version confirmed on npm
Version6.0.0-RC.59is 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 unusedinjectimport frominversify.
1-1: Inconsistent AI summary
The AI summary mentions updatingSupportedChainIdimports 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
SwitchingSupportedChainIdto come from@cowprotocol/cow-sdkaligns with the centralized enum.libs/services/src/SlippageService/SlippageServiceMain.ts (1)
11-12: Split import sources appropriately
Correctly migratingSupportedChainIdto@cowprotocol/cow-sdkwhile retainingtoTokenAddressfrom@cowprotocol/shared.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryMoralis.spec.ts (1)
1-1: Import path updated correctly
TheSupportedChainIdenum 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
ImportingSupportedChainIdfrom@cowprotocol/cow-sdkis 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 thatMORALIS_CLIENT_NETWORK_MAPPINGinlibs/repositories/src/datasources/moralis.tsincludes entries forSupportedChainId.POLYGONandSupportedChainId.AVALANCHEto 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.tsLength of output: 434
Consistent import verified – mappings complete
I’ve confirmed thatMORALIS_CLIENT_NETWORK_MAPPINGinlibs/repositories/src/datasources/moralis.tsincludes 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-sdkis correct. Please verify thatGOLD_RUSH_CLIENT_NETWORK_MAPPINGinlibs/repositories/src/datasources/goldRush.tscontains mappings forSupportedChainId.POLYGONandSupportedChainId.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.tsLength of output: 426
Approve migration to @cowprotocol/cow-sdk
Verified thatGOLD_RUSH_CLIENT_NETWORK_MAPPINGinlibs/repositories/src/datasources/goldRush.tsincludes 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
UpdatedSupportedChainIdimport to@cowprotocol/cow-sdkto centralize chain ID definitions.libs/repositories/src/repos/Erc20Repository/Erc20Repository.ts (1)
1-1: Approve import source migration
SwitchingSupportedChainIdimport to@cowprotocol/cow-sdkaligns with the shared enum relocation.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryFallback.spec.ts (1)
1-1: Approve import source migration
ImportingSupportedChainIdfrom@cowprotocol/cow-sdkis consistent with the rest of the codebase.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryCache.ts (1)
2-2: Approve import source migration
UpdatingSupportedChainIdimport to@cowprotocol/cow-sdkmaintains consistency.libs/repositories/src/repos/UsdRepository/UsdRepositoryCache.spec.ts (1)
5-5: Approve import source migration
ChangedSupportedChainIdimport to@cowprotocol/cow-sdkas expected.apps/notification-producer/src/producers/trade/fromOrderInvalidationToNotification.ts (1)
1-3: Consistent import forSupportedChainId
ImportingSupportedChainIdfrom@cowprotocol/cow-sdkaligns 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
SwitchingSupportedChainIdimport to@cowprotocol/cow-sdkis 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 localSupportedChainIdimport with the SDK version—nice consolidation. Please verify thatEXPLORER_NETWORK_NAMESincludes entries forSupportedChainId.POLYGONandSupportedChainId.AVALANCHE, sogetExplorerBaseUrlresolves correctly for those networks.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryEthplorer.ts (1)
6-6: Align import to central SDK
ImportingSupportedChainIdfrom@cowprotocol/cow-sdkfollows the standardization strategy across repos. This segment looks good.libs/repositories/src/repos/SimulationRepository/SimulationrepositoryTenderly.test.ts (1)
3-3: Centralize chain ID import
UpdatingSupportedChainIdto 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 ofSupportedChainIdhas 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 ofSupportedChainIdto@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 importsSupportedChainIdfrom@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 importSupportedChainIdfrom@cowprotocol/cow-sdkinstead of the deprecated package.libs/services/src/SimulationService/SimulationService.ts (1)
7-7: Updated import for SupportedChainId in service
Migrated theSupportedChainIdimport to@cowprotocol/cow-sdkfor consistency across services.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryFallback.ts (1)
6-6: Unify SupportedChainId import sourceThe
SupportedChainIdtype 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 sourceSwitched the
SupportedChainIdimport to@cowprotocol/cow-sdk, aligning with the updated central package.libs/services/src/TokenHolderService/TokenHolderService.ts (1)
6-6: Unify SupportedChainId import sourceReplaced
SupportedChainIdimport with@cowprotocol/cow-sdkto maintain consistency in service definitions.libs/repositories/src/repos/SimulationRepository/SimulationRepositoryTenderly.ts (1)
1-2: Add and verify importsLine 1: Introduced
SupportedChainIdimport from@cowprotocol/cow-sdkper the centralized type migration.
Line 2: Retainsloggerfrom@cowprotocol/shared, which remains correct.libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.ts (1)
1-2: Add and verify importsLine 1: Updated
SupportedChainIdimport to@cowprotocol/cow-sdkfor unified chain ID references.
Line 2: Keepsloggerimport from@cowprotocol/sharedunchanged.libs/repositories/src/repos/UsdRepository/UsdRepositoryFallback.spec.ts (1)
1-1: Updated import for SupportedChainIdThe import source for
SupportedChainIdhas been correctly moved to@cowprotocol/cow-sdk, centralizing chain IDs.libs/repositories/src/repos/TokenHolderRepository/TokenHolderRepositoryCache.spec.ts (1)
4-4: Updated import source
SupportedChainIdimport has been updated to@cowprotocol/cow-sdkas part of the refactor.libs/repositories/src/datasources/cowApi.ts (1)
5-6: Align chain ID importsThe import of
SupportedChainIdfrom@cowprotocol/cow-sdkaligns with the new centralized enum, while other constants remain from@cowprotocol/shared. Ensure thatAllChainIdsin@cowprotocol/sharedincludes the newly addedPolygonandAvalancheIDs so clients are generated for those networks.apps/twap/src/app/utils/getConditionalOrderId.ts (1)
48-49: Verify handler addresses for new networksEntries for
POLYGONandAVALANCHEuse the sametwapHandlerAddresswith 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
SupportedChainIdis 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/sharedto@cowprotocol/cow-sdkforSupportedChainIdaligns with the PR objectives.
11-12: LGTM! Appropriate handling of unsupported networks.Setting
POLYGONandAVALANCHEtonullcorrectly 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/sharedto@cowprotocol/cow-sdkis consistent with the broader refactoring.
10-11: LGTM! Viem chain imports added correctly.The polygon and avalanche chain imports from
viem/chainsare 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_137for Polygon andRPC_URL_43114for 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 tsLength 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.examplefile already includes commented entries forRPC_URL_137(Polygon) andRPC_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-sdkaligns 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/sharedto@cowprotocol/cow-sdkaligns 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/sharedto@cowprotocol/cow-sdkaligns 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-posfor Polygon (chain ID 137)avalanchefor 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-mainnetfor Polygon (chain ID 137)avalanche-mainnetfor Avalanche (chain ID 43114)eth-sepoliafor Sepolia testnet (chain ID 11155111)libs/repositories/src/const.ts (2)
1-1: ImportSupportedChainIdfrom external SDK
Centralizing chain IDs to the SDK is correct.
Ensure that the project’s@cowprotocol/cow-sdkdependency 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 localSupportedChainIdimport 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-providedSupportedChainId
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 topolygonandavalanchematches API expectations.
| [SupportedChainId.POLYGON]: Orderbook; | ||
| [SupportedChainId.AVALANCHE]: Orderbook; |
There was a problem hiding this comment.
💡 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/AVALANCHEentries 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.
libs/shared/src/const.ts
Outdated
| [SupportedChainId.GNOSIS_CHAIN]: 'gc', | ||
| [SupportedChainId.ARBITRUM_ONE]: 'arb1', | ||
| [SupportedChainId.BASE]: 'base', | ||
| [SupportedChainId.POLYGON]: 'matic', |
There was a problem hiding this comment.
This one should be pol. It's the CoW Explorer prefix.
Description
AvalancheandPolygonnetworksSupportedChainIdfromcow-sdkSummary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores
Tests