@metamask-previews/assets-controller 11.0.0-preview-44376e0 → 11.0.0-preview-4343321
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 +0 -3
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +2 -2
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +2 -2
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +8 -50
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts +1 -2
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts +1 -2
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +8 -50
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/index.cjs +1 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/utils/snaps-assets-migration.cjs +0 -171
- package/dist/utils/snaps-assets-migration.cjs.map +0 -1
- package/dist/utils/snaps-assets-migration.d.cts +0 -113
- package/dist/utils/snaps-assets-migration.d.cts.map +0 -1
- package/dist/utils/snaps-assets-migration.d.mts +0 -113
- package/dist/utils/snaps-assets-migration.d.mts.map +0 -1
- package/dist/utils/snaps-assets-migration.mjs +0 -162
- package/dist/utils/snaps-assets-migration.mjs.map +0 -1
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { FeatureFlags } from "@metamask/remote-feature-flag-controller";
|
|
2
|
-
import type { Json } from "@metamask/utils";
|
|
3
|
-
import type { ChainId } from "../types.cjs";
|
|
4
|
-
/**
|
|
5
|
-
* Per-network rollout stage for the Snaps → AssetsController assets migration.
|
|
6
|
-
*
|
|
7
|
-
* The stage is resolved per CAIP-2 chain id, so each migration network (Solana,
|
|
8
|
-
* Stellar, Tron) advances and rolls back independently. A network with no flag
|
|
9
|
-
* (or an unknown/malformed value) resolves to {@link Off}.
|
|
10
|
-
*/
|
|
11
|
-
export declare enum SnapsAssetsMigrationStage {
|
|
12
|
-
/**
|
|
13
|
-
* Status quo — the Snap uses its own AssetsService and the AssetsController
|
|
14
|
-
* does NOT ingest for the network.
|
|
15
|
-
*/
|
|
16
|
-
Off = 0,
|
|
17
|
-
/**
|
|
18
|
-
* The AssetsController ingests for the network (Account Activity WebSocket +
|
|
19
|
-
* AccountsAPI) and reads route through it, falling back to the Snap's
|
|
20
|
-
* AssetsService when the controller has no value.
|
|
21
|
-
*/
|
|
22
|
-
ReadAssetsControllerWithFallback = 1,
|
|
23
|
-
/**
|
|
24
|
-
* Reads come from the AssetsController only (no fallback), but the Snap still
|
|
25
|
-
* tracks/persists in the background so rollback stays safe.
|
|
26
|
-
*/
|
|
27
|
-
ReadAssetsControllerWithoutFallback = 2,
|
|
28
|
-
/**
|
|
29
|
-
* The Snap stops tracking/persisting; the AssetsController is the only source.
|
|
30
|
-
*/
|
|
31
|
-
ReadAssetsControllerOnly = 3
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* CAIP-2 namespaces covered by the Snaps → AssetsController assets migration.
|
|
35
|
-
* Only chains in these namespaces are stage-gated; every other namespace
|
|
36
|
-
* (e.g. `eip155`) keeps its existing, ungated ingestion behavior.
|
|
37
|
-
*/
|
|
38
|
-
export declare const SNAPS_ASSETS_MIGRATION_NAMESPACES: readonly ["solana", "stellar", "tron"];
|
|
39
|
-
export type SnapsAssetsMigrationNamespace = (typeof SNAPS_ASSETS_MIGRATION_NAMESPACES)[number];
|
|
40
|
-
/**
|
|
41
|
-
* Per-network remote feature flag keys (LaunchDarkly) that drive the migration.
|
|
42
|
-
* Each flag's resolved value carries the {@link SnapsAssetsMigrationStage} for
|
|
43
|
-
* that network — see {@link parseSnapsAssetsMigrationStage}.
|
|
44
|
-
*/
|
|
45
|
-
export declare const SNAPS_ASSETS_MIGRATION_FLAG_KEYS: Record<SnapsAssetsMigrationNamespace, string>;
|
|
46
|
-
/**
|
|
47
|
-
* Resolve the CAIP-2 namespace of a chain when it belongs to a migration
|
|
48
|
-
* network (Solana, Stellar, Tron).
|
|
49
|
-
*
|
|
50
|
-
* @param chainId - The CAIP-2 chain id.
|
|
51
|
-
* @returns The migration namespace, or `undefined` for any other chain.
|
|
52
|
-
*/
|
|
53
|
-
export declare function getSnapsAssetsMigrationNamespace(chainId: ChainId): SnapsAssetsMigrationNamespace | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Whether a CAIP-2 chain id belongs to a network covered by the assets
|
|
56
|
-
* migration (Solana, Stellar, Tron).
|
|
57
|
-
*
|
|
58
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
59
|
-
* @returns True when the chain's namespace is a migration namespace.
|
|
60
|
-
*/
|
|
61
|
-
export declare function isSnapsAssetsMigrationNamespace(chainId: ChainId): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Coerce a resolved remote feature flag value into a {@link SnapsAssetsMigrationStage}.
|
|
64
|
-
*
|
|
65
|
-
* `RemoteFeatureFlagController` resolves a threshold-scoped flag to a
|
|
66
|
-
* `{ name, value }` variant, so the migration payload
|
|
67
|
-
* `{ featureVersion, minimumSnapVersion, stage }` (and thus `stage`) lives under
|
|
68
|
-
* `value` — the same nesting the sibling `assetsAccountsApiV6` flag uses. The
|
|
69
|
-
* top-level object is used as a fallback so a plain, unscoped `{ stage }`
|
|
70
|
-
* variation still resolves. Anything missing, malformed, or carrying an unknown
|
|
71
|
-
* `stage` resolves to {@link SnapsAssetsMigrationStage.Off}.
|
|
72
|
-
*
|
|
73
|
-
* @param flagValue - The resolved remote feature flag value for a network.
|
|
74
|
-
* @returns The migration stage.
|
|
75
|
-
*/
|
|
76
|
-
export declare function parseSnapsAssetsMigrationStage(flagValue: Json | undefined): SnapsAssetsMigrationStage;
|
|
77
|
-
/**
|
|
78
|
-
* Whether a network's migration stage is active, i.e. the AssetsController
|
|
79
|
-
* (rather than the Snap) is the source of assets for the network.
|
|
80
|
-
*
|
|
81
|
-
* A stage is active from {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback}
|
|
82
|
-
* onward and inactive at {@link SnapsAssetsMigrationStage.Off}.
|
|
83
|
-
*
|
|
84
|
-
* @param stage - The resolved per-network migration stage.
|
|
85
|
-
* @returns True when the migration is active for the network.
|
|
86
|
-
*/
|
|
87
|
-
export declare function isMigrationStageActive(stage: SnapsAssetsMigrationStage): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Resolve the Snaps → AssetsController migration stage for each migration
|
|
90
|
-
* network (Solana, Stellar, Tron) from the remote feature flags. The order
|
|
91
|
-
* matches {@link SNAPS_ASSETS_MIGRATION_NAMESPACES}, so the result can be joined
|
|
92
|
-
* into a stable primitive signature for change detection.
|
|
93
|
-
*
|
|
94
|
-
* @param remoteFeatureFlags - The remote feature flags state to resolve stages from.
|
|
95
|
-
* @returns An array of each migration namespace's resolved stage.
|
|
96
|
-
*/
|
|
97
|
-
export declare function getMigrationStages(remoteFeatureFlags: FeatureFlags): SnapsAssetsMigrationStage[];
|
|
98
|
-
/**
|
|
99
|
-
* Whether a supported network should be surfaced as an active chain, gated by
|
|
100
|
-
* the Snaps → AssetsController migration feature flags.
|
|
101
|
-
*
|
|
102
|
-
* Non-migration namespaces (e.g. `eip155`) are always surfaced. Migration
|
|
103
|
-
* networks (Solana, Stellar, Tron) are only surfaced once their per-network
|
|
104
|
-
* stage reaches {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback};
|
|
105
|
-
* they are excluded when the stage is `Off` (also the fail-safe when the flag is
|
|
106
|
-
* missing or the flags are unavailable).
|
|
107
|
-
*
|
|
108
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
109
|
-
* @param remoteFeatureFlags - The remote feature flags state, or `undefined` when unavailable.
|
|
110
|
-
* @returns `true` when the chain should be surfaced as an active chain.
|
|
111
|
-
*/
|
|
112
|
-
export declare function shouldSupportChain(chainId: ChainId, remoteFeatureFlags: FeatureFlags | undefined): boolean;
|
|
113
|
-
//# sourceMappingURL=snaps-assets-migration.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snaps-assets-migration.d.cts","sourceRoot":"","sources":["../../src/utils/snaps-assets-migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,OAAO,EAAE,qBAAiB;AAExC;;;;;;GAMG;AACH,oBAAY,yBAAyB;IACnC;;;OAGG;IACH,GAAG,IAAI;IACP;;;;OAIG;IACH,gCAAgC,IAAI;IACpC;;;OAGG;IACH,mCAAmC,IAAI;IACvC;;OAEG;IACH,wBAAwB,IAAI;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,wCAIpC,CAAC;AAEX,MAAM,MAAM,6BAA6B,GACvC,CAAC,OAAO,iCAAiC,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,EAAE,MAAM,CACnD,6BAA6B,EAC7B,MAAM,CAKP,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,OAAO,GACf,6BAA6B,GAAG,SAAS,CAW3C;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEzE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,IAAI,GAAG,SAAS,GAC1B,yBAAyB,CAwB3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,kBAAkB,EAAE,YAAY,GAC/B,yBAAyB,EAAE,CAM7B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,YAAY,GAAG,SAAS,GAC3C,OAAO,CAWT"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { FeatureFlags } from "@metamask/remote-feature-flag-controller";
|
|
2
|
-
import type { Json } from "@metamask/utils";
|
|
3
|
-
import type { ChainId } from "../types.mjs";
|
|
4
|
-
/**
|
|
5
|
-
* Per-network rollout stage for the Snaps → AssetsController assets migration.
|
|
6
|
-
*
|
|
7
|
-
* The stage is resolved per CAIP-2 chain id, so each migration network (Solana,
|
|
8
|
-
* Stellar, Tron) advances and rolls back independently. A network with no flag
|
|
9
|
-
* (or an unknown/malformed value) resolves to {@link Off}.
|
|
10
|
-
*/
|
|
11
|
-
export declare enum SnapsAssetsMigrationStage {
|
|
12
|
-
/**
|
|
13
|
-
* Status quo — the Snap uses its own AssetsService and the AssetsController
|
|
14
|
-
* does NOT ingest for the network.
|
|
15
|
-
*/
|
|
16
|
-
Off = 0,
|
|
17
|
-
/**
|
|
18
|
-
* The AssetsController ingests for the network (Account Activity WebSocket +
|
|
19
|
-
* AccountsAPI) and reads route through it, falling back to the Snap's
|
|
20
|
-
* AssetsService when the controller has no value.
|
|
21
|
-
*/
|
|
22
|
-
ReadAssetsControllerWithFallback = 1,
|
|
23
|
-
/**
|
|
24
|
-
* Reads come from the AssetsController only (no fallback), but the Snap still
|
|
25
|
-
* tracks/persists in the background so rollback stays safe.
|
|
26
|
-
*/
|
|
27
|
-
ReadAssetsControllerWithoutFallback = 2,
|
|
28
|
-
/**
|
|
29
|
-
* The Snap stops tracking/persisting; the AssetsController is the only source.
|
|
30
|
-
*/
|
|
31
|
-
ReadAssetsControllerOnly = 3
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* CAIP-2 namespaces covered by the Snaps → AssetsController assets migration.
|
|
35
|
-
* Only chains in these namespaces are stage-gated; every other namespace
|
|
36
|
-
* (e.g. `eip155`) keeps its existing, ungated ingestion behavior.
|
|
37
|
-
*/
|
|
38
|
-
export declare const SNAPS_ASSETS_MIGRATION_NAMESPACES: readonly ["solana", "stellar", "tron"];
|
|
39
|
-
export type SnapsAssetsMigrationNamespace = (typeof SNAPS_ASSETS_MIGRATION_NAMESPACES)[number];
|
|
40
|
-
/**
|
|
41
|
-
* Per-network remote feature flag keys (LaunchDarkly) that drive the migration.
|
|
42
|
-
* Each flag's resolved value carries the {@link SnapsAssetsMigrationStage} for
|
|
43
|
-
* that network — see {@link parseSnapsAssetsMigrationStage}.
|
|
44
|
-
*/
|
|
45
|
-
export declare const SNAPS_ASSETS_MIGRATION_FLAG_KEYS: Record<SnapsAssetsMigrationNamespace, string>;
|
|
46
|
-
/**
|
|
47
|
-
* Resolve the CAIP-2 namespace of a chain when it belongs to a migration
|
|
48
|
-
* network (Solana, Stellar, Tron).
|
|
49
|
-
*
|
|
50
|
-
* @param chainId - The CAIP-2 chain id.
|
|
51
|
-
* @returns The migration namespace, or `undefined` for any other chain.
|
|
52
|
-
*/
|
|
53
|
-
export declare function getSnapsAssetsMigrationNamespace(chainId: ChainId): SnapsAssetsMigrationNamespace | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Whether a CAIP-2 chain id belongs to a network covered by the assets
|
|
56
|
-
* migration (Solana, Stellar, Tron).
|
|
57
|
-
*
|
|
58
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
59
|
-
* @returns True when the chain's namespace is a migration namespace.
|
|
60
|
-
*/
|
|
61
|
-
export declare function isSnapsAssetsMigrationNamespace(chainId: ChainId): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Coerce a resolved remote feature flag value into a {@link SnapsAssetsMigrationStage}.
|
|
64
|
-
*
|
|
65
|
-
* `RemoteFeatureFlagController` resolves a threshold-scoped flag to a
|
|
66
|
-
* `{ name, value }` variant, so the migration payload
|
|
67
|
-
* `{ featureVersion, minimumSnapVersion, stage }` (and thus `stage`) lives under
|
|
68
|
-
* `value` — the same nesting the sibling `assetsAccountsApiV6` flag uses. The
|
|
69
|
-
* top-level object is used as a fallback so a plain, unscoped `{ stage }`
|
|
70
|
-
* variation still resolves. Anything missing, malformed, or carrying an unknown
|
|
71
|
-
* `stage` resolves to {@link SnapsAssetsMigrationStage.Off}.
|
|
72
|
-
*
|
|
73
|
-
* @param flagValue - The resolved remote feature flag value for a network.
|
|
74
|
-
* @returns The migration stage.
|
|
75
|
-
*/
|
|
76
|
-
export declare function parseSnapsAssetsMigrationStage(flagValue: Json | undefined): SnapsAssetsMigrationStage;
|
|
77
|
-
/**
|
|
78
|
-
* Whether a network's migration stage is active, i.e. the AssetsController
|
|
79
|
-
* (rather than the Snap) is the source of assets for the network.
|
|
80
|
-
*
|
|
81
|
-
* A stage is active from {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback}
|
|
82
|
-
* onward and inactive at {@link SnapsAssetsMigrationStage.Off}.
|
|
83
|
-
*
|
|
84
|
-
* @param stage - The resolved per-network migration stage.
|
|
85
|
-
* @returns True when the migration is active for the network.
|
|
86
|
-
*/
|
|
87
|
-
export declare function isMigrationStageActive(stage: SnapsAssetsMigrationStage): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Resolve the Snaps → AssetsController migration stage for each migration
|
|
90
|
-
* network (Solana, Stellar, Tron) from the remote feature flags. The order
|
|
91
|
-
* matches {@link SNAPS_ASSETS_MIGRATION_NAMESPACES}, so the result can be joined
|
|
92
|
-
* into a stable primitive signature for change detection.
|
|
93
|
-
*
|
|
94
|
-
* @param remoteFeatureFlags - The remote feature flags state to resolve stages from.
|
|
95
|
-
* @returns An array of each migration namespace's resolved stage.
|
|
96
|
-
*/
|
|
97
|
-
export declare function getMigrationStages(remoteFeatureFlags: FeatureFlags): SnapsAssetsMigrationStage[];
|
|
98
|
-
/**
|
|
99
|
-
* Whether a supported network should be surfaced as an active chain, gated by
|
|
100
|
-
* the Snaps → AssetsController migration feature flags.
|
|
101
|
-
*
|
|
102
|
-
* Non-migration namespaces (e.g. `eip155`) are always surfaced. Migration
|
|
103
|
-
* networks (Solana, Stellar, Tron) are only surfaced once their per-network
|
|
104
|
-
* stage reaches {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback};
|
|
105
|
-
* they are excluded when the stage is `Off` (also the fail-safe when the flag is
|
|
106
|
-
* missing or the flags are unavailable).
|
|
107
|
-
*
|
|
108
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
109
|
-
* @param remoteFeatureFlags - The remote feature flags state, or `undefined` when unavailable.
|
|
110
|
-
* @returns `true` when the chain should be surfaced as an active chain.
|
|
111
|
-
*/
|
|
112
|
-
export declare function shouldSupportChain(chainId: ChainId, remoteFeatureFlags: FeatureFlags | undefined): boolean;
|
|
113
|
-
//# sourceMappingURL=snaps-assets-migration.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snaps-assets-migration.d.mts","sourceRoot":"","sources":["../../src/utils/snaps-assets-migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iDAAiD;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,OAAO,EAAE,qBAAiB;AAExC;;;;;;GAMG;AACH,oBAAY,yBAAyB;IACnC;;;OAGG;IACH,GAAG,IAAI;IACP;;;;OAIG;IACH,gCAAgC,IAAI;IACpC;;;OAGG;IACH,mCAAmC,IAAI;IACvC;;OAEG;IACH,wBAAwB,IAAI;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,wCAIpC,CAAC;AAEX,MAAM,MAAM,6BAA6B,GACvC,CAAC,OAAO,iCAAiC,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,EAAE,MAAM,CACnD,6BAA6B,EAC7B,MAAM,CAKP,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,OAAO,GACf,6BAA6B,GAAG,SAAS,CAW3C;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEzE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,IAAI,GAAG,SAAS,GAC1B,yBAAyB,CAwB3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,kBAAkB,EAAE,YAAY,GAC/B,yBAAyB,EAAE,CAM7B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,YAAY,GAAG,SAAS,GAC3C,OAAO,CAWT"}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { parseCaipChainId } from "@metamask/utils";
|
|
2
|
-
/**
|
|
3
|
-
* Per-network rollout stage for the Snaps → AssetsController assets migration.
|
|
4
|
-
*
|
|
5
|
-
* The stage is resolved per CAIP-2 chain id, so each migration network (Solana,
|
|
6
|
-
* Stellar, Tron) advances and rolls back independently. A network with no flag
|
|
7
|
-
* (or an unknown/malformed value) resolves to {@link Off}.
|
|
8
|
-
*/
|
|
9
|
-
export var SnapsAssetsMigrationStage;
|
|
10
|
-
(function (SnapsAssetsMigrationStage) {
|
|
11
|
-
/**
|
|
12
|
-
* Status quo — the Snap uses its own AssetsService and the AssetsController
|
|
13
|
-
* does NOT ingest for the network.
|
|
14
|
-
*/
|
|
15
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["Off"] = 0] = "Off";
|
|
16
|
-
/**
|
|
17
|
-
* The AssetsController ingests for the network (Account Activity WebSocket +
|
|
18
|
-
* AccountsAPI) and reads route through it, falling back to the Snap's
|
|
19
|
-
* AssetsService when the controller has no value.
|
|
20
|
-
*/
|
|
21
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["ReadAssetsControllerWithFallback"] = 1] = "ReadAssetsControllerWithFallback";
|
|
22
|
-
/**
|
|
23
|
-
* Reads come from the AssetsController only (no fallback), but the Snap still
|
|
24
|
-
* tracks/persists in the background so rollback stays safe.
|
|
25
|
-
*/
|
|
26
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["ReadAssetsControllerWithoutFallback"] = 2] = "ReadAssetsControllerWithoutFallback";
|
|
27
|
-
/**
|
|
28
|
-
* The Snap stops tracking/persisting; the AssetsController is the only source.
|
|
29
|
-
*/
|
|
30
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["ReadAssetsControllerOnly"] = 3] = "ReadAssetsControllerOnly";
|
|
31
|
-
})(SnapsAssetsMigrationStage || (SnapsAssetsMigrationStage = {}));
|
|
32
|
-
/**
|
|
33
|
-
* CAIP-2 namespaces covered by the Snaps → AssetsController assets migration.
|
|
34
|
-
* Only chains in these namespaces are stage-gated; every other namespace
|
|
35
|
-
* (e.g. `eip155`) keeps its existing, ungated ingestion behavior.
|
|
36
|
-
*/
|
|
37
|
-
export const SNAPS_ASSETS_MIGRATION_NAMESPACES = [
|
|
38
|
-
'solana',
|
|
39
|
-
'stellar',
|
|
40
|
-
'tron',
|
|
41
|
-
];
|
|
42
|
-
/**
|
|
43
|
-
* Per-network remote feature flag keys (LaunchDarkly) that drive the migration.
|
|
44
|
-
* Each flag's resolved value carries the {@link SnapsAssetsMigrationStage} for
|
|
45
|
-
* that network — see {@link parseSnapsAssetsMigrationStage}.
|
|
46
|
-
*/
|
|
47
|
-
export const SNAPS_ASSETS_MIGRATION_FLAG_KEYS = {
|
|
48
|
-
solana: 'networkAssetsSnapsMigrationSolana',
|
|
49
|
-
stellar: 'networkAssetsSnapsMigrationStellar',
|
|
50
|
-
tron: 'networkAssetsSnapsMigrationTron',
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Resolve the CAIP-2 namespace of a chain when it belongs to a migration
|
|
54
|
-
* network (Solana, Stellar, Tron).
|
|
55
|
-
*
|
|
56
|
-
* @param chainId - The CAIP-2 chain id.
|
|
57
|
-
* @returns The migration namespace, or `undefined` for any other chain.
|
|
58
|
-
*/
|
|
59
|
-
export function getSnapsAssetsMigrationNamespace(chainId) {
|
|
60
|
-
try {
|
|
61
|
-
const { namespace } = parseCaipChainId(chainId);
|
|
62
|
-
return SNAPS_ASSETS_MIGRATION_NAMESPACES.includes(namespace)
|
|
63
|
-
? namespace
|
|
64
|
-
: undefined;
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Whether a CAIP-2 chain id belongs to a network covered by the assets
|
|
72
|
-
* migration (Solana, Stellar, Tron).
|
|
73
|
-
*
|
|
74
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
75
|
-
* @returns True when the chain's namespace is a migration namespace.
|
|
76
|
-
*/
|
|
77
|
-
export function isSnapsAssetsMigrationNamespace(chainId) {
|
|
78
|
-
return getSnapsAssetsMigrationNamespace(chainId) !== undefined;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Coerce a resolved remote feature flag value into a {@link SnapsAssetsMigrationStage}.
|
|
82
|
-
*
|
|
83
|
-
* `RemoteFeatureFlagController` resolves a threshold-scoped flag to a
|
|
84
|
-
* `{ name, value }` variant, so the migration payload
|
|
85
|
-
* `{ featureVersion, minimumSnapVersion, stage }` (and thus `stage`) lives under
|
|
86
|
-
* `value` — the same nesting the sibling `assetsAccountsApiV6` flag uses. The
|
|
87
|
-
* top-level object is used as a fallback so a plain, unscoped `{ stage }`
|
|
88
|
-
* variation still resolves. Anything missing, malformed, or carrying an unknown
|
|
89
|
-
* `stage` resolves to {@link SnapsAssetsMigrationStage.Off}.
|
|
90
|
-
*
|
|
91
|
-
* @param flagValue - The resolved remote feature flag value for a network.
|
|
92
|
-
* @returns The migration stage.
|
|
93
|
-
*/
|
|
94
|
-
export function parseSnapsAssetsMigrationStage(flagValue) {
|
|
95
|
-
if (typeof flagValue !== 'object' ||
|
|
96
|
-
flagValue === null ||
|
|
97
|
-
Array.isArray(flagValue)) {
|
|
98
|
-
return SnapsAssetsMigrationStage.Off;
|
|
99
|
-
}
|
|
100
|
-
const { value } = flagValue;
|
|
101
|
-
const payload = typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
102
|
-
? value
|
|
103
|
-
: flagValue;
|
|
104
|
-
const { stage } = payload;
|
|
105
|
-
switch (stage) {
|
|
106
|
-
case SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback:
|
|
107
|
-
case SnapsAssetsMigrationStage.ReadAssetsControllerWithoutFallback:
|
|
108
|
-
case SnapsAssetsMigrationStage.ReadAssetsControllerOnly:
|
|
109
|
-
return stage;
|
|
110
|
-
default:
|
|
111
|
-
return SnapsAssetsMigrationStage.Off;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Whether a network's migration stage is active, i.e. the AssetsController
|
|
116
|
-
* (rather than the Snap) is the source of assets for the network.
|
|
117
|
-
*
|
|
118
|
-
* A stage is active from {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback}
|
|
119
|
-
* onward and inactive at {@link SnapsAssetsMigrationStage.Off}.
|
|
120
|
-
*
|
|
121
|
-
* @param stage - The resolved per-network migration stage.
|
|
122
|
-
* @returns True when the migration is active for the network.
|
|
123
|
-
*/
|
|
124
|
-
export function isMigrationStageActive(stage) {
|
|
125
|
-
return stage >= SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Resolve the Snaps → AssetsController migration stage for each migration
|
|
129
|
-
* network (Solana, Stellar, Tron) from the remote feature flags. The order
|
|
130
|
-
* matches {@link SNAPS_ASSETS_MIGRATION_NAMESPACES}, so the result can be joined
|
|
131
|
-
* into a stable primitive signature for change detection.
|
|
132
|
-
*
|
|
133
|
-
* @param remoteFeatureFlags - The remote feature flags state to resolve stages from.
|
|
134
|
-
* @returns An array of each migration namespace's resolved stage.
|
|
135
|
-
*/
|
|
136
|
-
export function getMigrationStages(remoteFeatureFlags) {
|
|
137
|
-
return SNAPS_ASSETS_MIGRATION_NAMESPACES.map((namespace) => parseSnapsAssetsMigrationStage(remoteFeatureFlags[SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]]));
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Whether a supported network should be surfaced as an active chain, gated by
|
|
141
|
-
* the Snaps → AssetsController migration feature flags.
|
|
142
|
-
*
|
|
143
|
-
* Non-migration namespaces (e.g. `eip155`) are always surfaced. Migration
|
|
144
|
-
* networks (Solana, Stellar, Tron) are only surfaced once their per-network
|
|
145
|
-
* stage reaches {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback};
|
|
146
|
-
* they are excluded when the stage is `Off` (also the fail-safe when the flag is
|
|
147
|
-
* missing or the flags are unavailable).
|
|
148
|
-
*
|
|
149
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
150
|
-
* @param remoteFeatureFlags - The remote feature flags state, or `undefined` when unavailable.
|
|
151
|
-
* @returns `true` when the chain should be surfaced as an active chain.
|
|
152
|
-
*/
|
|
153
|
-
export function shouldSupportChain(chainId, remoteFeatureFlags) {
|
|
154
|
-
const namespace = getSnapsAssetsMigrationNamespace(chainId);
|
|
155
|
-
// Non-migration namespaces (e.g. `eip155`) are never gated.
|
|
156
|
-
if (!namespace) {
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
const stage = parseSnapsAssetsMigrationStage(remoteFeatureFlags?.[SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]]);
|
|
160
|
-
return isMigrationStageActive(stage);
|
|
161
|
-
}
|
|
162
|
-
//# sourceMappingURL=snaps-assets-migration.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snaps-assets-migration.mjs","sourceRoot":"","sources":["../../src/utils/snaps-assets-migration.ts"],"names":[],"mappings":"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","sourcesContent":["import type { FeatureFlags } from '@metamask/remote-feature-flag-controller';\nimport type { Json } from '@metamask/utils';\nimport { parseCaipChainId } from '@metamask/utils';\n\nimport type { ChainId } from '../types';\n\n/**\n * Per-network rollout stage for the Snaps → AssetsController assets migration.\n *\n * The stage is resolved per CAIP-2 chain id, so each migration network (Solana,\n * Stellar, Tron) advances and rolls back independently. A network with no flag\n * (or an unknown/malformed value) resolves to {@link Off}.\n */\nexport enum SnapsAssetsMigrationStage {\n /**\n * Status quo — the Snap uses its own AssetsService and the AssetsController\n * does NOT ingest for the network.\n */\n Off = 0,\n /**\n * The AssetsController ingests for the network (Account Activity WebSocket +\n * AccountsAPI) and reads route through it, falling back to the Snap's\n * AssetsService when the controller has no value.\n */\n ReadAssetsControllerWithFallback = 1,\n /**\n * Reads come from the AssetsController only (no fallback), but the Snap still\n * tracks/persists in the background so rollback stays safe.\n */\n ReadAssetsControllerWithoutFallback = 2,\n /**\n * The Snap stops tracking/persisting; the AssetsController is the only source.\n */\n ReadAssetsControllerOnly = 3,\n}\n\n/**\n * CAIP-2 namespaces covered by the Snaps → AssetsController assets migration.\n * Only chains in these namespaces are stage-gated; every other namespace\n * (e.g. `eip155`) keeps its existing, ungated ingestion behavior.\n */\nexport const SNAPS_ASSETS_MIGRATION_NAMESPACES = [\n 'solana',\n 'stellar',\n 'tron',\n] as const;\n\nexport type SnapsAssetsMigrationNamespace =\n (typeof SNAPS_ASSETS_MIGRATION_NAMESPACES)[number];\n\n/**\n * Per-network remote feature flag keys (LaunchDarkly) that drive the migration.\n * Each flag's resolved value carries the {@link SnapsAssetsMigrationStage} for\n * that network — see {@link parseSnapsAssetsMigrationStage}.\n */\nexport const SNAPS_ASSETS_MIGRATION_FLAG_KEYS: Record<\n SnapsAssetsMigrationNamespace,\n string\n> = {\n solana: 'networkAssetsSnapsMigrationSolana',\n stellar: 'networkAssetsSnapsMigrationStellar',\n tron: 'networkAssetsSnapsMigrationTron',\n};\n\n/**\n * Resolve the CAIP-2 namespace of a chain when it belongs to a migration\n * network (Solana, Stellar, Tron).\n *\n * @param chainId - The CAIP-2 chain id.\n * @returns The migration namespace, or `undefined` for any other chain.\n */\nexport function getSnapsAssetsMigrationNamespace(\n chainId: ChainId,\n): SnapsAssetsMigrationNamespace | undefined {\n try {\n const { namespace } = parseCaipChainId(chainId);\n return (SNAPS_ASSETS_MIGRATION_NAMESPACES as readonly string[]).includes(\n namespace,\n )\n ? (namespace as SnapsAssetsMigrationNamespace)\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Whether a CAIP-2 chain id belongs to a network covered by the assets\n * migration (Solana, Stellar, Tron).\n *\n * @param chainId - The CAIP-2 chain id to check.\n * @returns True when the chain's namespace is a migration namespace.\n */\nexport function isSnapsAssetsMigrationNamespace(chainId: ChainId): boolean {\n return getSnapsAssetsMigrationNamespace(chainId) !== undefined;\n}\n\n/**\n * Coerce a resolved remote feature flag value into a {@link SnapsAssetsMigrationStage}.\n *\n * `RemoteFeatureFlagController` resolves a threshold-scoped flag to a\n * `{ name, value }` variant, so the migration payload\n * `{ featureVersion, minimumSnapVersion, stage }` (and thus `stage`) lives under\n * `value` — the same nesting the sibling `assetsAccountsApiV6` flag uses. The\n * top-level object is used as a fallback so a plain, unscoped `{ stage }`\n * variation still resolves. Anything missing, malformed, or carrying an unknown\n * `stage` resolves to {@link SnapsAssetsMigrationStage.Off}.\n *\n * @param flagValue - The resolved remote feature flag value for a network.\n * @returns The migration stage.\n */\nexport function parseSnapsAssetsMigrationStage(\n flagValue: Json | undefined,\n): SnapsAssetsMigrationStage {\n if (\n typeof flagValue !== 'object' ||\n flagValue === null ||\n Array.isArray(flagValue)\n ) {\n return SnapsAssetsMigrationStage.Off;\n }\n\n const { value } = flagValue as { value?: unknown };\n const payload =\n typeof value === 'object' && value !== null && !Array.isArray(value)\n ? value\n : flagValue;\n\n const { stage } = payload as { stage?: unknown };\n switch (stage) {\n case SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback:\n case SnapsAssetsMigrationStage.ReadAssetsControllerWithoutFallback:\n case SnapsAssetsMigrationStage.ReadAssetsControllerOnly:\n return stage;\n default:\n return SnapsAssetsMigrationStage.Off;\n }\n}\n\n/**\n * Whether a network's migration stage is active, i.e. the AssetsController\n * (rather than the Snap) is the source of assets for the network.\n *\n * A stage is active from {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback}\n * onward and inactive at {@link SnapsAssetsMigrationStage.Off}.\n *\n * @param stage - The resolved per-network migration stage.\n * @returns True when the migration is active for the network.\n */\nexport function isMigrationStageActive(\n stage: SnapsAssetsMigrationStage,\n): boolean {\n return stage >= SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback;\n}\n\n/**\n * Resolve the Snaps → AssetsController migration stage for each migration\n * network (Solana, Stellar, Tron) from the remote feature flags. The order\n * matches {@link SNAPS_ASSETS_MIGRATION_NAMESPACES}, so the result can be joined\n * into a stable primitive signature for change detection.\n *\n * @param remoteFeatureFlags - The remote feature flags state to resolve stages from.\n * @returns An array of each migration namespace's resolved stage.\n */\nexport function getMigrationStages(\n remoteFeatureFlags: FeatureFlags,\n): SnapsAssetsMigrationStage[] {\n return SNAPS_ASSETS_MIGRATION_NAMESPACES.map((namespace) =>\n parseSnapsAssetsMigrationStage(\n remoteFeatureFlags[SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]],\n ),\n );\n}\n\n/**\n * Whether a supported network should be surfaced as an active chain, gated by\n * the Snaps → AssetsController migration feature flags.\n *\n * Non-migration namespaces (e.g. `eip155`) are always surfaced. Migration\n * networks (Solana, Stellar, Tron) are only surfaced once their per-network\n * stage reaches {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback};\n * they are excluded when the stage is `Off` (also the fail-safe when the flag is\n * missing or the flags are unavailable).\n *\n * @param chainId - The CAIP-2 chain id to check.\n * @param remoteFeatureFlags - The remote feature flags state, or `undefined` when unavailable.\n * @returns `true` when the chain should be surfaced as an active chain.\n */\nexport function shouldSupportChain(\n chainId: ChainId,\n remoteFeatureFlags: FeatureFlags | undefined,\n): boolean {\n const namespace = getSnapsAssetsMigrationNamespace(chainId);\n // Non-migration namespaces (e.g. `eip155`) are never gated.\n if (!namespace) {\n return true;\n }\n\n const stage = parseSnapsAssetsMigrationStage(\n remoteFeatureFlags?.[SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]],\n );\n return isMigrationStageActive(stage);\n}\n"]}
|