Skip to content

# formatting utilities and CAIP network support updates #877

@Dargon789

Description

@Dargon789

Reviewer's Guide

Implements chain-specific SLIP-44 overrides for native BNB on Binance Smart Chain and opBNB in CAIP-19 asset formatting, adds regression tests, updates supported CAIP networks, and bumps the viem dependency and package version across the monorepo.

Class diagram for formatting utilities and CAIP network support updates

classDiagram
  class ExchangeUtil {
    <<module>>
    CHAIN_ASSET_INFO_MAP
    EVM_NATIVE_SLIP44_OVERRIDES
    +getApiUrl()
    +formatCaip19Asset(caipNetworkId, asset) string
  }

  class AssetUtil {
    <<module>>
    CHAIN_ASSET_INFO_MAP
    EVM_NATIVE_SLIP44_OVERRIDES
    +formatCaip19Asset(caipNetworkId, asset) string
  }

  class CaipNetworkUtil {
    <<module>>
    WC_HTTP_RPC_SUPPORTED_CHAINS
    +someNetworkHelpers()
    +WC_HTTP_RPC_SUPPORTED_CHAINS includes eip155:55931
  }

  class EVM_NATIVE_SLIP44_OVERRIDES_Map {
    <<value-object>>
    +key chainId string
    +value slip44CoinType string
    +entry 56 -> 714
    +entry 204 -> 714
  }

  ExchangeUtil --> EVM_NATIVE_SLIP44_OVERRIDES_Map : uses
  AssetUtil --> EVM_NATIVE_SLIP44_OVERRIDES_Map : uses

  class AppkitPackages {
    <<monorepo-packages>>
    +dependOnViem >= 2.45.0
    +PACKAGE_VERSION 1.8.17
  }

  AppkitPackages ..> ExchangeUtil : runtime usage
  AppkitPackages ..> AssetUtil : runtime usage
  AppkitPackages ..> CaipNetworkUtil : runtime usage
Loading

Flow diagram for CAIP-19 asset formatting with SLIP-44 overrides

flowchart TD
  A["Call formatCaip19Asset(caipNetworkId, asset)"] --> B["ParseUtil.parseCaipNetworkId(caipNetworkId)\nextract chainNamespace, chainId"]
  B --> C["Lookup chainInfo from CHAIN_ASSET_INFO_MAP using caipNetworkId"]
  C --> D{Is asset equal to native?}

  D -- "No, non-native asset" --> E["assetNamespace = chainInfo.defaultTokenNamespace\nassetReference = asset"]
  E --> H["Build CAIP-19: chainNamespace:chainId/assetNamespace:assetReference"]

  D -- "Yes, native asset" --> F{Is chainNamespace eip155 and override exists for chainId?}

  F -- "Yes" --> G["assetNamespace = chainInfo.defaultNativeNamespace (unchanged)\nassetReference = EVM_NATIVE_SLIP44_OVERRIDES[chainId]\n(uses chain-specific SLIP-44 coin type, e.g. 714 for BNB)"]
  G --> H

  F -- "No" --> I["assetNamespace = chainInfo.defaultNativeNamespace\nassetReference = chainInfo.defaultNativeReference (existing behavior)"]
  I --> H

  H --> J["Return formatted CAIP-19 asset string"]
Loading

File-Level Changes

Change Details Files
Add CAIP-19 formatting override so native BNB on Binance Smart Chain and opBNB uses SLIP-44 coin type 714 instead of the generic EVM type.
  • Introduce EVM_NATIVE_SLIP44_OVERRIDES map keyed by EVM chainId to SLIP-44 coin type in controllers ExchangeUtil and pay AssetUtil utilities.
  • Update formatCaip19Asset to check for eip155 native assets in the overrides map and use the chain-specific SLIP-44 value for the assetReference when asset is 'native'.
  • Ensure non-native assets still use the chain default token namespace and asset address without being affected by overrides.
packages/controllers/src/utils/ExchangeUtil.ts
packages/pay/src/utils/AssetUtil.ts
Add tests to validate BNB CAIP-19 formatting behavior and guard against regressions.
  • Add tests asserting that native BNB on Binance Smart Chain (eip155:56) and opBNB (eip155:204) format to caip19 with slip44:714.
  • Add a test confirming that ERC20 token formatting on BSC remains unchanged and not impacted by native-token overrides.
packages/controllers/tests/utils/ExchangeUtil.test.ts
Update viem dependency version and related peer dependency constraints across apps, packages, and examples, and bump appkit package version.
  • Bump viem from 2.44.2 to 2.45.0 in multiple app and example package.json files and in packages that depend on viem.
  • Adjust peerDependency ranges that reference viem to require >=2.45.0.
  • Increment PACKAGE_VERSION from 1.8.16 to 1.8.17 in appkit constants.
apps/browser-extension/package.json
apps/demo/package.json
apps/laboratory/package.json
examples/next-ak-basic-app-router/package.json
examples/next-ak-basic-sign-client-app-router/package.json
examples/next-ak-basic-up-app-router/package.json
examples/next-bitcoin-app-router/package.json
examples/next-ep-app-router/package.json
examples/next-ethers-app-router/package.json
examples/next-wagmi-app-router/package.json
examples/next-wagmi-solana-bitcoin-app-router/package.json
examples/nuxt-wagmi-solana-bitcoin/package.json
examples/nuxt-wagmi/package.json
examples/parcel/package.json
examples/react-wagmi/package.json
examples/sveltekit-4-wagmi/package.json
examples/sveltekit-wagmi/package.json
examples/vue-wagmi-solana/package.json
examples/vue-wagmi/package.json
packages/adapters/wagmi/package.json
packages/appkit-utils/package.json
packages/appkit/exports/constants.ts
packages/appkit/package.json
packages/cdn/package.json
packages/common/package.json
packages/controllers/package.json
packages/experimental/package.json
packages/siwe/package.json
packages/siwx/package.json
pnpm-lock.yaml
Expand the set of WC HTTP RPC supported chains to include a new EVM network.
  • Add eip155:55931 to WC_HTTP_RPC_SUPPORTED_CHAINS so it is recognized as supported for WalletConnect HTTP RPC flows.
packages/appkit-utils/src/CaipNetworkUtil.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #874 (comment)

Metadata

Metadata

Assignees

Labels

Projects

Status

In Review

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions