feat: restrict public api and swap widget to production-validated chains#12425
Conversation
Add a SUPPORTED_CHAIN_IDS allowlist matching the chains fully validated and enabled in the production web app, and filter the public surface by it: - /v1/chains now lists only supported chains instead of all KnownChainIds - /v1/assets and asset lookups exclude assets on unsupported chains, so /v1/rates and /v1/quote reject them as unknown assets - getAssetsById stays unfiltered for swapper deps (e.g. NearIntents denominates its affiliate fee in NEAR's fee asset) Second-class EVM chains (Monad, HyperEVM, Plasma, Katana) are excluded until their chain adapters are wired into the API in a follow-up PR. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Remove chains not fully validated in production from the widget's chain constants, wallet networks, and viem chain configs: - WorldChain (feature flag off in production) - Monad, HyperEVM, Plasma, Katana (second-class EVM chains pending chain adapter support in the public api) The widget derives its visible chain list from /v1/assets, so this aligns its local constants with the public api's supported chain set. Also key VIEM_CHAINS_BY_ID by chain.id instead of hardcoded numbers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR reduces the supported blockchain networks across the codebase by explicitly defining a SUPPORTED_CHAIN_IDS list and enforcing that constraint in asset export and chain enumeration logic. Five EVM chains (hyperevm, katana, monad, plasma, worldchain) are removed from swap widget configuration to maintain consistency. ChangesSupported Chains Reduction
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/public-api/src/constants.ts (1)
4-25: ⚡ Quick winAdd inline documentation for production sync requirement.
The PR objectives mention that
SUPPORTED_CHAIN_IDSshould stay in sync with production feature flags, but there's no inline comment documenting this constraint. Adding a brief comment here will help future maintainers understand the sync requirement and prevent drift.📝 Suggested documentation
+// IMPORTANT: This list must stay in sync with production feature flags. +// Only chains fully validated and enabled in the production web app should be included. export const SUPPORTED_CHAIN_IDS: readonly KnownChainIds[] = [ // EVM KnownChainIds.ArbitrumMainnet,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/public-api/src/constants.ts` around lines 4 - 25, Add a brief inline comment above the SUPPORTED_CHAIN_IDS constant stating that this list must be kept in sync with production feature flags (mentioning source of truth if known) and that any change here requires updating the production feature flags and running relevant deployment/tests; update the comment near the SUPPORTED_CHAIN_IDS declaration so future maintainers see the sync requirement when editing that array.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/public-api/src/routes/chains/utils.ts`:
- Around line 1-18: The comment claiming SUPPORTED_CHAIN_IDS only uses a subset
of CAIP namespaces is incorrect; update the documentation or in-code comment to
state that chainNamespaceToType (Record<ChainNamespace, ChainType>) exhaustively
covers all CAIP namespaces used by SUPPORTED_CHAIN_IDS (eip155, bip122, cosmos,
solana, near, starknet, sui, ton, tron). Locate the mapping in
chainNamespaceToType and the usage of SUPPORTED_CHAIN_IDS and change the
namespace coverage statement to list all the actual namespaces or simply assert
exhaustiveness via ChainNamespace so the claim matches the mapping.
---
Nitpick comments:
In `@packages/public-api/src/constants.ts`:
- Around line 4-25: Add a brief inline comment above the SUPPORTED_CHAIN_IDS
constant stating that this list must be kept in sync with production feature
flags (mentioning source of truth if known) and that any change here requires
updating the production feature flags and running relevant deployment/tests;
update the comment near the SUPPORTED_CHAIN_IDS declaration so future
maintainers see the sync requirement when editing that array.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a3a0cf20-0901-4321-be99-2fc5dbea759f
📒 Files selected for processing (7)
packages/public-api/src/assets.tspackages/public-api/src/constants.tspackages/public-api/src/routes/chains/utils.tspackages/swap-widget/src/config/appkit.tspackages/swap-widget/src/constants/chains.tspackages/swap-widget/src/constants/viemChains.tspackages/swap-widget/src/types/index.ts
💤 Files with no reviewable changes (3)
- packages/swap-widget/src/constants/chains.ts
- packages/swap-widget/src/config/appkit.ts
- packages/swap-widget/src/types/index.ts
Description
Aligns the supported chain set of the public API and swap widget with the chains fully validated and enabled in the production web app. Previously the public API exposed all 49
KnownChainIds(including ~29 chains feature-flagged off in production) and the widget shipped WorldChain, which is also flagged off.public-api:
SUPPORTED_CHAIN_IDSallowlist (16 chains: 8 EVM, 4 UTXO, 3 Cosmos SDK, Solana) inconstants.ts, documented to stay in sync with production feature flags/v1/chainslists only supported chains/v1/assets(list/count/by-id) excludes assets on unsupported chains;/v1/ratesand/v1/quoteconsequently reject them as unknown assetsgetAssetsById()stays unfiltered for swapper deps — NearIntents denominates its affiliate fee in NEAR's fee asset, which would otherwise silently drop affiliate fee metadatachainNamespaceToTypeis now an exhaustiveRecord<ChainNamespace, ChainType>keyed byCHAIN_NAMESPACEconstantsswap-widget:
SecondClassEvmAdapterwiring)VIEM_CHAINS_BY_IDkeyed bychain.idinstead of hardcoded numbersThe widget derives its visible chain list from
/v1/assets, so the server-side filter drives the UI; the local constant edits keep wallet networks and icons consistent.Issue (if applicable)
closes #
Risk
Low risk. No on-chain transaction logic changes — this only narrows which chains/assets the public API and widget expose. The web app is unaffected (its chain enablement still comes from feature flags). Existing quotes on removed chains were already broken or degraded (no chain adapters registered in the API).
Swap rates/quotes via the public API and swap widget only. Chains removed from the widget: WorldChain, Monad, HyperEVM, Plasma, Katana.
Testing
Engineering
pnpm devinpackages/public-api, then:GET /v1/chainsreturns exactly the 16 allowlisted chainsGET /v1/assets?chainId=eip155:480(WorldChain) returns empty; supported chains return assetsGET /v1/swap/rateswith a supported pair (e.g. ETH→USDC) works; with an unsupported-chain asset returns 400 "Unknown sell/buy asset"POST /v1/swap/quotewith a non-enabled swapper name returns 400 "Swapper not available"pnpm devinpackages/swap-widget, port 5174): chain selector no longer shows WorldChain/Monad/HyperEVM/Plasma/Katana; wallet network switching works on remaining EVM chainsOperations
Public API/widget surface only — verify in the widget demo that the chain list matches production web app chains and swaps quote end-to-end on a couple of chains (e.g. ETH mainnet, BTC).
Screenshots (if applicable)
🤖 Generated with Claude Code
Summary by CodeRabbit
Removals
Improvements