@metamask/assets-controllers 109.4.1 → 110.0.1
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 +55 -1
- package/LICENSE +1 -0
- package/dist/AccountTrackerController-method-action-types.cjs.map +1 -1
- package/dist/AccountTrackerController-method-action-types.d.cts.map +1 -1
- package/dist/AccountTrackerController-method-action-types.d.mts.map +1 -1
- package/dist/AccountTrackerController-method-action-types.mjs.map +1 -1
- package/dist/AccountTrackerController.cjs +8 -8
- package/dist/AccountTrackerController.cjs.map +1 -1
- package/dist/AccountTrackerController.d.cts.map +1 -1
- package/dist/AccountTrackerController.d.mts.map +1 -1
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/AssetsContractController-method-action-types.cjs.map +1 -1
- package/dist/AssetsContractController-method-action-types.d.cts.map +1 -1
- package/dist/AssetsContractController-method-action-types.d.mts.map +1 -1
- package/dist/AssetsContractController-method-action-types.mjs.map +1 -1
- package/dist/AssetsContractController.cjs +33 -32
- package/dist/AssetsContractController.cjs.map +1 -1
- package/dist/AssetsContractController.d.cts +1 -0
- package/dist/AssetsContractController.d.cts.map +1 -1
- package/dist/AssetsContractController.d.mts +1 -0
- package/dist/AssetsContractController.d.mts.map +1 -1
- package/dist/AssetsContractController.mjs +1 -0
- package/dist/AssetsContractController.mjs.map +1 -1
- package/dist/CurrencyRateController-method-action-types.cjs.map +1 -1
- package/dist/CurrencyRateController-method-action-types.d.cts.map +1 -1
- package/dist/CurrencyRateController-method-action-types.d.mts.map +1 -1
- package/dist/CurrencyRateController-method-action-types.mjs.map +1 -1
- package/dist/CurrencyRateController.cjs +2 -2
- package/dist/CurrencyRateController.cjs.map +1 -1
- package/dist/CurrencyRateController.d.cts.map +1 -1
- package/dist/CurrencyRateController.d.mts.map +1 -1
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.cjs +6 -6
- package/dist/DeFiPositionsController/DeFiPositionsController.cjs.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.d.cts.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.d.mts.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.mjs.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.cjs +7 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.cjs.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.d.cts +28 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.d.cts.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.d.mts +28 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.d.mts.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.mjs +6 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.mjs.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.cjs +128 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.cjs.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.d.cts +89 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.d.cts.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.d.mts +89 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.d.mts.map +1 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.mjs +123 -0
- package/dist/DeFiPositionsController/DeFiPositionsControllerV2.mjs.map +1 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.cjs +73 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.cjs.map +1 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.d.cts +34 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.d.cts.map +1 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.d.mts +34 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.d.mts.map +1 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.mjs +69 -0
- package/dist/DeFiPositionsController/build-defi-balances-query.mjs.map +1 -0
- package/dist/DeFiPositionsController/calculate-defi-metrics.cjs.map +1 -1
- package/dist/DeFiPositionsController/calculate-defi-metrics.d.cts.map +1 -1
- package/dist/DeFiPositionsController/calculate-defi-metrics.d.mts.map +1 -1
- package/dist/DeFiPositionsController/calculate-defi-metrics.mjs.map +1 -1
- package/dist/DeFiPositionsController/fetch-positions.cjs +2 -2
- package/dist/DeFiPositionsController/fetch-positions.cjs.map +1 -1
- package/dist/DeFiPositionsController/fetch-positions.mjs.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.cjs +235 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.cjs.map +1 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.cts +117 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.cts.map +1 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.mts +117 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.mts.map +1 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.mjs +231 -0
- package/dist/DeFiPositionsController/group-defi-positions-v6.mjs.map +1 -0
- package/dist/DeFiPositionsController/group-defi-positions.cjs.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions.d.cts.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions.d.mts.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions.mjs.map +1 -1
- package/dist/DeFiPositionsController/merge-positions-for-accounts.cjs +71 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.cjs.map +1 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.d.cts +16 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.d.cts.map +1 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.d.mts +16 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.d.mts.map +1 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.mjs +67 -0
- package/dist/DeFiPositionsController/merge-positions-for-accounts.mjs.map +1 -0
- package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.cjs.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.d.cts.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.d.mts.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.mjs.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.cjs +54 -31
- package/dist/MultichainAssetsController/MultichainAssetsController.cjs.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.d.cts +3 -17
- package/dist/MultichainAssetsController/MultichainAssetsController.d.cts.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.d.mts +3 -17
- package/dist/MultichainAssetsController/MultichainAssetsController.d.mts.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.mjs +52 -29
- package/dist/MultichainAssetsController/MultichainAssetsController.mjs.map +1 -1
- package/dist/MultichainAssetsController/index.cjs +3 -3
- package/dist/MultichainAssetsController/index.cjs.map +1 -1
- package/dist/MultichainAssetsController/index.d.cts.map +1 -1
- package/dist/MultichainAssetsController/index.d.mts.map +1 -1
- package/dist/MultichainAssetsController/index.mjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.cjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.d.cts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.d.mts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.mjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs +3 -3
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs.map +1 -1
- package/dist/MultichainAssetsRatesController/index.cjs +5 -5
- package/dist/MultichainAssetsRatesController/index.cjs.map +1 -1
- package/dist/MultichainAssetsRatesController/index.d.cts.map +1 -1
- package/dist/MultichainAssetsRatesController/index.d.mts.map +1 -1
- package/dist/MultichainAssetsRatesController/index.mjs.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.cjs +16 -62
- package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +5 -3
- package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +5 -3
- package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.mjs +16 -62
- package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -1
- package/dist/MultichainBalancesController/index.cjs +2 -2
- package/dist/MultichainBalancesController/index.cjs.map +1 -1
- package/dist/MultichainBalancesController/index.d.cts +1 -1
- package/dist/MultichainBalancesController/index.d.cts.map +1 -1
- package/dist/MultichainBalancesController/index.d.mts +1 -1
- package/dist/MultichainBalancesController/index.d.mts.map +1 -1
- package/dist/MultichainBalancesController/index.mjs.map +1 -1
- package/dist/NftController.cjs +14 -14
- package/dist/NftController.cjs.map +1 -1
- package/dist/NftController.d.cts.map +1 -1
- package/dist/NftController.d.mts.map +1 -1
- package/dist/NftController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs +2 -2
- package/dist/NftDetectionController.cjs.map +1 -1
- package/dist/NftDetectionController.d.cts.map +1 -1
- package/dist/NftDetectionController.d.mts.map +1 -1
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/RatesController/RatesController.cjs +2 -2
- package/dist/RatesController/RatesController.cjs.map +1 -1
- package/dist/RatesController/RatesController.d.cts.map +1 -1
- package/dist/RatesController/RatesController.d.mts.map +1 -1
- package/dist/RatesController/RatesController.mjs.map +1 -1
- package/dist/RatesController/index.cjs +3 -3
- package/dist/RatesController/index.cjs.map +1 -1
- package/dist/RatesController/index.d.cts.map +1 -1
- package/dist/RatesController/index.d.mts.map +1 -1
- package/dist/RatesController/index.mjs.map +1 -1
- package/dist/RatesController/types.cjs.map +1 -1
- package/dist/RatesController/types.d.cts.map +1 -1
- package/dist/RatesController/types.d.mts.map +1 -1
- package/dist/RatesController/types.mjs.map +1 -1
- package/dist/Standards/ERC20Standard.cjs +2 -2
- package/dist/Standards/ERC20Standard.cjs.map +1 -1
- package/dist/Standards/ERC20Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs +4 -4
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.cts.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +3 -3
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
- package/dist/TokenBalancesController-method-action-types.cjs.map +1 -1
- package/dist/TokenBalancesController-method-action-types.d.cts.map +1 -1
- package/dist/TokenBalancesController-method-action-types.d.mts.map +1 -1
- package/dist/TokenBalancesController-method-action-types.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +12 -12
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +1 -1
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +1 -1
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController-method-action-types.cjs.map +1 -1
- package/dist/TokenDetectionController-method-action-types.d.cts.map +1 -1
- package/dist/TokenDetectionController-method-action-types.d.mts.map +1 -1
- package/dist/TokenDetectionController-method-action-types.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +51 -20
- package/dist/TokenDetectionController.cjs.map +1 -1
- package/dist/TokenDetectionController.d.cts +4 -2
- package/dist/TokenDetectionController.d.cts.map +1 -1
- package/dist/TokenDetectionController.d.mts +4 -2
- package/dist/TokenDetectionController.d.mts.map +1 -1
- package/dist/TokenDetectionController.mjs +34 -3
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenListController.cjs +6 -6
- package/dist/TokenListController.cjs.map +1 -1
- package/dist/TokenListController.d.cts.map +1 -1
- package/dist/TokenListController.d.mts.map +1 -1
- package/dist/TokenListController.mjs.map +1 -1
- package/dist/TokenListService.cjs +5 -5
- package/dist/TokenListService.cjs.map +1 -1
- package/dist/TokenListService.d.cts.map +1 -1
- package/dist/TokenListService.d.mts.map +1 -1
- package/dist/TokenListService.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +6 -6
- package/dist/TokenRatesController.cjs.map +1 -1
- package/dist/TokenRatesController.d.cts.map +1 -1
- package/dist/TokenRatesController.d.mts.map +1 -1
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +5 -5
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/index.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/index.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/index.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/index.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
- package/dist/TokensController-method-action-types.cjs.map +1 -1
- package/dist/TokensController-method-action-types.d.cts.map +1 -1
- package/dist/TokensController-method-action-types.d.mts.map +1 -1
- package/dist/TokensController-method-action-types.mjs.map +1 -1
- package/dist/TokensController.cjs +10 -10
- package/dist/TokensController.cjs.map +1 -1
- package/dist/TokensController.d.cts.map +1 -1
- package/dist/TokensController.d.mts.map +1 -1
- package/dist/TokensController.mjs.map +1 -1
- package/dist/assetsUtil.cjs +3 -2
- package/dist/assetsUtil.cjs.map +1 -1
- package/dist/assetsUtil.d.cts +2 -1
- package/dist/assetsUtil.d.cts.map +1 -1
- package/dist/assetsUtil.d.mts +2 -1
- package/dist/assetsUtil.d.mts.map +1 -1
- package/dist/assetsUtil.mjs +1 -0
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/balances.cjs +4 -4
- package/dist/balances.cjs.map +1 -1
- package/dist/balances.d.cts.map +1 -1
- package/dist/balances.d.mts.map +1 -1
- package/dist/balances.mjs.map +1 -1
- package/dist/constants.cjs +2 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +2 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.cjs +2 -2
- package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
- package/dist/crypto-compare-service/index.cjs +3 -3
- package/dist/crypto-compare-service/index.cjs.map +1 -1
- package/dist/crypto-compare-service/index.d.cts.map +1 -1
- package/dist/crypto-compare-service/index.d.mts.map +1 -1
- package/dist/crypto-compare-service/index.mjs.map +1 -1
- package/dist/index.cjs +77 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -1
- package/dist/index.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +13 -13
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/index.cjs +3 -3
- package/dist/multi-chain-accounts-service/index.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/index.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/index.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/index.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-balances.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-balances.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-balances.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-balances.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
- package/dist/multicall.cjs +10 -10
- package/dist/multicall.cjs.map +1 -1
- package/dist/multicall.mjs.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.cjs +6 -6
- package/dist/rpc-service/rpc-balance-fetcher.cjs.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.d.cts.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.d.mts.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.mjs.map +1 -1
- package/dist/selectors/token-selectors.cjs +8 -11
- package/dist/selectors/token-selectors.cjs.map +1 -1
- package/dist/selectors/token-selectors.d.cts +25 -10
- package/dist/selectors/token-selectors.d.cts.map +1 -1
- package/dist/selectors/token-selectors.d.mts +25 -10
- package/dist/selectors/token-selectors.d.mts.map +1 -1
- package/dist/selectors/token-selectors.mjs +0 -3
- package/dist/selectors/token-selectors.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +43 -23
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +26 -5
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +26 -5
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +41 -22
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/dist/token-prices-service/index.cjs +10 -9
- package/dist/token-prices-service/index.cjs.map +1 -1
- package/dist/token-prices-service/index.d.cts +1 -1
- package/dist/token-prices-service/index.d.cts.map +1 -1
- package/dist/token-prices-service/index.d.mts +1 -1
- package/dist/token-prices-service/index.d.mts.map +1 -1
- package/dist/token-prices-service/index.mjs +1 -1
- package/dist/token-prices-service/index.mjs.map +1 -1
- package/dist/token-service.cjs +89 -10
- package/dist/token-service.cjs.map +1 -1
- package/dist/token-service.d.cts +4 -0
- package/dist/token-service.d.cts.map +1 -1
- package/dist/token-service.d.mts +4 -0
- package/dist/token-service.d.mts.map +1 -1
- package/dist/token-service.mjs +85 -7
- package/dist/token-service.mjs.map +1 -1
- package/package.json +17 -15
- package/dist/MultichainBalancesController/account-asset-info.cjs +0 -118
- package/dist/MultichainBalancesController/account-asset-info.cjs.map +0 -1
- package/dist/MultichainBalancesController/account-asset-info.d.cts +0 -82
- package/dist/MultichainBalancesController/account-asset-info.d.cts.map +0 -1
- package/dist/MultichainBalancesController/account-asset-info.d.mts +0 -82
- package/dist/MultichainBalancesController/account-asset-info.d.mts.map +0 -1
- package/dist/MultichainBalancesController/account-asset-info.mjs +0 -110
- package/dist/MultichainBalancesController/account-asset-info.mjs.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { CaipChainId } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Networks the DeFi balances (v6 multiaccount) endpoint supports.
|
|
5
|
+
* Cross-section of the supported chains from:
|
|
6
|
+
* https://developers.zerion.io/supported-blockchains
|
|
7
|
+
* https://accounts.api.cx.metamask.io/v2/supportedNetworks
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFI_SUPPORTED_NETWORKS: readonly CaipChainId[];
|
|
10
|
+
export type DeFiBalancesQuery = {
|
|
11
|
+
/** CAIP-2 networks to query, deduped across accounts. */
|
|
12
|
+
networks: CaipChainId[];
|
|
13
|
+
/**
|
|
14
|
+
* Request CAIP-10 account IDs → internal MetaMask account IDs
|
|
15
|
+
* (`InternalAccount.id`). EVM keys use the all-chains reference and a
|
|
16
|
+
* lowercased address; Solana keys keep address case.
|
|
17
|
+
*/
|
|
18
|
+
internalAccountIdByCaip: Map<string, string>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Builds the account IDs and networks to request DeFi positions for, from the
|
|
22
|
+
* accounts in the selected account group.
|
|
23
|
+
*
|
|
24
|
+
* Picks the group's EVM account (queried across all supported EVM chains) and
|
|
25
|
+
* its Solana account (queried on supported Solana chains). Enabled-network
|
|
26
|
+
* filtering is intentionally omitted here: positions are stored per chain, so
|
|
27
|
+
* the client can filter by enabled networks when reading state.
|
|
28
|
+
*
|
|
29
|
+
* @param internalAccounts - Accounts belonging to the selected account group.
|
|
30
|
+
* @returns Networks and a CAIP→internal account ID map for the v6 multiaccount
|
|
31
|
+
* balances request. Map keys are the CAIP account IDs to query.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildDeFiBalancesQuery(internalAccounts: InternalAccount[]): DeFiBalancesQuery;
|
|
34
|
+
//# sourceMappingURL=build-defi-balances-query.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-defi-balances-query.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/build-defi-balances-query.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAiB,WAAW,EAAE,wBAAwB;AAGlE;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,WAAW,EAczD,CAAC;AAIF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yDAAyD;IACzD,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB;;;;OAIG;IACH,uBAAuB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C,CAAC;AAaF;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,eAAe,EAAE,GAClC,iBAAiB,CA0CnB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isEvmAccountType, SolAccountType, SolScope } from "@metamask/keyring-api";
|
|
2
|
+
import { KnownCaipNamespace, toCaipAccountId } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Networks the DeFi balances (v6 multiaccount) endpoint supports.
|
|
5
|
+
* Cross-section of the supported chains from:
|
|
6
|
+
* https://developers.zerion.io/supported-blockchains
|
|
7
|
+
* https://accounts.api.cx.metamask.io/v2/supportedNetworks
|
|
8
|
+
*/
|
|
9
|
+
export const DEFI_SUPPORTED_NETWORKS = [
|
|
10
|
+
'eip155:1',
|
|
11
|
+
'eip155:137',
|
|
12
|
+
'eip155:56',
|
|
13
|
+
'eip155:1329',
|
|
14
|
+
'eip155:43114',
|
|
15
|
+
'eip155:59144',
|
|
16
|
+
'eip155:8453',
|
|
17
|
+
'eip155:10',
|
|
18
|
+
'eip155:42161',
|
|
19
|
+
'eip155:143',
|
|
20
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
|
|
21
|
+
'eip155:999',
|
|
22
|
+
'eip155:5042',
|
|
23
|
+
];
|
|
24
|
+
const SOLANA_MAINNET_CAIP_CHAIN_ID = SolScope.Mainnet;
|
|
25
|
+
/**
|
|
26
|
+
* Builds an EVM CAIP-10 account ID that spans every EVM chain (reference `0`).
|
|
27
|
+
* Addresses are lowercased because EVM addresses are case-insensitive.
|
|
28
|
+
*
|
|
29
|
+
* @param address - The EVM account address.
|
|
30
|
+
* @returns The CAIP-10 account ID for the address.
|
|
31
|
+
*/
|
|
32
|
+
function toEvmCaipAccountId(address) {
|
|
33
|
+
return toCaipAccountId(KnownCaipNamespace.Eip155, '0', address.toLowerCase());
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds the account IDs and networks to request DeFi positions for, from the
|
|
37
|
+
* accounts in the selected account group.
|
|
38
|
+
*
|
|
39
|
+
* Picks the group's EVM account (queried across all supported EVM chains) and
|
|
40
|
+
* its Solana account (queried on supported Solana chains). Enabled-network
|
|
41
|
+
* filtering is intentionally omitted here: positions are stored per chain, so
|
|
42
|
+
* the client can filter by enabled networks when reading state.
|
|
43
|
+
*
|
|
44
|
+
* @param internalAccounts - Accounts belonging to the selected account group.
|
|
45
|
+
* @returns Networks and a CAIP→internal account ID map for the v6 multiaccount
|
|
46
|
+
* balances request. Map keys are the CAIP account IDs to query.
|
|
47
|
+
*/
|
|
48
|
+
export function buildDeFiBalancesQuery(internalAccounts) {
|
|
49
|
+
const evmNetworks = DEFI_SUPPORTED_NETWORKS.filter((network) => network.startsWith(`${KnownCaipNamespace.Eip155}:`));
|
|
50
|
+
const solanaNetworks = DEFI_SUPPORTED_NETWORKS.filter((network) => network.startsWith(`${KnownCaipNamespace.Solana}:`));
|
|
51
|
+
const networks = [];
|
|
52
|
+
const internalAccountIdByCaip = new Map();
|
|
53
|
+
const evmAccount = internalAccounts.find((account) => isEvmAccountType(account.type));
|
|
54
|
+
if (evmAccount && evmNetworks.length > 0) {
|
|
55
|
+
internalAccountIdByCaip.set(toEvmCaipAccountId(evmAccount.address), evmAccount.id);
|
|
56
|
+
networks.push(...evmNetworks);
|
|
57
|
+
}
|
|
58
|
+
const solanaAccount = internalAccounts.find((account) => account.type === SolAccountType.DataAccount);
|
|
59
|
+
if (solanaAccount && solanaNetworks.length > 0) {
|
|
60
|
+
const [, solanaReference] = SOLANA_MAINNET_CAIP_CHAIN_ID.split(':');
|
|
61
|
+
internalAccountIdByCaip.set(toCaipAccountId(KnownCaipNamespace.Solana, solanaReference, solanaAccount.address), solanaAccount.id);
|
|
62
|
+
networks.push(...solanaNetworks);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
networks: [...new Set(networks)],
|
|
66
|
+
internalAccountIdByCaip,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=build-defi-balances-query.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-defi-balances-query.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/build-defi-balances-query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACT,8BAA8B;AAG/B,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,wBAAwB;AAEtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA2B;IAC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AAgB,CAAC,IAAI,CACzC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,WAAW,CACzD,CAAC;IACF,IAAI,aAAa,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,CAAC,EAAE,eAAe,CAAC,GAAG,4BAA4B,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpE,uBAAuB,CAAC,GAAG,CACzB,eAAe,CACb,kBAAkB,CAAC,MAAM,EACzB,eAAe,EACf,aAAa,CAAC,OAAO,CACtB,EACD,aAAa,CAAC,EAAE,CACjB,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;IACnC,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAkB;QACjD,uBAAuB;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import {\n isEvmAccountType,\n SolAccountType,\n SolScope,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { CaipAccountId, CaipChainId } from '@metamask/utils';\nimport { KnownCaipNamespace, toCaipAccountId } from '@metamask/utils';\n\n/**\n * Networks the DeFi balances (v6 multiaccount) endpoint supports.\n * Cross-section of the supported chains from:\n * https://developers.zerion.io/supported-blockchains\n * https://accounts.api.cx.metamask.io/v2/supportedNetworks\n */\nexport const DEFI_SUPPORTED_NETWORKS: readonly CaipChainId[] = [\n 'eip155:1',\n 'eip155:137',\n 'eip155:56',\n 'eip155:1329',\n 'eip155:43114',\n 'eip155:59144',\n 'eip155:8453',\n 'eip155:10',\n 'eip155:42161',\n 'eip155:143',\n 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n 'eip155:999',\n 'eip155:5042',\n];\n\nconst SOLANA_MAINNET_CAIP_CHAIN_ID: CaipChainId = SolScope.Mainnet;\n\nexport type DeFiBalancesQuery = {\n /** CAIP-2 networks to query, deduped across accounts. */\n networks: CaipChainId[];\n /**\n * Request CAIP-10 account IDs → internal MetaMask account IDs\n * (`InternalAccount.id`). EVM keys use the all-chains reference and a\n * lowercased address; Solana keys keep address case.\n */\n internalAccountIdByCaip: Map<string, string>;\n};\n\n/**\n * Builds an EVM CAIP-10 account ID that spans every EVM chain (reference `0`).\n * Addresses are lowercased because EVM addresses are case-insensitive.\n *\n * @param address - The EVM account address.\n * @returns The CAIP-10 account ID for the address.\n */\nfunction toEvmCaipAccountId(address: string): CaipAccountId {\n return toCaipAccountId(KnownCaipNamespace.Eip155, '0', address.toLowerCase());\n}\n\n/**\n * Builds the account IDs and networks to request DeFi positions for, from the\n * accounts in the selected account group.\n *\n * Picks the group's EVM account (queried across all supported EVM chains) and\n * its Solana account (queried on supported Solana chains). Enabled-network\n * filtering is intentionally omitted here: positions are stored per chain, so\n * the client can filter by enabled networks when reading state.\n *\n * @param internalAccounts - Accounts belonging to the selected account group.\n * @returns Networks and a CAIP→internal account ID map for the v6 multiaccount\n * balances request. Map keys are the CAIP account IDs to query.\n */\nexport function buildDeFiBalancesQuery(\n internalAccounts: InternalAccount[],\n): DeFiBalancesQuery {\n const evmNetworks = DEFI_SUPPORTED_NETWORKS.filter((network) =>\n network.startsWith(`${KnownCaipNamespace.Eip155}:`),\n );\n const solanaNetworks = DEFI_SUPPORTED_NETWORKS.filter((network) =>\n network.startsWith(`${KnownCaipNamespace.Solana}:`),\n );\n\n const networks: CaipChainId[] = [];\n const internalAccountIdByCaip = new Map<string, string>();\n\n const evmAccount = internalAccounts.find((account) =>\n isEvmAccountType(account.type),\n );\n if (evmAccount && evmNetworks.length > 0) {\n internalAccountIdByCaip.set(\n toEvmCaipAccountId(evmAccount.address),\n evmAccount.id,\n );\n networks.push(...evmNetworks);\n }\n\n const solanaAccount = internalAccounts.find(\n (account) => account.type === SolAccountType.DataAccount,\n );\n if (solanaAccount && solanaNetworks.length > 0) {\n const [, solanaReference] = SOLANA_MAINNET_CAIP_CHAIN_ID.split(':');\n internalAccountIdByCaip.set(\n toCaipAccountId(\n KnownCaipNamespace.Solana,\n solanaReference,\n solanaAccount.address,\n ),\n solanaAccount.id,\n );\n networks.push(...solanaNetworks);\n }\n\n return {\n networks: [...new Set(networks)] as CaipChainId[],\n internalAccountIdByCaip,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-defi-metrics.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":";;;AAOA;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAC1C,wBAAsD;IAEtD,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,MAAM,SAAS,GAKT,EAAE,CAAC;IAET,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAC9C,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE;QAC5B,MAAM,wBAAwB,GAAG,cAAc,CAAC,qBAAqB,CAAC;QACtE,mBAAmB,IAAI,wBAAwB,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAC9C,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE;YACzB,MAAM,2BAA2B,GAAG,QAAQ,CAAC,qBAAqB,CAAC;YAEnE,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,MAAM,CAChE,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,CACpB,GAAG,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,EAErD,CAAC,CACF,CAAC;YAEF,cAAc,IAAI,aAAa,CAAC;YAEhC,SAAS,CAAC,IAAI,CAAC;gBACb,UAAU;gBACV,cAAc,EAAE,2BAA2B;gBAC3C,OAAO,EAAE,OAAc;gBACvB,KAAK,EAAE,aAAa;aACrB,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CACF,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,YAAY;QACnB,UAAU,EAAE;YACV,mBAAmB;YACnB,cAAc;YACd,SAAS;SACV;KACF,CAAC;AACJ,CAAC;AAjDD,oEAiDC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type {\n GroupedDeFiPositionsPerChain,\n TrackingEventPayload,\n} from './DeFiPositionsController';\n\n/**\n * Calculates the total market value and total positions for a given account\n * and returns a breakdown of the market value per protocol.\n *\n * @param accountPositionsPerChain - The account positions per chain.\n * @returns An object containing the total market value, total positions, and a breakdown of the market value per protocol.\n */\nexport function calculateDeFiPositionMetrics(\n accountPositionsPerChain: GroupedDeFiPositionsPerChain,\n): TrackingEventPayload {\n let totalMarketValueUSD = 0;\n let totalPositions = 0;\n const breakdown: {\n protocolId: string;\n marketValueUSD: number;\n chainId: Hex;\n count: number;\n }[] = [];\n\n Object.entries(accountPositionsPerChain).forEach(\n ([chainId, chainPositions]) => {\n const chainTotalMarketValueUSD = chainPositions.aggregatedMarketValue;\n totalMarketValueUSD += chainTotalMarketValueUSD;\n\n Object.entries(chainPositions.protocols).forEach(\n ([protocolId, protocol]) => {\n const protocolTotalMarketValueUSD = protocol.aggregatedMarketValue;\n\n const protocolCount = Object.values(protocol.positionTypes).reduce(\n (acc, positionType) =>\n acc + (positionType?.positions?.flat().length || 0),\n\n 0,\n );\n\n totalPositions += protocolCount;\n\n breakdown.push({\n protocolId,\n marketValueUSD: protocolTotalMarketValueUSD,\n chainId: chainId as Hex,\n count: protocolCount,\n });\n },\n );\n },\n );\n return {\n category: 'DeFi',\n event: 'DeFi Stats',\n properties: {\n totalMarketValueUSD,\n totalPositions,\n breakdown,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"calculate-defi-metrics.cjs","sourceRoot":"","sources":["../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/utils';\n\nimport type {\n GroupedDeFiPositionsPerChain,\n TrackingEventPayload,\n} from './DeFiPositionsController.js';\n\n/**\n * Calculates the total market value and total positions for a given account\n * and returns a breakdown of the market value per protocol.\n *\n * @param accountPositionsPerChain - The account positions per chain.\n * @returns An object containing the total market value, total positions, and a breakdown of the market value per protocol.\n */\nexport function calculateDeFiPositionMetrics(\n accountPositionsPerChain: GroupedDeFiPositionsPerChain,\n): TrackingEventPayload {\n let totalMarketValueUSD = 0;\n let totalPositions = 0;\n const breakdown: {\n protocolId: string;\n marketValueUSD: number;\n chainId: Hex;\n count: number;\n }[] = [];\n\n Object.entries(accountPositionsPerChain).forEach(\n ([chainId, chainPositions]) => {\n const chainTotalMarketValueUSD = chainPositions.aggregatedMarketValue;\n totalMarketValueUSD += chainTotalMarketValueUSD;\n\n Object.entries(chainPositions.protocols).forEach(\n ([protocolId, protocol]) => {\n const protocolTotalMarketValueUSD = protocol.aggregatedMarketValue;\n\n const protocolCount = Object.values(protocol.positionTypes).reduce(\n (acc, positionType) =>\n acc + (positionType?.positions?.flat().length || 0),\n\n 0,\n );\n\n totalPositions += protocolCount;\n\n breakdown.push({\n protocolId,\n marketValueUSD: protocolTotalMarketValueUSD,\n chainId: chainId as Hex,\n count: protocolCount,\n });\n },\n );\n },\n );\n return {\n category: 'DeFi',\n event: 'DeFi Stats',\n properties: {\n totalMarketValueUSD,\n totalPositions,\n breakdown,\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-defi-metrics.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oBAAoB,EACrB,
|
|
1
|
+
{"version":3,"file":"calculate-defi-metrics.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oBAAoB,EACrB,sCAAqC;AAEtC;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,wBAAwB,EAAE,4BAA4B,GACrD,oBAAoB,CA+CtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-defi-metrics.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oBAAoB,EACrB,
|
|
1
|
+
{"version":3,"file":"calculate-defi-metrics.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oBAAoB,EACrB,sCAAqC;AAEtC;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,wBAAwB,EAAE,4BAA4B,GACrD,oBAAoB,CA+CtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-defi-metrics.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAC1C,wBAAsD;IAEtD,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,MAAM,SAAS,GAKT,EAAE,CAAC;IAET,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAC9C,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE;QAC5B,MAAM,wBAAwB,GAAG,cAAc,CAAC,qBAAqB,CAAC;QACtE,mBAAmB,IAAI,wBAAwB,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAC9C,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE;YACzB,MAAM,2BAA2B,GAAG,QAAQ,CAAC,qBAAqB,CAAC;YAEnE,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,MAAM,CAChE,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,CACpB,GAAG,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,EAErD,CAAC,CACF,CAAC;YAEF,cAAc,IAAI,aAAa,CAAC;YAEhC,SAAS,CAAC,IAAI,CAAC;gBACb,UAAU;gBACV,cAAc,EAAE,2BAA2B;gBAC3C,OAAO,EAAE,OAAc;gBACvB,KAAK,EAAE,aAAa;aACrB,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CACF,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,YAAY;QACnB,UAAU,EAAE;YACV,mBAAmB;YACnB,cAAc;YACd,SAAS;SACV;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type {\n GroupedDeFiPositionsPerChain,\n TrackingEventPayload,\n} from './DeFiPositionsController';\n\n/**\n * Calculates the total market value and total positions for a given account\n * and returns a breakdown of the market value per protocol.\n *\n * @param accountPositionsPerChain - The account positions per chain.\n * @returns An object containing the total market value, total positions, and a breakdown of the market value per protocol.\n */\nexport function calculateDeFiPositionMetrics(\n accountPositionsPerChain: GroupedDeFiPositionsPerChain,\n): TrackingEventPayload {\n let totalMarketValueUSD = 0;\n let totalPositions = 0;\n const breakdown: {\n protocolId: string;\n marketValueUSD: number;\n chainId: Hex;\n count: number;\n }[] = [];\n\n Object.entries(accountPositionsPerChain).forEach(\n ([chainId, chainPositions]) => {\n const chainTotalMarketValueUSD = chainPositions.aggregatedMarketValue;\n totalMarketValueUSD += chainTotalMarketValueUSD;\n\n Object.entries(chainPositions.protocols).forEach(\n ([protocolId, protocol]) => {\n const protocolTotalMarketValueUSD = protocol.aggregatedMarketValue;\n\n const protocolCount = Object.values(protocol.positionTypes).reduce(\n (acc, positionType) =>\n acc + (positionType?.positions?.flat().length || 0),\n\n 0,\n );\n\n totalPositions += protocolCount;\n\n breakdown.push({\n protocolId,\n marketValueUSD: protocolTotalMarketValueUSD,\n chainId: chainId as Hex,\n count: protocolCount,\n });\n },\n );\n },\n );\n return {\n category: 'DeFi',\n event: 'DeFi Stats',\n properties: {\n totalMarketValueUSD,\n totalPositions,\n breakdown,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"calculate-defi-metrics.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/calculate-defi-metrics.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAC1C,wBAAsD;IAEtD,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,MAAM,SAAS,GAKT,EAAE,CAAC;IAET,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAC9C,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE;QAC5B,MAAM,wBAAwB,GAAG,cAAc,CAAC,qBAAqB,CAAC;QACtE,mBAAmB,IAAI,wBAAwB,CAAC;QAEhD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAC9C,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE;YACzB,MAAM,2BAA2B,GAAG,QAAQ,CAAC,qBAAqB,CAAC;YAEnE,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,MAAM,CAChE,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,CACpB,GAAG,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,EAErD,CAAC,CACF,CAAC;YAEF,cAAc,IAAI,aAAa,CAAC;YAEhC,SAAS,CAAC,IAAI,CAAC;gBACb,UAAU;gBACV,cAAc,EAAE,2BAA2B;gBAC3C,OAAO,EAAE,OAAc;gBACvB,KAAK,EAAE,aAAa;aACrB,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CACF,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,YAAY;QACnB,UAAU,EAAE;YACV,mBAAmB;YACnB,cAAc;YACd,SAAS;SACV;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type {\n GroupedDeFiPositionsPerChain,\n TrackingEventPayload,\n} from './DeFiPositionsController.js';\n\n/**\n * Calculates the total market value and total positions for a given account\n * and returns a breakdown of the market value per protocol.\n *\n * @param accountPositionsPerChain - The account positions per chain.\n * @returns An object containing the total market value, total positions, and a breakdown of the market value per protocol.\n */\nexport function calculateDeFiPositionMetrics(\n accountPositionsPerChain: GroupedDeFiPositionsPerChain,\n): TrackingEventPayload {\n let totalMarketValueUSD = 0;\n let totalPositions = 0;\n const breakdown: {\n protocolId: string;\n marketValueUSD: number;\n chainId: Hex;\n count: number;\n }[] = [];\n\n Object.entries(accountPositionsPerChain).forEach(\n ([chainId, chainPositions]) => {\n const chainTotalMarketValueUSD = chainPositions.aggregatedMarketValue;\n totalMarketValueUSD += chainTotalMarketValueUSD;\n\n Object.entries(chainPositions.protocols).forEach(\n ([protocolId, protocol]) => {\n const protocolTotalMarketValueUSD = protocol.aggregatedMarketValue;\n\n const protocolCount = Object.values(protocol.positionTypes).reduce(\n (acc, positionType) =>\n acc + (positionType?.positions?.flat().length || 0),\n\n 0,\n );\n\n totalPositions += protocolCount;\n\n breakdown.push({\n protocolId,\n marketValueUSD: protocolTotalMarketValueUSD,\n chainId: chainId as Hex,\n count: protocolCount,\n });\n },\n );\n },\n );\n return {\n category: 'DeFi',\n event: 'DeFi Stats',\n properties: {\n totalMarketValueUSD,\n totalPositions,\n breakdown,\n },\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildPositionFetcher = exports.DEFI_POSITIONS_API_URL = void 0;
|
|
4
|
-
const
|
|
4
|
+
const timeout_with_retry_js_1 = require("../utils/timeout-with-retry.cjs");
|
|
5
5
|
// TODO: Update with prod API URL when available
|
|
6
6
|
exports.DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';
|
|
7
7
|
const EIGHT_SECONDS_IN_MS = 8000;
|
|
@@ -13,7 +13,7 @@ const MAX_RETRIES = 1;
|
|
|
13
13
|
*/
|
|
14
14
|
function buildPositionFetcher() {
|
|
15
15
|
return async (accountAddress) => {
|
|
16
|
-
const defiPositionsResponse = await (0,
|
|
16
|
+
const defiPositionsResponse = await (0, timeout_with_retry_js_1.timeoutWithRetry)(() => fetch(`${exports.DEFI_POSITIONS_API_URL}/positions/${accountAddress}`), EIGHT_SECONDS_IN_MS, MAX_RETRIES);
|
|
17
17
|
if (defiPositionsResponse.status !== 200) {
|
|
18
18
|
throw new Error(`Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`);
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"fetch-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":";;;AAAA,2EAAkE;AA2DlE,gDAAgD;AACnC,QAAA,sBAAsB,GAAG,yCAAyC,CAAC;AAEhF,MAAM,mBAAmB,GAAG,IAAK,CAAC;AAClC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;GAIG;AACH,SAAgB,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,IAAA,wCAAgB,EAClD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,8BAAsB,cAAc,cAAc,EAAE,CAAC,EACpE,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC;AAhBD,oDAgBC","sourcesContent":["import { timeoutWithRetry } from '../utils/timeout-with-retry.js';\n\nexport type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';\n\nconst EIGHT_SECONDS_IN_MS = 8_000;\nconst MAX_RETRIES = 1;\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await timeoutWithRetry(\n () => fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`),\n EIGHT_SECONDS_IN_MS,\n MAX_RETRIES,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"fetch-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wCAAuC;AA2DlE,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GAAG,yCAAyC,CAAC;AAEhF,MAAM,mBAAmB,GAAG,IAAK,CAAC;AAClC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,gBAAgB,CAClD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,sBAAsB,cAAc,cAAc,EAAE,CAAC,EACpE,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { timeoutWithRetry } from '../utils/timeout-with-retry.js';\n\nexport type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';\n\nconst EIGHT_SECONDS_IN_MS = 8_000;\nconst MAX_RETRIES = 1;\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await timeoutWithRetry(\n () => fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`),\n EIGHT_SECONDS_IN_MS,\n MAX_RETRIES,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupDeFiPositionsV6 = exports.DEFI_POSITION_LIABILITY_TYPES = exports.DEFI_POSITION_TYPES = void 0;
|
|
4
|
+
const core_backend_1 = require("@metamask/core-backend");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */
|
|
7
|
+
const STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';
|
|
8
|
+
/**
|
|
9
|
+
* Possible `positionType` values from Accounts API v6 DeFi metadata.
|
|
10
|
+
* Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.
|
|
11
|
+
*/
|
|
12
|
+
exports.DEFI_POSITION_TYPES = core_backend_1.V6_DEFI_POSITION_TYPES;
|
|
13
|
+
/**
|
|
14
|
+
* Position types whose fiat value is a liability and is subtracted from the
|
|
15
|
+
* protocol group's aggregated `marketValue`.
|
|
16
|
+
*/
|
|
17
|
+
exports.DEFI_POSITION_LIABILITY_TYPES = new Set(['loan']);
|
|
18
|
+
// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple
|
|
19
|
+
// underlyings. Display-only.
|
|
20
|
+
const SYMBOL_PRIORITY = ['ETH', 'WETH'];
|
|
21
|
+
/**
|
|
22
|
+
* Builds a static token icon URL for a CAIP asset ID.
|
|
23
|
+
*
|
|
24
|
+
* @param assetId - The CAIP-19 asset ID.
|
|
25
|
+
* @returns The token icon URL, or `undefined` when it cannot be built.
|
|
26
|
+
*/
|
|
27
|
+
function getDefiTokenImageUrl(assetId) {
|
|
28
|
+
try {
|
|
29
|
+
const { chainId } = (0, utils_1.parseCaipAssetType)(assetId);
|
|
30
|
+
const { namespace } = (0, utils_1.parseCaipChainId)(chainId);
|
|
31
|
+
const isEvm = namespace === utils_1.KnownCaipNamespace.Eip155;
|
|
32
|
+
const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(/:/gu, '/');
|
|
33
|
+
return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns whether a balance row is a DeFi position carrying protocol metadata.
|
|
41
|
+
*
|
|
42
|
+
* @param balance - A balance row from the v6 API.
|
|
43
|
+
* @returns True when the row is a `category: defi` row with protocol metadata.
|
|
44
|
+
*/
|
|
45
|
+
function isDefiBalanceWithMetadata(balance) {
|
|
46
|
+
return (balance.category === 'defi' &&
|
|
47
|
+
balance.metadata !== undefined &&
|
|
48
|
+
balance.metadata.protocolId !== undefined);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the fiat market value for a v6 DeFi balance row.
|
|
52
|
+
*
|
|
53
|
+
* @param balance - A balance row from the v6 API.
|
|
54
|
+
* @returns The fiat value, or `undefined` when price is missing or the
|
|
55
|
+
* balance/price is invalid.
|
|
56
|
+
*/
|
|
57
|
+
function getMarketValue(balance) {
|
|
58
|
+
if (balance.price === undefined) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const normalizedBalance = Number.parseFloat(balance.balance);
|
|
62
|
+
const price = Number.parseFloat(balance.price);
|
|
63
|
+
if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return normalizedBalance * price;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the sign used when rolling a position's market value into a protocol
|
|
70
|
+
* group total. Liability types (currently `lending`) subtract; all others add.
|
|
71
|
+
*
|
|
72
|
+
* @param positionType - The position's protocol module type.
|
|
73
|
+
* @returns `-1` for liabilities, `1` otherwise.
|
|
74
|
+
*/
|
|
75
|
+
function getMarketValueSign(positionType) {
|
|
76
|
+
return exports.DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.
|
|
80
|
+
*
|
|
81
|
+
* @param iconGroup - The icon-group entries to reorder.
|
|
82
|
+
*/
|
|
83
|
+
function orderIconGroup(iconGroup) {
|
|
84
|
+
const priorityIndex = iconGroup.findIndex((item) => SYMBOL_PRIORITY.includes(item.symbol));
|
|
85
|
+
if (priorityIndex > 0) {
|
|
86
|
+
const [priorityIcon] = iconGroup.splice(priorityIndex, 1);
|
|
87
|
+
iconGroup.unshift(priorityIcon);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Maps a DeFi balance row to a details-page underlying position.
|
|
92
|
+
*
|
|
93
|
+
* @param balance - A DeFi balance row with protocol metadata.
|
|
94
|
+
* @returns The underlying position for the details page.
|
|
95
|
+
*/
|
|
96
|
+
function toUnderlyingPosition(balance) {
|
|
97
|
+
const assetId = balance.assetId;
|
|
98
|
+
const { chainId } = (0, utils_1.parseCaipAssetType)(assetId);
|
|
99
|
+
const { positionType, poolAddress, groupId } = balance.metadata;
|
|
100
|
+
return {
|
|
101
|
+
assetId,
|
|
102
|
+
chainId,
|
|
103
|
+
symbol: balance.symbol,
|
|
104
|
+
name: balance.name,
|
|
105
|
+
balance: balance.balance,
|
|
106
|
+
decimals: balance.decimals,
|
|
107
|
+
marketValue: getMarketValue(balance),
|
|
108
|
+
positionType,
|
|
109
|
+
poolAddress,
|
|
110
|
+
groupId,
|
|
111
|
+
tokenImage: getDefiTokenImageUrl(assetId),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds a chain-reference-agnostic key (`namespace:address`) for matching the
|
|
116
|
+
* CAIP-10 account IDs we request against the ones the v6 API echoes back.
|
|
117
|
+
*
|
|
118
|
+
* We request EVM balances with the all-chains reference (`eip155:0:<address>`),
|
|
119
|
+
* but the response echoes a separate per-chain ID for every chain
|
|
120
|
+
* (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full
|
|
121
|
+
* CAIP-10 string therefore fails, so we drop the reference and match on
|
|
122
|
+
* namespace + address instead. EVM addresses are lowercased; other namespaces
|
|
123
|
+
* keep their case.
|
|
124
|
+
*
|
|
125
|
+
* @param caipAccountId - A CAIP-10 account ID.
|
|
126
|
+
* @returns The match key, or a case-normalized fallback if parsing fails.
|
|
127
|
+
*/
|
|
128
|
+
function toAccountMatchKey(caipAccountId) {
|
|
129
|
+
try {
|
|
130
|
+
const { chain: { namespace }, address, } = (0, utils_1.parseCaipAccountId)(caipAccountId);
|
|
131
|
+
const normalizedAddress = namespace === utils_1.KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;
|
|
132
|
+
return `${namespace}:${normalizedAddress}`;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return caipAccountId.startsWith(`${utils_1.KnownCaipNamespace.Eip155}:`)
|
|
136
|
+
? caipAccountId.toLowerCase()
|
|
137
|
+
: caipAccountId;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Transforms a v6 multiaccount balances response into the stored DeFi state:
|
|
142
|
+
* positions keyed by internal account ID, each mapping to a flat list of
|
|
143
|
+
* protocol groups. Every group carries its own `chainId` (so the client can
|
|
144
|
+
* filter without a nested chain map) plus both the DeFi-tab summary and the
|
|
145
|
+
* details-page sections. Accounts present in the response but with no DeFi
|
|
146
|
+
* positions are included with an empty list so stale data is cleared.
|
|
147
|
+
*
|
|
148
|
+
* When `internalAccountIdByCaip` is provided, response account IDs are matched
|
|
149
|
+
* to internal MetaMask account IDs via namespace + address (ignoring chain
|
|
150
|
+
* reference and EVM case). Unmatched accounts are skipped. When omitted, the
|
|
151
|
+
* response account ID is used as-is (handy for unit tests).
|
|
152
|
+
*
|
|
153
|
+
* @param response - The v6 multiaccount balances response.
|
|
154
|
+
* @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs
|
|
155
|
+
* to internal MetaMask account IDs.
|
|
156
|
+
* @returns DeFi positions keyed by internal account ID.
|
|
157
|
+
*/
|
|
158
|
+
function groupDeFiPositionsV6(response, internalAccountIdByCaip) {
|
|
159
|
+
const internalAccountIdByMatchKey = internalAccountIdByCaip
|
|
160
|
+
? new Map([...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [
|
|
161
|
+
toAccountMatchKey(caipAccountId),
|
|
162
|
+
internalId,
|
|
163
|
+
]))
|
|
164
|
+
: undefined;
|
|
165
|
+
// Accumulate groups per resolved internal account ID. The v6 response returns
|
|
166
|
+
// a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),
|
|
167
|
+
// and several of them can resolve to the same internal account ID, so we must
|
|
168
|
+
// merge across all of them rather than overwrite per response account.
|
|
169
|
+
const groupsByAccountKey = new Map();
|
|
170
|
+
for (const account of response.accounts) {
|
|
171
|
+
const accountId = internalAccountIdByMatchKey
|
|
172
|
+
? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))
|
|
173
|
+
: account.accountId;
|
|
174
|
+
if (accountId === undefined) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
// Seed every queried account so accounts that no longer hold positions
|
|
178
|
+
// overwrite (clear) any previously stored data.
|
|
179
|
+
let groupsByKey = groupsByAccountKey.get(accountId);
|
|
180
|
+
if (!groupsByKey) {
|
|
181
|
+
groupsByKey = new Map();
|
|
182
|
+
groupsByAccountKey.set(accountId, groupsByKey);
|
|
183
|
+
}
|
|
184
|
+
for (const balance of account.balances) {
|
|
185
|
+
if (!isDefiBalanceWithMetadata(balance)) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const position = toUnderlyingPosition(balance);
|
|
189
|
+
const { protocolId, productName, protocolIconUrl } = balance.metadata;
|
|
190
|
+
const groupKey = `${position.chainId}#${protocolId}`;
|
|
191
|
+
let group = groupsByKey.get(groupKey);
|
|
192
|
+
if (!group) {
|
|
193
|
+
group = {
|
|
194
|
+
protocolId,
|
|
195
|
+
productName,
|
|
196
|
+
protocolIconUrl,
|
|
197
|
+
chainId: position.chainId,
|
|
198
|
+
marketValue: 0,
|
|
199
|
+
iconGroup: [],
|
|
200
|
+
sections: [],
|
|
201
|
+
};
|
|
202
|
+
groupsByKey.set(groupKey, group);
|
|
203
|
+
}
|
|
204
|
+
if (position.marketValue !== undefined) {
|
|
205
|
+
group.marketValue +=
|
|
206
|
+
position.marketValue * getMarketValueSign(position.positionType);
|
|
207
|
+
}
|
|
208
|
+
if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {
|
|
209
|
+
group.iconGroup.push({
|
|
210
|
+
symbol: position.symbol,
|
|
211
|
+
avatarValue: position.tokenImage,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// Sections are keyed by productName; distinct groupIds under the same
|
|
215
|
+
// product remain available on each underlying position.
|
|
216
|
+
let section = group.sections.find((item) => item.productName === productName);
|
|
217
|
+
if (!section) {
|
|
218
|
+
section = { productName, positions: [] };
|
|
219
|
+
group.sections.push(section);
|
|
220
|
+
}
|
|
221
|
+
section.positions.push(position);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const result = {};
|
|
225
|
+
for (const [accountId, groupsByKey] of groupsByAccountKey) {
|
|
226
|
+
const groups = [...groupsByKey.values()];
|
|
227
|
+
for (const group of groups) {
|
|
228
|
+
orderIconGroup(group.iconGroup);
|
|
229
|
+
}
|
|
230
|
+
result[accountId] = groups;
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
exports.groupDeFiPositionsV6 = groupDeFiPositionsV6;
|
|
235
|
+
//# sourceMappingURL=group-defi-positions-v6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-defi-positions-v6.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":";;;AAAA,yDAAgE;AAYhE,2CAKyB;AAEzB,+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,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAhGD,oDAgGC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['loan']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { V6BalancesResponse, V6DeFiPositionType } from "@metamask/core-backend";
|
|
2
|
+
import type { CaipAssetType, CaipChainId } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Possible `positionType` values from Accounts API v6 DeFi metadata.
|
|
5
|
+
* Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFI_POSITION_TYPES: readonly ["deposit", "loan", "locked", "staked", "reward", "wallet", "investment"];
|
|
8
|
+
/**
|
|
9
|
+
* The specific module or functionality within a DeFi protocol where a position
|
|
10
|
+
* is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.
|
|
11
|
+
*/
|
|
12
|
+
export type DeFiPositionType = V6DeFiPositionType;
|
|
13
|
+
/**
|
|
14
|
+
* Position types whose fiat value is a liability and is subtracted from the
|
|
15
|
+
* protocol group's aggregated `marketValue`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType>;
|
|
18
|
+
/**
|
|
19
|
+
* An icon-group entry shown next to a protocol in the DeFi tab list.
|
|
20
|
+
*/
|
|
21
|
+
export type DeFiPositionIconGroupItem = {
|
|
22
|
+
/** Token icon URL, when one can be built for the asset. */
|
|
23
|
+
avatarValue?: string;
|
|
24
|
+
symbol: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A single underlying position row shown on the DeFi details page.
|
|
28
|
+
*/
|
|
29
|
+
export type DeFiUnderlyingPosition = {
|
|
30
|
+
assetId: CaipAssetType;
|
|
31
|
+
chainId: CaipChainId;
|
|
32
|
+
symbol: string;
|
|
33
|
+
name: string;
|
|
34
|
+
decimals: number;
|
|
35
|
+
/** Raw balance string as returned by the API. */
|
|
36
|
+
balance: string;
|
|
37
|
+
/** Fiat market value in the requested currency, when a price is available. */
|
|
38
|
+
marketValue?: number;
|
|
39
|
+
/** Position type from protocol metadata. */
|
|
40
|
+
positionType: DeFiPositionType;
|
|
41
|
+
/** Address of the pool this position belongs to. */
|
|
42
|
+
poolAddress: string;
|
|
43
|
+
/**
|
|
44
|
+
* Upstream grouping id from the API. Rows that share a `productName` can
|
|
45
|
+
* still carry distinct `groupId`s (e.g. multiple Pendle YT markets).
|
|
46
|
+
*/
|
|
47
|
+
groupId: string;
|
|
48
|
+
/** Token icon URL, when one can be built for the asset. */
|
|
49
|
+
tokenImage?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A section of the details page, grouping positions that share the same
|
|
53
|
+
* API `productName`. A single `protocolId` can have multiple products
|
|
54
|
+
* (different pools/markets under one protocol), so a group may contain
|
|
55
|
+
* several sections.
|
|
56
|
+
*/
|
|
57
|
+
export type DeFiPositionDetailsSection = {
|
|
58
|
+
/** Section label from the API (`metadata.productName`). */
|
|
59
|
+
productName: string;
|
|
60
|
+
positions: DeFiUnderlyingPosition[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* One row in the DeFi tab list (a protocol on a given chain), with the details
|
|
64
|
+
* needed to render the details page embedded directly inside it.
|
|
65
|
+
*/
|
|
66
|
+
export type DeFiProtocolPositionGroup = {
|
|
67
|
+
protocolId: string;
|
|
68
|
+
/**
|
|
69
|
+
* Product name from the first position seen for this protocol. Prefer
|
|
70
|
+
* `protocolId` for the list-row title; use section `productName`s for
|
|
71
|
+
* per-product detail headings.
|
|
72
|
+
*/
|
|
73
|
+
productName: string;
|
|
74
|
+
protocolIconUrl: string;
|
|
75
|
+
chainId: CaipChainId;
|
|
76
|
+
/**
|
|
77
|
+
* Aggregated fiat market value across all positions in the group.
|
|
78
|
+
* `lending` positions are subtracted; all other types are added.
|
|
79
|
+
*/
|
|
80
|
+
marketValue: number;
|
|
81
|
+
/** Icon-group entries for the list row. */
|
|
82
|
+
iconGroup: DeFiPositionIconGroupItem[];
|
|
83
|
+
/**
|
|
84
|
+
* Detail sections consumed by the details page, one per distinct API
|
|
85
|
+
* `productName` under this `protocolId`.
|
|
86
|
+
*/
|
|
87
|
+
sections: DeFiPositionDetailsSection[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* DeFi positions for every queried account, keyed by the internal MetaMask
|
|
91
|
+
* account ID (`InternalAccount.id` UUID), the same key AssetsController uses.
|
|
92
|
+
* Each account maps to a flat list of protocol groups; filter by each group's
|
|
93
|
+
* `chainId` rather than digging through a nested chain map.
|
|
94
|
+
*/
|
|
95
|
+
export type DeFiPositionsByAccount = {
|
|
96
|
+
[accountId: string]: DeFiProtocolPositionGroup[];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Transforms a v6 multiaccount balances response into the stored DeFi state:
|
|
100
|
+
* positions keyed by internal account ID, each mapping to a flat list of
|
|
101
|
+
* protocol groups. Every group carries its own `chainId` (so the client can
|
|
102
|
+
* filter without a nested chain map) plus both the DeFi-tab summary and the
|
|
103
|
+
* details-page sections. Accounts present in the response but with no DeFi
|
|
104
|
+
* positions are included with an empty list so stale data is cleared.
|
|
105
|
+
*
|
|
106
|
+
* When `internalAccountIdByCaip` is provided, response account IDs are matched
|
|
107
|
+
* to internal MetaMask account IDs via namespace + address (ignoring chain
|
|
108
|
+
* reference and EVM case). Unmatched accounts are skipped. When omitted, the
|
|
109
|
+
* response account ID is used as-is (handy for unit tests).
|
|
110
|
+
*
|
|
111
|
+
* @param response - The v6 multiaccount balances response.
|
|
112
|
+
* @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs
|
|
113
|
+
* to internal MetaMask account IDs.
|
|
114
|
+
* @returns DeFi positions keyed by internal account ID.
|
|
115
|
+
*/
|
|
116
|
+
export declare function groupDeFiPositionsV6(response: V6BalancesResponse, internalAccountIdByCaip?: Map<string, string>): DeFiPositionsByAccount;
|
|
117
|
+
//# sourceMappingURL=group-defi-positions-v6.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-defi-positions-v6.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,oFAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,WAAW,CAAC,gBAAgB,CACnC,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM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