diff --git a/src/consts.ts b/src/consts.ts index 1d34f879..e9ef924c 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -32,6 +32,9 @@ export const SYSTEM_PARACHAINS_NAMES = [ export const POLKADOT_ASSET_HUB_SPEC_NAMES = ['statemint', 'asset-hub-polkadot']; export const KUSAMA_ASSET_HUB_SPEC_NAMES = ['statemine', 'asset-hub-kusama']; export const WESTEND_ASSET_HUB_SPEC_NAMES = ['westmint', 'asset-hub-westend']; +// Rococo's asset hub is currently labeled as `statemine` within our registry. +// There I put both names a recognizable just in case it changes in polkadot-js. +export const ROCOCO_ASSET_HUB_SPEC_NAME = ['rococo', 'statemine', 'asset-hub-rococo']; /** * The default xcm version to construct a xcm message. diff --git a/src/registry/Registry.spec.ts b/src/registry/Registry.spec.ts index e2f77c51..a47bd002 100644 --- a/src/registry/Registry.spec.ts +++ b/src/registry/Registry.spec.ts @@ -3,6 +3,12 @@ import type { ForeignAssetsData } from './types'; describe('Registry', () => { const registry = new Registry('polkadot', {}); + describe('initialization', () => { + it('Should initalize rococo correctly', () => { + const registry = new Registry('rococo', {}); + expect(registry.relayChain).toEqual('rococo'); + }); + }); describe('lookupTokenSymbol', () => { it('Should return the correct result', () => { const res = registry.lookupTokenSymbol('GLMR'); diff --git a/src/registry/findRelayChain.ts b/src/registry/findRelayChain.ts index e994f6ed..5ab86d80 100644 --- a/src/registry/findRelayChain.ts +++ b/src/registry/findRelayChain.ts @@ -1,4 +1,9 @@ -import { KUSAMA_ASSET_HUB_SPEC_NAMES, POLKADOT_ASSET_HUB_SPEC_NAMES, WESTEND_ASSET_HUB_SPEC_NAMES } from '../consts'; +import { + KUSAMA_ASSET_HUB_SPEC_NAMES, + POLKADOT_ASSET_HUB_SPEC_NAMES, + ROCOCO_ASSET_HUB_SPEC_NAME, + WESTEND_ASSET_HUB_SPEC_NAMES, +} from '../consts'; import { BaseError, BaseErrorsEnum } from '../errors'; import type { ChainInfoRegistry, RelayChains } from './types'; /** @@ -21,5 +26,10 @@ export const findRelayChain = (specName: string, registry: ChainInfoRegistry): R if (westendChains.includes(specName.toLowerCase()) || WESTEND_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase())) return 'westend'; + const rococoChains = Object.keys(registry.rococo).map((val) => registry.rococo[val].specName); + if (rococoChains.includes(specName.toLowerCase()) || ROCOCO_ASSET_HUB_SPEC_NAME) { + return 'rococo'; + } + throw new BaseError(`Cannot find the relay chain for specName: ${specName}`, BaseErrorsEnum.InternalError); };