@metamask/assets-controllers 37.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 +50 -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} +10 -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} +5 -5
- 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} +9 -9
- 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} +10 -10
- 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 +24 -18
- 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-54JUUBXY.mjs +0 -813
- package/dist/chunk-54JUUBXY.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-ADJ3IFJH.js +0 -813
- package/dist/chunk-ADJ3IFJH.js.map +0 -1
- package/dist/chunk-AX522TDL.mjs +0 -85
- package/dist/chunk-AX522TDL.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-CN53OZAM.mjs +0 -428
- package/dist/chunk-CN53OZAM.mjs.map +0 -1
- package/dist/chunk-CP3HC7AQ.mjs +0 -12
- package/dist/chunk-CP3HC7AQ.mjs.map +0 -1
- package/dist/chunk-CUFSPB7T.mjs +0 -530
- package/dist/chunk-CUFSPB7T.mjs.map +0 -1
- package/dist/chunk-F6L3DFOZ.js +0 -204
- package/dist/chunk-F6L3DFOZ.js.map +0 -1
- package/dist/chunk-GHG3DOUK.js +0 -428
- package/dist/chunk-GHG3DOUK.js.map +0 -1
- package/dist/chunk-HJ5GXVDT.mjs +0 -157
- package/dist/chunk-HJ5GXVDT.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-JTXPJ6TK.mjs +0 -68
- package/dist/chunk-JTXPJ6TK.mjs.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-MZI3SDQN.js +0 -215
- package/dist/chunk-MZI3SDQN.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-SBWPU4VT.mjs +0 -204
- package/dist/chunk-SBWPU4VT.mjs.map +0 -1
- package/dist/chunk-SK2B36Q4.mjs +0 -1405
- package/dist/chunk-SK2B36Q4.mjs.map +0 -1
- package/dist/chunk-T5ZX5BV7.js +0 -157
- package/dist/chunk-T5ZX5BV7.js.map +0 -1
- package/dist/chunk-TFLYM4PY.mjs +0 -291
- package/dist/chunk-TFLYM4PY.mjs.map +0 -1
- package/dist/chunk-TTH3ES66.mjs +0 -1
- package/dist/chunk-TTH3ES66.mjs.map +0 -1
- package/dist/chunk-V6DNVROD.js +0 -348
- package/dist/chunk-V6DNVROD.js.map +0 -1
- package/dist/chunk-X2HRAVDO.js +0 -530
- package/dist/chunk-X2HRAVDO.js.map +0 -1
- package/dist/chunk-XC3SOOGC.js +0 -1
- package/dist/chunk-XC3SOOGC.js.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/chunk-ZG5MS2TO.js +0 -68
- package/dist/chunk-ZG5MS2TO.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,170 @@
|
|
|
1
|
+
import type { AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedEvmAccountChangeEvent } from "@metamask/accounts-controller";
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
3
|
+
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
4
|
+
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
5
|
+
import { type Hex } from "@metamask/utils";
|
|
6
|
+
import type { AbstractTokenPricesService } from "./token-prices-service/abstract-token-prices-service.mjs";
|
|
7
|
+
import type { TokensControllerGetStateAction, TokensControllerStateChangeEvent } from "./TokensController.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* @type Token
|
|
10
|
+
*
|
|
11
|
+
* Token representation
|
|
12
|
+
* @property address - Hex address of the token contract
|
|
13
|
+
* @property decimals - Number of decimals the token uses
|
|
14
|
+
* @property symbol - Symbol of the token
|
|
15
|
+
* @property aggregators - An array containing the token's aggregators
|
|
16
|
+
* @property image - Image of the token, url or bit32 image
|
|
17
|
+
* @property hasBalanceError - 'true' if there is an error while updating the token balance
|
|
18
|
+
* @property isERC721 - 'true' if the token is a ERC721 token
|
|
19
|
+
* @property name - Name of the token
|
|
20
|
+
*/
|
|
21
|
+
export type Token = {
|
|
22
|
+
address: string;
|
|
23
|
+
decimals: number;
|
|
24
|
+
symbol: string;
|
|
25
|
+
aggregators?: string[];
|
|
26
|
+
image?: string;
|
|
27
|
+
hasBalanceError?: boolean;
|
|
28
|
+
isERC721?: boolean;
|
|
29
|
+
name?: string;
|
|
30
|
+
};
|
|
31
|
+
export type ContractExchangeRates = {
|
|
32
|
+
[address: string]: number | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type MarketDataDetails = {
|
|
35
|
+
tokenAddress: `0x${string}`;
|
|
36
|
+
currency: string;
|
|
37
|
+
allTimeHigh: number;
|
|
38
|
+
allTimeLow: number;
|
|
39
|
+
circulatingSupply: number;
|
|
40
|
+
dilutedMarketCap: number;
|
|
41
|
+
high1d: number;
|
|
42
|
+
low1d: number;
|
|
43
|
+
marketCap: number;
|
|
44
|
+
marketCapPercentChange1d: number;
|
|
45
|
+
price: number;
|
|
46
|
+
priceChange1d: number;
|
|
47
|
+
pricePercentChange1d: number;
|
|
48
|
+
pricePercentChange1h: number;
|
|
49
|
+
pricePercentChange1y: number;
|
|
50
|
+
pricePercentChange7d: number;
|
|
51
|
+
pricePercentChange14d: number;
|
|
52
|
+
pricePercentChange30d: number;
|
|
53
|
+
pricePercentChange200d: number;
|
|
54
|
+
totalVolume: number;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Represents a mapping of token contract addresses to their market data.
|
|
58
|
+
*/
|
|
59
|
+
export type ContractMarketData = Record<Hex, MarketDataDetails>;
|
|
60
|
+
/**
|
|
61
|
+
* The external actions available to the {@link TokenRatesController}.
|
|
62
|
+
*/
|
|
63
|
+
export type AllowedActions = TokensControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction;
|
|
64
|
+
/**
|
|
65
|
+
* The external events available to the {@link TokenRatesController}.
|
|
66
|
+
*/
|
|
67
|
+
export type AllowedEvents = TokensControllerStateChangeEvent | NetworkControllerStateChangeEvent | AccountsControllerSelectedEvmAccountChangeEvent;
|
|
68
|
+
/**
|
|
69
|
+
* The name of the {@link TokenRatesController}.
|
|
70
|
+
*/
|
|
71
|
+
export declare const controllerName = "TokenRatesController";
|
|
72
|
+
/**
|
|
73
|
+
* @type TokenRatesState
|
|
74
|
+
*
|
|
75
|
+
* Token rates controller state
|
|
76
|
+
* @property marketData - Market data for tokens, keyed by chain ID and then token contract address.
|
|
77
|
+
*/
|
|
78
|
+
export type TokenRatesControllerState = {
|
|
79
|
+
marketData: Record<Hex, Record<Hex, MarketDataDetails>>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The action that can be performed to get the state of the {@link TokenRatesController}.
|
|
83
|
+
*/
|
|
84
|
+
export type TokenRatesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, TokenRatesControllerState>;
|
|
85
|
+
/**
|
|
86
|
+
* The actions that can be performed using the {@link TokenRatesController}.
|
|
87
|
+
*/
|
|
88
|
+
export type TokenRatesControllerActions = TokenRatesControllerGetStateAction;
|
|
89
|
+
/**
|
|
90
|
+
* The event that {@link TokenRatesController} can emit.
|
|
91
|
+
*/
|
|
92
|
+
export type TokenRatesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, TokenRatesControllerState>;
|
|
93
|
+
/**
|
|
94
|
+
* The events that {@link TokenRatesController} can emit.
|
|
95
|
+
*/
|
|
96
|
+
export type TokenRatesControllerEvents = TokenRatesControllerStateChangeEvent;
|
|
97
|
+
/**
|
|
98
|
+
* The messenger of the {@link TokenRatesController} for communication.
|
|
99
|
+
*/
|
|
100
|
+
export type TokenRatesControllerMessenger = RestrictedControllerMessenger<typeof controllerName, TokenRatesControllerActions | AllowedActions, TokenRatesControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
101
|
+
/**
|
|
102
|
+
* Get the default {@link TokenRatesController} state.
|
|
103
|
+
*
|
|
104
|
+
* @returns The default {@link TokenRatesController} state.
|
|
105
|
+
*/
|
|
106
|
+
export declare const getDefaultTokenRatesControllerState: () => TokenRatesControllerState;
|
|
107
|
+
/**
|
|
108
|
+
* Controller that passively polls on a set interval for token-to-fiat exchange rates
|
|
109
|
+
* for tokens stored in the TokensController
|
|
110
|
+
*/
|
|
111
|
+
export declare class TokenRatesController extends StaticIntervalPollingController<typeof controllerName, TokenRatesControllerState, TokenRatesControllerMessenger> {
|
|
112
|
+
#private;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a TokenRatesController instance.
|
|
115
|
+
*
|
|
116
|
+
* @param options - The controller options.
|
|
117
|
+
* @param options.interval - The polling interval in ms
|
|
118
|
+
* @param options.disabled - Boolean to track if network requests are blocked
|
|
119
|
+
* @param options.tokenPricesService - An object in charge of retrieving token price
|
|
120
|
+
* @param options.messenger - The controller messenger instance for communication
|
|
121
|
+
* @param options.state - Initial state to set on this controller
|
|
122
|
+
*/
|
|
123
|
+
constructor({ interval, disabled, tokenPricesService, messenger, state, }: {
|
|
124
|
+
interval?: number;
|
|
125
|
+
disabled?: boolean;
|
|
126
|
+
tokenPricesService: AbstractTokenPricesService;
|
|
127
|
+
messenger: TokenRatesControllerMessenger;
|
|
128
|
+
state?: Partial<TokenRatesControllerState>;
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Allows controller to make active and passive polling requests
|
|
132
|
+
*/
|
|
133
|
+
enable(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Blocks controller from making network calls
|
|
136
|
+
*/
|
|
137
|
+
disable(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Start (or restart) polling.
|
|
140
|
+
*/
|
|
141
|
+
start(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Stop polling.
|
|
144
|
+
*/
|
|
145
|
+
stop(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Updates exchange rates for all tokens.
|
|
148
|
+
*/
|
|
149
|
+
updateExchangeRates(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Updates exchange rates for all tokens.
|
|
152
|
+
*
|
|
153
|
+
* @param options - The options to fetch exchange rates.
|
|
154
|
+
* @param options.chainId - The chain ID.
|
|
155
|
+
* @param options.nativeCurrency - The ticker for the chain.
|
|
156
|
+
*/
|
|
157
|
+
updateExchangeRatesByChainId({ chainId, nativeCurrency, }: {
|
|
158
|
+
chainId: Hex;
|
|
159
|
+
nativeCurrency: string;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Updates token rates for the given networkClientId
|
|
163
|
+
*
|
|
164
|
+
* @param networkClientId - The network client ID used to get a ticker value.
|
|
165
|
+
* @returns The controller state.
|
|
166
|
+
*/
|
|
167
|
+
_executePoll(networkClientId: NetworkClientId): Promise<void>;
|
|
168
|
+
}
|
|
169
|
+
export default TokenRatesController;
|
|
170
|
+
//# sourceMappingURL=TokenRatesController.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenRatesController.d.mts","sourceRoot":"","sources":["../src/TokenRatesController.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,18 +1,448 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "./chunk-CUFSPB7T.mjs";
|
|
7
|
-
import "./chunk-XQO3EG4J.mjs";
|
|
8
|
-
import "./chunk-TTH3ES66.mjs";
|
|
9
|
-
import "./chunk-JTXPJ6TK.mjs";
|
|
10
|
-
import "./chunk-BZEAPSD5.mjs";
|
|
11
|
-
import "./chunk-XUI43LEZ.mjs";
|
|
12
|
-
export {
|
|
13
|
-
TokenRatesController,
|
|
14
|
-
controllerName,
|
|
15
|
-
TokenRatesController_default as default,
|
|
16
|
-
getDefaultTokenRatesControllerState
|
|
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;
|
|
17
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 _TokenRatesController_instances, _TokenRatesController_handle, _TokenRatesController_pollState, _TokenRatesController_tokenPricesService, _TokenRatesController_inProcessExchangeRateUpdates, _TokenRatesController_selectedAccountId, _TokenRatesController_disabled, _TokenRatesController_chainId, _TokenRatesController_ticker, _TokenRatesController_interval, _TokenRatesController_allTokens, _TokenRatesController_allDetectedTokens, _TokenRatesController_subscribeToTokensStateChange, _TokenRatesController_subscribeToNetworkStateChange, _TokenRatesController_subscribeToAccountChange, _TokenRatesController_getTokenAddresses, _TokenRatesController_getSelectedAccount, _TokenRatesController_getChainIdAndTicker, _TokenRatesController_getTokensControllerState, _TokenRatesController_stopPoll, _TokenRatesController_poll, _TokenRatesController_fetchAndMapExchangeRates, _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency, _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency;
|
|
13
|
+
import { safelyExecute, toChecksumHexAddress, FALL_BACK_VS_CURRENCY, toHex } from "@metamask/controller-utils";
|
|
14
|
+
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
15
|
+
import { createDeferredPromise } from "@metamask/utils";
|
|
16
|
+
import $lodash from "lodash";
|
|
17
|
+
const { isEqual } = $lodash;
|
|
18
|
+
import { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from "./assetsUtil.mjs";
|
|
19
|
+
import { fetchExchangeRate as fetchNativeCurrencyExchangeRate } from "./crypto-compare-service/index.mjs";
|
|
20
|
+
import { ZERO_ADDRESS } from "./token-prices-service/codefi-v2.mjs";
|
|
21
|
+
const DEFAULT_INTERVAL = 180000;
|
|
22
|
+
var PollState;
|
|
23
|
+
(function (PollState) {
|
|
24
|
+
PollState["Active"] = "Active";
|
|
25
|
+
PollState["Inactive"] = "Inactive";
|
|
26
|
+
})(PollState || (PollState = {}));
|
|
27
|
+
/**
|
|
28
|
+
* The name of the {@link TokenRatesController}.
|
|
29
|
+
*/
|
|
30
|
+
export const controllerName = 'TokenRatesController';
|
|
31
|
+
/**
|
|
32
|
+
* Uses the CryptoCompare API to fetch the exchange rate between one currency
|
|
33
|
+
* and another, i.e., the multiplier to apply the amount of one currency in
|
|
34
|
+
* order to convert it to another.
|
|
35
|
+
*
|
|
36
|
+
* @param args - The arguments to this function.
|
|
37
|
+
* @param args.from - The currency to convert from.
|
|
38
|
+
* @param args.to - The currency to convert to.
|
|
39
|
+
* @returns The exchange rate between `fromCurrency` to `toCurrency` if one
|
|
40
|
+
* exists, or null if one does not.
|
|
41
|
+
*/
|
|
42
|
+
async function getCurrencyConversionRate({ from, to, }) {
|
|
43
|
+
const includeUSDRate = false;
|
|
44
|
+
try {
|
|
45
|
+
const result = await fetchNativeCurrencyExchangeRate(to, from, includeUSDRate);
|
|
46
|
+
return result.conversionRate;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof Error &&
|
|
50
|
+
error.message.includes('market does not exist for this coin pair')) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const tokenRatesControllerMetadata = {
|
|
57
|
+
marketData: { persist: true, anonymous: false },
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Get the default {@link TokenRatesController} state.
|
|
61
|
+
*
|
|
62
|
+
* @returns The default {@link TokenRatesController} state.
|
|
63
|
+
*/
|
|
64
|
+
export const getDefaultTokenRatesControllerState = () => {
|
|
65
|
+
return {
|
|
66
|
+
marketData: {},
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Controller that passively polls on a set interval for token-to-fiat exchange rates
|
|
71
|
+
* for tokens stored in the TokensController
|
|
72
|
+
*/
|
|
73
|
+
export class TokenRatesController extends StaticIntervalPollingController {
|
|
74
|
+
/**
|
|
75
|
+
* Creates a TokenRatesController instance.
|
|
76
|
+
*
|
|
77
|
+
* @param options - The controller options.
|
|
78
|
+
* @param options.interval - The polling interval in ms
|
|
79
|
+
* @param options.disabled - Boolean to track if network requests are blocked
|
|
80
|
+
* @param options.tokenPricesService - An object in charge of retrieving token price
|
|
81
|
+
* @param options.messenger - The controller messenger instance for communication
|
|
82
|
+
* @param options.state - Initial state to set on this controller
|
|
83
|
+
*/
|
|
84
|
+
constructor({ interval = DEFAULT_INTERVAL, disabled = false, tokenPricesService, messenger, state, }) {
|
|
85
|
+
super({
|
|
86
|
+
name: controllerName,
|
|
87
|
+
messenger,
|
|
88
|
+
state: { ...getDefaultTokenRatesControllerState(), ...state },
|
|
89
|
+
metadata: tokenRatesControllerMetadata,
|
|
90
|
+
});
|
|
91
|
+
_TokenRatesController_instances.add(this);
|
|
92
|
+
_TokenRatesController_handle.set(this, void 0);
|
|
93
|
+
_TokenRatesController_pollState.set(this, PollState.Inactive);
|
|
94
|
+
_TokenRatesController_tokenPricesService.set(this, void 0);
|
|
95
|
+
_TokenRatesController_inProcessExchangeRateUpdates.set(this, {});
|
|
96
|
+
_TokenRatesController_selectedAccountId.set(this, void 0);
|
|
97
|
+
_TokenRatesController_disabled.set(this, void 0);
|
|
98
|
+
_TokenRatesController_chainId.set(this, void 0);
|
|
99
|
+
_TokenRatesController_ticker.set(this, void 0);
|
|
100
|
+
_TokenRatesController_interval.set(this, void 0);
|
|
101
|
+
_TokenRatesController_allTokens.set(this, void 0);
|
|
102
|
+
_TokenRatesController_allDetectedTokens.set(this, void 0);
|
|
103
|
+
this.setIntervalLength(interval);
|
|
104
|
+
__classPrivateFieldSet(this, _TokenRatesController_tokenPricesService, tokenPricesService, "f");
|
|
105
|
+
__classPrivateFieldSet(this, _TokenRatesController_disabled, disabled, "f");
|
|
106
|
+
__classPrivateFieldSet(this, _TokenRatesController_interval, interval, "f");
|
|
107
|
+
const { chainId: currentChainId, ticker: currentTicker } = __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getChainIdAndTicker).call(this);
|
|
108
|
+
__classPrivateFieldSet(this, _TokenRatesController_chainId, currentChainId, "f");
|
|
109
|
+
__classPrivateFieldSet(this, _TokenRatesController_ticker, currentTicker, "f");
|
|
110
|
+
__classPrivateFieldSet(this, _TokenRatesController_selectedAccountId, __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getSelectedAccount).call(this).id, "f");
|
|
111
|
+
const { allTokens, allDetectedTokens } = __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getTokensControllerState).call(this);
|
|
112
|
+
__classPrivateFieldSet(this, _TokenRatesController_allTokens, allTokens, "f");
|
|
113
|
+
__classPrivateFieldSet(this, _TokenRatesController_allDetectedTokens, allDetectedTokens, "f");
|
|
114
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_subscribeToTokensStateChange).call(this);
|
|
115
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_subscribeToNetworkStateChange).call(this);
|
|
116
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_subscribeToAccountChange).call(this);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Allows controller to make active and passive polling requests
|
|
120
|
+
*/
|
|
121
|
+
enable() {
|
|
122
|
+
__classPrivateFieldSet(this, _TokenRatesController_disabled, false, "f");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Blocks controller from making network calls
|
|
126
|
+
*/
|
|
127
|
+
disable() {
|
|
128
|
+
__classPrivateFieldSet(this, _TokenRatesController_disabled, true, "f");
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Start (or restart) polling.
|
|
132
|
+
*/
|
|
133
|
+
async start() {
|
|
134
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_stopPoll).call(this);
|
|
135
|
+
__classPrivateFieldSet(this, _TokenRatesController_pollState, PollState.Active, "f");
|
|
136
|
+
await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_poll).call(this);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Stop polling.
|
|
140
|
+
*/
|
|
141
|
+
stop() {
|
|
142
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_stopPoll).call(this);
|
|
143
|
+
__classPrivateFieldSet(this, _TokenRatesController_pollState, PollState.Inactive, "f");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Updates exchange rates for all tokens.
|
|
147
|
+
*/
|
|
148
|
+
async updateExchangeRates() {
|
|
149
|
+
await this.updateExchangeRatesByChainId({
|
|
150
|
+
chainId: __classPrivateFieldGet(this, _TokenRatesController_chainId, "f"),
|
|
151
|
+
nativeCurrency: __classPrivateFieldGet(this, _TokenRatesController_ticker, "f"),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Updates exchange rates for all tokens.
|
|
156
|
+
*
|
|
157
|
+
* @param options - The options to fetch exchange rates.
|
|
158
|
+
* @param options.chainId - The chain ID.
|
|
159
|
+
* @param options.nativeCurrency - The ticker for the chain.
|
|
160
|
+
*/
|
|
161
|
+
async updateExchangeRatesByChainId({ chainId, nativeCurrency, }) {
|
|
162
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_disabled, "f")) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const tokenAddresses = __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getTokenAddresses).call(this, chainId);
|
|
166
|
+
const updateKey = `${chainId}:${nativeCurrency}`;
|
|
167
|
+
if (updateKey in __classPrivateFieldGet(this, _TokenRatesController_inProcessExchangeRateUpdates, "f")) {
|
|
168
|
+
// This prevents redundant updates
|
|
169
|
+
// This promise is resolved after the in-progress update has finished,
|
|
170
|
+
// and state has been updated.
|
|
171
|
+
await __classPrivateFieldGet(this, _TokenRatesController_inProcessExchangeRateUpdates, "f")[updateKey];
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const { promise: inProgressUpdate, resolve: updateSucceeded, reject: updateFailed, } = createDeferredPromise({ suppressUnhandledRejection: true });
|
|
175
|
+
__classPrivateFieldGet(this, _TokenRatesController_inProcessExchangeRateUpdates, "f")[updateKey] = inProgressUpdate;
|
|
176
|
+
try {
|
|
177
|
+
const contractInformations = await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRates).call(this, {
|
|
178
|
+
tokenAddresses,
|
|
179
|
+
chainId,
|
|
180
|
+
nativeCurrency,
|
|
181
|
+
});
|
|
182
|
+
const marketData = {
|
|
183
|
+
[chainId]: {
|
|
184
|
+
...(contractInformations ?? {}),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
this.update((state) => {
|
|
188
|
+
state.marketData = marketData;
|
|
189
|
+
});
|
|
190
|
+
updateSucceeded();
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
updateFailed(error);
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
delete __classPrivateFieldGet(this, _TokenRatesController_inProcessExchangeRateUpdates, "f")[updateKey];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Updates token rates for the given networkClientId
|
|
202
|
+
*
|
|
203
|
+
* @param networkClientId - The network client ID used to get a ticker value.
|
|
204
|
+
* @returns The controller state.
|
|
205
|
+
*/
|
|
206
|
+
async _executePoll(networkClientId) {
|
|
207
|
+
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
|
|
208
|
+
await this.updateExchangeRatesByChainId({
|
|
209
|
+
chainId: networkClient.configuration.chainId,
|
|
210
|
+
nativeCurrency: networkClient.configuration.ticker,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
_TokenRatesController_handle = new WeakMap(), _TokenRatesController_pollState = new WeakMap(), _TokenRatesController_tokenPricesService = new WeakMap(), _TokenRatesController_inProcessExchangeRateUpdates = new WeakMap(), _TokenRatesController_selectedAccountId = new WeakMap(), _TokenRatesController_disabled = new WeakMap(), _TokenRatesController_chainId = new WeakMap(), _TokenRatesController_ticker = new WeakMap(), _TokenRatesController_interval = new WeakMap(), _TokenRatesController_allTokens = new WeakMap(), _TokenRatesController_allDetectedTokens = new WeakMap(), _TokenRatesController_instances = new WeakSet(), _TokenRatesController_subscribeToTokensStateChange = function _TokenRatesController_subscribeToTokensStateChange() {
|
|
215
|
+
this.messagingSystem.subscribe('TokensController:stateChange',
|
|
216
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
218
|
+
async ({ allTokens, allDetectedTokens }) => {
|
|
219
|
+
const previousTokenAddresses = __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getTokenAddresses).call(this, __classPrivateFieldGet(this, _TokenRatesController_chainId, "f"));
|
|
220
|
+
__classPrivateFieldSet(this, _TokenRatesController_allTokens, allTokens, "f");
|
|
221
|
+
__classPrivateFieldSet(this, _TokenRatesController_allDetectedTokens, allDetectedTokens, "f");
|
|
222
|
+
const newTokenAddresses = __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getTokenAddresses).call(this, __classPrivateFieldGet(this, _TokenRatesController_chainId, "f"));
|
|
223
|
+
if (!isEqual(previousTokenAddresses, newTokenAddresses) &&
|
|
224
|
+
__classPrivateFieldGet(this, _TokenRatesController_pollState, "f") === PollState.Active) {
|
|
225
|
+
await this.updateExchangeRates();
|
|
226
|
+
}
|
|
227
|
+
}, ({ allTokens, allDetectedTokens }) => {
|
|
228
|
+
return { allTokens, allDetectedTokens };
|
|
229
|
+
});
|
|
230
|
+
}, _TokenRatesController_subscribeToNetworkStateChange = function _TokenRatesController_subscribeToNetworkStateChange() {
|
|
231
|
+
this.messagingSystem.subscribe('NetworkController:stateChange',
|
|
232
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
234
|
+
async ({ selectedNetworkClientId }) => {
|
|
235
|
+
const { configuration: { chainId, ticker }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
236
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_chainId, "f") !== chainId || __classPrivateFieldGet(this, _TokenRatesController_ticker, "f") !== ticker) {
|
|
237
|
+
this.update((state) => {
|
|
238
|
+
state.marketData = {};
|
|
239
|
+
});
|
|
240
|
+
__classPrivateFieldSet(this, _TokenRatesController_chainId, chainId, "f");
|
|
241
|
+
__classPrivateFieldSet(this, _TokenRatesController_ticker, ticker, "f");
|
|
242
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_pollState, "f") === PollState.Active) {
|
|
243
|
+
await this.updateExchangeRates();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}, _TokenRatesController_subscribeToAccountChange = function _TokenRatesController_subscribeToAccountChange() {
|
|
248
|
+
this.messagingSystem.subscribe('AccountsController:selectedEvmAccountChange',
|
|
249
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
251
|
+
async (selectedAccount) => {
|
|
252
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_selectedAccountId, "f") !== selectedAccount.id) {
|
|
253
|
+
__classPrivateFieldSet(this, _TokenRatesController_selectedAccountId, selectedAccount.id, "f");
|
|
254
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_pollState, "f") === PollState.Active) {
|
|
255
|
+
await this.updateExchangeRates();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}, _TokenRatesController_getTokenAddresses = function _TokenRatesController_getTokenAddresses(chainId) {
|
|
260
|
+
const selectedAccount = this.messagingSystem.call('AccountsController:getAccount', __classPrivateFieldGet(this, _TokenRatesController_selectedAccountId, "f"));
|
|
261
|
+
const selectedAddress = selectedAccount?.address ?? '';
|
|
262
|
+
const tokens = __classPrivateFieldGet(this, _TokenRatesController_allTokens, "f")[chainId]?.[selectedAddress] || [];
|
|
263
|
+
const detectedTokens = __classPrivateFieldGet(this, _TokenRatesController_allDetectedTokens, "f")[chainId]?.[selectedAddress] || [];
|
|
264
|
+
return [
|
|
265
|
+
...new Set([...tokens, ...detectedTokens].map((token) => toHex(toChecksumHexAddress(token.address)))),
|
|
266
|
+
].sort();
|
|
267
|
+
}, _TokenRatesController_getSelectedAccount = function _TokenRatesController_getSelectedAccount() {
|
|
268
|
+
const selectedAccount = this.messagingSystem.call('AccountsController:getSelectedAccount');
|
|
269
|
+
return selectedAccount;
|
|
270
|
+
}, _TokenRatesController_getChainIdAndTicker = function _TokenRatesController_getChainIdAndTicker() {
|
|
271
|
+
const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
|
|
272
|
+
const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
273
|
+
return {
|
|
274
|
+
chainId: networkClient.configuration.chainId,
|
|
275
|
+
ticker: networkClient.configuration.ticker,
|
|
276
|
+
};
|
|
277
|
+
}, _TokenRatesController_getTokensControllerState = function _TokenRatesController_getTokensControllerState() {
|
|
278
|
+
const { allTokens, allDetectedTokens } = this.messagingSystem.call('TokensController:getState');
|
|
279
|
+
return {
|
|
280
|
+
allTokens,
|
|
281
|
+
allDetectedTokens,
|
|
282
|
+
};
|
|
283
|
+
}, _TokenRatesController_stopPoll = function _TokenRatesController_stopPoll() {
|
|
284
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_handle, "f")) {
|
|
285
|
+
clearTimeout(__classPrivateFieldGet(this, _TokenRatesController_handle, "f"));
|
|
286
|
+
}
|
|
287
|
+
}, _TokenRatesController_poll =
|
|
288
|
+
/**
|
|
289
|
+
* Poll for exchange rate updates.
|
|
290
|
+
*/
|
|
291
|
+
async function _TokenRatesController_poll() {
|
|
292
|
+
await safelyExecute(() => this.updateExchangeRates());
|
|
293
|
+
// Poll using recursive `setTimeout` instead of `setInterval` so that
|
|
294
|
+
// requests don't stack if they take longer than the polling interval
|
|
295
|
+
__classPrivateFieldSet(this, _TokenRatesController_handle, setTimeout(() => {
|
|
296
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
297
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
298
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_poll).call(this);
|
|
299
|
+
}, __classPrivateFieldGet(this, _TokenRatesController_interval, "f")), "f");
|
|
300
|
+
}, _TokenRatesController_fetchAndMapExchangeRates =
|
|
301
|
+
/**
|
|
302
|
+
* Uses the token prices service to retrieve exchange rates for tokens in a
|
|
303
|
+
* particular currency.
|
|
304
|
+
*
|
|
305
|
+
* If the price API does not support the given chain ID, returns an empty
|
|
306
|
+
* object.
|
|
307
|
+
*
|
|
308
|
+
* If the price API does not support the given currency, retrieves exchange
|
|
309
|
+
* rates in a known currency instead, then converts those rates using the
|
|
310
|
+
* exchange rate between the known currency and desired currency.
|
|
311
|
+
*
|
|
312
|
+
* @param args - The arguments to this function.
|
|
313
|
+
* @param args.tokenAddresses - Addresses for tokens.
|
|
314
|
+
* @param args.chainId - The EIP-155 ID of the chain where the tokens live.
|
|
315
|
+
* @param args.nativeCurrency - The native currency in which to request
|
|
316
|
+
* exchange rates.
|
|
317
|
+
* @returns A map from token address to its exchange rate in the native
|
|
318
|
+
* currency, or an empty map if no exchange rates can be obtained for the
|
|
319
|
+
* chain ID.
|
|
320
|
+
*/
|
|
321
|
+
async function _TokenRatesController_fetchAndMapExchangeRates({ tokenAddresses, chainId, nativeCurrency, }) {
|
|
322
|
+
if (!__classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").validateChainIdSupported(chainId)) {
|
|
323
|
+
return tokenAddresses.reduce((obj, tokenAddress) => {
|
|
324
|
+
obj = {
|
|
325
|
+
...obj,
|
|
326
|
+
[tokenAddress]: undefined,
|
|
327
|
+
};
|
|
328
|
+
return obj;
|
|
329
|
+
}, {});
|
|
330
|
+
}
|
|
331
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").validateCurrencySupported(nativeCurrency)) {
|
|
332
|
+
return await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency).call(this, {
|
|
333
|
+
tokenAddresses,
|
|
334
|
+
chainId,
|
|
335
|
+
nativeCurrency,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency).call(this, {
|
|
339
|
+
tokenAddresses,
|
|
340
|
+
nativeCurrency,
|
|
341
|
+
});
|
|
342
|
+
}, _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency =
|
|
343
|
+
/**
|
|
344
|
+
* Retrieves prices in the given currency for the given tokens on the given
|
|
345
|
+
* chain. Ensures that token addresses are checksum addresses.
|
|
346
|
+
*
|
|
347
|
+
* @param args - The arguments to this function.
|
|
348
|
+
* @param args.tokenAddresses - Addresses for tokens.
|
|
349
|
+
* @param args.chainId - The EIP-155 ID of the chain where the tokens live.
|
|
350
|
+
* @param args.nativeCurrency - The native currency in which to request
|
|
351
|
+
* prices.
|
|
352
|
+
* @returns A map of the token addresses (as checksums) to their prices in the
|
|
353
|
+
* native currency.
|
|
354
|
+
*/
|
|
355
|
+
async function _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency({ tokenAddresses, chainId, nativeCurrency, }) {
|
|
356
|
+
let contractNativeInformations;
|
|
357
|
+
const tokenPricesByTokenAddress = await reduceInBatchesSerially({
|
|
358
|
+
values: [...tokenAddresses].sort(),
|
|
359
|
+
batchSize: TOKEN_PRICES_BATCH_SIZE,
|
|
360
|
+
eachBatch: async (allTokenPricesByTokenAddress, batch) => {
|
|
361
|
+
const tokenPricesByTokenAddressForBatch = await __classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").fetchTokenPrices({
|
|
362
|
+
tokenAddresses: batch,
|
|
363
|
+
chainId,
|
|
364
|
+
currency: nativeCurrency,
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
...allTokenPricesByTokenAddress,
|
|
368
|
+
...tokenPricesByTokenAddressForBatch,
|
|
369
|
+
};
|
|
370
|
+
},
|
|
371
|
+
initialResult: {},
|
|
372
|
+
});
|
|
373
|
+
contractNativeInformations = tokenPricesByTokenAddress;
|
|
374
|
+
// fetch for native token
|
|
375
|
+
if (tokenAddresses.length === 0) {
|
|
376
|
+
const contractNativeInformationsNative = await __classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").fetchTokenPrices({
|
|
377
|
+
tokenAddresses: [],
|
|
378
|
+
chainId,
|
|
379
|
+
currency: nativeCurrency,
|
|
380
|
+
});
|
|
381
|
+
contractNativeInformations = {
|
|
382
|
+
[ZERO_ADDRESS]: {
|
|
383
|
+
currency: nativeCurrency,
|
|
384
|
+
...contractNativeInformationsNative[ZERO_ADDRESS],
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return Object.entries(contractNativeInformations).reduce((obj, [tokenAddress, token]) => {
|
|
389
|
+
obj = {
|
|
390
|
+
...obj,
|
|
391
|
+
[tokenAddress]: { ...token },
|
|
392
|
+
};
|
|
393
|
+
return obj;
|
|
394
|
+
}, {});
|
|
395
|
+
}, _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency =
|
|
396
|
+
/**
|
|
397
|
+
* If the price API does not support a given native currency, then we need to
|
|
398
|
+
* convert it to a fallback currency and feed that currency into the price
|
|
399
|
+
* API, then convert the prices to our desired native currency.
|
|
400
|
+
*
|
|
401
|
+
* @param args - The arguments to this function.
|
|
402
|
+
* @param args.tokenAddresses - Addresses for tokens.
|
|
403
|
+
* @param args.nativeCurrency - The native currency in which to request
|
|
404
|
+
* prices.
|
|
405
|
+
* @returns A map of the token addresses (as checksums) to their prices in the
|
|
406
|
+
* native currency.
|
|
407
|
+
*/
|
|
408
|
+
async function _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency({ tokenAddresses, nativeCurrency, }) {
|
|
409
|
+
const [contractExchangeInformations, fallbackCurrencyToNativeCurrencyConversionRate,] = await Promise.all([
|
|
410
|
+
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency).call(this, {
|
|
411
|
+
tokenAddresses,
|
|
412
|
+
chainId: __classPrivateFieldGet(this, _TokenRatesController_chainId, "f"),
|
|
413
|
+
nativeCurrency: FALL_BACK_VS_CURRENCY,
|
|
414
|
+
}),
|
|
415
|
+
getCurrencyConversionRate({
|
|
416
|
+
from: FALL_BACK_VS_CURRENCY,
|
|
417
|
+
to: nativeCurrency,
|
|
418
|
+
}),
|
|
419
|
+
]);
|
|
420
|
+
if (fallbackCurrencyToNativeCurrencyConversionRate === null) {
|
|
421
|
+
return {};
|
|
422
|
+
}
|
|
423
|
+
// Converts the price in the fallback currency to the native currency
|
|
424
|
+
const convertFallbackToNative = (value) => value !== undefined && value !== null
|
|
425
|
+
? value * fallbackCurrencyToNativeCurrencyConversionRate
|
|
426
|
+
: undefined;
|
|
427
|
+
const updatedContractExchangeRates = Object.entries(contractExchangeInformations).reduce((acc, [tokenAddress, token]) => {
|
|
428
|
+
acc = {
|
|
429
|
+
...acc,
|
|
430
|
+
[tokenAddress]: {
|
|
431
|
+
...token,
|
|
432
|
+
currency: nativeCurrency,
|
|
433
|
+
price: convertFallbackToNative(token.price),
|
|
434
|
+
marketCap: convertFallbackToNative(token.marketCap),
|
|
435
|
+
allTimeHigh: convertFallbackToNative(token.allTimeHigh),
|
|
436
|
+
allTimeLow: convertFallbackToNative(token.allTimeLow),
|
|
437
|
+
totalVolume: convertFallbackToNative(token.totalVolume),
|
|
438
|
+
high1d: convertFallbackToNative(token.high1d),
|
|
439
|
+
low1d: convertFallbackToNative(token.low1d),
|
|
440
|
+
dilutedMarketCap: convertFallbackToNative(token.dilutedMarketCap),
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
return acc;
|
|
444
|
+
}, {});
|
|
445
|
+
return updatedContractExchangeRates;
|
|
446
|
+
};
|
|
447
|
+
export default TokenRatesController;
|
|
18
448
|
//# sourceMappingURL=TokenRatesController.mjs.map
|