Skip to content

feat: add bsc support to CoW swapper#11360

Merged
gomesalexandre merged 2 commits intodevelopfrom
add-bnb-to-cow
Dec 11, 2025
Merged

feat: add bsc support to CoW swapper#11360
gomesalexandre merged 2 commits intodevelopfrom
add-bnb-to-cow

Conversation

@0xApotheosis
Copy link
Copy Markdown
Member

@0xApotheosis 0xApotheosis commented Dec 11, 2025

Description

Add Binance Smart Chain support to CoW swapper.

Issue (if applicable)

None, I just realised we didn't support this, but we should.

Risk

Low

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

CoW swaps on BSC

Testing

Ensure CoW trades on BSC work.

Engineering

👆

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

👆

Screenshots (if applicable)

Screenshot 2025-12-11 at 12 39 00 pm

Note

Adds BNB Smart Chain support by enabling BSC chain ID, network mapping, and CowNetwork enum value.

  • CoW Swapper utils:
    • Update SUPPORTED_CHAIN_IDS in packages/swapper/src/cowswap-utils/constants.ts to include KnownChainIds.BnbSmartChainMainnet.
    • Map KnownChainIds.BnbSmartChainMainnet to CowNetwork.Bnb in getCowNetwork (packages/swapper/src/cowswap-utils/index.ts).
  • Types:
    • Add CowNetwork.Bnb to packages/types/src/cowSwap.ts.

Written by Cursor Bugbot for commit b15e421. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • New Features
    • Added support for BNB Smart Chain Mainnet to the swapper service, expanding available blockchain networks for trading operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@0xApotheosis 0xApotheosis requested a review from a team as a code owner December 11, 2025 01:42
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 11, 2025

📝 Walkthrough

Walkthrough

BNB Smart Chain Mainnet support is added to the cowswap utilities across three files: the CowNetwork enum is extended with a new Bnb member, the supported chain IDs constant is updated to include the BNB chain ID, and the chain-to-network mapping logic is extended with a corresponding case for routing.

Changes

Cohort / File(s) Summary
BNB Network Support
packages/types/src/cowSwap.ts, packages/swapper/src/cowswap-utils/constants.ts, packages/swapper/src/cowswap-utils/index.ts
Adds BNB Smart Chain Mainnet support by introducing CowNetwork.Bnb enum member, including KnownChainIds.BnbSmartChainMainnet in SUPPORTED_CHAIN_IDS, and mapping the chain ID to CowNetwork.Bnb in the getCowNetwork switch statement.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5–10 minutes

  • Verify enum value matches expected string identifier ('bnb')
  • Confirm chain ID constant is correctly placed in the array
  • Validate switch case mapping logic connects all three changes consistently

Suggested reviewers

  • NeOMakinG
  • kaladinlight

Poem

🐰 Hop, hop, the chains multiply!
BNB joins the cowswap supply,
Enum, constant, mapping aligned,
Three little changes, perfectly designed!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat: add bsc support to CoW swapper' directly and accurately summarizes the main change: adding Binance Smart Chain (BSC) support to the CoW swapper, which aligns perfectly with the modifications across three files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-bnb-to-cow

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a834359 and b15e421.

📒 Files selected for processing (3)
  • packages/swapper/src/cowswap-utils/constants.ts (1 hunks)
  • packages/swapper/src/cowswap-utils/index.ts (1 hunks)
  • packages/types/src/cowSwap.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Never assume a library is available - always check imports/package.json first
Prefer composition over inheritance
Write self-documenting code with clear variable and function names
Keep functions small and focused on a single responsibility
Avoid deep nesting - use early returns instead
Prefer procedural and easy to understand code
Never expose, log, or commit secrets, API keys, or credentials
Validate all inputs, especially user inputs
Handle errors gracefully with meaningful messages
Don't silently catch and ignore exceptions
Log errors appropriately for debugging
Provide fallback behavior when possible
Use appropriate data structures for the task
Never add code comments unless explicitly requested
When modifying code, do not add comments that reference previous implementations or explain what changed. Comments should only describe the current logic and functionality.
Use meaningful names for branches, variables, and functions
Always run yarn lint --fix and yarn type-check after making changes
Avoid let variable assignments - prefer const with inline IIFE switch statements or extract to functions for conditional logic

Files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
  • packages/types/src/cowSwap.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Avoid useEffect where practical - use it only when necessary and following best practices
Avoid 'any' types - use specific type annotations instead
For default values with user overrides, use computed values (useMemo) instead of useEffect - pattern: userSelected ?? smartDefault ?? fallback
When function parameters are unused due to interface requirements, refactor the interface or implementation to remove them rather than prefixing with underscore
Sanitize data before displaying to prevent XSS
Memoize aggressively - wrap component variables in useMemo and callbacks in useCallback where possible
For static JSX icon elements (e.g., <TbCopy />) that don't depend on state/props, define them as constants outside the component to avoid re-renders instead of using useMemo
Account for light/dark mode using useColorModeValue hook
Account for responsive mobile designs in all UI components
When applying styles, use the existing standards and conventions of the codebase
Use Chakra UI components and conventions
All copy/text must use translation keys - never hardcode strings
Use the translation hook: useTranslate() from react-polyglot
Use useFeatureFlag('FlagName') hook to access feature flag values in components
Prefer type over interface for type definitions
Use strict typing - avoid any
Use Nominal types for domain identifiers (e.g., WalletId, AccountId)
Import types from @shapeshiftoss/caip for chain/account/asset IDs
Use useAppSelector for Redux state
Use useAppDispatch for Redux actions
Memoize expensive computations with useMemo
Memoize callbacks with useCallback

