@metamask/assets-controllers 38.0.0 → 38.1.0
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 +37 -1
- package/dist/AccountTrackerController.cjs +245 -0
- package/dist/AccountTrackerController.cjs.map +1 -0
- package/dist/{types/AccountTrackerController.d.ts → AccountTrackerController.d.cts} +6 -6
- package/dist/AccountTrackerController.d.cts.map +1 -0
- package/dist/AccountTrackerController.d.mts +112 -0
- package/dist/AccountTrackerController.d.mts.map +1 -0
- package/dist/AccountTrackerController.mjs +244 -8
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/AssetsContractController.cjs +389 -0
- package/dist/AssetsContractController.cjs.map +1 -0
- package/dist/{types/AssetsContractController.d.ts → AssetsContractController.d.cts} +9 -9
- package/dist/AssetsContractController.d.cts.map +1 -0
- package/dist/AssetsContractController.d.mts +277 -0
- package/dist/AssetsContractController.d.mts.map +1 -0
- package/dist/AssetsContractController.mjs +387 -16
- package/dist/AssetsContractController.mjs.map +1 -1
- package/dist/CurrencyRateController.cjs +156 -0
- package/dist/CurrencyRateController.cjs.map +1 -0
- package/dist/{types/CurrencyRateController.d.ts → CurrencyRateController.d.cts} +5 -5
- package/dist/CurrencyRateController.d.cts.map +1 -0
- package/dist/CurrencyRateController.d.mts +80 -0
- package/dist/CurrencyRateController.d.mts.map +1 -0
- package/dist/CurrencyRateController.mjs +150 -10
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/NftController.cjs +1159 -0
- package/dist/NftController.cjs.map +1 -0
- package/dist/{types/NftController.d.ts → NftController.d.cts} +11 -11
- package/dist/NftController.d.cts.map +1 -0
- package/dist/NftController.d.mts +424 -0
- package/dist/NftController.d.mts.map +1 -0
- package/dist/NftController.mjs +1156 -12
- package/dist/NftController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs +237 -0
- package/dist/NftDetectionController.cjs.map +1 -0
- package/dist/{types/NftDetectionController.d.ts → NftDetectionController.d.cts} +9 -9
- package/dist/NftDetectionController.d.cts.map +1 -0
- package/dist/NftDetectionController.d.mts +368 -0
- package/dist/NftDetectionController.d.mts.map +1 -0
- package/dist/NftDetectionController.mjs +231 -14
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/RatesController/RatesController.cjs +189 -0
- package/dist/RatesController/RatesController.cjs.map +1 -0
- package/dist/{types/RatesController/RatesController.d.ts → RatesController/RatesController.d.cts} +3 -3
- package/dist/RatesController/RatesController.d.cts.map +1 -0
- package/dist/RatesController/RatesController.d.mts +44 -0
- package/dist/RatesController/RatesController.d.mts.map +1 -0
- package/dist/RatesController/RatesController.mjs +183 -12
- package/dist/RatesController/RatesController.mjs.map +1 -1
- package/dist/RatesController/index.cjs +7 -0
- package/dist/RatesController/index.cjs.map +1 -0
- package/dist/{types/RatesController/index.d.ts → RatesController/index.d.cts} +3 -3
- package/dist/RatesController/index.d.cts.map +1 -0
- package/dist/RatesController/index.d.mts +3 -0
- package/dist/RatesController/index.d.mts.map +1 -0
- package/dist/RatesController/index.mjs +1 -12
- package/dist/RatesController/index.mjs.map +1 -1
- package/dist/RatesController/types.cjs +3 -0
- package/dist/RatesController/types.cjs.map +1 -0
- package/dist/{types/RatesController/types.d.ts → RatesController/types.d.cts} +4 -4
- package/dist/RatesController/types.d.cts.map +1 -0
- package/dist/RatesController/types.d.mts +100 -0
- package/dist/RatesController/types.d.mts.map +1 -0
- package/dist/RatesController/types.mjs +1 -0
- package/dist/RatesController/types.mjs.map +1 -1
- package/dist/Standards/ERC20Standard.cjs +124 -0
- package/dist/Standards/ERC20Standard.cjs.map +1 -0
- package/dist/{types/Standards/ERC20Standard.d.ts → Standards/ERC20Standard.d.cts} +3 -3
- package/dist/Standards/ERC20Standard.d.cts.map +1 -0
- package/dist/Standards/ERC20Standard.d.mts +49 -0
- package/dist/Standards/ERC20Standard.d.mts.map +1 -0
- package/dist/Standards/ERC20Standard.mjs +121 -8
- package/dist/Standards/ERC20Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs +189 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs.map +1 -0
- package/dist/{types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts → Standards/NftStandards/ERC1155/ERC1155Standard.d.cts} +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.cts.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts +95 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +184 -8
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +167 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -0
- package/dist/{types/Standards/NftStandards/ERC721/ERC721Standard.d.ts → Standards/NftStandards/ERC721/ERC721Standard.d.cts} +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.cts.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts +89 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +162 -8
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +136 -0
- package/dist/TokenBalancesController.cjs.map +1 -0
- package/dist/{types/TokenBalancesController.d.ts → TokenBalancesController.d.cts} +7 -7
- package/dist/TokenBalancesController.d.cts.map +1 -0
- package/dist/TokenBalancesController.d.mts +82 -0
- package/dist/TokenBalancesController.d.mts.map +1 -0
- package/dist/TokenBalancesController.mjs +129 -10
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +368 -0
- package/dist/TokenDetectionController.cjs.map +1 -0
- package/dist/{types/TokenDetectionController.d.ts → TokenDetectionController.d.cts} +10 -10
- package/dist/TokenDetectionController.d.cts.map +1 -0
- package/dist/TokenDetectionController.d.mts +109 -0
- package/dist/TokenDetectionController.d.mts.map +1 -0
- package/dist/TokenDetectionController.mjs +365 -15
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenListController.cjs +274 -0
- package/dist/TokenListController.cjs.map +1 -0
- package/dist/{types/TokenListController.d.ts → TokenListController.d.cts} +5 -5
- package/dist/TokenListController.d.cts.map +1 -0
- package/dist/TokenListController.d.mts +117 -0
- package/dist/TokenListController.d.mts.map +1 -0
- package/dist/TokenListController.mjs +267 -12
- package/dist/TokenListController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +452 -0
- package/dist/TokenRatesController.cjs.map +1 -0
- package/dist/{types/TokenRatesController.d.ts → TokenRatesController.d.cts} +8 -8
- package/dist/TokenRatesController.d.cts.map +1 -0
- package/dist/TokenRatesController.d.mts +170 -0
- package/dist/TokenRatesController.d.mts.map +1 -0
- package/dist/TokenRatesController.mjs +446 -16
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokensController.cjs +678 -0
- package/dist/TokensController.cjs.map +1 -0
- package/dist/{types/TokensController.d.ts → TokensController.d.cts} +9 -9
- package/dist/TokensController.d.cts.map +1 -0
- package/dist/TokensController.d.mts +165 -0
- package/dist/TokensController.d.mts.map +1 -0
- package/dist/TokensController.mjs +675 -14
- package/dist/TokensController.mjs.map +1 -1
- package/dist/assetsUtil.cjs +358 -0
- package/dist/assetsUtil.cjs.map +1 -0
- package/dist/{types/assetsUtil.d.ts → assetsUtil.d.cts} +7 -7
- package/dist/assetsUtil.d.cts.map +1 -0
- package/dist/assetsUtil.d.mts +177 -0
- package/dist/assetsUtil.d.mts.map +1 -0
- package/dist/assetsUtil.mjs +343 -36
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/constants.cjs +10 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +6 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +6 -7
- package/dist/constants.mjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.cjs +119 -0
- package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -0
- package/dist/{types/crypto-compare-service/crypto-compare.d.ts → crypto-compare-service/crypto-compare.d.cts} +1 -1
- package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.d.mts +22 -0
- package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +113 -9
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
- package/dist/crypto-compare-service/index.cjs +7 -0
- package/dist/crypto-compare-service/index.cjs.map +1 -0
- package/dist/crypto-compare-service/index.d.cts +2 -0
- package/dist/crypto-compare-service/index.d.cts.map +1 -0
- package/dist/crypto-compare-service/index.d.mts +2 -0
- package/dist/crypto-compare-service/index.d.mts.map +1 -0
- package/dist/crypto-compare-service/index.mjs +1 -10
- package/dist/crypto-compare-service/index.mjs.map +1 -1
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/index.d.ts → index.d.cts} +24 -24
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -80
- package/dist/index.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs +3 -0
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -0
- package/dist/{types/token-prices-service/abstract-token-prices-service.d.ts → token-prices-service/abstract-token-prices-service.d.cts} +2 -2
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +79 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +352 -0
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -0
- package/dist/{types/token-prices-service/codefi-v2.d.ts → token-prices-service/codefi-v2.d.cts} +3 -3
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -0
- package/dist/token-prices-service/codefi-v2.d.mts +97 -0
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -0
- package/dist/token-prices-service/codefi-v2.mjs +347 -12
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/dist/token-prices-service/index.cjs +7 -0
- package/dist/token-prices-service/index.cjs.map +1 -0
- package/dist/token-prices-service/index.d.cts +3 -0
- package/dist/token-prices-service/index.d.cts.map +1 -0
- package/dist/token-prices-service/index.d.mts +3 -0
- package/dist/token-prices-service/index.d.mts.map +1 -0
- package/dist/token-prices-service/index.mjs +1 -10
- package/dist/token-prices-service/index.mjs.map +1 -1
- package/dist/token-service.cjs +130 -0
- package/dist/token-service.cjs.map +1 -0
- package/dist/{types/token-service.d.ts → token-service.d.cts} +2 -2
- package/dist/token-service.d.cts.map +1 -0
- package/dist/token-service.d.mts +31 -0
- package/dist/token-service.d.mts.map +1 -0
- package/dist/token-service.mjs +124 -14
- package/dist/token-service.mjs.map +1 -1
- package/package.json +21 -16
- package/dist/AccountTrackerController.js +0 -10
- package/dist/AccountTrackerController.js.map +0 -1
- package/dist/AssetsContractController.js +0 -18
- package/dist/AssetsContractController.js.map +0 -1
- package/dist/CurrencyRateController.js +0 -12
- package/dist/CurrencyRateController.js.map +0 -1
- package/dist/NftController.js +0 -14
- package/dist/NftController.js.map +0 -1
- package/dist/NftDetectionController.js +0 -16
- package/dist/NftDetectionController.js.map +0 -1
- package/dist/RatesController/RatesController.js +0 -14
- package/dist/RatesController/RatesController.js.map +0 -1
- package/dist/RatesController/index.js +0 -13
- package/dist/RatesController/index.js.map +0 -1
- package/dist/RatesController/types.js +0 -1
- package/dist/RatesController/types.js.map +0 -1
- package/dist/Standards/ERC20Standard.js +0 -9
- package/dist/Standards/ERC20Standard.js.map +0 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +0 -9
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +0 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +0 -9
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +0 -1
- package/dist/TokenBalancesController.js +0 -12
- package/dist/TokenBalancesController.js.map +0 -1
- package/dist/TokenDetectionController.js +0 -17
- package/dist/TokenDetectionController.js.map +0 -1
- package/dist/TokenListController.js +0 -14
- package/dist/TokenListController.js.map +0 -1
- package/dist/TokenRatesController.js +0 -18
- package/dist/TokenRatesController.js.map +0 -1
- package/dist/TokensController.js +0 -16
- package/dist/TokensController.js.map +0 -1
- package/dist/assetsUtil.js +0 -38
- package/dist/assetsUtil.js.map +0 -1
- package/dist/chunk-27KOXCQK.mjs +0 -1
- package/dist/chunk-27KOXCQK.mjs.map +0 -1
- package/dist/chunk-2TZK6YZA.js +0 -1405
- package/dist/chunk-2TZK6YZA.js.map +0 -1
- package/dist/chunk-3LPQTUGG.js +0 -434
- package/dist/chunk-3LPQTUGG.js.map +0 -1
- package/dist/chunk-3QDXAE2D.mjs +0 -178
- package/dist/chunk-3QDXAE2D.mjs.map +0 -1
- package/dist/chunk-46KUC5FH.mjs +0 -434
- package/dist/chunk-46KUC5FH.mjs.map +0 -1
- package/dist/chunk-4QZESU46.mjs +0 -530
- package/dist/chunk-4QZESU46.mjs.map +0 -1
- package/dist/chunk-5QLC2MHV.js +0 -215
- package/dist/chunk-5QLC2MHV.js.map +0 -1
- package/dist/chunk-7K6PSEAA.js +0 -1
- package/dist/chunk-7K6PSEAA.js.map +0 -1
- package/dist/chunk-AX522TDL.mjs +0 -85
- package/dist/chunk-AX522TDL.mjs.map +0 -1
- package/dist/chunk-AZSIKIMK.mjs +0 -429
- package/dist/chunk-AZSIKIMK.mjs.map +0 -1
- package/dist/chunk-BBCZM5P4.js +0 -300
- package/dist/chunk-BBCZM5P4.js.map +0 -1
- package/dist/chunk-BZEAPSD5.mjs +0 -215
- package/dist/chunk-BZEAPSD5.mjs.map +0 -1
- package/dist/chunk-C7LNCQXM.mjs +0 -300
- package/dist/chunk-C7LNCQXM.mjs.map +0 -1
- package/dist/chunk-CP3HC7AQ.mjs +0 -12
- package/dist/chunk-CP3HC7AQ.mjs.map +0 -1
- package/dist/chunk-FWKV5FGP.mjs +0 -71
- package/dist/chunk-FWKV5FGP.mjs.map +0 -1
- package/dist/chunk-GDFLKKDY.js +0 -71
- package/dist/chunk-GDFLKKDY.js.map +0 -1
- package/dist/chunk-GW6RE66P.mjs +0 -210
- package/dist/chunk-GW6RE66P.mjs.map +0 -1
- package/dist/chunk-HVOIBGYN.js +0 -282
- package/dist/chunk-HVOIBGYN.js.map +0 -1
- package/dist/chunk-ISK2VSBB.js +0 -178
- package/dist/chunk-ISK2VSBB.js.map +0 -1
- package/dist/chunk-JCR4H6YL.js +0 -115
- package/dist/chunk-JCR4H6YL.js.map +0 -1
- package/dist/chunk-JJX7TMH5.mjs +0 -135
- package/dist/chunk-JJX7TMH5.mjs.map +0 -1
- package/dist/chunk-JMZ7KWJS.js +0 -157
- package/dist/chunk-JMZ7KWJS.js.map +0 -1
- package/dist/chunk-JYHAAA6W.mjs +0 -1
- package/dist/chunk-JYHAAA6W.mjs.map +0 -1
- package/dist/chunk-K7A3EOIM.js +0 -85
- package/dist/chunk-K7A3EOIM.js.map +0 -1
- package/dist/chunk-KPBNX6GP.mjs +0 -215
- package/dist/chunk-KPBNX6GP.mjs.map +0 -1
- package/dist/chunk-LKVWPNXY.js +0 -429
- package/dist/chunk-LKVWPNXY.js.map +0 -1
- package/dist/chunk-MZI3SDQN.js +0 -215
- package/dist/chunk-MZI3SDQN.js.map +0 -1
- package/dist/chunk-NDUMUEE6.js +0 -812
- package/dist/chunk-NDUMUEE6.js.map +0 -1
- package/dist/chunk-OBUR4TXH.js +0 -1
- package/dist/chunk-OBUR4TXH.js.map +0 -1
- package/dist/chunk-RGHTNZQ6.js +0 -12
- package/dist/chunk-RGHTNZQ6.js.map +0 -1
- package/dist/chunk-S5CFNNOM.mjs +0 -115
- package/dist/chunk-S5CFNNOM.mjs.map +0 -1
- package/dist/chunk-SK2B36Q4.mjs +0 -1405
- package/dist/chunk-SK2B36Q4.mjs.map +0 -1
- package/dist/chunk-TFLYM4PY.mjs +0 -291
- package/dist/chunk-TFLYM4PY.mjs.map +0 -1
- package/dist/chunk-TIFLP53R.js +0 -210
- package/dist/chunk-TIFLP53R.js.map +0 -1
- package/dist/chunk-TTH3ES66.mjs +0 -1
- package/dist/chunk-TTH3ES66.mjs.map +0 -1
- package/dist/chunk-UKXD6WUT.mjs +0 -157
- package/dist/chunk-UKXD6WUT.mjs.map +0 -1
- package/dist/chunk-UUF4E7OG.js +0 -530
- package/dist/chunk-UUF4E7OG.js.map +0 -1
- package/dist/chunk-V6DNVROD.js +0 -348
- package/dist/chunk-V6DNVROD.js.map +0 -1
- package/dist/chunk-XC3SOOGC.js +0 -1
- package/dist/chunk-XC3SOOGC.js.map +0 -1
- package/dist/chunk-XMQA5NLX.mjs +0 -812
- package/dist/chunk-XMQA5NLX.mjs.map +0 -1
- package/dist/chunk-XQO3EG4J.mjs +0 -348
- package/dist/chunk-XQO3EG4J.mjs.map +0 -1
- package/dist/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-XUI43LEZ.mjs.map +0 -1
- package/dist/chunk-YGGUAMHV.js +0 -135
- package/dist/chunk-YGGUAMHV.js.map +0 -1
- package/dist/chunk-Z4BLTVTB.js +0 -30
- package/dist/chunk-Z4BLTVTB.js.map +0 -1
- package/dist/chunk-Z7RMCHD4.mjs +0 -282
- package/dist/chunk-Z7RMCHD4.mjs.map +0 -1
- package/dist/chunk-ZAR4BIOC.js +0 -291
- package/dist/chunk-ZAR4BIOC.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/crypto-compare-service/crypto-compare.js +0 -10
- package/dist/crypto-compare-service/crypto-compare.js.map +0 -1
- package/dist/crypto-compare-service/index.js +0 -11
- package/dist/crypto-compare-service/index.js.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.js +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.js.map +0 -1
- package/dist/token-prices-service/codefi-v2.js +0 -14
- package/dist/token-prices-service/codefi-v2.js.map +0 -1
- package/dist/token-prices-service/index.js +0 -11
- package/dist/token-prices-service/index.js.map +0 -1
- package/dist/token-service.js +0 -15
- package/dist/token-service.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/AccountTrackerController.d.ts.map +0 -1
- package/dist/types/AssetsContractController.d.ts.map +0 -1
- package/dist/types/CurrencyRateController.d.ts.map +0 -1
- package/dist/types/NftController.d.ts.map +0 -1
- package/dist/types/NftDetectionController.d.ts.map +0 -1
- package/dist/types/RatesController/RatesController.d.ts.map +0 -1
- package/dist/types/RatesController/index.d.ts.map +0 -1
- package/dist/types/RatesController/types.d.ts.map +0 -1
- package/dist/types/Standards/ERC20Standard.d.ts.map +0 -1
- package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
- package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
- package/dist/types/TokenBalancesController.d.ts.map +0 -1
- package/dist/types/TokenDetectionController.d.ts.map +0 -1
- package/dist/types/TokenListController.d.ts.map +0 -1
- package/dist/types/TokenRatesController.d.ts.map +0 -1
- package/dist/types/TokensController.d.ts.map +0 -1
- package/dist/types/assetsUtil.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +0 -1
- package/dist/types/crypto-compare-service/index.d.ts +0 -2
- package/dist/types/crypto-compare-service/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +0 -1
- package/dist/types/token-prices-service/index.d.ts +0 -3
- package/dist/types/token-prices-service/index.d.ts.map +0 -1
- package/dist/types/token-service.d.ts.map +0 -1
|
@@ -1,16 +1,677 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import "./chunk-S5CFNNOM.mjs";
|
|
7
|
-
import "./chunk-KPBNX6GP.mjs";
|
|
8
|
-
import "./chunk-AX522TDL.mjs";
|
|
9
|
-
import "./chunk-BZEAPSD5.mjs";
|
|
10
|
-
import "./chunk-XUI43LEZ.mjs";
|
|
11
|
-
export {
|
|
12
|
-
TokensController,
|
|
13
|
-
TokensController_default as default,
|
|
14
|
-
getDefaultTokensState
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
6
|
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _TokensController_instances, _TokensController_mutex, _TokensController_chainId, _TokensController_selectedAccountId, _TokensController_provider, _TokensController_abortController, _TokensController_onNetworkDidChange, _TokensController_onSelectedAccountChange, _TokensController_fetchTokenMetadata, _TokensController_updateTokensAttribute, _TokensController_detectIsERC721, _TokensController_getProvider, _TokensController_createEthersContract, _TokensController_generateRandomId, _TokensController_getNewAllTokensState, _TokensController_getAddressOrSelectedAddress, _TokensController_isInteractingWithWallet, _TokensController_requestApproval, _TokensController_getSelectedAccount, _TokensController_getSelectedAddress;
|
|
13
|
+
function $importDefault(module) {
|
|
14
|
+
if (module?.__esModule) {
|
|
15
|
+
return module.default;
|
|
16
|
+
}
|
|
17
|
+
return module;
|
|
18
|
+
}
|
|
19
|
+
import { Contract } from "@ethersproject/contracts";
|
|
20
|
+
import { Web3Provider } from "@ethersproject/providers";
|
|
21
|
+
import { BaseController } from "@metamask/base-controller";
|
|
22
|
+
import $contractsMap from "@metamask/contract-metadata";
|
|
23
|
+
const contractsMap = $importDefault($contractsMap);
|
|
24
|
+
import { toChecksumHexAddress, ERC721_INTERFACE_ID, ORIGIN_METAMASK, ApprovalType, ERC20, ERC721, ERC1155, isValidHexAddress, safelyExecute } from "@metamask/controller-utils";
|
|
25
|
+
import { abiERC721 } from "@metamask/metamask-eth-abis";
|
|
26
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
27
|
+
import { Mutex } from "async-mutex";
|
|
28
|
+
import { v1 as random } from "uuid";
|
|
29
|
+
import { formatAggregatorNames, formatIconUrlWithProxy } from "./assetsUtil.mjs";
|
|
30
|
+
import { ERC20Standard } from "./Standards/ERC20Standard.mjs";
|
|
31
|
+
import { ERC1155Standard } from "./Standards/NftStandards/ERC1155/ERC1155Standard.mjs";
|
|
32
|
+
import { fetchTokenMetadata, TOKEN_METADATA_NO_SUPPORT_ERROR } from "./token-service.mjs";
|
|
33
|
+
const metadata = {
|
|
34
|
+
tokens: {
|
|
35
|
+
persist: true,
|
|
36
|
+
anonymous: false,
|
|
37
|
+
},
|
|
38
|
+
ignoredTokens: {
|
|
39
|
+
persist: true,
|
|
40
|
+
anonymous: false,
|
|
41
|
+
},
|
|
42
|
+
detectedTokens: {
|
|
43
|
+
persist: true,
|
|
44
|
+
anonymous: false,
|
|
45
|
+
},
|
|
46
|
+
allTokens: {
|
|
47
|
+
persist: true,
|
|
48
|
+
anonymous: false,
|
|
49
|
+
},
|
|
50
|
+
allIgnoredTokens: {
|
|
51
|
+
persist: true,
|
|
52
|
+
anonymous: false,
|
|
53
|
+
},
|
|
54
|
+
allDetectedTokens: {
|
|
55
|
+
persist: true,
|
|
56
|
+
anonymous: false,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const controllerName = 'TokensController';
|
|
60
|
+
export const getDefaultTokensState = () => {
|
|
61
|
+
return {
|
|
62
|
+
tokens: [],
|
|
63
|
+
ignoredTokens: [],
|
|
64
|
+
detectedTokens: [],
|
|
65
|
+
allTokens: {},
|
|
66
|
+
allIgnoredTokens: {},
|
|
67
|
+
allDetectedTokens: {},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Controller that stores assets and exposes convenience methods
|
|
72
|
+
*/
|
|
73
|
+
export class TokensController extends BaseController {
|
|
74
|
+
/**
|
|
75
|
+
* Tokens controller options
|
|
76
|
+
* @param options - Constructor options.
|
|
77
|
+
* @param options.chainId - The chain ID of the current network.
|
|
78
|
+
* @param options.provider - Network provider.
|
|
79
|
+
* @param options.state - Initial state to set on this controller.
|
|
80
|
+
* @param options.messenger - The controller messenger.
|
|
81
|
+
*/
|
|
82
|
+
constructor({ chainId: initialChainId, provider, state, messenger, }) {
|
|
83
|
+
super({
|
|
84
|
+
name: controllerName,
|
|
85
|
+
metadata,
|
|
86
|
+
messenger,
|
|
87
|
+
state: {
|
|
88
|
+
...getDefaultTokensState(),
|
|
89
|
+
...state,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
_TokensController_instances.add(this);
|
|
93
|
+
_TokensController_mutex.set(this, new Mutex());
|
|
94
|
+
_TokensController_chainId.set(this, void 0);
|
|
95
|
+
_TokensController_selectedAccountId.set(this, void 0);
|
|
96
|
+
_TokensController_provider.set(this, void 0);
|
|
97
|
+
_TokensController_abortController.set(this, void 0);
|
|
98
|
+
__classPrivateFieldSet(this, _TokensController_chainId, initialChainId, "f");
|
|
99
|
+
__classPrivateFieldSet(this, _TokensController_provider, provider, "f");
|
|
100
|
+
__classPrivateFieldSet(this, _TokensController_selectedAccountId, __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAccount).call(this).id, "f");
|
|
101
|
+
__classPrivateFieldSet(this, _TokensController_abortController, new AbortController(), "f");
|
|
102
|
+
this.messagingSystem.registerActionHandler(`${controllerName}:addDetectedTokens`, this.addDetectedTokens.bind(this));
|
|
103
|
+
this.messagingSystem.subscribe('AccountsController:selectedEvmAccountChange', __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_onSelectedAccountChange).bind(this));
|
|
104
|
+
this.messagingSystem.subscribe('NetworkController:networkDidChange', __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_onNetworkDidChange).bind(this));
|
|
105
|
+
this.messagingSystem.subscribe('TokenListController:stateChange', ({ tokenList }) => {
|
|
106
|
+
const { tokens } = this.state;
|
|
107
|
+
if (tokens.length && !tokens[0].name) {
|
|
108
|
+
__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_updateTokensAttribute).call(this, tokenList, 'name');
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Adds a token to the stored token list.
|
|
114
|
+
*
|
|
115
|
+
* @param options - The method argument object.
|
|
116
|
+
* @param options.address - Hex address of the token contract.
|
|
117
|
+
* @param options.symbol - Symbol of the token.
|
|
118
|
+
* @param options.decimals - Number of decimals the token uses.
|
|
119
|
+
* @param options.name - Name of the token.
|
|
120
|
+
* @param options.image - Image of the token.
|
|
121
|
+
* @param options.interactingAddress - The address of the account to add a token to.
|
|
122
|
+
* @param options.networkClientId - Network Client ID.
|
|
123
|
+
* @returns Current token list.
|
|
124
|
+
*/
|
|
125
|
+
async addToken({ address, symbol, decimals, name, image, interactingAddress, networkClientId, }) {
|
|
126
|
+
const chainId = __classPrivateFieldGet(this, _TokensController_chainId, "f");
|
|
127
|
+
const releaseLock = await __classPrivateFieldGet(this, _TokensController_mutex, "f").acquire();
|
|
128
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
129
|
+
let currentChainId = chainId;
|
|
130
|
+
if (networkClientId) {
|
|
131
|
+
currentChainId = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
132
|
+
}
|
|
133
|
+
const accountAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getAddressOrSelectedAddress).call(this, interactingAddress);
|
|
134
|
+
const isInteractingWithWalletAccount = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_isInteractingWithWallet).call(this, accountAddress);
|
|
135
|
+
try {
|
|
136
|
+
address = toChecksumHexAddress(address);
|
|
137
|
+
const tokens = allTokens[currentChainId]?.[accountAddress] || [];
|
|
138
|
+
const ignoredTokens = allIgnoredTokens[currentChainId]?.[accountAddress] || [];
|
|
139
|
+
const detectedTokens = allDetectedTokens[currentChainId]?.[accountAddress] || [];
|
|
140
|
+
const newTokens = [...tokens];
|
|
141
|
+
const [isERC721, tokenMetadata] = await Promise.all([
|
|
142
|
+
__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_detectIsERC721).call(this, address, networkClientId),
|
|
143
|
+
// TODO parameterize the token metadata fetch by networkClientId
|
|
144
|
+
__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_fetchTokenMetadata).call(this, address),
|
|
145
|
+
]);
|
|
146
|
+
// TODO remove this once this method is fully parameterized by networkClientId
|
|
147
|
+
if (!networkClientId && currentChainId !== __classPrivateFieldGet(this, _TokensController_chainId, "f")) {
|
|
148
|
+
throw new Error('TokensController Error: Switched networks while adding token');
|
|
149
|
+
}
|
|
150
|
+
const newEntry = {
|
|
151
|
+
address,
|
|
152
|
+
symbol,
|
|
153
|
+
decimals,
|
|
154
|
+
image: image ||
|
|
155
|
+
formatIconUrlWithProxy({
|
|
156
|
+
chainId: currentChainId,
|
|
157
|
+
tokenAddress: address,
|
|
158
|
+
}),
|
|
159
|
+
isERC721,
|
|
160
|
+
aggregators: formatAggregatorNames(tokenMetadata?.aggregators || []),
|
|
161
|
+
name,
|
|
162
|
+
};
|
|
163
|
+
const previousIndex = newTokens.findIndex((token) => token.address.toLowerCase() === address.toLowerCase());
|
|
164
|
+
if (previousIndex !== -1) {
|
|
165
|
+
newTokens[previousIndex] = newEntry;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
newTokens.push(newEntry);
|
|
169
|
+
}
|
|
170
|
+
const newIgnoredTokens = ignoredTokens.filter((tokenAddress) => tokenAddress.toLowerCase() !== address.toLowerCase());
|
|
171
|
+
const newDetectedTokens = detectedTokens.filter((token) => token.address.toLowerCase() !== address.toLowerCase());
|
|
172
|
+
const { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens } = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getNewAllTokensState).call(this, {
|
|
173
|
+
newTokens,
|
|
174
|
+
newIgnoredTokens,
|
|
175
|
+
newDetectedTokens,
|
|
176
|
+
interactingAddress: accountAddress,
|
|
177
|
+
interactingChainId: currentChainId,
|
|
178
|
+
});
|
|
179
|
+
let newState = {
|
|
180
|
+
allTokens: newAllTokens,
|
|
181
|
+
allIgnoredTokens: newAllIgnoredTokens,
|
|
182
|
+
allDetectedTokens: newAllDetectedTokens,
|
|
183
|
+
};
|
|
184
|
+
// Only update active tokens if user is interacting with their active wallet account.
|
|
185
|
+
if (isInteractingWithWalletAccount) {
|
|
186
|
+
newState = {
|
|
187
|
+
...newState,
|
|
188
|
+
tokens: newTokens,
|
|
189
|
+
ignoredTokens: newIgnoredTokens,
|
|
190
|
+
detectedTokens: newDetectedTokens,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
this.update((state) => {
|
|
194
|
+
Object.assign(state, newState);
|
|
195
|
+
});
|
|
196
|
+
return newTokens;
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
releaseLock();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Add a batch of tokens.
|
|
204
|
+
*
|
|
205
|
+
* @param tokensToImport - Array of tokens to import.
|
|
206
|
+
* @param networkClientId - Optional network client ID used to determine interacting chain ID.
|
|
207
|
+
*/
|
|
208
|
+
async addTokens(tokensToImport, networkClientId) {
|
|
209
|
+
const releaseLock = await __classPrivateFieldGet(this, _TokensController_mutex, "f").acquire();
|
|
210
|
+
const { tokens, detectedTokens, ignoredTokens } = this.state;
|
|
211
|
+
const importedTokensMap = {};
|
|
212
|
+
// Used later to dedupe imported tokens
|
|
213
|
+
const newTokensMap = tokens.reduce((output, current) => {
|
|
214
|
+
output[current.address] = current;
|
|
215
|
+
return output;
|
|
216
|
+
}, {});
|
|
217
|
+
try {
|
|
218
|
+
tokensToImport.forEach((tokenToAdd) => {
|
|
219
|
+
const { address, symbol, decimals, image, aggregators, name } = tokenToAdd;
|
|
220
|
+
const checksumAddress = toChecksumHexAddress(address);
|
|
221
|
+
const formattedToken = {
|
|
222
|
+
address: checksumAddress,
|
|
223
|
+
symbol,
|
|
224
|
+
decimals,
|
|
225
|
+
image,
|
|
226
|
+
aggregators,
|
|
227
|
+
name,
|
|
228
|
+
};
|
|
229
|
+
newTokensMap[address] = formattedToken;
|
|
230
|
+
importedTokensMap[address.toLowerCase()] = true;
|
|
231
|
+
return formattedToken;
|
|
232
|
+
});
|
|
233
|
+
const newTokens = Object.values(newTokensMap);
|
|
234
|
+
const newDetectedTokens = detectedTokens.filter((token) => !importedTokensMap[token.address.toLowerCase()]);
|
|
235
|
+
const newIgnoredTokens = ignoredTokens.filter((tokenAddress) => !newTokensMap[tokenAddress.toLowerCase()]);
|
|
236
|
+
let interactingChainId;
|
|
237
|
+
if (networkClientId) {
|
|
238
|
+
interactingChainId = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
239
|
+
}
|
|
240
|
+
const { newAllTokens, newAllDetectedTokens, newAllIgnoredTokens } = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getNewAllTokensState).call(this, {
|
|
241
|
+
newTokens,
|
|
242
|
+
newDetectedTokens,
|
|
243
|
+
newIgnoredTokens,
|
|
244
|
+
interactingChainId,
|
|
245
|
+
});
|
|
246
|
+
this.update((state) => {
|
|
247
|
+
state.tokens = newTokens;
|
|
248
|
+
state.allTokens = newAllTokens;
|
|
249
|
+
state.detectedTokens = newDetectedTokens;
|
|
250
|
+
state.allDetectedTokens = newAllDetectedTokens;
|
|
251
|
+
state.ignoredTokens = newIgnoredTokens;
|
|
252
|
+
state.allIgnoredTokens = newAllIgnoredTokens;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
releaseLock();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Ignore a batch of tokens.
|
|
261
|
+
*
|
|
262
|
+
* @param tokenAddressesToIgnore - Array of token addresses to ignore.
|
|
263
|
+
*/
|
|
264
|
+
ignoreTokens(tokenAddressesToIgnore) {
|
|
265
|
+
const { ignoredTokens, detectedTokens, tokens } = this.state;
|
|
266
|
+
const ignoredTokensMap = {};
|
|
267
|
+
let newIgnoredTokens = [...ignoredTokens];
|
|
268
|
+
const checksummedTokenAddresses = tokenAddressesToIgnore.map((address) => {
|
|
269
|
+
const checksumAddress = toChecksumHexAddress(address);
|
|
270
|
+
ignoredTokensMap[address.toLowerCase()] = true;
|
|
271
|
+
return checksumAddress;
|
|
272
|
+
});
|
|
273
|
+
newIgnoredTokens = [...ignoredTokens, ...checksummedTokenAddresses];
|
|
274
|
+
const newDetectedTokens = detectedTokens.filter((token) => !ignoredTokensMap[token.address.toLowerCase()]);
|
|
275
|
+
const newTokens = tokens.filter((token) => !ignoredTokensMap[token.address.toLowerCase()]);
|
|
276
|
+
const { newAllIgnoredTokens, newAllDetectedTokens, newAllTokens } = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getNewAllTokensState).call(this, {
|
|
277
|
+
newIgnoredTokens,
|
|
278
|
+
newDetectedTokens,
|
|
279
|
+
newTokens,
|
|
280
|
+
});
|
|
281
|
+
this.update((state) => {
|
|
282
|
+
state.ignoredTokens = newIgnoredTokens;
|
|
283
|
+
state.tokens = newTokens;
|
|
284
|
+
state.detectedTokens = newDetectedTokens;
|
|
285
|
+
state.allIgnoredTokens = newAllIgnoredTokens;
|
|
286
|
+
state.allDetectedTokens = newAllDetectedTokens;
|
|
287
|
+
state.allTokens = newAllTokens;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Adds a batch of detected tokens to the stored token list.
|
|
292
|
+
*
|
|
293
|
+
* @param incomingDetectedTokens - Array of detected tokens to be added or updated.
|
|
294
|
+
* @param detectionDetails - An object containing the chain ID and address of the currently selected network on which the incomingDetectedTokens were detected.
|
|
295
|
+
* @param detectionDetails.selectedAddress - the account address on which the incomingDetectedTokens were detected.
|
|
296
|
+
* @param detectionDetails.chainId - the chainId on which the incomingDetectedTokens were detected.
|
|
297
|
+
*/
|
|
298
|
+
async addDetectedTokens(incomingDetectedTokens, detectionDetails) {
|
|
299
|
+
const releaseLock = await __classPrivateFieldGet(this, _TokensController_mutex, "f").acquire();
|
|
300
|
+
const chainId = detectionDetails?.chainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f");
|
|
301
|
+
// Previously selectedAddress could be an empty string. This is to preserve the behaviour
|
|
302
|
+
const accountAddress = detectionDetails?.selectedAddress ?? __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
303
|
+
const { allTokens, allDetectedTokens, allIgnoredTokens } = this.state;
|
|
304
|
+
let newTokens = [...(allTokens?.[chainId]?.[accountAddress] ?? [])];
|
|
305
|
+
let newDetectedTokens = [
|
|
306
|
+
...(allDetectedTokens?.[chainId]?.[accountAddress] ?? []),
|
|
307
|
+
];
|
|
308
|
+
try {
|
|
309
|
+
incomingDetectedTokens.forEach((tokenToAdd) => {
|
|
310
|
+
const { address, symbol, decimals, image, aggregators, isERC721, name, } = tokenToAdd;
|
|
311
|
+
const checksumAddress = toChecksumHexAddress(address);
|
|
312
|
+
const newEntry = {
|
|
313
|
+
address: checksumAddress,
|
|
314
|
+
symbol,
|
|
315
|
+
decimals,
|
|
316
|
+
image,
|
|
317
|
+
isERC721,
|
|
318
|
+
aggregators,
|
|
319
|
+
name,
|
|
320
|
+
};
|
|
321
|
+
const previousImportedIndex = newTokens.findIndex((token) => token.address.toLowerCase() === checksumAddress.toLowerCase());
|
|
322
|
+
if (previousImportedIndex !== -1) {
|
|
323
|
+
// Update existing data of imported token
|
|
324
|
+
newTokens[previousImportedIndex] = newEntry;
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
const ignoredTokenIndex = allIgnoredTokens?.[chainId]?.[accountAddress]?.indexOf(address) ??
|
|
328
|
+
-1;
|
|
329
|
+
if (ignoredTokenIndex === -1) {
|
|
330
|
+
// Add detected token
|
|
331
|
+
const previousDetectedIndex = newDetectedTokens.findIndex((token) => token.address.toLowerCase() === checksumAddress.toLowerCase());
|
|
332
|
+
if (previousDetectedIndex !== -1) {
|
|
333
|
+
newDetectedTokens[previousDetectedIndex] = newEntry;
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
newDetectedTokens.push(newEntry);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
const { newAllTokens, newAllDetectedTokens } = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getNewAllTokensState).call(this, {
|
|
342
|
+
newTokens,
|
|
343
|
+
newDetectedTokens,
|
|
344
|
+
interactingAddress: accountAddress,
|
|
345
|
+
interactingChainId: chainId,
|
|
346
|
+
});
|
|
347
|
+
// We may be detecting tokens on a different chain/account pair than are currently configured.
|
|
348
|
+
// Re-point `tokens` and `detectedTokens` to keep them referencing the current chain/account.
|
|
349
|
+
const selectedAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
350
|
+
newTokens = newAllTokens?.[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAddress] || [];
|
|
351
|
+
newDetectedTokens =
|
|
352
|
+
newAllDetectedTokens?.[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAddress] || [];
|
|
353
|
+
this.update((state) => {
|
|
354
|
+
state.tokens = newTokens;
|
|
355
|
+
state.allTokens = newAllTokens;
|
|
356
|
+
state.detectedTokens = newDetectedTokens;
|
|
357
|
+
state.allDetectedTokens = newAllDetectedTokens;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
releaseLock();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Adds isERC721 field to token object. This is called when a user attempts to add tokens that
|
|
366
|
+
* were previously added which do not yet had isERC721 field.
|
|
367
|
+
*
|
|
368
|
+
* @param tokenAddress - The contract address of the token requiring the isERC721 field added.
|
|
369
|
+
* @returns The new token object with the added isERC721 field.
|
|
370
|
+
*/
|
|
371
|
+
async updateTokenType(tokenAddress) {
|
|
372
|
+
const isERC721 = await __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_detectIsERC721).call(this, tokenAddress);
|
|
373
|
+
const tokens = [...this.state.tokens];
|
|
374
|
+
const tokenIndex = tokens.findIndex((token) => {
|
|
375
|
+
return token.address.toLowerCase() === tokenAddress.toLowerCase();
|
|
376
|
+
});
|
|
377
|
+
const updatedToken = { ...tokens[tokenIndex], isERC721 };
|
|
378
|
+
tokens[tokenIndex] = updatedToken;
|
|
379
|
+
this.update((state) => {
|
|
380
|
+
state.tokens = tokens;
|
|
381
|
+
});
|
|
382
|
+
return updatedToken;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Adds a new suggestedAsset to the list of watched assets.
|
|
386
|
+
* Parameters will be validated according to the asset type being watched.
|
|
387
|
+
*
|
|
388
|
+
* @param options - The method options.
|
|
389
|
+
* @param options.asset - The asset to be watched. For now only ERC20 tokens are accepted.
|
|
390
|
+
* @param options.type - The asset type.
|
|
391
|
+
* @param options.interactingAddress - The address of the account that is requesting to watch the asset.
|
|
392
|
+
* @param options.networkClientId - Network Client ID.
|
|
393
|
+
* @returns A promise that resolves if the asset was watched successfully, and rejects otherwise.
|
|
394
|
+
*/
|
|
395
|
+
async watchAsset({ asset, type, interactingAddress, networkClientId, }) {
|
|
396
|
+
if (type !== ERC20) {
|
|
397
|
+
throw new Error(`Asset of type ${type} not supported`);
|
|
398
|
+
}
|
|
399
|
+
if (!asset.address) {
|
|
400
|
+
throw rpcErrors.invalidParams('Address must be specified');
|
|
401
|
+
}
|
|
402
|
+
if (!isValidHexAddress(asset.address)) {
|
|
403
|
+
throw rpcErrors.invalidParams(`Invalid address "${asset.address}"`);
|
|
404
|
+
}
|
|
405
|
+
const selectedAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getAddressOrSelectedAddress).call(this, interactingAddress);
|
|
406
|
+
// Validate contract
|
|
407
|
+
if (await __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_detectIsERC721).call(this, asset.address, networkClientId)) {
|
|
408
|
+
throw rpcErrors.invalidParams(
|
|
409
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
410
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
411
|
+
`Contract ${asset.address} must match type ${type}, but was detected as ${ERC721}`);
|
|
412
|
+
}
|
|
413
|
+
const provider = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getProvider).call(this, networkClientId);
|
|
414
|
+
const isErc1155 = await safelyExecute(() => new ERC1155Standard(provider).contractSupportsBase1155Interface(asset.address));
|
|
415
|
+
if (isErc1155) {
|
|
416
|
+
throw rpcErrors.invalidParams(
|
|
417
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
418
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
419
|
+
`Contract ${asset.address} must match type ${type}, but was detected as ${ERC1155}`);
|
|
420
|
+
}
|
|
421
|
+
const erc20 = new ERC20Standard(provider);
|
|
422
|
+
const [contractName, contractSymbol, contractDecimals] = await Promise.all([
|
|
423
|
+
safelyExecute(() => erc20.getTokenName(asset.address)),
|
|
424
|
+
safelyExecute(() => erc20.getTokenSymbol(asset.address)),
|
|
425
|
+
safelyExecute(async () => erc20.getTokenDecimals(asset.address)),
|
|
426
|
+
]);
|
|
427
|
+
asset.name = contractName;
|
|
428
|
+
// Validate symbol
|
|
429
|
+
if (!asset.symbol && !contractSymbol) {
|
|
430
|
+
throw rpcErrors.invalidParams('A symbol is required, but was not found in either the request or contract');
|
|
431
|
+
}
|
|
432
|
+
if (contractSymbol !== undefined &&
|
|
433
|
+
asset.symbol !== undefined &&
|
|
434
|
+
asset.symbol.toUpperCase() !== contractSymbol.toUpperCase()) {
|
|
435
|
+
throw rpcErrors.invalidParams(
|
|
436
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
438
|
+
`The symbol in the request (${asset.symbol}) does not match the symbol in the contract (${contractSymbol})`);
|
|
439
|
+
}
|
|
440
|
+
asset.symbol = contractSymbol ?? asset.symbol;
|
|
441
|
+
if (typeof asset.symbol !== 'string') {
|
|
442
|
+
throw rpcErrors.invalidParams(`Invalid symbol: not a string`);
|
|
443
|
+
}
|
|
444
|
+
if (asset.symbol.length > 11) {
|
|
445
|
+
throw rpcErrors.invalidParams(`Invalid symbol "${asset.symbol}": longer than 11 characters`);
|
|
446
|
+
}
|
|
447
|
+
// Validate decimals
|
|
448
|
+
if (asset.decimals === undefined && contractDecimals === undefined) {
|
|
449
|
+
throw rpcErrors.invalidParams('Decimals are required, but were not found in either the request or contract');
|
|
450
|
+
}
|
|
451
|
+
if (contractDecimals !== undefined &&
|
|
452
|
+
asset.decimals !== undefined &&
|
|
453
|
+
String(asset.decimals) !== contractDecimals) {
|
|
454
|
+
throw rpcErrors.invalidParams(
|
|
455
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
456
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
457
|
+
`The decimals in the request (${asset.decimals}) do not match the decimals in the contract (${contractDecimals})`);
|
|
458
|
+
}
|
|
459
|
+
const decimalsStr = contractDecimals ?? asset.decimals;
|
|
460
|
+
const decimalsNum = parseInt(decimalsStr, 10);
|
|
461
|
+
if (!Number.isInteger(decimalsNum) || decimalsNum > 36 || decimalsNum < 0) {
|
|
462
|
+
throw rpcErrors.invalidParams(
|
|
463
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
464
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
465
|
+
`Invalid decimals "${decimalsStr}": must be an integer 0 <= 36`);
|
|
466
|
+
}
|
|
467
|
+
asset.decimals = decimalsNum;
|
|
468
|
+
const suggestedAssetMeta = {
|
|
469
|
+
asset,
|
|
470
|
+
id: __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_generateRandomId).call(this),
|
|
471
|
+
time: Date.now(),
|
|
472
|
+
type,
|
|
473
|
+
interactingAddress: selectedAddress,
|
|
474
|
+
};
|
|
475
|
+
await __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_requestApproval).call(this, suggestedAssetMeta);
|
|
476
|
+
const { address, symbol, decimals, name, image } = asset;
|
|
477
|
+
await this.addToken({
|
|
478
|
+
address,
|
|
479
|
+
symbol,
|
|
480
|
+
decimals,
|
|
481
|
+
name,
|
|
482
|
+
image,
|
|
483
|
+
interactingAddress: suggestedAssetMeta.interactingAddress,
|
|
484
|
+
networkClientId,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Removes all tokens from the ignored list.
|
|
489
|
+
*/
|
|
490
|
+
clearIgnoredTokens() {
|
|
491
|
+
this.update((state) => {
|
|
492
|
+
state.ignoredTokens = [];
|
|
493
|
+
state.allIgnoredTokens = {};
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
_TokensController_mutex = new WeakMap(), _TokensController_chainId = new WeakMap(), _TokensController_selectedAccountId = new WeakMap(), _TokensController_provider = new WeakMap(), _TokensController_abortController = new WeakMap(), _TokensController_instances = new WeakSet(), _TokensController_onNetworkDidChange = function _TokensController_onNetworkDidChange({ selectedNetworkClientId }) {
|
|
498
|
+
const selectedNetworkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
499
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
500
|
+
const { chainId } = selectedNetworkClient.configuration;
|
|
501
|
+
__classPrivateFieldGet(this, _TokensController_abortController, "f").abort();
|
|
502
|
+
__classPrivateFieldSet(this, _TokensController_abortController, new AbortController(), "f");
|
|
503
|
+
__classPrivateFieldSet(this, _TokensController_chainId, chainId, "f");
|
|
504
|
+
const selectedAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
505
|
+
this.update((state) => {
|
|
506
|
+
state.tokens = allTokens[chainId]?.[selectedAddress] || [];
|
|
507
|
+
state.ignoredTokens = allIgnoredTokens[chainId]?.[selectedAddress] || [];
|
|
508
|
+
state.detectedTokens =
|
|
509
|
+
allDetectedTokens[chainId]?.[selectedAddress] || [];
|
|
510
|
+
});
|
|
511
|
+
}, _TokensController_onSelectedAccountChange = function _TokensController_onSelectedAccountChange(selectedAccount) {
|
|
512
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
513
|
+
__classPrivateFieldSet(this, _TokensController_selectedAccountId, selectedAccount.id, "f");
|
|
514
|
+
this.update((state) => {
|
|
515
|
+
state.tokens = allTokens[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAccount.address] ?? [];
|
|
516
|
+
state.ignoredTokens =
|
|
517
|
+
allIgnoredTokens[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAccount.address] ?? [];
|
|
518
|
+
state.detectedTokens =
|
|
519
|
+
allDetectedTokens[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAccount.address] ?? [];
|
|
520
|
+
});
|
|
521
|
+
}, _TokensController_fetchTokenMetadata =
|
|
522
|
+
/**
|
|
523
|
+
* Fetch metadata for a token.
|
|
524
|
+
*
|
|
525
|
+
* @param tokenAddress - The address of the token.
|
|
526
|
+
* @returns The token metadata.
|
|
527
|
+
*/
|
|
528
|
+
async function _TokensController_fetchTokenMetadata(tokenAddress) {
|
|
529
|
+
try {
|
|
530
|
+
const token = await fetchTokenMetadata(__classPrivateFieldGet(this, _TokensController_chainId, "f"), tokenAddress, __classPrivateFieldGet(this, _TokensController_abortController, "f").signal);
|
|
531
|
+
return token;
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
if (error instanceof Error &&
|
|
535
|
+
error.message.includes(TOKEN_METADATA_NO_SUPPORT_ERROR)) {
|
|
536
|
+
return undefined;
|
|
537
|
+
}
|
|
538
|
+
throw error;
|
|
539
|
+
}
|
|
540
|
+
}, _TokensController_updateTokensAttribute = function _TokensController_updateTokensAttribute(tokenList, tokenAttribute) {
|
|
541
|
+
const { tokens } = this.state;
|
|
542
|
+
const newTokens = tokens.map((token) => {
|
|
543
|
+
const newToken = tokenList[token.address.toLowerCase()];
|
|
544
|
+
return !token[tokenAttribute] && newToken?.[tokenAttribute]
|
|
545
|
+
? { ...token, [tokenAttribute]: newToken[tokenAttribute] }
|
|
546
|
+
: { ...token };
|
|
547
|
+
});
|
|
548
|
+
this.update((state) => {
|
|
549
|
+
state.tokens = newTokens;
|
|
550
|
+
});
|
|
551
|
+
}, _TokensController_detectIsERC721 =
|
|
552
|
+
/**
|
|
553
|
+
* Detects whether or not a token is ERC-721 compatible.
|
|
554
|
+
*
|
|
555
|
+
* @param tokenAddress - The token contract address.
|
|
556
|
+
* @param networkClientId - Optional network client ID to fetch contract info with.
|
|
557
|
+
* @returns A boolean indicating whether the token address passed in supports the EIP-721
|
|
558
|
+
* interface.
|
|
559
|
+
*/
|
|
560
|
+
async function _TokensController_detectIsERC721(tokenAddress, networkClientId) {
|
|
561
|
+
const checksumAddress = toChecksumHexAddress(tokenAddress);
|
|
562
|
+
// if this token is already in our contract metadata map we don't need
|
|
563
|
+
// to check against the contract
|
|
564
|
+
if (contractsMap[checksumAddress]?.erc721 === true) {
|
|
565
|
+
return Promise.resolve(true);
|
|
566
|
+
}
|
|
567
|
+
else if (contractsMap[checksumAddress]?.erc20 === true) {
|
|
568
|
+
return Promise.resolve(false);
|
|
569
|
+
}
|
|
570
|
+
const tokenContract = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_createEthersContract).call(this, tokenAddress, abiERC721, networkClientId);
|
|
571
|
+
try {
|
|
572
|
+
return await tokenContract.supportsInterface(ERC721_INTERFACE_ID);
|
|
573
|
+
}
|
|
574
|
+
catch (error) {
|
|
575
|
+
// currently we see a variety of errors across different networks when
|
|
576
|
+
// token contracts are not ERC721 compatible. We need to figure out a better
|
|
577
|
+
// way of differentiating token interface types but for now if we get an error
|
|
578
|
+
// we have to assume the token is not ERC721 compatible.
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
}, _TokensController_getProvider = function _TokensController_getProvider(networkClientId) {
|
|
582
|
+
return new Web3Provider(networkClientId
|
|
583
|
+
? this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).provider
|
|
584
|
+
: __classPrivateFieldGet(this, _TokensController_provider, "f"));
|
|
585
|
+
}, _TokensController_createEthersContract = function _TokensController_createEthersContract(tokenAddress, abi, networkClientId) {
|
|
586
|
+
const web3provider = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getProvider).call(this, networkClientId);
|
|
587
|
+
const tokenContract = new Contract(tokenAddress, abi, web3provider);
|
|
588
|
+
return tokenContract;
|
|
589
|
+
}, _TokensController_generateRandomId = function _TokensController_generateRandomId() {
|
|
590
|
+
return random();
|
|
591
|
+
}, _TokensController_getNewAllTokensState = function _TokensController_getNewAllTokensState(params) {
|
|
592
|
+
const { newTokens, newIgnoredTokens, newDetectedTokens, interactingAddress, interactingChainId, } = params;
|
|
593
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
594
|
+
const userAddressToAddTokens = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getAddressOrSelectedAddress).call(this, interactingAddress);
|
|
595
|
+
const chainIdToAddTokens = interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f");
|
|
596
|
+
let newAllTokens = allTokens;
|
|
597
|
+
if (newTokens?.length ||
|
|
598
|
+
(newTokens &&
|
|
599
|
+
allTokens &&
|
|
600
|
+
allTokens[chainIdToAddTokens] &&
|
|
601
|
+
allTokens[chainIdToAddTokens][userAddressToAddTokens])) {
|
|
602
|
+
const networkTokens = allTokens[chainIdToAddTokens];
|
|
603
|
+
const newNetworkTokens = {
|
|
604
|
+
...networkTokens,
|
|
605
|
+
...{ [userAddressToAddTokens]: newTokens },
|
|
606
|
+
};
|
|
607
|
+
newAllTokens = {
|
|
608
|
+
...allTokens,
|
|
609
|
+
...{ [chainIdToAddTokens]: newNetworkTokens },
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
let newAllIgnoredTokens = allIgnoredTokens;
|
|
613
|
+
if (newIgnoredTokens?.length ||
|
|
614
|
+
(newIgnoredTokens &&
|
|
615
|
+
allIgnoredTokens &&
|
|
616
|
+
allIgnoredTokens[chainIdToAddTokens] &&
|
|
617
|
+
allIgnoredTokens[chainIdToAddTokens][userAddressToAddTokens])) {
|
|
618
|
+
const networkIgnoredTokens = allIgnoredTokens[chainIdToAddTokens];
|
|
619
|
+
const newIgnoredNetworkTokens = {
|
|
620
|
+
...networkIgnoredTokens,
|
|
621
|
+
...{ [userAddressToAddTokens]: newIgnoredTokens },
|
|
622
|
+
};
|
|
623
|
+
newAllIgnoredTokens = {
|
|
624
|
+
...allIgnoredTokens,
|
|
625
|
+
...{ [chainIdToAddTokens]: newIgnoredNetworkTokens },
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
let newAllDetectedTokens = allDetectedTokens;
|
|
629
|
+
if (newDetectedTokens?.length ||
|
|
630
|
+
(newDetectedTokens &&
|
|
631
|
+
allDetectedTokens &&
|
|
632
|
+
allDetectedTokens[chainIdToAddTokens] &&
|
|
633
|
+
allDetectedTokens[chainIdToAddTokens][userAddressToAddTokens])) {
|
|
634
|
+
const networkDetectedTokens = allDetectedTokens[chainIdToAddTokens];
|
|
635
|
+
const newDetectedNetworkTokens = {
|
|
636
|
+
...networkDetectedTokens,
|
|
637
|
+
...{ [userAddressToAddTokens]: newDetectedTokens },
|
|
638
|
+
};
|
|
639
|
+
newAllDetectedTokens = {
|
|
640
|
+
...allDetectedTokens,
|
|
641
|
+
...{ [chainIdToAddTokens]: newDetectedNetworkTokens },
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
return { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens };
|
|
645
|
+
}, _TokensController_getAddressOrSelectedAddress = function _TokensController_getAddressOrSelectedAddress(address) {
|
|
646
|
+
if (address) {
|
|
647
|
+
return address;
|
|
648
|
+
}
|
|
649
|
+
return __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
650
|
+
}, _TokensController_isInteractingWithWallet = function _TokensController_isInteractingWithWallet(address) {
|
|
651
|
+
const selectedAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
652
|
+
return selectedAddress === address;
|
|
653
|
+
}, _TokensController_requestApproval = async function _TokensController_requestApproval(suggestedAssetMeta) {
|
|
654
|
+
return this.messagingSystem.call('ApprovalController:addRequest', {
|
|
655
|
+
id: suggestedAssetMeta.id,
|
|
656
|
+
origin: ORIGIN_METAMASK,
|
|
657
|
+
type: ApprovalType.WatchAsset,
|
|
658
|
+
requestData: {
|
|
659
|
+
id: suggestedAssetMeta.id,
|
|
660
|
+
interactingAddress: suggestedAssetMeta.interactingAddress,
|
|
661
|
+
asset: {
|
|
662
|
+
address: suggestedAssetMeta.asset.address,
|
|
663
|
+
decimals: suggestedAssetMeta.asset.decimals,
|
|
664
|
+
symbol: suggestedAssetMeta.asset.symbol,
|
|
665
|
+
image: suggestedAssetMeta.asset.image || null,
|
|
666
|
+
},
|
|
667
|
+
},
|
|
668
|
+
}, true);
|
|
669
|
+
}, _TokensController_getSelectedAccount = function _TokensController_getSelectedAccount() {
|
|
670
|
+
return this.messagingSystem.call('AccountsController:getSelectedAccount');
|
|
671
|
+
}, _TokensController_getSelectedAddress = function _TokensController_getSelectedAddress() {
|
|
672
|
+
// If the address is not defined (or empty), we fallback to the currently selected account's address
|
|
673
|
+
const account = this.messagingSystem.call('AccountsController:getAccount', __classPrivateFieldGet(this, _TokensController_selectedAccountId, "f"));
|
|
674
|
+
return account?.address || '';
|
|
675
|
+
};
|
|
676
|
+
export default TokensController;
|
|
16
677
|
//# sourceMappingURL=TokensController.mjs.map
|