@metamask-previews/assets-controller 14.0.2-preview-3866c0ff1 → 14.0.2-preview-e3275932a
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 -1
- package/dist/AssetsController-method-action-types.cjs +7 -0
- package/dist/AssetsController-method-action-types.cjs.map +1 -0
- package/dist/{AssetsController-method-action-types.d.ts → AssetsController-method-action-types.d.cts} +2 -2
- package/dist/AssetsController-method-action-types.d.cts.map +1 -0
- package/dist/AssetsController-method-action-types.d.mts +181 -0
- package/dist/AssetsController-method-action-types.d.mts.map +1 -0
- package/dist/{AssetsController-method-action-types.js → AssetsController-method-action-types.mjs} +1 -1
- package/dist/AssetsController-method-action-types.mjs.map +1 -0
- package/dist/AssetsController.cjs +2596 -0
- package/dist/AssetsController.cjs.map +1 -0
- package/dist/{AssetsController.d.ts → AssetsController.d.cts} +30 -30
- package/dist/AssetsController.d.cts.map +1 -0
- package/dist/AssetsController.d.mts +395 -0
- package/dist/AssetsController.d.mts.map +1 -0
- package/dist/AssetsController.mjs +2589 -0
- package/dist/AssetsController.mjs.map +1 -0
- package/dist/data-sources/AbstractDataSource.cjs +111 -0
- package/dist/data-sources/AbstractDataSource.cjs.map +1 -0
- package/dist/data-sources/{AbstractDataSource.d.ts → AbstractDataSource.d.cts} +2 -2
- package/dist/data-sources/AbstractDataSource.d.cts.map +1 -0
- package/dist/data-sources/AbstractDataSource.d.mts +113 -0
- package/dist/data-sources/AbstractDataSource.d.mts.map +1 -0
- package/dist/data-sources/{AbstractDataSource.js → AbstractDataSource.mjs} +3 -5
- package/dist/data-sources/AbstractDataSource.mjs.map +1 -0
- package/dist/data-sources/AccountActivityDataSource.cjs +267 -0
- package/dist/data-sources/AccountActivityDataSource.cjs.map +1 -0
- package/dist/data-sources/{AccountActivityDataSource.d.ts → AccountActivityDataSource.d.cts} +6 -6
- package/dist/data-sources/AccountActivityDataSource.d.cts.map +1 -0
- package/dist/data-sources/AccountActivityDataSource.d.mts +80 -0
- package/dist/data-sources/AccountActivityDataSource.d.mts.map +1 -0
- package/dist/data-sources/AccountActivityDataSource.mjs +259 -0
- package/dist/data-sources/AccountActivityDataSource.mjs.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.cjs +586 -0
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -0
- package/dist/data-sources/{AccountsApiDataSource.d.ts → AccountsApiDataSource.d.cts} +7 -7
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.d.mts +82 -0
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.mjs +581 -0
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -0
- package/dist/data-sources/PriceDataSource.cjs +466 -0
- package/dist/data-sources/PriceDataSource.cjs.map +1 -0
- package/dist/data-sources/{PriceDataSource.d.ts → PriceDataSource.d.cts} +5 -5
- package/dist/data-sources/PriceDataSource.d.cts.map +1 -0
- package/dist/data-sources/PriceDataSource.d.mts +100 -0
- package/dist/data-sources/PriceDataSource.d.mts.map +1 -0
- package/dist/data-sources/{PriceDataSource.js → PriceDataSource.mjs} +185 -179
- package/dist/data-sources/PriceDataSource.mjs.map +1 -0
- package/dist/data-sources/RpcDataSource.cjs +1021 -0
- package/dist/data-sources/RpcDataSource.cjs.map +1 -0
- package/dist/data-sources/{RpcDataSource.d.ts → RpcDataSource.d.cts} +10 -10
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -0
- package/dist/data-sources/RpcDataSource.d.mts +174 -0
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -0
- package/dist/data-sources/RpcDataSource.mjs +1012 -0
- package/dist/data-sources/RpcDataSource.mjs.map +1 -0
- package/dist/data-sources/SnapDataSource.cjs +443 -0
- package/dist/data-sources/SnapDataSource.cjs.map +1 -0
- package/dist/data-sources/{SnapDataSource.d.ts → SnapDataSource.d.cts} +8 -8
- package/dist/data-sources/SnapDataSource.d.cts.map +1 -0
- package/dist/data-sources/SnapDataSource.d.mts +127 -0
- package/dist/data-sources/SnapDataSource.d.mts.map +1 -0
- package/dist/data-sources/{SnapDataSource.js → SnapDataSource.mjs} +177 -225
- package/dist/data-sources/SnapDataSource.mjs.map +1 -0
- package/dist/data-sources/StakedBalanceDataSource.cjs +616 -0
- package/dist/data-sources/StakedBalanceDataSource.cjs.map +1 -0
- package/dist/data-sources/{StakedBalanceDataSource.d.ts → StakedBalanceDataSource.d.cts} +5 -5
- package/dist/data-sources/StakedBalanceDataSource.d.cts.map +1 -0
- package/dist/data-sources/StakedBalanceDataSource.d.mts +72 -0
- package/dist/data-sources/StakedBalanceDataSource.d.mts.map +1 -0
- package/dist/data-sources/StakedBalanceDataSource.mjs +612 -0
- package/dist/data-sources/StakedBalanceDataSource.mjs.map +1 -0
- package/dist/data-sources/TokenDataSource.cjs +583 -0
- package/dist/data-sources/TokenDataSource.cjs.map +1 -0
- package/dist/data-sources/{TokenDataSource.d.ts → TokenDataSource.d.cts} +5 -5
- package/dist/data-sources/TokenDataSource.d.cts.map +1 -0
- package/dist/data-sources/TokenDataSource.d.mts +81 -0
- package/dist/data-sources/TokenDataSource.d.mts.map +1 -0
- package/dist/data-sources/{TokenDataSource.js → TokenDataSource.mjs} +164 -157
- package/dist/data-sources/TokenDataSource.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs +705 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/{MulticallClient.d.ts → MulticallClient.d.cts} +3 -3
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts +65 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/{MulticallClient.js → MulticallClient.mjs} +160 -148
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.cjs +312 -0
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/{TokensApiClient.d.ts → TokensApiClient.d.cts} +2 -2
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.mts +61 -0
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.mjs +308 -0
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.cjs +10 -0
- package/dist/data-sources/evm-rpc-services/clients/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.cts +4 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.mts +4 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.mjs +3 -0
- package/dist/data-sources/evm-rpc-services/clients/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.cjs +17 -0
- package/dist/data-sources/evm-rpc-services/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/{index.d.ts → index.d.cts} +5 -5
- package/dist/data-sources/evm-rpc-services/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.d.mts +5 -0
- package/dist/data-sources/evm-rpc-services/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.mjs +4 -0
- package/dist/data-sources/evm-rpc-services/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs +247 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/{BalanceFetcher.d.ts → BalanceFetcher.d.cts} +11 -11
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts +96 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs +243 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.cjs +132 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/{StakedBalanceFetcher.d.ts → StakedBalanceFetcher.d.cts} +14 -13
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.mts +81 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/{StakedBalanceFetcher.js → StakedBalanceFetcher.mjs} +27 -13
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs +230 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/{TokenDetector.d.ts → TokenDetector.d.cts} +12 -12
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts +78 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs +226 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.cjs +13 -0
- package/dist/data-sources/evm-rpc-services/services/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/{index.d.ts → index.d.cts} +4 -4
- package/dist/data-sources/evm-rpc-services/services/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.mts +4 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.mjs +4 -0
- package/dist/data-sources/evm-rpc-services/services/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/assets.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/{assets.d.ts → assets.d.cts} +3 -3
- package/dist/data-sources/evm-rpc-services/types/assets.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.d.mts +53 -0
- package/dist/data-sources/evm-rpc-services/types/assets.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/assets.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/config.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/{config.d.ts → config.d.cts} +2 -2
- package/dist/data-sources/evm-rpc-services/types/config.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.d.mts +18 -0
- package/dist/data-sources/evm-rpc-services/types/config.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/config.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/core.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/{core.d.ts → core.d.cts} +2 -2
- package/dist/data-sources/evm-rpc-services/types/core.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.d.mts +19 -0
- package/dist/data-sources/evm-rpc-services/types/core.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/core.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.cts +7 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.mts +7 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/{multicall.d.ts → multicall.d.cts} +2 -2
- package/dist/data-sources/evm-rpc-services/types/multicall.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.d.mts +24 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/services.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/{services.d.ts → services.d.cts} +3 -3
- package/dist/data-sources/evm-rpc-services/types/services.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.mts +70 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/services.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/state.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/{state.d.ts → state.d.cts} +2 -2
- package/dist/data-sources/evm-rpc-services/types/state.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.d.mts +58 -0
- package/dist/data-sources/evm-rpc-services/types/state.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/state.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/assets.cjs +9 -0
- package/dist/data-sources/evm-rpc-services/utils/assets.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{assets.d.ts → assets.d.cts} +2 -2
- package/dist/data-sources/evm-rpc-services/utils/assets.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/assets.d.mts +3 -0
- package/dist/data-sources/evm-rpc-services/utils/assets.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{assets.js → assets.mjs} +2 -2
- package/dist/data-sources/evm-rpc-services/utils/assets.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.cjs +45 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{batch.d.ts → batch.d.cts} +1 -1
- package/dist/data-sources/evm-rpc-services/utils/batch.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.d.mts +28 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{batch.js → batch.mjs} +1 -1
- package/dist/data-sources/evm-rpc-services/utils/batch.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/index.cjs +15 -0
- package/dist/data-sources/evm-rpc-services/utils/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/index.d.cts +4 -0
- package/dist/data-sources/evm-rpc-services/utils/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/index.d.mts +4 -0
- package/dist/data-sources/evm-rpc-services/utils/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/index.mjs +4 -0
- package/dist/data-sources/evm-rpc-services/utils/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.cjs +47 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{parsing.d.ts → parsing.d.cts} +3 -3
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.mts +25 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{parsing.js → parsing.mjs} +3 -3
- package/dist/data-sources/evm-rpc-services/utils/parsing.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.cjs +68 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{staking-contracts.d.ts → staking-contracts.d.cts} +1 -1
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.mts +25 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/{staking-contracts.js → staking-contracts.mjs} +3 -3
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.mjs.map +1 -0
- package/dist/data-sources/index.cjs +30 -0
- package/dist/data-sources/index.cjs.map +1 -0
- package/dist/data-sources/{index.d.ts → index.d.cts} +9 -9
- package/dist/data-sources/index.d.cts.map +1 -0
- package/dist/data-sources/index.d.mts +9 -0
- package/dist/data-sources/index.d.mts.map +1 -0
- package/dist/data-sources/index.mjs +14 -0
- package/dist/data-sources/index.mjs.map +1 -0
- package/dist/defaults.cjs +125 -0
- package/dist/defaults.cjs.map +1 -0
- package/dist/{defaults.d.ts → defaults.d.cts} +2 -2
- package/dist/defaults.d.cts.map +1 -0
- package/dist/defaults.d.mts +50 -0
- package/dist/defaults.d.mts.map +1 -0
- package/dist/{defaults.js → defaults.mjs} +1 -1
- package/dist/defaults.mjs.map +1 -0
- package/dist/errors.cjs +25 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{errors.d.ts → errors.d.cts} +1 -1
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +25 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/{errors.js → errors.mjs} +1 -7
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +67 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +26 -26
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/{index.js → index.mjs} +13 -13
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +4 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/middlewares/CustomAssetGraduationMiddleware.cjs +132 -0
- package/dist/middlewares/CustomAssetGraduationMiddleware.cjs.map +1 -0
- package/dist/middlewares/{CustomAssetGraduationMiddleware.d.ts → CustomAssetGraduationMiddleware.d.cts} +2 -2
- package/dist/middlewares/CustomAssetGraduationMiddleware.d.cts.map +1 -0
- package/dist/middlewares/CustomAssetGraduationMiddleware.d.mts +32 -0
- package/dist/middlewares/CustomAssetGraduationMiddleware.d.mts.map +1 -0
- package/dist/middlewares/{CustomAssetGraduationMiddleware.js → CustomAssetGraduationMiddleware.mjs} +25 -12
- package/dist/middlewares/CustomAssetGraduationMiddleware.mjs.map +1 -0
- package/dist/middlewares/DetectionMiddleware.cjs +154 -0
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -0
- package/dist/middlewares/{DetectionMiddleware.d.ts → DetectionMiddleware.d.cts} +2 -2
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -0
- package/dist/middlewares/DetectionMiddleware.d.mts +40 -0
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -0
- package/dist/middlewares/{DetectionMiddleware.js → DetectionMiddleware.mjs} +7 -5
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -0
- package/dist/middlewares/ParallelMiddleware.cjs +263 -0
- package/dist/middlewares/ParallelMiddleware.cjs.map +1 -0
- package/dist/middlewares/{ParallelMiddleware.d.ts → ParallelMiddleware.d.cts} +2 -2
- package/dist/middlewares/ParallelMiddleware.d.cts.map +1 -0
- package/dist/middlewares/ParallelMiddleware.d.mts +41 -0
- package/dist/middlewares/ParallelMiddleware.d.mts.map +1 -0
- package/dist/middlewares/{ParallelMiddleware.js → ParallelMiddleware.mjs} +11 -4
- package/dist/middlewares/ParallelMiddleware.mjs.map +1 -0
- package/dist/middlewares/RpcFallbackMiddleware.cjs +90 -0
- package/dist/middlewares/RpcFallbackMiddleware.cjs.map +1 -0
- package/dist/middlewares/{RpcFallbackMiddleware.d.ts → RpcFallbackMiddleware.d.cts} +2 -2
- package/dist/middlewares/RpcFallbackMiddleware.d.cts.map +1 -0
- package/dist/middlewares/RpcFallbackMiddleware.d.mts +23 -0
- package/dist/middlewares/RpcFallbackMiddleware.d.mts.map +1 -0
- package/dist/middlewares/{RpcFallbackMiddleware.js → RpcFallbackMiddleware.mjs} +21 -8
- package/dist/middlewares/RpcFallbackMiddleware.mjs.map +1 -0
- package/dist/middlewares/index.cjs +14 -0
- package/dist/middlewares/index.cjs.map +1 -0
- package/dist/middlewares/index.d.cts +9 -0
- package/dist/middlewares/index.d.cts.map +1 -0
- package/dist/middlewares/index.d.mts +9 -0
- package/dist/middlewares/index.d.mts.map +1 -0
- package/dist/middlewares/index.mjs +5 -0
- package/dist/middlewares/index.mjs.map +1 -0
- package/dist/migrations/healAssetsInfoMetadata.cjs +539 -0
- package/dist/migrations/healAssetsInfoMetadata.cjs.map +1 -0
- package/dist/migrations/{healAssetsInfoMetadata.d.ts → healAssetsInfoMetadata.d.cts} +5 -5
- package/dist/migrations/healAssetsInfoMetadata.d.cts.map +1 -0
- package/dist/migrations/healAssetsInfoMetadata.d.mts +140 -0
- package/dist/migrations/healAssetsInfoMetadata.d.mts.map +1 -0
- package/dist/migrations/{healAssetsInfoMetadata.js → healAssetsInfoMetadata.mjs} +11 -9
- package/dist/migrations/healAssetsInfoMetadata.mjs.map +1 -0
- package/dist/selectors/balance.cjs +532 -0
- package/dist/selectors/balance.cjs.map +1 -0
- package/dist/selectors/{balance.d.ts → balance.d.cts} +6 -6
- package/dist/selectors/balance.d.cts.map +1 -0
- package/dist/selectors/balance.d.mts +103 -0
- package/dist/selectors/balance.d.mts.map +1 -0
- package/dist/selectors/{balance.js → balance.mjs} +5 -5
- package/dist/selectors/balance.mjs.map +1 -0
- package/dist/types.cjs +39 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +4 -4
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +533 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils/constants.cjs +5 -0
- package/dist/utils/constants.cjs.map +1 -0
- package/dist/utils/constants.d.cts +2 -0
- package/dist/utils/constants.d.cts.map +1 -0
- package/dist/utils/constants.d.mts +2 -0
- package/dist/utils/constants.d.mts.map +1 -0
- package/dist/utils/{constants.js → constants.mjs} +1 -1
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/customAssetsRpcSupplement.cjs +72 -0
- package/dist/utils/customAssetsRpcSupplement.cjs.map +1 -0
- package/dist/utils/{customAssetsRpcSupplement.d.ts → customAssetsRpcSupplement.d.cts} +2 -2
- package/dist/utils/customAssetsRpcSupplement.d.cts.map +1 -0
- package/dist/utils/customAssetsRpcSupplement.d.mts +60 -0
- package/dist/utils/customAssetsRpcSupplement.d.mts.map +1 -0
- package/dist/utils/{customAssetsRpcSupplement.js → customAssetsRpcSupplement.mjs} +2 -2
- package/dist/utils/customAssetsRpcSupplement.mjs.map +1 -0
- package/dist/utils/dedupingBatchFetcher.cjs +168 -0
- package/dist/utils/dedupingBatchFetcher.cjs.map +1 -0
- package/dist/utils/{dedupingBatchFetcher.d.ts → dedupingBatchFetcher.d.cts} +1 -1
- package/dist/utils/dedupingBatchFetcher.d.cts.map +1 -0
- package/dist/utils/dedupingBatchFetcher.d.mts +72 -0
- package/dist/utils/dedupingBatchFetcher.d.mts.map +1 -0
- package/dist/utils/dedupingBatchFetcher.mjs +164 -0
- package/dist/utils/dedupingBatchFetcher.mjs.map +1 -0
- package/dist/utils/fetchWithTimeout.cjs +30 -0
- package/dist/utils/fetchWithTimeout.cjs.map +1 -0
- package/dist/utils/{fetchWithTimeout.d.ts → fetchWithTimeout.d.cts} +1 -1
- package/dist/utils/fetchWithTimeout.d.cts.map +1 -0
- package/dist/utils/fetchWithTimeout.d.mts +11 -0
- package/dist/utils/fetchWithTimeout.d.mts.map +1 -0
- package/dist/utils/{fetchWithTimeout.js → fetchWithTimeout.mjs} +1 -1
- package/dist/utils/fetchWithTimeout.mjs.map +1 -0
- package/dist/utils/formatExchangeRatesForBridge.cjs +161 -0
- package/dist/utils/formatExchangeRatesForBridge.cjs.map +1 -0
- package/dist/utils/{formatExchangeRatesForBridge.d.ts → formatExchangeRatesForBridge.d.cts} +3 -3
- package/dist/utils/formatExchangeRatesForBridge.d.cts.map +1 -0
- package/dist/utils/formatExchangeRatesForBridge.d.mts +43 -0
- package/dist/utils/formatExchangeRatesForBridge.d.mts.map +1 -0
- package/dist/utils/{formatExchangeRatesForBridge.js → formatExchangeRatesForBridge.mjs} +7 -6
- package/dist/utils/formatExchangeRatesForBridge.mjs.map +1 -0
- package/dist/utils/formatStateForTransactionPay.cjs +174 -0
- package/dist/utils/formatStateForTransactionPay.cjs.map +1 -0
- package/dist/utils/{formatStateForTransactionPay.d.ts → formatStateForTransactionPay.d.cts} +3 -3
- package/dist/utils/formatStateForTransactionPay.d.cts.map +1 -0
- package/dist/utils/formatStateForTransactionPay.d.mts +72 -0
- package/dist/utils/formatStateForTransactionPay.d.mts.map +1 -0
- package/dist/utils/{formatStateForTransactionPay.js → formatStateForTransactionPay.mjs} +15 -13
- package/dist/utils/formatStateForTransactionPay.mjs.map +1 -0
- package/dist/utils/index.cjs +21 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +9 -0
- package/dist/utils/index.d.cts.map +1 -0
- package/dist/utils/index.d.mts +9 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +7 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/native-assets.cjs +64 -0
- package/dist/utils/native-assets.cjs.map +1 -0
- package/dist/utils/{native-assets.d.ts → native-assets.d.cts} +2 -2
- package/dist/utils/native-assets.d.cts.map +1 -0
- package/dist/utils/native-assets.d.mts +19 -0
- package/dist/utils/native-assets.d.mts.map +1 -0
- package/dist/utils/{native-assets.js → native-assets.mjs} +6 -6
- package/dist/utils/native-assets.mjs.map +1 -0
- package/dist/utils/normalizeAmountString.cjs +64 -0
- package/dist/utils/normalizeAmountString.cjs.map +1 -0
- package/dist/utils/{normalizeAmountString.d.ts → normalizeAmountString.d.cts} +1 -1
- package/dist/utils/normalizeAmountString.d.cts.map +1 -0
- package/dist/utils/normalizeAmountString.d.mts +35 -0
- package/dist/utils/normalizeAmountString.d.mts.map +1 -0
- package/dist/utils/{normalizeAmountString.js → normalizeAmountString.mjs} +2 -2
- package/dist/utils/normalizeAmountString.mjs.map +1 -0
- package/dist/utils/normalizeAssetId.cjs +60 -0
- package/dist/utils/normalizeAssetId.cjs.map +1 -0
- package/dist/utils/{normalizeAssetId.d.ts → normalizeAssetId.d.cts} +3 -3
- package/dist/utils/normalizeAssetId.d.cts.map +1 -0
- package/dist/utils/normalizeAssetId.d.mts +32 -0
- package/dist/utils/normalizeAssetId.d.mts.map +1 -0
- package/dist/utils/{normalizeAssetId.js → normalizeAssetId.mjs} +11 -4
- package/dist/utils/normalizeAssetId.mjs.map +1 -0
- package/dist/utils/snaps-assets-migration.cjs +171 -0
- package/dist/utils/snaps-assets-migration.cjs.map +1 -0
- package/dist/utils/{snaps-assets-migration.d.ts → snaps-assets-migration.d.cts} +5 -5
- package/dist/utils/snaps-assets-migration.d.cts.map +1 -0
- package/dist/utils/snaps-assets-migration.d.mts +113 -0
- package/dist/utils/snaps-assets-migration.d.mts.map +1 -0
- package/dist/utils/{snaps-assets-migration.js → snaps-assets-migration.mjs} +2 -2
- package/dist/utils/snaps-assets-migration.mjs.map +1 -0
- package/dist/utils/trace.cjs +120 -0
- package/dist/utils/trace.cjs.map +1 -0
- package/dist/utils/{trace.d.ts → trace.d.cts} +2 -2
- package/dist/utils/trace.d.cts.map +1 -0
- package/dist/utils/trace.d.mts +52 -0
- package/dist/utils/trace.d.mts.map +1 -0
- package/dist/utils/{trace.js → trace.mjs} +1 -1
- package/dist/utils/trace.mjs.map +1 -0
- package/package.json +17 -14
- package/dist/AssetsController-method-action-types.d.ts.map +0 -1
- package/dist/AssetsController-method-action-types.js.map +0 -1
- package/dist/AssetsController.d.ts.map +0 -1
- package/dist/AssetsController.js +0 -2934
- package/dist/AssetsController.js.map +0 -1
- package/dist/data-sources/AbstractDataSource.d.ts.map +0 -1
- package/dist/data-sources/AbstractDataSource.js.map +0 -1
- package/dist/data-sources/AccountActivityDataSource.d.ts.map +0 -1
- package/dist/data-sources/AccountActivityDataSource.js +0 -272
- package/dist/data-sources/AccountActivityDataSource.js.map +0 -1
- package/dist/data-sources/AccountsApiDataSource.d.ts.map +0 -1
- package/dist/data-sources/AccountsApiDataSource.js +0 -609
- package/dist/data-sources/AccountsApiDataSource.js.map +0 -1
- package/dist/data-sources/PriceDataSource.d.ts.map +0 -1
- package/dist/data-sources/PriceDataSource.js.map +0 -1
- package/dist/data-sources/RpcDataSource.d.ts.map +0 -1
- package/dist/data-sources/RpcDataSource.js +0 -1077
- package/dist/data-sources/RpcDataSource.js.map +0 -1
- package/dist/data-sources/SnapDataSource.d.ts.map +0 -1
- package/dist/data-sources/SnapDataSource.js.map +0 -1
- package/dist/data-sources/StakedBalanceDataSource.d.ts.map +0 -1
- package/dist/data-sources/StakedBalanceDataSource.js +0 -675
- package/dist/data-sources/StakedBalanceDataSource.js.map +0 -1
- package/dist/data-sources/TokenDataSource.d.ts.map +0 -1
- package/dist/data-sources/TokenDataSource.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.js +0 -297
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/clients/index.d.ts +0 -4
- package/dist/data-sources/evm-rpc-services/clients/index.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/clients/index.js +0 -3
- package/dist/data-sources/evm-rpc-services/clients/index.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/index.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/index.js +0 -4
- package/dist/data-sources/evm-rpc-services/index.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.js +0 -241
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.js +0 -217
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/index.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/services/index.js +0 -4
- package/dist/data-sources/evm-rpc-services/services/index.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/assets.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/assets.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/assets.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/config.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/config.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/config.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/core.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/core.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/core.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/index.d.ts +0 -7
- package/dist/data-sources/evm-rpc-services/types/index.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/index.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/index.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/multicall.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/multicall.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/multicall.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/services.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/services.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/services.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/state.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/types/state.js +0 -2
- package/dist/data-sources/evm-rpc-services/types/state.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/assets.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/assets.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/batch.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/batch.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/index.d.ts +0 -4
- package/dist/data-sources/evm-rpc-services/utils/index.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/index.js +0 -4
- package/dist/data-sources/evm-rpc-services/utils/index.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/parsing.js.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.ts.map +0 -1
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.js.map +0 -1
- package/dist/data-sources/index.d.ts.map +0 -1
- package/dist/data-sources/index.js +0 -14
- package/dist/data-sources/index.js.map +0 -1
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -4
- package/dist/logger.js.map +0 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.d.ts.map +0 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.js.map +0 -1
- package/dist/middlewares/DetectionMiddleware.d.ts.map +0 -1
- package/dist/middlewares/DetectionMiddleware.js.map +0 -1
- package/dist/middlewares/ParallelMiddleware.d.ts.map +0 -1
- package/dist/middlewares/ParallelMiddleware.js.map +0 -1
- package/dist/middlewares/RpcFallbackMiddleware.d.ts.map +0 -1
- package/dist/middlewares/RpcFallbackMiddleware.js.map +0 -1
- package/dist/middlewares/index.d.ts +0 -9
- package/dist/middlewares/index.d.ts.map +0 -1
- package/dist/middlewares/index.js +0 -5
- package/dist/middlewares/index.js.map +0 -1
- package/dist/migrations/healAssetsInfoMetadata.d.ts.map +0 -1
- package/dist/migrations/healAssetsInfoMetadata.js.map +0 -1
- package/dist/selectors/balance.d.ts.map +0 -1
- package/dist/selectors/balance.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/constants.d.ts +0 -2
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/customAssetsRpcSupplement.d.ts.map +0 -1
- package/dist/utils/customAssetsRpcSupplement.js.map +0 -1
- package/dist/utils/dedupingBatchFetcher.d.ts.map +0 -1
- package/dist/utils/dedupingBatchFetcher.js +0 -177
- package/dist/utils/dedupingBatchFetcher.js.map +0 -1
- package/dist/utils/fetchWithTimeout.d.ts.map +0 -1
- package/dist/utils/fetchWithTimeout.js.map +0 -1
- package/dist/utils/formatExchangeRatesForBridge.d.ts.map +0 -1
- package/dist/utils/formatExchangeRatesForBridge.js.map +0 -1
- package/dist/utils/formatStateForTransactionPay.d.ts.map +0 -1
- package/dist/utils/formatStateForTransactionPay.js.map +0 -1
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -7
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/native-assets.d.ts.map +0 -1
- package/dist/utils/native-assets.js.map +0 -1
- package/dist/utils/normalizeAmountString.d.ts.map +0 -1
- package/dist/utils/normalizeAmountString.js.map +0 -1
- package/dist/utils/normalizeAssetId.d.ts.map +0 -1
- package/dist/utils/normalizeAssetId.js.map +0 -1
- package/dist/utils/snaps-assets-migration.d.ts.map +0 -1
- package/dist/utils/snaps-assets-migration.js.map +0 -1
- package/dist/utils/trace.d.ts.map +0 -1
- package/dist/utils/trace.js.map +0 -1
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deduplicates batched fetches by key across two dimensions:
|
|
3
|
-
*
|
|
4
|
-
* 1. **Freshness TTL** — keys fetched within `freshnessTtlMs` are skipped
|
|
5
|
-
* entirely. Note the freshness window only starts once a fetch *completes*,
|
|
6
|
-
* so it does not cover requests that are still in flight.
|
|
7
|
-
* 2. **Inflight coalescing** — if a fetch is already in progress for a key,
|
|
8
|
-
* concurrent callers join the existing promise instead of issuing a new
|
|
9
|
-
* request. This covers the request-in-flight window the freshness TTL
|
|
10
|
-
* structurally cannot.
|
|
11
|
-
*
|
|
12
|
-
* Both layers are per-key, so a call for a partially-overlapping set of keys
|
|
13
|
-
* reuses the fresh/inflight keys and only fetches the genuinely-missing ones.
|
|
14
|
-
*
|
|
15
|
-
* The fetch is batched: all stale, not-inflight keys from a single `fetch()`
|
|
16
|
-
* call are passed to `fetchBatch` together, then split into per-key results so
|
|
17
|
-
* each key can be joined independently.
|
|
18
|
-
*/
|
|
19
|
-
export class DedupingBatchFetcher {
|
|
20
|
-
#fetchBatch;
|
|
21
|
-
#freshnessTtlMs;
|
|
22
|
-
/** Tracks the last successful fetch time per key (freshness gating). */
|
|
23
|
-
#fetchedAt = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Per-key inflight fetch promises. Each resolves to the value, or `undefined`
|
|
26
|
-
* if the batch failed or returned no data for that key.
|
|
27
|
-
*/
|
|
28
|
-
#inflight = new Map();
|
|
29
|
-
constructor(options) {
|
|
30
|
-
this.#fetchBatch = options.fetchBatch;
|
|
31
|
-
this.#freshnessTtlMs = options.freshnessTtlMs;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Minimum age (ms) before a key is re-fetched.
|
|
35
|
-
*
|
|
36
|
-
* @returns The current freshness TTL in milliseconds.
|
|
37
|
-
*/
|
|
38
|
-
get freshnessTtlMs() {
|
|
39
|
-
return this.#freshnessTtlMs;
|
|
40
|
-
}
|
|
41
|
-
set freshnessTtlMs(ms) {
|
|
42
|
-
this.#freshnessTtlMs = ms;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Fetch values for the given keys, deduplicating against fresh and inflight
|
|
46
|
-
* fetches.
|
|
47
|
-
*
|
|
48
|
-
* @param keys - The keys to fetch.
|
|
49
|
-
* @returns Values keyed by key. Only contains entries for keys that were
|
|
50
|
-
* actually fetched (or joined from inflight) and had a value.
|
|
51
|
-
*/
|
|
52
|
-
async fetch(keys) {
|
|
53
|
-
const { staleKeys, inflightKeys } = this.#partition(keys);
|
|
54
|
-
if (staleKeys.length === 0 && inflightKeys.length === 0) {
|
|
55
|
-
return {};
|
|
56
|
-
}
|
|
57
|
-
// Start a fetch for stale keys and join any fetches already in progress.
|
|
58
|
-
const batchPromise = staleKeys.length > 0 ? this.#startBatchFetch(staleKeys) : undefined;
|
|
59
|
-
const values = await this.#joinInflight(inflightKeys);
|
|
60
|
-
if (batchPromise) {
|
|
61
|
-
Object.assign(values, await batchPromise);
|
|
62
|
-
}
|
|
63
|
-
return values;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Clear the freshness cache, forcing the next fetch to re-request every key
|
|
67
|
-
* regardless of TTL. Does not affect inflight fetches.
|
|
68
|
-
*/
|
|
69
|
-
invalidate() {
|
|
70
|
-
this.#fetchedAt.clear();
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Clear freshness for specific keys only, forcing the next fetch to
|
|
74
|
-
* re-request those keys regardless of TTL. Does not affect inflight fetches.
|
|
75
|
-
*
|
|
76
|
-
* @param keys - Keys to mark stale.
|
|
77
|
-
*/
|
|
78
|
-
invalidateKeys(keys) {
|
|
79
|
-
for (const key of keys) {
|
|
80
|
-
this.#fetchedAt.delete(key);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/** Clear all freshness and inflight state. */
|
|
84
|
-
destroy() {
|
|
85
|
-
this.#fetchedAt.clear();
|
|
86
|
-
this.#inflight.clear();
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Split keys into those that need a fresh fetch and those already being
|
|
90
|
-
* fetched by another caller. Keys still within the freshness TTL are dropped.
|
|
91
|
-
*
|
|
92
|
-
* @param keys - The keys to classify.
|
|
93
|
-
* @returns `staleKeys` (need fetching) and `inflightKeys` (join existing fetch).
|
|
94
|
-
*/
|
|
95
|
-
#partition(keys) {
|
|
96
|
-
const now = Date.now();
|
|
97
|
-
const staleKeys = [];
|
|
98
|
-
const inflightKeys = [];
|
|
99
|
-
for (const key of keys) {
|
|
100
|
-
if (this.#isFresh(key, now)) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (this.#inflight.has(key)) {
|
|
104
|
-
inflightKeys.push(key);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
staleKeys.push(key);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return { staleKeys, inflightKeys };
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Returns true if the key's last fetch is still within the freshness TTL.
|
|
114
|
-
*
|
|
115
|
-
* @param key - The key to check.
|
|
116
|
-
* @param now - Current timestamp (avoids repeated clock reads).
|
|
117
|
-
* @returns True if the key was fetched within the freshness TTL.
|
|
118
|
-
*/
|
|
119
|
-
#isFresh(key, now) {
|
|
120
|
-
const fetchedAt = this.#fetchedAt.get(key);
|
|
121
|
-
return fetchedAt !== undefined && now - fetchedAt < this.#freshnessTtlMs;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Launch a batch fetch and register a per-key inflight promise for each key
|
|
125
|
-
* so concurrent callers can join. On success, all requested keys are marked
|
|
126
|
-
* fresh — including keys the source returned no value for, since the absence
|
|
127
|
-
* of a value is itself a valid answer that should not be re-asked until the
|
|
128
|
-
* TTL expires. A failed batch leaves keys stale so they are retried.
|
|
129
|
-
*
|
|
130
|
-
* @param staleKeys - Keys to fetch (none of which are already inflight).
|
|
131
|
-
* @returns The batch fetch promise.
|
|
132
|
-
*/
|
|
133
|
-
#startBatchFetch(staleKeys) {
|
|
134
|
-
const batchPromise = this.#fetchBatch(staleKeys).then((values) => {
|
|
135
|
-
const fetchedAt = Date.now();
|
|
136
|
-
for (const key of staleKeys) {
|
|
137
|
-
this.#fetchedAt.set(key, fetchedAt);
|
|
138
|
-
}
|
|
139
|
-
return values;
|
|
140
|
-
});
|
|
141
|
-
for (const key of staleKeys) {
|
|
142
|
-
const perKey = batchPromise.then((values) => values[key], () => undefined);
|
|
143
|
-
this.#inflight.set(key, perKey);
|
|
144
|
-
}
|
|
145
|
-
// Clean up inflight entries once the batch settles (success or failure).
|
|
146
|
-
// Rejection is already surfaced to the caller via the returned batchPromise.
|
|
147
|
-
batchPromise
|
|
148
|
-
.finally(() => {
|
|
149
|
-
for (const key of staleKeys) {
|
|
150
|
-
this.#inflight.delete(key);
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
.catch(() => undefined);
|
|
154
|
-
return batchPromise;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Join the inflight fetches for the given keys and collect their values. Keys
|
|
158
|
-
* whose inflight fetch produced no value are omitted.
|
|
159
|
-
*
|
|
160
|
-
* @param inflightKeys - Keys whose fetches are already in progress.
|
|
161
|
-
* @returns Values keyed by key.
|
|
162
|
-
*/
|
|
163
|
-
async #joinInflight(inflightKeys) {
|
|
164
|
-
const values = {};
|
|
165
|
-
const results = await Promise.all(inflightKeys.map(async (key) => {
|
|
166
|
-
const value = await this.#inflight.get(key);
|
|
167
|
-
return [key, value];
|
|
168
|
-
}));
|
|
169
|
-
for (const [key, value] of results) {
|
|
170
|
-
if (value !== undefined) {
|
|
171
|
-
values[key] = value;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return values;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
//# sourceMappingURL=dedupingBatchFetcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dedupingBatchFetcher.js","sourceRoot":"","sources":["../../src/utils/dedupingBatchFetcher.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,oBAAoB;IACtB,WAAW,CAA2B;IAE/C,eAAe,CAAS;IAExB,wEAAwE;IAC/D,UAAU,GAAG,IAAI,GAAG,EAAe,CAAC;IAE7C;;;OAGG;IACM,SAAS,GAAG,IAAI,GAAG,EAAmC,CAAC;IAEhE,YAAY,OAAgD;QAC1D,IAAI,CAAC,WAAW,GAAG,O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etch for a set of keys. Only keys that have\n * a value need to be present in the returned record; keys the source had no\n * data for are simply omitted (they are still marked fresh — see\n * {@link DedupingBatchFetcher.fetch}).\n *\n * @param keys - The keys to fetch (already filtered to stale, not-inflight keys).\n * @returns The fetched values keyed by key.\n */\nexport type BatchFetchFn<Key extends string, Value> = (\n keys: Key[],\n) => Promise<Record<Key, Value>>;\n\nexport type DedupingBatchFetcherOptions<Key extends string, Value> = {\n /** Performs the actual batched fetch for stale, not-inflight keys. */\n fetchBatch: BatchFetchFn<Key, Value>;\n /**\n * Minimum age (ms) before a key is considered stale and re-fetched. Keys\n * fetched more recently than this are skipped entirely.\n */\n freshnessTtlMs: number;\n};\n\n/**\n * Deduplicates batched fetches by key across two dimensions:\n *\n * 1. **Freshness TTL** — keys fetched within `freshnessTtlMs` are skipped\n * entirely. Note the freshness window only starts once a fetch *completes*,\n * so it does not cover requests that are still in flight.\n * 2. **Inflight coalescing** — if a fetch is already in progress for a key,\n * concurrent callers join the existing promise instead of issuing a new\n * request. This covers the request-in-flight window the freshness TTL\n * structurally cannot.\n *\n * Both layers are per-key, so a call for a partially-overlapping set of keys\n * reuses the fresh/inflight keys and only fetches the genuinely-missing ones.\n *\n * The fetch is batched: all stale, not-inflight keys from a single `fetch()`\n * call are passed to `fetchBatch` together, then split into per-key results so\n * each key can be joined independently.\n */\nexport class DedupingBatchFetcher<Key extends string, Value> {\n readonly #fetchBatch: BatchFetchFn<Key, Value>;\n\n #freshnessTtlMs: number;\n\n /** Tracks the last successful fetch time per key (freshness gating). */\n readonly #fetchedAt = new Map<Key, number>();\n\n /**\n * Per-key inflight fetch promises. Each resolves to the value, or `undefined`\n * if the batch failed or returned no data for that key.\n */\n readonly #inflight = new Map<Key, Promise<Value | undefined>>();\n\n constructor(options: DedupingBatchFetcherOptions<Key, Value>) {\n this.#fetchBatch = options.fetchBatch;\n this.#freshnessTtlMs = options.freshnessTtlMs;\n }\n\n /**\n * Minimum age (ms) before a key is re-fetched.\n *\n * @returns The current freshness TTL in milliseconds.\n */\n get freshnessTtlMs(): number {\n return this.#freshnessTtlMs;\n }\n\n set freshnessTtlMs(ms: number) {\n this.#freshnessTtlMs = ms;\n }\n\n /**\n * Fetch values for the given keys, deduplicating against fresh and inflight\n * fetches.\n *\n * @param keys - The keys to fetch.\n * @returns Values keyed by key. Only contains entries for keys that were\n * actually fetched (or joined from inflight) and had a value.\n */\n async fetch(keys: Key[]): Promise<Record<Key, Value>> {\n const { staleKeys, inflightKeys } = this.#partition(keys);\n\n if (staleKeys.length === 0 && inflightKeys.length === 0) {\n return {} as Record<Key, Value>;\n }\n\n // Start a fetch for stale keys and join any fetches already in progress.\n const batchPromise =\n staleKeys.length > 0 ? this.#startBatchFetch(staleKeys) : undefined;\n const values = await this.#joinInflight(inflightKeys);\n\n if (batchPromise) {\n Object.assign(values, await batchPromise);\n }\n\n return values;\n }\n\n /**\n * Clear the freshness cache, forcing the next fetch to re-request every key\n * regardless of TTL. Does not affect inflight fetches.\n */\n invalidate(): void {\n this.#fetchedAt.clear();\n }\n\n /**\n * Clear freshness for specific keys only, forcing the next fetch to\n * re-request those keys regardless of TTL. Does not affect inflight fetches.\n *\n * @param keys - Keys to mark stale.\n */\n invalidateKeys(keys: Key[]): void {\n for (const key of keys) {\n this.#fetchedAt.delete(key);\n }\n }\n\n /** Clear all freshness and inflight state. */\n destroy(): void {\n this.#fetchedAt.clear();\n this.#inflight.clear();\n }\n\n /**\n * Split keys into those that need a fresh fetch and those already being\n * fetched by another caller. Keys still within the freshness TTL are dropped.\n *\n * @param keys - The keys to classify.\n * @returns `staleKeys` (need fetching) and `inflightKeys` (join existing fetch).\n */\n #partition(keys: Key[]): { staleKeys: Key[]; inflightKeys: Key[] } {\n const now = Date.now();\n const staleKeys: Key[] = [];\n const inflightKeys: Key[] = [];\n\n for (const key of keys) {\n if (this.#isFresh(key, now)) {\n continue;\n }\n if (this.#inflight.has(key)) {\n inflightKeys.push(key);\n } else {\n staleKeys.push(key);\n }\n }\n\n return { staleKeys, inflightKeys };\n }\n\n /**\n * Returns true if the key's last fetch is still within the freshness TTL.\n *\n * @param key - The key to check.\n * @param now - Current timestamp (avoids repeated clock reads).\n * @returns True if the key was fetched within the freshness TTL.\n */\n #isFresh(key: Key, now: number): boolean {\n const fetchedAt = this.#fetchedAt.get(key);\n return fetchedAt !== undefined && now - fetchedAt < this.#freshnessTtlMs;\n }\n\n /**\n * Launch a batch fetch and register a per-key inflight promise for each key\n * so concurrent callers can join. On success, all requested keys are marked\n * fresh — including keys the source returned no value for, since the absence\n * of a value is itself a valid answer that should not be re-asked until the\n * TTL expires. A failed batch leaves keys stale so they are retried.\n *\n * @param staleKeys - Keys to fetch (none of which are already inflight).\n * @returns The batch fetch promise.\n */\n #startBatchFetch(staleKeys: Key[]): Promise<Record<Key, Value>> {\n const batchPromise = this.#fetchBatch(staleKeys).then((values) => {\n const fetchedAt = Date.now();\n for (const key of staleKeys) {\n this.#fetchedAt.set(key, fetchedAt);\n }\n return values;\n });\n\n for (const key of staleKeys) {\n const perKey = batchPromise.then(\n (values) => values[key],\n () => undefined,\n );\n this.#inflight.set(key, perKey);\n }\n\n // Clean up inflight entries once the batch settles (success or failure).\n // Rejection is already surfaced to the caller via the returned batchPromise.\n batchPromise\n .finally(() => {\n for (const key of staleKeys) {\n this.#inflight.delete(key);\n }\n })\n .catch(() => undefined);\n\n return batchPromise;\n }\n\n /**\n * Join the inflight fetches for the given keys and collect their values. Keys\n * whose inflight fetch produced no value are omitted.\n *\n * @param inflightKeys - Keys whose fetches are already in progress.\n * @returns Values keyed by key.\n */\n async #joinInflight(inflightKeys: Key[]): Promise<Record<Key, Value>> {\n const values = {} as Record<Key, Value>;\n\n const results = await Promise.all(\n inflightKeys.map(async (key) => {\n const value = await this.#inflight.get(key);\n return [key, value] as const;\n }),\n );\n\n for (const [key, value] of results) {\n if (value !== undefined) {\n values[key] = value;\n }\n }\n\n return values;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchWithTimeout.d.ts","sourceRoot":"","sources":["../../src/utils/fetchWithTimeout.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAC1C,IAAI,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,EAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,KAAK,CAAC,CAchB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchWithTimeout.js","sourceRoot":"","sources":["../../src/utils/fetchWithTimeout.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAA0B,EAC1B,SAAiB;IAEjB,IAAI,SAAoD,CAAC;IACzD,MAAM,cAAc,GAAG,IAAI,OAAO,CAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;QAC7D,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1B,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,SAAS,IAAI,CAAC,CAAC,CAAC;QAC5D,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC;IACtD,CAAC;YAAS,CAAC;QACT,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Race an async task against a timeout. The returned promise rejects with\n * `new Error('Fetch timed out after <n>ms')` when the timeout wins, letting\n * the caller handle timeouts identically to network errors.\n *\n * @param task - The async task to run (e.g. the raw API call).\n * @param timeoutMs - The timeout in milliseconds.\n * @returns The task's resolved value when it wins the race.\n */\nexport async function fetchWithTimeout<Value>(\n task: () => Promise<Value>,\n timeoutMs: number,\n): Promise<Value> {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<never>((_resolve, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(`Fetch timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n try {\n return await Promise.race([task(), timeoutPromise]);\n } finally {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatExchangeRatesForBridge.d.ts","sourceRoot":"","sources":["../../src/utils/formatExchangeRatesForBridge.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAGjB,oCAAoC,EACpC,yBAAyB,EAE1B,MAAM,8BAA8B,CAAC;AAKtC,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EAGX,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,eAAe,EAAE,oCAAoC,CAAC,iBAAiB,CAAC,CAAC;IACzE,aAAa,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAClD,UAAU,EAAE,yBAAyB,CAAC,YAAY,CAAC,CAAC;IACpD,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,kCAAkC,GAAG;IAC/C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,8BAA8B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9E,CAAC;AAOF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,kCAAkC,GACzC,yBAAyB,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;4BACjD,GAAG,EAAE,SAAS,CAAC,oBAA8B;yBAC9C;qBACF;iBACwE,CAAC;YAC9E,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,2BAA2B;QAC7B,CAAC;IACH,CAAC;IAED,OAAO;QACL,eAAe;QACf,aAAa;QACb,UAAU;QACV,eAAe,EAAE,gBAAgB;KAClC,CAAC;AACJ,CAAC","sourcesContent":["import { toChecksumAddress } from '@ethereumjs/util';\nimport {\n CurrencyRateState,\n MAP_CAIP_CURRENCIES,\n MarketDataDetails,\n MultichainAssetsRatesControllerState,\n TokenRatesControllerState,\n getNativeTokenAddress,\n} from '@metamask/assets-controllers';\nimport { Hex, KnownCaipNamespace, numberToHex } from '@metamask/utils';\nimport { parseCaipAssetType, parseCaipChainId } from '@metamask/utils';\nimport { isEqual } from 'lodash-es';\n\nimport type {\n AssetMetadata,\n AssetPrice,\n FungibleAssetPrice,\n Caip19AssetId,\n} from '../types.js';\n\n/**\n * Exchange rates in the format expected by the bridge controller:\n * conversionRates (MultichainAssetsRatesController) + currencyRates (CurrencyRateController)\n * + marketData (TokenRatesController) + currentCurrency.\n */\nexport type BridgeExchangeRatesFormat = {\n conversionRates: MultichainAssetsRatesControllerState['conversionRates'];\n currencyRates: CurrencyRateState['currencyRates'];\n marketData: TokenRatesControllerState['marketData'];\n currentCurrency: string;\n};\n\n/** Parameters accepted by {@link formatExchangeRatesForBridge}. */\nexport type FormatExchangeRatesForBridgeParams = {\n assetsInfo: Record<string, AssetMetadata>;\n assetsPrice: Record<string, AssetPrice>;\n selectedCurrency: string;\n nativeAssetIdentifiers: Record<string, string>;\n networkConfigurationsByChainId?: Record<string, { nativeCurrency?: string }>;\n};\n\nlet lastCall: {\n params: FormatExchangeRatesForBridgeParams;\n result: BridgeExchangeRatesFormat;\n} | null = null;\n\n/**\n * Converts AssetsController state (assetsPrice, selectedCurrency) into the\n * same format the bridge expects from MultichainAssetsRatesController,\n * CurrencyRateController, and TokenRatesController so the bridge can use\n * a single action when useAssetsControllerForRates is true.\n *\n * Memoized on input identity for BaseController state slices (`===`) and\n * lodash `isEqual` for rebuilt maps (`nativeAssetIdentifiers`). Bridge quote\n * / rate paths call this repeatedly while assets state is unchanged; recomputing\n * runs keccak256 (`toChecksumAddress`) and CAIP parsing per priced asset.\n *\n * @param params - Conversion parameters.\n * @returns Bridge-compatible conversionRates, currencyRates, marketData, currentCurrency.\n */\nexport function formatExchangeRatesForBridge(\n params: FormatExchangeRatesForBridgeParams,\n): BridgeExchangeRatesFormat {\n if (\n lastCall?.params.assetsInfo === params.assetsInfo &&\n lastCall.params.assetsPrice === params.assetsPrice &&\n lastCall.params.selectedCurrency === params.selectedCurrency &&\n lastCall.params.networkConfigurationsByChainId ===\n params.networkConfigurationsByChainId &&\n isEqual(\n lastCall.params.nativeAssetIdentifiers,\n params.nativeAssetIdentifiers,\n )\n ) {\n return lastCall.result;\n }\n\n const result = computeExchangeRatesForBridge(params);\n lastCall = { params, result };\n return result;\n}\n\n/**\n * Clears the {@link formatExchangeRatesForBridge} memoize cache. Exported for tests.\n */\nexport function clearFormatExchangeRatesForBridgeCacheForTesting(): void {\n lastCall = null;\n}\n\n/**\n * Performs the actual exchange-rate conversion for\n * {@link formatExchangeRatesForBridge}.\n *\n * @param params - Conversion parameters.\n * @returns Bridge-compatible rates.\n */\nfunction computeExchangeRatesForBridge(\n params: FormatExchangeRatesForBridgeParams,\n): BridgeExchangeRatesFormat {\n const {\n assetsInfo,\n assetsPrice,\n selectedCurrency,\n nativeAssetIdentifiers,\n networkConfigurationsByChainId = {},\n } = params;\n const conversionRates: MultichainAssetsRatesControllerState['conversionRates'] =\n {};\n const currencyRates: CurrencyRateState['currencyRates'] = {};\n const marketData: TokenRatesControllerState['marketData'] = {};\n\n const currencyCaip = MAP_CAIP_CURRENCIES[selectedCurrency.toLowerCase()];\n if (!currencyCaip) {\n return {\n conversionRates: {},\n currencyRates: {},\n marketData: {},\n currentCurrency: selectedCurrency,\n };\n }\n\n const fungibleAssetsPrice = Object.entries(assetsPrice).reduce<\n Record<Caip19AssetId, FungibleAssetPrice>\n >((acc, [assetId, priceData]) => {\n if (priceData.assetPriceType === 'fungible') {\n acc[assetId as Caip19AssetId] = priceData;\n }\n return acc;\n }, {});\n\n for (const [assetId, priceData] of Object.entries(fungibleAssetsPrice)) {\n const { price, usdPrice, lastUpdated } = priceData;\n if (price < 0) {\n continue;\n }\n\n const lastUpdatedInSeconds = lastUpdated / 1000;\n const expirationOffsetInSeconds = 60;\n const expirationTime = lastUpdatedInSeconds + expirationOffsetInSeconds;\n\n try {\n const isNative = assetsInfo[assetId]?.type === 'native';\n const parsed = parseCaipAssetType(assetId as Caip19AssetId);\n const chainIdParsed = parseCaipChainId(parsed.chainId);\n\n if (chainIdParsed.namespace === KnownCaipNamespace.Eip155) {\n const chainIdHex = numberToHex(parseInt(chainIdParsed.reference, 10));\n\n const nativeAssetId = (\n isNative ? assetId : nativeAssetIdentifiers[parsed.chainId]\n ) as Caip19AssetId | undefined;\n\n const nativeCurrencySymbol =\n networkConfigurationsByChainId[chainIdHex]?.nativeCurrency;\n\n const nativeAssetUsdPrice =\n nativeAssetId && fungibleAssetsPrice[nativeAssetId]?.usdPrice;\n\n if (\n !nativeAssetId ||\n !nativeCurrencySymbol ||\n nativeAssetUsdPrice === undefined\n ) {\n // If we do not have a native asset for that chain or a price for it, the asset needs to be skipped\n continue;\n }\n\n let tokenAddress: Hex | undefined;\n if (parsed.assetNamespace === 'erc20') {\n tokenAddress = toChecksumAddress(parsed.assetReference);\n } else if (isNative) {\n tokenAddress = toChecksumAddress(getNativeTokenAddress(chainIdHex));\n }\n\n if (tokenAddress) {\n const priceInNative =\n nativeAssetUsdPrice > 0 ? usdPrice / nativeAssetUsdPrice : usdPrice;\n if (!marketData[chainIdHex]) {\n marketData[chainIdHex] = {};\n }\n marketData[chainIdHex][tokenAddress] = {\n ...priceData,\n price: priceInNative,\n currency: nativeCurrencySymbol,\n assetId,\n chainId: chainIdHex,\n tokenAddress,\n } as MarketDataDetails;\n }\n\n if (isNative) {\n currencyRates[nativeCurrencySymbol] = {\n conversionDate: lastUpdatedInSeconds,\n conversionRate: price,\n usdConversionRate: usdPrice,\n };\n }\n } else {\n conversionRates[assetId as Caip19AssetId] = {\n rate: String(price),\n currency: currencyCaip,\n conversionTime: lastUpdatedInSeconds,\n expirationTime,\n marketData: {\n fungible: true,\n allTimeHigh: `${priceData.allTimeHigh}`,\n allTimeLow: `${priceData.allTimeLow}`,\n circulatingSupply: `${priceData.circulatingSupply}`,\n marketCap: `${priceData.marketCap}`,\n totalVolume: `${priceData.totalVolume}`,\n pricePercentChange: {\n PT1H: priceData.pricePercentChange1h as number,\n P1D: priceData.pricePercentChange1d as number,\n P7D: priceData.pricePercentChange7d as number,\n P14D: priceData.pricePercentChange14d as number,\n P30D: priceData.pricePercentChange30d as number,\n P200D: priceData.pricePercentChange200d as number,\n P1Y: priceData.pricePercentChange1y as number,\n },\n },\n } as MultichainAssetsRatesControllerState['conversionRates'][Caip19AssetId];\n }\n } catch {\n // Skip malformed asset IDs\n }\n }\n\n return {\n conversionRates,\n currencyRates,\n marketData,\n currentCurrency: selectedCurrency,\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatStateForTransactionPay.d.ts","sourceRoot":"","sources":["../../src/utils/formatStateForTransactionPay.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAEnF,sEAAsE;AACtE,MAAM,MAAM,sBAAsB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MA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,IAAI,EAAE,QAAQ,CAAC,IAAI;aACpB,CAAC;YACF,gBAAgB,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACpC,IACE,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,IAAI,CAChC,CAAC,QAAQ,EAAE,EAAE,CACX,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,WAAW,EAAE,CAC3D,EACD,CAAC;gBACD,gBAAgB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,2BAA2B;QAC7B,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAA4C,EAAE,CAAC;IAC9D,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACjE,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,aAAa,GAAG,4BAA4B,CAAC;QACjD,UAAU;QACV,WAAW;QACX,gBAAgB;QAChB,sBAAsB;QACtB,8BAA8B;KAC/B,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,SAAS;QACT,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,aAAa,EAAE,aAAa,CAAC,aAAa;QAC1C,eAAe,EAAE,aAAa,CAAC,eAAe;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import { toChecksumAddress } from '@ethereumjs/util';\nimport { getNativeTokenAddress } from '@metamask/assets-controllers';\nimport { numberToHex } from '@metamask/utils';\nimport { parseCaipAssetType, parseCaipChainId } from '@metamask/utils';\nimport { isEqual } from 'lodash-es';\n\nimport type {\n AssetBalance,\n AssetMetadata,\n AssetPrice,\n Caip19AssetId,\n} from '../types.js';\nimport { formatExchangeRatesForBridge } from './formatExchangeRatesForBridge.js';\nimport type { BridgeExchangeRatesFormat } from './formatExchangeRatesForBridge.js';\n\n/** Account with id and address for mapping state to legacy format. */\nexport type AccountForLegacyFormat = { id: string; address: string };\n\n/**\n * Legacy Token shape expected by TokensController / transaction-pay-controller.\n */\nexport type LegacyToken = {\n address: string;\n decimals: number;\n symbol: string;\n name?: string;\n [key: string]: unknown;\n};\n\n/**\n * Legacy state shape that transaction-pay-controller reads from\n * TokenBalancesController, AccountTrackerController, TokensController,\n * TokenRatesController, and CurrencyRateController.\n */\nexport type TransactionPayLegacyFormat = {\n /** TokenBalancesController:getState().tokenBalances */\n tokenBalances: Record<string, Record<string, Record<string, `0x${string}`>>>;\n /** AccountTrackerController:getState().accountsByChainId */\n accountsByChainId: Record<\n string,\n Record<string, { balance: string; stakedBalance?: string }>\n >;\n /** TokensController:getState().allTokens (chainId -> key -> Token[]) */\n allTokens: Record<string, Record<string, LegacyToken[]>>;\n /** TokenRatesController:getState().marketData */\n marketData: BridgeExchangeRatesFormat['marketData'];\n /** CurrencyRateController:getState().currencyRates */\n currencyRates: BridgeExchangeRatesFormat['currencyRates'];\n /** CurrencyRateController:getState().currentCurrency */\n currentCurrency: string;\n};\n\n/** Parameters accepted by {@link formatStateForTransactionPay}. */\nexport type FormatStateForTransactionPayParams = {\n assetsBalance: Record<string, Record<string, AssetBalance>>;\n assetsInfo: Record<string, AssetMetadata>;\n assetsPrice: Record<string, AssetPrice>;\n selectedCurrency: string;\n accounts: AccountForLegacyFormat[];\n nativeAssetIdentifiers: Record<string, string>;\n networkConfigurationsByChainId?: Record<string, { nativeCurrency?: string }>;\n};\n\nfunction amountToHex(amount: string): `0x${string}` {\n const hexString = BigInt(amount).toString(16);\n return `0x${hexString}`;\n}\n\n/**\n * Determines whether two sets of {@link formatStateForTransactionPay}\n * parameters are identical for memoization purposes.\n *\n * State slices (`assetsBalance`, `assetsInfo`, `assetsPrice`,\n * `networkConfigurationsByChainId`) are compared by reference since\n * BaseController state updates are immutable. The `accounts` and\n * `nativeAssetIdentifiers` inputs are rebuilt on every call, so they are\n * compared by value instead.\n *\n * @param a - Previous parameters.\n * @param b - Next parameters.\n * @returns True if the parameters are identical.\n */\nfunction isTransactionPayParamsIdentical(\n a: FormatStateForTransactionPayParams,\n b: FormatStateForTransactionPayParams,\n): boolean {\n return (\n a.assetsBalance === b.assetsBalance &&\n a.assetsInfo === b.assetsInfo &&\n a.assetsPrice === b.assetsPrice &&\n a.selectedCurrency === b.selectedCurrency &&\n a.networkConfigurationsByChainId === b.networkConfigurationsByChainId &&\n isEqual(a.accounts, b.accounts) &&\n isEqual(a.nativeAssetIdentifiers, b.nativeAssetIdentifiers)\n );\n}\n\nfunction getAmountFromBalance(balance: AssetBalance): string {\n return typeof balance === 'object' && balance !== null && 'amount' in balance\n ? String((balance as { amount: string }).amount)\n : '0';\n}\n\nlet lastCall: {\n params: FormatStateForTransactionPayParams;\n result: TransactionPayLegacyFormat;\n} | null = null;\n\n/**\n * Converts AssetsController state into the legacy format consumed by\n * transaction-pay-controller (TokenBalancesController, AccountTrackerController,\n * TokensController, TokenRatesController, CurrencyRateController shapes).\n *\n * The last result is memoized on input identity: this function is invoked (via\n * `AssetsController:getStateForTransactionPay`) on every\n * `TransactionController:stateChange`, but its inputs only change when the\n * assets pipeline updates. Recomputing runs keccak256 (`toChecksumAddress`)\n * per asset per call, which dominates CPU profiles during transaction\n * approval.\n *\n * @param params - Conversion parameters.\n * @returns Legacy-compatible state for transaction-pay-controller.\n */\nexport function formatStateForTransactionPay(\n params: FormatStateForTransactionPayParams,\n): TransactionPayLegacyFormat {\n if (lastCall && isTransactionPayParamsIdentical(lastCall.params, params)) {\n return lastCall.result;\n }\n\n const result = computeStateForTransactionPay(params);\n lastCall = { params, result: Object.freeze(result) };\n return result;\n}\n\n/**\n * Clears the {@link formatStateForTransactionPay} memoize cache. Exported for tests.\n */\nexport function clearFormatStateForTransactionPayCacheForTesting(): void {\n lastCall = null;\n}\n\n/**\n * Performs the actual state conversion for\n * {@link formatStateForTransactionPay}.\n *\n * @param params - Conversion parameters.\n * @returns Legacy-compatible state for transaction-pay-controller.\n */\nfunction computeStateForTransactionPay(\n params: FormatStateForTransactionPayParams,\n): TransactionPayLegacyFormat {\n const {\n assetsBalance,\n assetsInfo,\n assetsPrice,\n selectedCurrency,\n accounts,\n nativeAssetIdentifiers,\n networkConfigurationsByChainId = {},\n } = params;\n\n const tokenBalances: TransactionPayLegacyFormat['tokenBalances'] = {};\n const accountsByChainId: TransactionPayLegacyFormat['accountsByChainId'] = {};\n const allTokensByChain: Record<string, LegacyToken[]> = {};\n\n for (const account of accounts) {\n const accountAddressLower = account.address.toLowerCase();\n const accountBalances = assetsBalance[account.id];\n if (!accountBalances) {\n continue;\n }\n\n for (const [assetId, balance] of Object.entries(accountBalances)) {\n try {\n const parsed = parseCaipAssetType(assetId as Caip19AssetId);\n const chainIdParsed = parseCaipChainId(parsed.chainId);\n if (chainIdParsed.namespace !== 'eip155') {\n continue;\n }\n const chainIdHex = numberToHex(parseInt(chainIdParsed.reference, 10));\n const amount = getAmountFromBalance(balance);\n const balanceHex = amountToHex(amount);\n\n if (assetsInfo[assetId]?.type === 'native') {\n const nativeAddress = toChecksumAddress(\n getNativeTokenAddress(chainIdHex),\n );\n const checksumAddress = toChecksumAddress(account.address);\n tokenBalances[accountAddressLower] ??= {};\n tokenBalances[accountAddressLower][chainIdHex] ??= {};\n tokenBalances[accountAddressLower][chainIdHex][nativeAddress] =\n balanceHex;\n accountsByChainId[chainIdHex] ??= {};\n accountsByChainId[chainIdHex][checksumAddress] = {\n balance: balanceHex,\n };\n } else if (parsed.assetNamespace === 'erc20') {\n const tokenAddress = toChecksumAddress(String(parsed.assetReference));\n tokenBalances[accountAddressLower] ??= {};\n tokenBalances[accountAddressLower][chainIdHex] ??= {};\n tokenBalances[accountAddressLower][chainIdHex][tokenAddress] =\n balanceHex;\n }\n } catch {\n // Skip malformed asset IDs\n }\n }\n }\n\n for (const [assetId, metadata] of Object.entries(assetsInfo)) {\n try {\n const parsed = parseCaipAssetType(assetId as Caip19AssetId);\n const chainIdParsed = parseCaipChainId(parsed.chainId);\n if (chainIdParsed.namespace !== 'eip155') {\n continue;\n }\n const chainIdHex = numberToHex(parseInt(chainIdParsed.reference, 10));\n const address =\n metadata.type === 'native'\n ? getNativeTokenAddress(chainIdHex)\n : toChecksumAddress(String(parsed.assetReference));\n const token: LegacyToken = {\n address,\n decimals: metadata.decimals,\n symbol: metadata.symbol,\n name: metadata.name,\n };\n allTokensByChain[chainIdHex] ??= [];\n if (\n !allTokensByChain[chainIdHex].some(\n (existing) =>\n existing.address.toLowerCase() === address.toLowerCase(),\n )\n ) {\n allTokensByChain[chainIdHex].push(token);\n }\n } catch {\n // Skip malformed asset IDs\n }\n }\n\n const allTokens: TransactionPayLegacyFormat['allTokens'] = {};\n for (const [chainId, tokens] of Object.entries(allTokensByChain)) {\n allTokens[chainId] = { '': tokens };\n }\n\n const exchangeRates = formatExchangeRatesForBridge({\n assetsInfo,\n assetsPrice,\n selectedCurrency,\n nativeAssetIdentifiers,\n networkConfigurationsByChainId,\n });\n\n return {\n tokenBalances,\n accountsByChainId,\n allTokens,\n marketData: exchangeRates.marketData,\n currencyRates: exchangeRates.currencyRates,\n currentCurrency: exchangeRates.currentCurrency,\n };\n}\n"]}
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { fetchWithTimeout } from './fetchWithTimeout.js';
|
|
2
|
-
export { normalizeAmountString } from './normalizeAmountString.js';
|
|
3
|
-
export { normalizeAssetId, safeNormalizeAssetId, clearNormalizeAssetIdCacheForTesting, } from './normalizeAssetId.js';
|
|
4
|
-
export { formatExchangeRatesForBridge, clearFormatExchangeRatesForBridgeCacheForTesting, } from './formatExchangeRatesForBridge.js';
|
|
5
|
-
export { formatStateForTransactionPay, clearFormatStateForTransactionPayCacheForTesting, } from './formatStateForTransactionPay.js';
|
|
6
|
-
export type { BridgeExchangeRatesFormat, FormatExchangeRatesForBridgeParams, } from './formatExchangeRatesForBridge.js';
|
|
7
|
-
export type { AccountForLegacyFormat, FormatStateForTransactionPayParams, LegacyToken, TransactionPayLegacyFormat, } from './formatStateForTransactionPay.js';
|
|
8
|
-
export { buildNativeAssetsFromConstant, buildNativeAssetsFromApi, } from './native-assets.js';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oCAAoC,GACrC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,4BAA4B,EAC5B,gDAAgD,GACjD,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,4BAA4B,EAC5B,gDAAgD,GACjD,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EACV,yBAAyB,EACzB,kCAAkC,GACnC,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EACV,sBAAsB,EACtB,kCAAkC,EAClC,WAAW,EACX,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,oBAAoB,CAAC"}
|
package/dist/utils/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { fetchWithTimeout } from './fetchWithTimeout.js';
|
|
2
|
-
export { normalizeAmountString } from './normalizeAmountString.js';
|
|
3
|
-
export { normalizeAssetId, safeNormalizeAssetId, clearNormalizeAssetIdCacheForTesting, } from './normalizeAssetId.js';
|
|
4
|
-
export { formatExchangeRatesForBridge, clearFormatExchangeRatesForBridgeCacheForTesting, } from './formatExchangeRatesForBridge.js';
|
|
5
|
-
export { formatStateForTransactionPay, clearFormatStateForTransactionPayCacheForTesting, } from './formatStateForTransactionPay.js';
|
|
6
|
-
export { buildNativeAssetsFromConstant, buildNativeAssetsFromApi, } from './native-assets.js';
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oCAAoC,GACrC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,4BAA4B,EAC5B,gDAAgD,GACjD,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,4BAA4B,EAC5B,gDAAgD,GACjD,MAAM,mCAAmC,CAAC;AAW3C,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,oBAAoB,CAAC","sourcesContent":["export { fetchWithTimeout } from './fetchWithTimeout.js';\nexport { normalizeAmountString } from './normalizeAmountString.js';\nexport {\n normalizeAssetId,\n safeNormalizeAssetId,\n clearNormalizeAssetIdCacheForTesting,\n} from './normalizeAssetId.js';\nexport {\n formatExchangeRatesForBridge,\n clearFormatExchangeRatesForBridgeCacheForTesting,\n} from './formatExchangeRatesForBridge.js';\nexport {\n formatStateForTransactionPay,\n clearFormatStateForTransactionPayCacheForTesting,\n} from './formatStateForTransactionPay.js';\nexport type {\n BridgeExchangeRatesFormat,\n FormatExchangeRatesForBridgeParams,\n} from './formatExchangeRatesForBridge.js';\nexport type {\n AccountForLegacyFormat,\n FormatStateForTransactionPayParams,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './formatStateForTransactionPay.js';\nexport {\n buildNativeAssetsFromConstant,\n buildNativeAssetsFromApi,\n} from './native-assets.js';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"native-assets.d.ts","sourceRoot":"","sources":["../../src/utils/native-assets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAU1D;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,MAAM,CACrD,OAAO,EACP,aAAa,CACd,CAOA;AAED;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAC/B,CAmCA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"native-assets.js","sourceRoot":"","sources":["../../src/utils/native-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAOlE;;;;GAIG;AACH,MAAM,UAAU,6BAA6B;IAI3C,MAAM,eAAe,GAAmC,EAAE,CAAC;IAC3D,KAAK,MAAM,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,EAAE,CAAC;QACpE,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC;QACtD,eAAe,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAG5C,MAAM,eAAe,GAAG,6BAA6B,EAAE,CAAC;IAExD,IAAI,CAAC;QACH,MAAM,MAAM,GACV,MAAM,sBAAsB,CAAC;YAC3B,GAAG,EAAE,mBAAmB;YACxB,OAAO,EAAE,MAAM;SAChB,CAAC,CAAC;QAEL,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,IACE,CAAC,KAAK,CAAC,OAAO;oBACd,CAAC,KAAK,CAAC,MAAM;oBACb,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC;oBAChC,KAAK,CAAC,OAAO,GAAG,CAAC;oBACjB,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;oBAC/B,KAAK,CAAC,MAAM,GAAG,CAAC,EAChB,CAAC;oBACD,SAAS;gBACX,CAAC;gBAED,MAAM,WAAW,GAAG,UAAU,KAAK,CAAC,OAAO,EAAa,CAAC;gBACzD,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC;oBAClC,eAAe,CAAC,WAAW,CAAC;wBAC1B,UAAU,KAAK,CAAC,OAAO,WAAW,KAAK,CAAC,MAAM,EAAmB,CAAC;gBACtE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,sDAAsD;IACxD,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { SPOT_PRICES_SUPPORT_INFO } from '@metamask/assets-controllers';\nimport { fetchWithErrorHandling } from '@metamask/controller-utils';\nimport { parseCaipAssetType } from '@metamask/utils';\n\nimport type { Caip19AssetId, ChainId } from '../types.js';\nimport { normalizeAssetId } from './normalizeAssetId.js';\n\nconst CHAINID_NETWORK_URL = 'https://chainid.network/chains.json';\n\ntype ChainIdNetworkEntry = {\n chainId: number;\n slip44?: number;\n};\n\n/**\n * Builds a native asset map from the hardcoded SPOT_PRICES_SUPPORT_INFO constant.\n *\n * @returns A record mapping CAIP-2 chain IDs to their CAIP-19 native asset IDs.\n */\nexport function buildNativeAssetsFromConstant(): Record<\n ChainId,\n Caip19AssetId\n> {\n const nativeAssetsMap: Record<ChainId, Caip19AssetId> = {};\n for (const nativeAssetId of Object.values(SPOT_PRICES_SUPPORT_INFO)) {\n const { chainId } = parseCaipAssetType(nativeAssetId);\n nativeAssetsMap[chainId] = normalizeAssetId(nativeAssetId);\n }\n return nativeAssetsMap;\n}\n\n/**\n * Fetches chain data from chainid.network and merges it with the seed\n * native asset map built from {@link buildNativeAssetsFromConstant}.\n *\n * Remote entries only fill gaps — chains already present in the seed map\n * are never overwritten. Invalid entries (missing/negative chainId or slip44)\n * are silently skipped.\n *\n * @returns The merged native asset map.\n */\nexport async function buildNativeAssetsFromApi(): Promise<\n Record<ChainId, Caip19AssetId>\n> {\n const nativeAssetsMap = buildNativeAssetsFromConstant();\n\n try {\n const chains: ChainIdNetworkEntry[] | undefined =\n await fetchWithErrorHandling({\n url: CHAINID_NETWORK_URL,\n timeout: 10_000,\n });\n\n if (chains && Array.isArray(chains)) {\n for (const chain of chains) {\n if (\n !chain.chainId ||\n !chain.slip44 ||\n !Number.isInteger(chain.chainId) ||\n chain.chainId < 1 ||\n !Number.isInteger(chain.slip44) ||\n chain.slip44 < 1\n ) {\n continue;\n }\n\n const caipChainId = `eip155:${chain.chainId}` as ChainId;\n if (!nativeAssetsMap[caipChainId]) {\n nativeAssetsMap[caipChainId] =\n `eip155:${chain.chainId}/slip44:${chain.slip44}` as Caip19AssetId;\n }\n }\n }\n } catch {\n // Non-fatal: caller should fall back to the seed map.\n }\n\n return nativeAssetsMap;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeAmountString.d.ts","sourceRoot":"","sources":["../../src/utils/normalizeAmountString.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAsBR"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeAmountString.js","sourceRoot":"","sources":["../../src/utils/normalizeAmountString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAe,EACf,QAAiB;IAEjB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,KAAa,CAAC;IAClB,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACzE,yEAAyE;QACzE,KAAK,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,4EAA4E;IAC5E,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { BigNumber as BigNumberJS } from 'bignumber.js';\n\n/**\n * Normalize an asset balance `amount` string into a canonical plain-decimal\n * form (no scientific notation), optionally truncating to the asset's decimal\n * precision.\n *\n * Amounts entering `assetsBalance` state come from external sources (snaps,\n * accounts API, websocket, RPC) and may be serialized from JavaScript Numbers\n * as `\"1e-18\"`. Downstream consumers (e.g. the extension's\n * `parseBalanceWithDecimals`) split on `'.'` and feed the result to `BigInt()`,\n * which throws on exponent-form strings. Normalizing at the controller\n * boundary keeps the invariant that `amount` is always a plain decimal so\n * every current and future data source is safe without per-source changes.\n *\n * When `decimals` is provided (i.e. the asset's metadata is registered),\n * fractional digits beyond `decimals` are truncated using round-toward-zero\n * to match the extension's `parseBalanceWithDecimals`, which slices off any\n * fractional digits beyond `decimals`.\n *\n * When `decimals` is omitted (metadata not yet known for this asset), the\n * amount is left at its natural precision — exponent form is still converted\n * to plain decimal, but no digits are dropped. This preserves balances that\n * arrive before their metadata without lossy truncation.\n *\n * Non-finite or non-string inputs collapse to `'0'` rather than throwing,\n * because controller state must remain JSON-serializable and a malformed\n * upstream payload should not corrupt the rest of the update.\n *\n * @param amount - The raw amount string from a data source.\n * @param decimals - The asset's decimal precision (from `assetsInfo`). Pass\n * `undefined` when metadata is unknown to skip truncation.\n * @returns A plain decimal string (e.g. `\"0.000000000000000001\"`), or `'0'`\n * for non-finite / non-string input.\n */\nexport function normalizeAmountString(\n amount: unknown,\n decimals?: number,\n): string {\n if (typeof amount !== 'string' || amount.length === 0) {\n return '0';\n }\n const bn = new BigNumberJS(amount);\n if (!bn.isFinite()) {\n return '0';\n }\n\n let fixed: string;\n if (decimals === undefined || !Number.isFinite(decimals) || decimals < 0) {\n // Metadata unknown — preserve full precision, just defeat exponent form.\n fixed = bn.toFixed();\n } else {\n fixed = bn.toFixed(Math.floor(decimals), BigNumberJS.ROUND_DOWN);\n }\n\n if (!fixed.includes('.')) {\n return fixed;\n }\n // Trim trailing zeros and a dangling dot: \"1.500\" -> \"1.5\", \"1.000\" -> \"1\".\n return fixed.replace(/0+$/u, '').replace(/\\.$/u, '');\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeAssetId.d.ts","sourceRoot":"","sources":["../../src/utils/normalizeAssetId.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,aAAa,KAAK,aAAa,CAAC,GACxE,gBAcA,CAAC;AAEH;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAM1E;AAED;;GAEG;AACH,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeAssetId.js","sourceRoot":"","sources":["../../src/utils/normalizeAssetId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAIvE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,gBAAgB,GACR,OAAO,CAAC,CAAC,OAAsB,EAAiB,EAAE;IACrE,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEvD,oCAAoC;IACpC,IACE,aAAa,CAAC,SAAS,KAAK,QAAQ;QACpC,MAAM,CAAC,cAAc,KAAK,OAAO,EACjC,CAAC;QACD,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACpE,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,cAAc,IAAI,kBAAkB,EAAmB,CAAC;IAC7F,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAsB;IACzD,IAAI,CAAC;QACH,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oCAAoC;IAClD,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { toChecksumAddress } from '@ethereumjs/util';\nimport { parseCaipAssetType, parseCaipChainId } from '@metamask/utils';\n// `@types/lodash-es` only re-exports the functions, so the helper type\n// comes from `@types/lodash`. This is erased at compile time.\nimport type { MemoizedFunction } from 'lodash';\nimport { memoize } from 'lodash-es';\n\nimport type { Caip19AssetId } from '../types.js';\n\n/**\n * Normalizes a CAIP-19 asset ID by checksumming EVM addresses.\n * This ensures consistent asset IDs regardless of the data source format.\n *\n * For EVM ERC20 tokens (e.g., \"eip155:1/erc20:0x...\"), the address is checksummed.\n * All other asset types are returned unchanged.\n *\n * Results are memoized with lodash: repeated calls with the same ID (common after\n * the first pipeline pass, when IDs are already checksummed) skip re-parsing and\n * keccak256 checksum work.\n *\n * @param assetId - The CAIP-19 asset ID to normalize\n * @returns The normalized asset ID with checksummed address (for EVM tokens)\n */\nexport const normalizeAssetId: ((assetId: Caip19AssetId) => Caip19AssetId) &\n MemoizedFunction = memoize((assetId: Caip19AssetId): Caip19AssetId => {\n const parsed = parseCaipAssetType(assetId);\n const chainIdParsed = parseCaipChainId(parsed.chainId);\n\n // Only checksum EVM ERC20 addresses\n if (\n chainIdParsed.namespace === 'eip155' &&\n parsed.assetNamespace === 'erc20'\n ) {\n const checksummedAddress = toChecksumAddress(parsed.assetReference);\n return `${parsed.chainId}/${parsed.assetNamespace}:${checksummedAddress}` as Caip19AssetId;\n }\n\n return assetId;\n});\n\n/**\n * Normalize a CAIP-19 asset ID, returning the original on failure. Some\n * malformed IDs (e.g. an asset reference that fails address checksumming)\n * make {@link normalizeAssetId} throw; callers processing untrusted input\n * use this so one bad ID cannot abort a whole batch.\n *\n * @param assetId - The CAIP-19 asset ID to normalize.\n * @returns The normalized ID, or the original on failure.\n */\nexport function safeNormalizeAssetId(assetId: Caip19AssetId): Caip19AssetId {\n try {\n return normalizeAssetId(assetId);\n } catch {\n return assetId;\n }\n}\n\n/**\n * Clears the {@link normalizeAssetId} memoize cache. Exported for unit tests.\n */\nexport function clearNormalizeAssetIdCacheForTesting(): void {\n normalizeAssetId.cache.clear?.();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snaps-assets-migration.d.ts","sourceRoot":"","sources":["../../src/utils/snaps-assets-migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;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,YAC5C,QAAQ,EACR,SAAS,EACT,MAAM,CACE,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snaps-assets-migration.js","sourceRoot":"","sources":["../../src/utils/snaps-assets-migration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAInD;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,yBAqBX;AArBD,WAAY,yBAAyB;IACnC;;;OAGG;IACH,uEAAO,CAAA;IACP;;;;OAIG;IACH,iIAAoC,CAAA;IACpC;;;OAGG;IACH,uIAAuC,CAAA;IACvC;;OAEG;IACH,iHAA4B,CAAA;AAC9B,CAAC,EArBW,yBAAyB,KAAzB,yBAAyB,QAqBpC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,QAAQ;IACR,SAAS;IACT,MAAM;CACE,CAAC;AAKX;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAGzC;IACF,MAAM,EAAE,mCAAmC;IAC3C,OAAO,EAAE,oCAAoC;IAC7C,IAAI,EAAE,iCAAiC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAAgB;IAEhB,IAAI,CAAC;Q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CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,kBAAgC;IAEhC,OAAO,iCAAiC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CACzD,8BAA8B,CAC5B,kBAAkB,CAAC,gCAAgC,CAAC,SAAS,CAAC,CAAC,CAChE,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAgB,EAChB,kBAA4C;IAE5C,MAAM,SAAS,GAAG,gCAAgC,CAAC,OAAO,CAAC,CAAC;IAC5D,4DAA4D;IAC5D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,8BAA8B,CAC1C,kBAAkB,EAAE,CAAC,gCAAgC,CAAC,SAAS,CAAC,CAAC,CAClE,CAAC;IACF,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC","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.js';\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/utils/trace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAM9E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAEtE,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,MAAM,IAAI;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,aAAa,CAAC;IACpB,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACtD,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA2CF;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAmB,EACnB,aAAa,EACb,SAAS,EAAE,iBAAiB,GAC7B,EAAE,eAAe,GAAG,IAAI,CAuBxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,EACtC,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,EAAE,EACF,IAAmB,EACnB,SAAS,EAAE,iBAAiB,GAC7B,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CA+C3C"}
|
package/dist/utils/trace.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/utils/trace.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAA8C;IAC9D,UAAU,EAAE,kBAAkB;CAC/B,CAAC;AAyBF;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CACvB,IAAmB,EACnB,IAAmB,EACnB,SAAkB;IAElB,MAAM,eAAe,GAA2B,EAAE,CAAC;IACnD,KAAK,MAAM,CAA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C5D,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,UAAU,CAAC,EAAE,EAAE,CAAC;QAClB,OAAO,UAAU,CAAC,KAAK,CAAC;IAC1B,CAAC;IACD,MAAM,UAAU,CAAC,KAAK,CAAC;AACzB,CAAC","sourcesContent":["import type { TraceCallback, TraceContext } from '@metamask/controller-utils';\n\nconst DEFAULT_TAGS: Record<string, number | string | boolean> = {\n controller: 'AssetsController',\n};\n\nexport type TraceSpanData = Record<string, number | string | boolean>;\n\nexport type EmitTraceParams = {\n name: string;\n /** When omitted / undefined, this is a no-op (bake call-site gating here). */\n trace?: TraceCallback;\n data: TraceSpanData;\n tags?: TraceSpanData;\n parentContext?: TraceContext;\n /** Override span start; otherwise derived from `data.duration_ms` when present. */\n startTime?: number;\n};\n\nexport type WithTraceParams<Result> = {\n name: string;\n /** When omitted / undefined, `fn` runs with no parent context. */\n trace?: TraceCallback;\n data: TraceSpanData;\n fn: (parentContext?: TraceContext) => Promise<Result>;\n tags?: TraceSpanData;\n startTime?: number;\n};\n\n/**\n * Build request tags / startTime for MetaMask's Sentry adapter.\n * Numeric `data` fields become tags (measurements); `duration_ms` backdates start.\n *\n * @param data - Span data attributes.\n * @param tags - Caller tags.\n * @param startTime - Optional explicit start override.\n * @returns tags and optional startTime for the TraceRequest.\n */\nfunction buildTraceTiming(\n data: TraceSpanData,\n tags: TraceSpanData,\n startTime?: number,\n): { tags: TraceSpanData; startTime?: number } {\n const numericFromData: Record<string, number> = {};\n for (const [key, value] of Object.entries(data)) {\n if (typeof value === 'number') {\n numericFromData[key] = value;\n }\n }\n const requestTags = {\n ...tags,\n ...numericFromData,\n };\n\n if (startTime !== undefined) {\n return { tags: requestTags, startTime };\n }\n\n const durationMs =\n typeof data.duration_ms === 'number' ? data.duration_ms : undefined;\n if (durationMs === undefined) {\n return { tags: requestTags };\n }\n\n return {\n tags: requestTags,\n startTime: performance.timeOrigin + performance.now() - durationMs,\n };\n}\n\n/**\n * Fire-and-forget Sentry span. Swallows errors so telemetry never breaks callers.\n * Pass `parentContext` to nest as a subspan. Omit `trace` to skip emission.\n *\n * @param params - Span configuration.\n * @param params.name - Trace / span name visible in Sentry.\n * @param params.trace - Optional client trace callback; omit to no-op.\n * @param params.data - Key-value pairs attached as span data.\n * @param params.tags - Key-value pairs used for Sentry filtering.\n * @param params.parentContext - Optional parent span context for nesting.\n * @param params.startTime - Optional explicit start; else derived from `duration_ms`.\n */\nexport function emitTrace({\n name,\n trace,\n data,\n tags = DEFAULT_TAGS,\n parentContext,\n startTime: startTimeOverride,\n}: EmitTraceParams): void {\n if (!trace) {\n return;\n }\n\n const { tags: requestTags, startTime } = buildTraceTiming(\n data,\n tags,\n startTimeOverride,\n );\n\n trace(\n {\n name,\n data,\n tags: requestTags,\n parentContext,\n ...(startTime === undefined ? {} : { startTime }),\n },\n () => undefined,\n )?.catch(() => {\n // Telemetry failure must not break.\n });\n}\n\n/**\n * Run work inside a parent Sentry span and pass its context for nested\n * {@link emitTrace} subspans.\n *\n * When `trace` is omitted, runs `fn(undefined)` with no span.\n * Telemetry failures are swallowed; errors from `fn` still propagate.\n *\n * @param params - Parent span config and work callback.\n * @param params.name - Parent span name.\n * @param params.trace - Optional client trace callback; omit to skip wrapping.\n * @param params.data - Key-value pairs attached as span data.\n * @param params.fn - Work to run; receives the parent span context.\n * @param params.tags - Key-value pairs used for Sentry filtering.\n * @param params.startTime - Optional explicit start; else derived from `duration_ms`.\n * @returns The result of `fn`.\n */\nexport async function withTrace<Result>({\n name,\n trace,\n data,\n fn,\n tags = DEFAULT_TAGS,\n startTime: startTimeOverride,\n}: WithTraceParams<Result>): Promise<Result> {\n if (!trace) {\n return fn(undefined);\n }\n\n const { tags: requestTags, startTime } = buildTraceTiming(\n data,\n tags,\n startTimeOverride,\n );\n\n let workResult:\n | { ok: true; value: Result }\n | { ok: false; error: unknown }\n | undefined;\n\n try {\n await trace(\n {\n name,\n data,\n tags: requestTags,\n ...(startTime === undefined ? {} : { startTime }),\n },\n async (parentContext) => {\n try {\n const value = await fn(parentContext);\n workResult = { ok: true, value };\n return value;\n } catch (error) {\n workResult = { ok: false, error };\n throw error;\n }\n },\n );\n } catch {\n // Telemetry failure must not break — unless the work itself failed.\n }\n\n if (workResult === undefined) {\n // `trace` failed before invoking `fn` (or never called it).\n return fn(undefined);\n }\n if (workResult.ok) {\n return workResult.value;\n }\n throw workResult.error;\n}\n"]}
|