@metamask/assets-controllers 38.0.0 → 38.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 +27 -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 +369 -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 +366 -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 +20 -15
- 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
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
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;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TokensController = exports.getDefaultTokensState = void 0;
|
|
19
|
+
const contracts_1 = require("@ethersproject/contracts");
|
|
20
|
+
const providers_1 = require("@ethersproject/providers");
|
|
21
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
22
|
+
const contract_metadata_1 = __importDefault(require("@metamask/contract-metadata"));
|
|
23
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
24
|
+
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
25
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
26
|
+
const async_mutex_1 = require("async-mutex");
|
|
27
|
+
const uuid_1 = require("uuid");
|
|
28
|
+
const assetsUtil_1 = require("./assetsUtil.cjs");
|
|
29
|
+
const ERC20Standard_1 = require("./Standards/ERC20Standard.cjs");
|
|
30
|
+
const ERC1155Standard_1 = require("./Standards/NftStandards/ERC1155/ERC1155Standard.cjs");
|
|
31
|
+
const token_service_1 = require("./token-service.cjs");
|
|
32
|
+
const metadata = {
|
|
33
|
+
tokens: {
|
|
34
|
+
persist: true,
|
|
35
|
+
anonymous: false,
|
|
36
|
+
},
|
|
37
|
+
ignoredTokens: {
|
|
38
|
+
persist: true,
|
|
39
|
+
anonymous: false,
|
|
40
|
+
},
|
|
41
|
+
detectedTokens: {
|
|
42
|
+
persist: true,
|
|
43
|
+
anonymous: false,
|
|
44
|
+
},
|
|
45
|
+
allTokens: {
|
|
46
|
+
persist: true,
|
|
47
|
+
anonymous: false,
|
|
48
|
+
},
|
|
49
|
+
allIgnoredTokens: {
|
|
50
|
+
persist: true,
|
|
51
|
+
anonymous: false,
|
|
52
|
+
},
|
|
53
|
+
allDetectedTokens: {
|
|
54
|
+
persist: true,
|
|
55
|
+
anonymous: false,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const controllerName = 'TokensController';
|
|
59
|
+
const getDefaultTokensState = () => {
|
|
60
|
+
return {
|
|
61
|
+
tokens: [],
|
|
62
|
+
ignoredTokens: [],
|
|
63
|
+
detectedTokens: [],
|
|
64
|
+
allTokens: {},
|
|
65
|
+
allIgnoredTokens: {},
|
|
66
|
+
allDetectedTokens: {},
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.getDefaultTokensState = getDefaultTokensState;
|
|
70
|
+
/**
|
|
71
|
+
* Controller that stores assets and exposes convenience methods
|
|
72
|
+
*/
|
|
73
|
+
class TokensController extends base_controller_1.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
|
+
...(0, exports.getDefaultTokensState)(),
|
|
89
|
+
...state,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
_TokensController_instances.add(this);
|
|
93
|
+
_TokensController_mutex.set(this, new async_mutex_1.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 = (0, controller_utils_1.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
|
+
(0, assetsUtil_1.formatIconUrlWithProxy)({
|
|
156
|
+
chainId: currentChainId,
|
|
157
|
+
tokenAddress: address,
|
|
158
|
+
}),
|
|
159
|
+
isERC721,
|
|
160
|
+
aggregators: (0, assetsUtil_1.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 = (0, controller_utils_1.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 = (0, controller_utils_1.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 = (0, controller_utils_1.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 !== controller_utils_1.ERC20) {
|
|
397
|
+
throw new Error(`Asset of type ${type} not supported`);
|
|
398
|
+
}
|
|
399
|
+
if (!asset.address) {
|
|
400
|
+
throw rpc_errors_1.rpcErrors.invalidParams('Address must be specified');
|
|
401
|
+
}
|
|
402
|
+
if (!(0, controller_utils_1.isValidHexAddress)(asset.address)) {
|
|
403
|
+
throw rpc_errors_1.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 rpc_errors_1.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 ${controller_utils_1.ERC721}`);
|
|
412
|
+
}
|
|
413
|
+
const provider = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getProvider).call(this, networkClientId);
|
|
414
|
+
const isErc1155 = await (0, controller_utils_1.safelyExecute)(() => new ERC1155Standard_1.ERC1155Standard(provider).contractSupportsBase1155Interface(asset.address));
|
|
415
|
+
if (isErc1155) {
|
|
416
|
+
throw rpc_errors_1.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 ${controller_utils_1.ERC1155}`);
|
|
420
|
+
}
|
|
421
|
+
const erc20 = new ERC20Standard_1.ERC20Standard(provider);
|
|
422
|
+
const [contractName, contractSymbol, contractDecimals] = await Promise.all([
|
|
423
|
+
(0, controller_utils_1.safelyExecute)(() => erc20.getTokenName(asset.address)),
|
|
424
|
+
(0, controller_utils_1.safelyExecute)(() => erc20.getTokenSymbol(asset.address)),
|
|
425
|
+
(0, controller_utils_1.safelyExecute)(async () => erc20.getTokenDecimals(asset.address)),
|
|
426
|
+
]);
|
|
427
|
+
asset.name = contractName;
|
|
428
|
+
// Validate symbol
|
|
429
|
+
if (!asset.symbol && !contractSymbol) {
|
|
430
|
+
throw rpc_errors_1.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 rpc_errors_1.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 rpc_errors_1.rpcErrors.invalidParams(`Invalid symbol: not a string`);
|
|
443
|
+
}
|
|
444
|
+
if (asset.symbol.length > 11) {
|
|
445
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid symbol "${asset.symbol}": longer than 11 characters`);
|
|
446
|
+
}
|
|
447
|
+
// Validate decimals
|
|
448
|
+
if (asset.decimals === undefined && contractDecimals === undefined) {
|
|
449
|
+
throw rpc_errors_1.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 rpc_errors_1.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 rpc_errors_1.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
|
+
exports.TokensController = TokensController;
|
|
498
|
+
_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 }) {
|
|
499
|
+
const selectedNetworkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
500
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
501
|
+
const { chainId } = selectedNetworkClient.configuration;
|
|
502
|
+
__classPrivateFieldGet(this, _TokensController_abortController, "f").abort();
|
|
503
|
+
__classPrivateFieldSet(this, _TokensController_abortController, new AbortController(), "f");
|
|
504
|
+
__classPrivateFieldSet(this, _TokensController_chainId, chainId, "f");
|
|
505
|
+
const selectedAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
506
|
+
this.update((state) => {
|
|
507
|
+
state.tokens = allTokens[chainId]?.[selectedAddress] || [];
|
|
508
|
+
state.ignoredTokens = allIgnoredTokens[chainId]?.[selectedAddress] || [];
|
|
509
|
+
state.detectedTokens =
|
|
510
|
+
allDetectedTokens[chainId]?.[selectedAddress] || [];
|
|
511
|
+
});
|
|
512
|
+
}, _TokensController_onSelectedAccountChange = function _TokensController_onSelectedAccountChange(selectedAccount) {
|
|
513
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
514
|
+
__classPrivateFieldSet(this, _TokensController_selectedAccountId, selectedAccount.id, "f");
|
|
515
|
+
this.update((state) => {
|
|
516
|
+
state.tokens = allTokens[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAccount.address] ?? [];
|
|
517
|
+
state.ignoredTokens =
|
|
518
|
+
allIgnoredTokens[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAccount.address] ?? [];
|
|
519
|
+
state.detectedTokens =
|
|
520
|
+
allDetectedTokens[__classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[selectedAccount.address] ?? [];
|
|
521
|
+
});
|
|
522
|
+
}, _TokensController_fetchTokenMetadata =
|
|
523
|
+
/**
|
|
524
|
+
* Fetch metadata for a token.
|
|
525
|
+
*
|
|
526
|
+
* @param tokenAddress - The address of the token.
|
|
527
|
+
* @returns The token metadata.
|
|
528
|
+
*/
|
|
529
|
+
async function _TokensController_fetchTokenMetadata(tokenAddress) {
|
|
530
|
+
try {
|
|
531
|
+
const token = await (0, token_service_1.fetchTokenMetadata)(__classPrivateFieldGet(this, _TokensController_chainId, "f"), tokenAddress, __classPrivateFieldGet(this, _TokensController_abortController, "f").signal);
|
|
532
|
+
return token;
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
if (error instanceof Error &&
|
|
536
|
+
error.message.includes(token_service_1.TOKEN_METADATA_NO_SUPPORT_ERROR)) {
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
541
|
+
}, _TokensController_updateTokensAttribute = function _TokensController_updateTokensAttribute(tokenList, tokenAttribute) {
|
|
542
|
+
const { tokens } = this.state;
|
|
543
|
+
const newTokens = tokens.map((token) => {
|
|
544
|
+
const newToken = tokenList[token.address.toLowerCase()];
|
|
545
|
+
return !token[tokenAttribute] && newToken?.[tokenAttribute]
|
|
546
|
+
? { ...token, [tokenAttribute]: newToken[tokenAttribute] }
|
|
547
|
+
: { ...token };
|
|
548
|
+
});
|
|
549
|
+
this.update((state) => {
|
|
550
|
+
state.tokens = newTokens;
|
|
551
|
+
});
|
|
552
|
+
}, _TokensController_detectIsERC721 =
|
|
553
|
+
/**
|
|
554
|
+
* Detects whether or not a token is ERC-721 compatible.
|
|
555
|
+
*
|
|
556
|
+
* @param tokenAddress - The token contract address.
|
|
557
|
+
* @param networkClientId - Optional network client ID to fetch contract info with.
|
|
558
|
+
* @returns A boolean indicating whether the token address passed in supports the EIP-721
|
|
559
|
+
* interface.
|
|
560
|
+
*/
|
|
561
|
+
async function _TokensController_detectIsERC721(tokenAddress, networkClientId) {
|
|
562
|
+
const checksumAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
|
|
563
|
+
// if this token is already in our contract metadata map we don't need
|
|
564
|
+
// to check against the contract
|
|
565
|
+
if (contract_metadata_1.default[checksumAddress]?.erc721 === true) {
|
|
566
|
+
return Promise.resolve(true);
|
|
567
|
+
}
|
|
568
|
+
else if (contract_metadata_1.default[checksumAddress]?.erc20 === true) {
|
|
569
|
+
return Promise.resolve(false);
|
|
570
|
+
}
|
|
571
|
+
const tokenContract = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_createEthersContract).call(this, tokenAddress, metamask_eth_abis_1.abiERC721, networkClientId);
|
|
572
|
+
try {
|
|
573
|
+
return await tokenContract.supportsInterface(controller_utils_1.ERC721_INTERFACE_ID);
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
// currently we see a variety of errors across different networks when
|
|
577
|
+
// token contracts are not ERC721 compatible. We need to figure out a better
|
|
578
|
+
// way of differentiating token interface types but for now if we get an error
|
|
579
|
+
// we have to assume the token is not ERC721 compatible.
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
}, _TokensController_getProvider = function _TokensController_getProvider(networkClientId) {
|
|
583
|
+
return new providers_1.Web3Provider(networkClientId
|
|
584
|
+
? this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).provider
|
|
585
|
+
: __classPrivateFieldGet(this, _TokensController_provider, "f"));
|
|
586
|
+
}, _TokensController_createEthersContract = function _TokensController_createEthersContract(tokenAddress, abi, networkClientId) {
|
|
587
|
+
const web3provider = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getProvider).call(this, networkClientId);
|
|
588
|
+
const tokenContract = new contracts_1.Contract(tokenAddress, abi, web3provider);
|
|
589
|
+
return tokenContract;
|
|
590
|
+
}, _TokensController_generateRandomId = function _TokensController_generateRandomId() {
|
|
591
|
+
return (0, uuid_1.v1)();
|
|
592
|
+
}, _TokensController_getNewAllTokensState = function _TokensController_getNewAllTokensState(params) {
|
|
593
|
+
const { newTokens, newIgnoredTokens, newDetectedTokens, interactingAddress, interactingChainId, } = params;
|
|
594
|
+
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
|
|
595
|
+
const userAddressToAddTokens = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getAddressOrSelectedAddress).call(this, interactingAddress);
|
|
596
|
+
const chainIdToAddTokens = interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f");
|
|
597
|
+
let newAllTokens = allTokens;
|
|
598
|
+
if (newTokens?.length ||
|
|
599
|
+
(newTokens &&
|
|
600
|
+
allTokens &&
|
|
601
|
+
allTokens[chainIdToAddTokens] &&
|
|
602
|
+
allTokens[chainIdToAddTokens][userAddressToAddTokens])) {
|
|
603
|
+
const networkTokens = allTokens[chainIdToAddTokens];
|
|
604
|
+
const newNetworkTokens = {
|
|
605
|
+
...networkTokens,
|
|
606
|
+
...{ [userAddressToAddTokens]: newTokens },
|
|
607
|
+
};
|
|
608
|
+
newAllTokens = {
|
|
609
|
+
...allTokens,
|
|
610
|
+
...{ [chainIdToAddTokens]: newNetworkTokens },
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
let newAllIgnoredTokens = allIgnoredTokens;
|
|
614
|
+
if (newIgnoredTokens?.length ||
|
|
615
|
+
(newIgnoredTokens &&
|
|
616
|
+
allIgnoredTokens &&
|
|
617
|
+
allIgnoredTokens[chainIdToAddTokens] &&
|
|
618
|
+
allIgnoredTokens[chainIdToAddTokens][userAddressToAddTokens])) {
|
|
619
|
+
const networkIgnoredTokens = allIgnoredTokens[chainIdToAddTokens];
|
|
620
|
+
const newIgnoredNetworkTokens = {
|
|
621
|
+
...networkIgnoredTokens,
|
|
622
|
+
...{ [userAddressToAddTokens]: newIgnoredTokens },
|
|
623
|
+
};
|
|
624
|
+
newAllIgnoredTokens = {
|
|
625
|
+
...allIgnoredTokens,
|
|
626
|
+
...{ [chainIdToAddTokens]: newIgnoredNetworkTokens },
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
let newAllDetectedTokens = allDetectedTokens;
|
|
630
|
+
if (newDetectedTokens?.length ||
|
|
631
|
+
(newDetectedTokens &&
|
|
632
|
+
allDetectedTokens &&
|
|
633
|
+
allDetectedTokens[chainIdToAddTokens] &&
|
|
634
|
+
allDetectedTokens[chainIdToAddTokens][userAddressToAddTokens])) {
|
|
635
|
+
const networkDetectedTokens = allDetectedTokens[chainIdToAddTokens];
|
|
636
|
+
const newDetectedNetworkTokens = {
|
|
637
|
+
...networkDetectedTokens,
|
|
638
|
+
...{ [userAddressToAddTokens]: newDetectedTokens },
|
|
639
|
+
};
|
|
640
|
+
newAllDetectedTokens = {
|
|
641
|
+
...allDetectedTokens,
|
|
642
|
+
...{ [chainIdToAddTokens]: newDetectedNetworkTokens },
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
return { newAllTokens, newAllIgnoredTokens, newAllDetectedTokens };
|
|
646
|
+
}, _TokensController_getAddressOrSelectedAddress = function _TokensController_getAddressOrSelectedAddress(address) {
|
|
647
|
+
if (address) {
|
|
648
|
+
return address;
|
|
649
|
+
}
|
|
650
|
+
return __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
651
|
+
}, _TokensController_isInteractingWithWallet = function _TokensController_isInteractingWithWallet(address) {
|
|
652
|
+
const selectedAddress = __classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this);
|
|
653
|
+
return selectedAddress === address;
|
|
654
|
+
}, _TokensController_requestApproval = async function _TokensController_requestApproval(suggestedAssetMeta) {
|
|
655
|
+
return this.messagingSystem.call('ApprovalController:addRequest', {
|
|
656
|
+
id: suggestedAssetMeta.id,
|
|
657
|
+
origin: controller_utils_1.ORIGIN_METAMASK,
|
|
658
|
+
type: controller_utils_1.ApprovalType.WatchAsset,
|
|
659
|
+
requestData: {
|
|
660
|
+
id: suggestedAssetMeta.id,
|
|
661
|
+
interactingAddress: suggestedAssetMeta.interactingAddress,
|
|
662
|
+
asset: {
|
|
663
|
+
address: suggestedAssetMeta.asset.address,
|
|
664
|
+
decimals: suggestedAssetMeta.asset.decimals,
|
|
665
|
+
symbol: suggestedAssetMeta.asset.symbol,
|
|
666
|
+
image: suggestedAssetMeta.asset.image || null,
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
}, true);
|
|
670
|
+
}, _TokensController_getSelectedAccount = function _TokensController_getSelectedAccount() {
|
|
671
|
+
return this.messagingSystem.call('AccountsController:getSelectedAccount');
|
|
672
|
+
}, _TokensController_getSelectedAddress = function _TokensController_getSelectedAddress() {
|
|
673
|
+
// If the address is not defined (or empty), we fallback to the currently selected account's address
|
|
674
|
+
const account = this.messagingSystem.call('AccountsController:getAccount', __classPrivateFieldGet(this, _TokensController_selectedAccountId, "f"));
|
|
675
|
+
return account?.address || '';
|
|
676
|
+
};
|
|
677
|
+
exports.default = TokensController;
|
|
678
|
+
//# sourceMappingURL=TokensController.cjs.map
|