@metamask-previews/assets-controller 7.1.1-preview-2fd84c8 → 7.1.1-preview-c04e6a2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/data-sources/RpcDataSource.cjs +25 -5
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +25 -5
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/defaults.cjs +18 -10
- package/dist/defaults.cjs.map +1 -1
- package/dist/defaults.d.cts +3 -3
- package/dist/defaults.d.cts.map +1 -1
- package/dist/defaults.d.mts +3 -3
- package/dist/defaults.d.mts.map +1 -1
- package/dist/defaults.mjs +18 -10
- package/dist/defaults.mjs.map +1 -1
- package/package.json +1 -1
package/dist/defaults.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.mjs","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAOA
|
|
1
|
+
{"version":3,"file":"defaults.mjs","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAElE;;;;GAIG;AACH,MAAM,aAAa,GAA0B;IAC3C,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,cAAc;IACpB,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,OAAgB;IACnC,OAAO,GAAG,OAAO,UAAU,YAAY,EAAmB,CAAC;AAC7D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAGxC,IAAI,GAAG,CAAoC;IAC7C,CAAC,UAAqB,EAAE,CAAC,WAAW,CAAC,UAAqB,CAAC,CAAC,CAAC;IAC7D,CAAC,cAAyB,EAAE,CAAC,WAAW,CAAC,cAAyB,CAAC,CAAC,CAAC;IACrE,CAAC,YAAuB,EAAE,CAAC,WAAW,CAAC,YAAuB,CAAC,CAAC,CAAC;CAClE,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAyB,IAAI,GAAG,CAC7E,+BAA+B,CAAC,IAAI,EAAE,CACvC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GACjC,IAAI,GAAG,CAAwB;IAC7B,CAAC,WAAW,CAAC,UAAqB,CAAC,EAAE,aAAa,CAAC;IACnD,CAAC,WAAW,CAAC,cAAyB,CAAC,EAAE,aAAa,CAAC;IACvD,CAAC,WAAW,CAAC,YAAuB,CAAC,EAAE,aAAa,CAAC;CACtD,CAAC,CAAC;AAEL;;;;;;GAMG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAgB;IAEhB,OAAO,+BAA+B,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAsB;IAEtB,OAAO,sBAAsB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,IAAI,GAAyC,EAAE,CAAC;IACtD,KAAK,MAAM,QAAQ,IAAI,+BAA+B,CAAC,MAAM,EAAE,EAAE,CAAC;QAChE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type {\n AssetMetadata,\n Caip19AssetId,\n ChainId,\n FungibleAssetMetadata,\n} from './types';\n\n/**\n * EIP-55 checksummed address of MetaMask USD (mUSD) — same canonical contract\n * address across every chain we deploy it to.\n *\n * Must be checksummed so that the CAIP-19 asset IDs produced by\n * `musdAssetId()` (and therefore the keys seeded into `assetsInfo` by\n * `buildDefaultAssetsInfo()`) match the keys written by data sources, which\n * always pass IDs through `normalizeAssetId` → `toChecksumAddress` before\n * emitting a `DataResponse`. Using a lowercase address would cause the\n * pre-seeded keys to diverge from the data-source keys, leaving a duplicate\n * entry in `assetsInfo` after the first balance or token-data poll.\n */\nconst MUSD_ADDRESS = '0xacA92E438df0B2401fF60dA7E4337B687a2435DA';\n\n/**\n * Hardcoded metadata for MetaMask USD. Pre-seeding this in default\n * state makes the token immediately renderable in the UI before any\n * on-chain balance has been fetched.\n */\nconst MUSD_METADATA: FungibleAssetMetadata = {\n type: 'erc20',\n symbol: 'mUSD',\n name: 'MetaMask USD',\n decimals: 6,\n};\n\n/**\n * Build the CAIP-19 asset ID for the mUSD ERC-20 token on a given EVM\n * chain.\n *\n * @param chainId - The CAIP-2 chain identifier (e.g. `eip155:1`).\n * @returns The CAIP-19 asset ID for mUSD on that chain.\n */\nfunction musdAssetId(chainId: ChainId): Caip19AssetId {\n return `${chainId}/erc20:${MUSD_ADDRESS}` as Caip19AssetId;\n}\n\n/**\n * Default tracked tokens — assets the controller surfaces in state for\n * every account on the listed chain even when the on-chain balance is\n * still zero. Keyed by CAIP-2 chain id.\n *\n * To extend mUSD coverage to a new chain, add an entry here. To add a\n * different default token, append its CAIP-19 asset id to the\n * appropriate chain entry and provide its metadata in\n * {@link DEFAULT_ASSET_METADATA}.\n */\nexport const DEFAULT_TRACKED_ASSETS_BY_CHAIN: ReadonlyMap<\n ChainId,\n readonly Caip19AssetId[]\n> = new Map<ChainId, readonly Caip19AssetId[]>([\n ['eip155:1' as ChainId, [musdAssetId('eip155:1' as ChainId)]],\n ['eip155:59144' as ChainId, [musdAssetId('eip155:59144' as ChainId)]],\n ['eip155:143' as ChainId, [musdAssetId('eip155:143' as ChainId)]],\n]);\n\n/**\n * Chains that have at least one default tracked asset. Useful for\n * quickly answering \"should we seed defaults for this chain?\".\n */\nexport const CHAINS_WITH_DEFAULT_TRACKED_ASSETS: ReadonlySet<ChainId> = new Set(\n DEFAULT_TRACKED_ASSETS_BY_CHAIN.keys(),\n);\n\n/**\n * Pre-seeded metadata for every default tracked asset, keyed by the\n * checksummed CAIP-19 id. All callers must pass a checksummed asset ID;\n * use `normalizeAssetId` to ensure the correct format before looking up.\n */\nexport const DEFAULT_ASSET_METADATA: ReadonlyMap<string, AssetMetadata> =\n new Map<string, AssetMetadata>([\n [musdAssetId('eip155:1' as ChainId), MUSD_METADATA],\n [musdAssetId('eip155:59144' as ChainId), MUSD_METADATA],\n [musdAssetId('eip155:143' as ChainId), MUSD_METADATA],\n ]);\n\n/**\n * Return the default tracked assets for a CAIP-2 chain id. Empty when\n * the chain has no defaults.\n *\n * @param chainId - CAIP-2 chain id to look up.\n * @returns The default asset ids for that chain.\n */\nexport function getDefaultTrackedAssetsForChain(\n chainId: ChainId,\n): readonly Caip19AssetId[] {\n return DEFAULT_TRACKED_ASSETS_BY_CHAIN.get(chainId) ?? [];\n}\n\n/**\n * Look up pre-seeded metadata for a default tracked asset.\n *\n * @param assetId - CAIP-19 asset id (must be EIP-55 checksummed for EVM tokens).\n * @returns The metadata if the asset is a default tracked asset,\n * otherwise `undefined`.\n */\nexport function getDefaultAssetMetadata(\n assetId: Caip19AssetId,\n): AssetMetadata | undefined {\n return DEFAULT_ASSET_METADATA.get(assetId);\n}\n\n/**\n * Build the `assetsInfo` map to use in default controller state —\n * pre-populated with metadata for every default tracked asset across\n * every default tracked chain. This is what makes `assetsInfo[mUSD]`\n * exist from the very first render, before any RPC poll completes.\n *\n * @returns A new map keyed by CAIP-19 id (canonical case from the\n * defaults registry) with the corresponding metadata.\n */\nexport function buildDefaultAssetsInfo(): Record<Caip19AssetId, AssetMetadata> {\n const info: Record<Caip19AssetId, AssetMetadata> = {};\n for (const assetIds of DEFAULT_TRACKED_ASSETS_BY_CHAIN.values()) {\n for (const assetId of assetIds) {\n info[assetId] = MUSD_METADATA;\n }\n }\n return info;\n}\n"]}
|
package/package.json
CHANGED