**/*.{ts,tsx}: Use Result<T, E> pattern for error handling in swappers and APIs; ALWAYS use Ok() and Err() from @sniptt/monads; AVOID throwing within swapper API implementations
ALWAYS use custom error classes from @shapeshiftoss/errors with meaningful error codes for internationalization and relevant details in error objects
ALWAYS wrap async op...

Files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
  • packages/types/src/cowSwap.ts
**/swapper{s,}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/error-handling.mdc)

ALWAYS use makeSwapErrorRight for swapper errors with TradeQuoteError enum for error codes and provide detailed error information

Files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/naming-conventions.mdc)

**/*.{js,jsx,ts,tsx}: Use camelCase for variables, functions, and methods with descriptive names that explain the purpose
Use verb prefixes for functions that perform actions (e.g., fetch, validate, execute, update, calculate)
Use UPPER_SNAKE_CASE for constants and configuration values with descriptive names
Use handle prefix for event handlers with descriptive names in camelCase
Use descriptive boolean variable names with is, has, can, should prefixes
Use named exports for components, functions, and utilities instead of default exports
Use descriptive import names and avoid renaming imports unless necessary
Avoid non-descriptive variable names like data, item, obj, and single-letter variable names except in loops
Avoid abbreviations in names unless they are widely understood
Avoid generic function names like fn, func, or callback

Files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
  • packages/types/src/cowSwap.ts
packages/swapper/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/swapper.mdc)

packages/swapper/**/*.ts: Use TypeScript with explicit types (e.g., SupportedChainIds) for all code in the Swapper system
Use camelCase for variable and function names in the Swapper system
Use PascalCase for types, interfaces, and enums in the Swapper system
Use kebab-case for filenames in the Swapper system

Files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
🧠 Learnings (11)
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/swappers/*/utils/constants.ts : Define supported chain IDs for each swapper in utils/constants.ts with both 'sell' and 'buy' properties following the pattern: SupportedChainIds type

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
  • packages/types/src/cowSwap.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/**/*.ts : Use TypeScript with explicit types (e.g., SupportedChainIds) for all code in the Swapper system

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
  • packages/types/src/cowSwap.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/swappers/*/*.ts : Implement filterBuyAssetsBySellAssetId method to filter assets by supported chain IDs in the buy property

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/swappers/**/*.ts : Avoid side effects in swap logic; ensure swap methods are deterministic and stateless

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/constants.ts : Register new swappers in packages/swapper/src/constants.ts with an entry in the swappers registry mapping SwapperName enum to swapper implementation

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
  • packages/types/src/cowSwap.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/swappers/*/*.ts : Implement filterAssetIdsBySellable method to filter assets by supported chain IDs in the sell property

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
  • packages/swapper/src/cowswap-utils/constants.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/index.ts : Export unique functions and types from packages/swapper/src/index.ts only if needed for external consumption

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/swappers/*/endpoints.ts : Reuse checkEvmSwapStatus utility for checking EVM swap status instead of implementing custom status checks

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/**/*.ts : Use camelCase for variable and function names in the Swapper system

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
📚 Learning: 2025-11-24T21:20:57.909Z
Learnt from: CR
Repo: shapeshift/web PR: 0
File: .cursor/rules/swapper.mdc:0-0
Timestamp: 2025-11-24T21:20:57.909Z
Learning: Applies to packages/swapper/src/swappers/*/*.ts : Reuse executeEvmTransaction utility for EVM-based swappers instead of implementing custom transaction execution

Applied to files:

  • packages/swapper/src/cowswap-utils/index.ts
📚 Learning: 2025-10-23T14:27:19.073Z
Learnt from: gomesalexandre
Repo: shapeshift/web PR: 10857
File: src/plugins/walletConnectToDapps/eventsManager/useWalletConnectEventsHandler.ts:101-104
Timestamp: 2025-10-23T14:27:19.073Z
Learning: In WalletConnect wallet_switchEthereumChain and wallet_addEthereumChain requests, the chainId parameter is always present as per the protocol spec. Type guards checking for missing chainId in these handlers (like `if (!evmNetworkIdHex) return`) are solely for TypeScript compiler satisfaction, not real runtime edge cases.

Applied to files:

  • packages/swapper/src/cowswap-utils/constants.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: Install and Cache
🔇 Additional comments (3)
packages/types/src/cowSwap.ts (1)

316-324: Enum extension for BNB looks consistent

Adding CowNetwork.Bnb = 'bnb' aligns with existing naming (lowercase slugs) and is wired up by the new mapping in the swappers utils. No issues from a typing or enum-usage perspective.

packages/swapper/src/cowswap-utils/index.ts (1)

33-52: BNB chain-to-network mapping is correctly wired

The new case KnownChainIds.BnbSmartChainMainnet: return CowNetwork.Bnb matches the existing mapping pattern and preserves the existing default behavior for unsupported chains. Looks good; just ensure BSC CoW trades are covered in your test runs.

packages/swapper/src/cowswap-utils/constants.ts (1)

24-32: Supported chains list now includes BNB consistently

Adding KnownChainIds.BnbSmartChainMainnet to SUPPORTED_CHAIN_IDS keeps this list aligned with the new getCowNetwork case and the CowNetwork.Bnb enum member. No issues spotted here.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

@gomesalexandre gomesalexandre merged commit a93e3c0 into develop Dec 11, 2025
4 checks passed
@gomesalexandre gomesalexandre deleted the add-bnb-to-cow branch December 11, 2025 15:11
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