@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/token-service.ts"],"names":[],"mappings":";;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,IAAM,sBAAsB;AAC5B,IAAM,kCACX;AAQF,SAAS,aAAa,SAAc;AAClC,QAAM,kBAAkB,YAAY,QAAQ,eAAe,IAAI,IAAI;AAGnE,SAAO,GAAG,mBAAmB,WAAW;AAAA,IACtC;AAAA,EACF,CAAC,oBAAoB,eAAe;AACtC;AASA,SAAS,oBAAoB,SAAc,cAAsB;AAG/D,SAAO,GAAG,mBAAmB,UAAU;AAAA,IACrC;AAAA,EACF,CAAC,YAAY,YAAY;AAC3B;AAEA,IAAM,2BAA2B;AAIjC,IAAM,iBAAiB;AAYvB,eAAsB,wBACpB,SACA,aACA,EAAE,UAAU,eAAe,IAAI,CAAC,GACd;AAClB,QAAM,WAAW,aAAa,OAAO;AACrC,QAAM,WAAW,MAAM,SAAS,UAAU,aAAa,OAAO;AAC9D,MAAI,UAAU;AACZ,UAAM,SAAS,MAAM,kBAAkB,QAAQ;AAC/C,QAAI,MAAM,QAAQ,MAAM,KAAK,YAAY,QAAQ,eAAe,GAAG;AACjE,aAAO,OAAO;AAAA,QACZ,CAAC,QACC,IAAI,YAAY,SAAS,WAAW,KAAK,IAAI,YAAY,UAAU;AAAA,MACvE;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAeA,eAAsB,mBACpB,SACA,cACA,aACA,EAAE,UAAU,eAAe,IAAI,CAAC,GACR;AACxB,MAAI,CAAC,+BAA+B,OAAO,GAAG;AAC5C,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,mBAAmB,oBAAoB,SAAS,YAAY;AAClE,QAAM,WAAW,MAAM,SAAS,kBAAkB,aAAa,OAAO;AACtE,MAAI,UAAU;AACZ,WAAO,kBAAkB,QAAQ;AAAA,EACnC;AACA,SAAO;AACT;AAUA,eAAe,SACb,QACA,aACA,SAC+B;AAC/B,QAAM,eAA4B;AAAA,IAChC,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACA,eAAa,UAAU,IAAI,OAAO,QAAQ;AAC1C,eAAa,QAAQ,IAAI,gBAAgB,kBAAkB;AAC3D,MAAI;AACF,WAAO,MAAM,aAAa,QAAQ,cAAc,OAAO;AAAA,EACzD,SAAS,OAAO;AACd,QAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc;AACzD,cAAQ,IAAI,oBAAoB;AAAA,IAClC;AAAA,EACF;AACA,SAAO;AACT;AASA,eAAe,kBAAkB,aAAyC;AACxE,QAAM,cAAc,MAAM,YAAY,KAAK;AAE3C,MAAI,aAAa,OAAO;AAGtB,UAAM,IAAI,MAAM,uBAAuB,YAAY,KAAK,EAAE;AAAA,EAC5D;AACA,SAAO;AACT","sourcesContent":["import {\n ChainId,\n convertHexToDecimal,\n timeoutFetch,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { isTokenListSupportedForNetwork } from './assetsUtil';\n\nexport const TOKEN_END_POINT_API = 'https://token.api.cx.metamask.io';\nexport const TOKEN_METADATA_NO_SUPPORT_ERROR =\n 'TokenService Error: Network does not support fetchTokenMetadata';\n\n/**\n * Get the tokens URL for a specific network.\n *\n * @param chainId - The chain ID of the network the tokens requested are on.\n * @returns The tokens URL.\n */\nfunction getTokensURL(chainId: Hex) {\n const occurrenceFloor = chainId === ChainId['linea-mainnet'] ? 1 : 3;\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${TOKEN_END_POINT_API}/tokens/${convertHexToDecimal(\n chainId,\n )}?occurrenceFloor=${occurrenceFloor}&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`;\n}\n\n/**\n * Get the token metadata URL for the given network and token.\n *\n * @param chainId - The chain ID of the network the token is on.\n * @param tokenAddress - The token address.\n * @returns The token metadata URL.\n */\nfunction getTokenMetadataURL(chainId: Hex, tokenAddress: string) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${TOKEN_END_POINT_API}/token/${convertHexToDecimal(\n chainId,\n )}?address=${tokenAddress}`;\n}\n\nconst tenSecondsInMilliseconds = 10_000;\n\n// Token list averages 1.6 MB in size\n// timeoutFetch by default has a 500ms timeout, which will almost always timeout given the response size.\nconst defaultTimeout = tenSecondsInMilliseconds;\n\n/**\n * Fetch the list of token metadata for a given network. This request is cancellable using the\n * abort signal passed in.\n *\n * @param chainId - The chain ID of the network the requested tokens are on.\n * @param abortSignal - The abort signal used to cancel the request if necessary.\n * @param options - Additional fetch options.\n * @param options.timeout - The fetch timeout.\n * @returns The token list, or `undefined` if the request was cancelled.\n */\nexport async function fetchTokenListByChainId(\n chainId: Hex,\n abortSignal: AbortSignal,\n { timeout = defaultTimeout } = {},\n): Promise<unknown> {\n const tokenURL = getTokensURL(chainId);\n const response = await queryApi(tokenURL, abortSignal, timeout);\n if (response) {\n const result = await parseJsonResponse(response);\n if (Array.isArray(result) && chainId === ChainId['linea-mainnet']) {\n return result.filter(\n (elm) =>\n elm.aggregators.includes('lineaTeam') || elm.aggregators.length >= 3,\n );\n }\n return result;\n }\n return undefined;\n}\n\n/**\n * Fetch metadata for the token address provided for a given network. This request is cancellable\n * using the abort signal passed in.\n *\n * @param chainId - The chain ID of the network the token is on.\n * @param tokenAddress - The address of the token to fetch metadata for.\n * @param abortSignal - The abort signal used to cancel the request if necessary.\n * @param options - Additional fetch options.\n * @param options.timeout - The fetch timeout.\n * @returns The token metadata, or `undefined` if the request was either aborted or failed.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport async function fetchTokenMetadata<T>(\n chainId: Hex,\n tokenAddress: string,\n abortSignal: AbortSignal,\n { timeout = defaultTimeout } = {},\n): Promise<T | undefined> {\n if (!isTokenListSupportedForNetwork(chainId)) {\n throw new Error(TOKEN_METADATA_NO_SUPPORT_ERROR);\n }\n const tokenMetadataURL = getTokenMetadataURL(chainId, tokenAddress);\n const response = await queryApi(tokenMetadataURL, abortSignal, timeout);\n if (response) {\n return parseJsonResponse(response) as Promise<T>;\n }\n return undefined;\n}\n\n/**\n * Perform fetch request against the api.\n *\n * @param apiURL - The URL of the API to fetch.\n * @param abortSignal - The abort signal used to cancel the request if necessary.\n * @param timeout - The fetch timeout.\n * @returns Promise resolving request response.\n */\nasync function queryApi(\n apiURL: string,\n abortSignal: AbortSignal,\n timeout: number,\n): Promise<Response | undefined> {\n const fetchOptions: RequestInit = {\n referrer: apiURL,\n referrerPolicy: 'no-referrer-when-downgrade',\n method: 'GET',\n mode: 'cors',\n signal: abortSignal,\n cache: 'default',\n };\n fetchOptions.headers = new window.Headers();\n fetchOptions.headers.set('Content-Type', 'application/json');\n try {\n return await timeoutFetch(apiURL, fetchOptions, timeout);\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n console.log('Request is aborted');\n }\n }\n return undefined;\n}\n\n/**\n * Parse an API response and return the response JSON data.\n *\n * @param apiResponse - The API response to parse.\n * @returns The response JSON data.\n * @throws Will throw if the response includes an error.\n */\nasync function parseJsonResponse(apiResponse: Response): Promise<unknown> {\n const responseObj = await apiResponse.json();\n // api may return errors as json without setting an error http status code\n if (responseObj?.error) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`TokenService Error: ${responseObj.error}`);\n }\n return responseObj;\n}\n"]}
|
package/dist/chunk-KPBNX6GP.mjs
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ethersBigNumberToBN,
|
|
3
|
-
getFormattedIpfsUrl
|
|
4
|
-
} from "./chunk-BZEAPSD5.mjs";
|
|
5
|
-
|
|
6
|
-
// src/Standards/NftStandards/ERC1155/ERC1155Standard.ts
|
|
7
|
-
import { Contract } from "@ethersproject/contracts";
|
|
8
|
-
import {
|
|
9
|
-
ERC1155,
|
|
10
|
-
ERC1155_INTERFACE_ID,
|
|
11
|
-
ERC1155_METADATA_URI_INTERFACE_ID,
|
|
12
|
-
ERC1155_TOKEN_RECEIVER_INTERFACE_ID,
|
|
13
|
-
safelyExecute,
|
|
14
|
-
timeoutFetch
|
|
15
|
-
} from "@metamask/controller-utils";
|
|
16
|
-
import { abiERC1155 } from "@metamask/metamask-eth-abis";
|
|
17
|
-
var ERC1155Standard = class {
|
|
18
|
-
constructor(provider) {
|
|
19
|
-
this.provider = provider;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Query if contract implements ERC1155 URI Metadata interface.
|
|
23
|
-
*
|
|
24
|
-
* @param address - ERC1155 asset contract address.
|
|
25
|
-
* @returns Promise resolving to whether the contract implements ERC1155 URI Metadata interface.
|
|
26
|
-
*/
|
|
27
|
-
async contractSupportsURIMetadataInterface(address) {
|
|
28
|
-
return this.contractSupportsInterface(
|
|
29
|
-
address,
|
|
30
|
-
ERC1155_METADATA_URI_INTERFACE_ID
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Query if contract implements ERC1155 Token Receiver interface.
|
|
35
|
-
*
|
|
36
|
-
* @param address - ERC1155 asset contract address.
|
|
37
|
-
* @returns Promise resolving to whether the contract implements ERC1155 Token Receiver interface.
|
|
38
|
-
*/
|
|
39
|
-
async contractSupportsTokenReceiverInterface(address) {
|
|
40
|
-
return this.contractSupportsInterface(
|
|
41
|
-
address,
|
|
42
|
-
ERC1155_TOKEN_RECEIVER_INTERFACE_ID
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Query if contract implements ERC1155 interface.
|
|
47
|
-
*
|
|
48
|
-
* @param address - ERC1155 asset contract address.
|
|
49
|
-
* @returns Promise resolving to whether the contract implements the base ERC1155 interface.
|
|
50
|
-
*/
|
|
51
|
-
async contractSupportsBase1155Interface(address) {
|
|
52
|
-
return this.contractSupportsInterface(address, ERC1155_INTERFACE_ID);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Query for tokenURI for a given asset.
|
|
56
|
-
*
|
|
57
|
-
* @param address - ERC1155 asset contract address.
|
|
58
|
-
* @param tokenId - ERC1155 asset identifier.
|
|
59
|
-
* @returns Promise resolving to the 'tokenURI'.
|
|
60
|
-
*/
|
|
61
|
-
async getTokenURI(address, tokenId) {
|
|
62
|
-
const contract = new Contract(address, abiERC1155, this.provider);
|
|
63
|
-
return contract.uri(tokenId);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Query for balance of a given ERC1155 token.
|
|
67
|
-
*
|
|
68
|
-
* @param contractAddress - ERC1155 asset contract address.
|
|
69
|
-
* @param address - Wallet public address.
|
|
70
|
-
* @param tokenId - ERC1155 asset identifier.
|
|
71
|
-
* @returns Promise resolving to the 'balanceOf'.
|
|
72
|
-
*/
|
|
73
|
-
async getBalanceOf(contractAddress, address, tokenId) {
|
|
74
|
-
const contract = new Contract(contractAddress, abiERC1155, this.provider);
|
|
75
|
-
const balance = await contract.balanceOf(address, tokenId);
|
|
76
|
-
return ethersBigNumberToBN(balance);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Transfer single ERC1155 token.
|
|
80
|
-
* When minting/creating tokens, the from arg MUST be set to 0x0 (i.e. zero address).
|
|
81
|
-
* When burning/destroying tokens, the to arg MUST be set to 0x0 (i.e. zero address).
|
|
82
|
-
*
|
|
83
|
-
* @param operator - ERC1155 token address.
|
|
84
|
-
* @param from - ERC1155 token holder.
|
|
85
|
-
* @param to - ERC1155 token recipient.
|
|
86
|
-
* @param id - ERC1155 token id.
|
|
87
|
-
* @param value - Number of tokens to be sent.
|
|
88
|
-
* @returns Promise resolving to the 'transferSingle'.
|
|
89
|
-
*/
|
|
90
|
-
async transferSingle(operator, from, to, id, value) {
|
|
91
|
-
const contract = new Contract(operator, abiERC1155, this.provider);
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
contract.transferSingle(
|
|
94
|
-
operator,
|
|
95
|
-
from,
|
|
96
|
-
to,
|
|
97
|
-
id,
|
|
98
|
-
value,
|
|
99
|
-
(error, result) => {
|
|
100
|
-
if (error) {
|
|
101
|
-
reject(error);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
resolve(result);
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Query for symbol for a given asset.
|
|
111
|
-
*
|
|
112
|
-
* @param address - ERC1155 asset contract address.
|
|
113
|
-
* @returns Promise resolving to the 'symbol'.
|
|
114
|
-
*/
|
|
115
|
-
async getAssetSymbol(address) {
|
|
116
|
-
const contract = new Contract(
|
|
117
|
-
address,
|
|
118
|
-
// Contract ABI fragment containing only the symbol method to fetch the symbol of the contract.
|
|
119
|
-
[
|
|
120
|
-
{
|
|
121
|
-
inputs: [],
|
|
122
|
-
name: "symbol",
|
|
123
|
-
outputs: [{ name: "_symbol", type: "string" }],
|
|
124
|
-
stateMutability: "view",
|
|
125
|
-
type: "function",
|
|
126
|
-
payable: false
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
this.provider
|
|
130
|
-
);
|
|
131
|
-
return contract.symbol();
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Query for name for a given asset.
|
|
135
|
-
*
|
|
136
|
-
* @param address - ERC1155 asset contract address.
|
|
137
|
-
* @returns Promise resolving to the 'name'.
|
|
138
|
-
*/
|
|
139
|
-
async getAssetName(address) {
|
|
140
|
-
const contract = new Contract(
|
|
141
|
-
address,
|
|
142
|
-
// Contract ABI fragment containing only the name method to fetch the name of the contract.
|
|
143
|
-
[
|
|
144
|
-
{
|
|
145
|
-
inputs: [],
|
|
146
|
-
name: "name",
|
|
147
|
-
outputs: [{ name: "_name", type: "string" }],
|
|
148
|
-
stateMutability: "view",
|
|
149
|
-
type: "function",
|
|
150
|
-
payable: false
|
|
151
|
-
}
|
|
152
|
-
],
|
|
153
|
-
this.provider
|
|
154
|
-
);
|
|
155
|
-
return contract.name();
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Query if a contract implements an interface.
|
|
159
|
-
*
|
|
160
|
-
* @param address - ERC1155 asset contract address.
|
|
161
|
-
* @param interfaceId - Interface identifier.
|
|
162
|
-
* @returns Promise resolving to whether the contract implements `interfaceID`.
|
|
163
|
-
*/
|
|
164
|
-
async contractSupportsInterface(address, interfaceId) {
|
|
165
|
-
const contract = new Contract(address, abiERC1155, this.provider);
|
|
166
|
-
return contract.supportsInterface(interfaceId);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Query if a contract implements an interface.
|
|
170
|
-
*
|
|
171
|
-
* @param address - Asset contract address.
|
|
172
|
-
* @param ipfsGateway - The user's preferred IPFS gateway.
|
|
173
|
-
* @param tokenId - tokenId of a given token in the contract.
|
|
174
|
-
* @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.
|
|
175
|
-
*/
|
|
176
|
-
async getDetails(address, ipfsGateway, tokenId) {
|
|
177
|
-
const isERC1155 = await this.contractSupportsBase1155Interface(address);
|
|
178
|
-
if (!isERC1155) {
|
|
179
|
-
throw new Error("This isn't a valid ERC1155 contract");
|
|
180
|
-
}
|
|
181
|
-
let image;
|
|
182
|
-
const [symbol, name, tokenURI] = await Promise.all([
|
|
183
|
-
safelyExecute(() => this.getAssetSymbol(address)),
|
|
184
|
-
safelyExecute(() => this.getAssetName(address)),
|
|
185
|
-
tokenId ? safelyExecute(
|
|
186
|
-
() => this.getTokenURI(address, tokenId).then(
|
|
187
|
-
(uri) => uri.startsWith("ipfs://") ? getFormattedIpfsUrl(ipfsGateway, uri, true) : uri
|
|
188
|
-
)
|
|
189
|
-
) : void 0
|
|
190
|
-
]);
|
|
191
|
-
if (tokenURI) {
|
|
192
|
-
try {
|
|
193
|
-
const response = await timeoutFetch(tokenURI);
|
|
194
|
-
const object = await response.json();
|
|
195
|
-
image = object?.image;
|
|
196
|
-
if (image?.startsWith("ipfs://")) {
|
|
197
|
-
image = getFormattedIpfsUrl(ipfsGateway, image, true);
|
|
198
|
-
}
|
|
199
|
-
} catch {
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
standard: ERC1155,
|
|
204
|
-
tokenURI,
|
|
205
|
-
image,
|
|
206
|
-
symbol,
|
|
207
|
-
name
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
export {
|
|
213
|
-
ERC1155Standard
|
|
214
|
-
};
|
|
215
|
-
//# sourceMappingURL=chunk-KPBNX6GP.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Standards/NftStandards/ERC1155/ERC1155Standard.ts"],"sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n ERC1155,\n ERC1155_INTERFACE_ID,\n ERC1155_METADATA_URI_INTERFACE_ID,\n ERC1155_TOKEN_RECEIVER_INTERFACE_ID,\n safelyExecute,\n timeoutFetch,\n} from '@metamask/controller-utils';\nimport { abiERC1155 } from '@metamask/metamask-eth-abis';\nimport type * as BN from 'bn.js';\n\nimport { getFormattedIpfsUrl, ethersBigNumberToBN } from '../../../assetsUtil';\n\nexport class ERC1155Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC1155 URI Metadata interface.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC1155 URI Metadata interface.\n */\n async contractSupportsURIMetadataInterface(\n address: string,\n ): Promise<boolean> {\n return this.contractSupportsInterface(\n address,\n ERC1155_METADATA_URI_INTERFACE_ID,\n );\n }\n\n /**\n * Query if contract implements ERC1155 Token Receiver interface.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC1155 Token Receiver interface.\n */\n async contractSupportsTokenReceiverInterface(\n address: string,\n ): Promise<boolean> {\n return this.contractSupportsInterface(\n address,\n ERC1155_TOKEN_RECEIVER_INTERFACE_ID,\n );\n }\n\n /**\n * Query if contract implements ERC1155 interface.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to whether the contract implements the base ERC1155 interface.\n */\n async contractSupportsBase1155Interface(address: string): Promise<boolean> {\n return this.contractSupportsInterface(address, ERC1155_INTERFACE_ID);\n }\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @param tokenId - ERC1155 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n async getTokenURI(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC1155, this.provider);\n return contract.uri(tokenId);\n }\n\n /**\n * Query for balance of a given ERC1155 token.\n *\n * @param contractAddress - ERC1155 asset contract address.\n * @param address - Wallet public address.\n * @param tokenId - ERC1155 asset identifier.\n * @returns Promise resolving to the 'balanceOf'.\n */\n async getBalanceOf(\n contractAddress: string,\n address: string,\n tokenId: string,\n ): Promise<BN> {\n const contract = new Contract(contractAddress, abiERC1155, this.provider);\n const balance = await contract.balanceOf(address, tokenId);\n return ethersBigNumberToBN(balance);\n }\n\n /**\n * Transfer single ERC1155 token.\n * When minting/creating tokens, the from arg MUST be set to 0x0 (i.e. zero address).\n * When burning/destroying tokens, the to arg MUST be set to 0x0 (i.e. zero address).\n *\n * @param operator - ERC1155 token address.\n * @param from - ERC1155 token holder.\n * @param to - ERC1155 token recipient.\n * @param id - ERC1155 token id.\n * @param value - Number of tokens to be sent.\n * @returns Promise resolving to the 'transferSingle'.\n */\n async transferSingle(\n operator: string,\n from: string,\n to: string,\n id: string,\n value: string,\n ): Promise<void> {\n const contract = new Contract(operator, abiERC1155, this.provider);\n return new Promise<void>((resolve, reject) => {\n contract.transferSingle(\n operator,\n from,\n to,\n id,\n value,\n (error: Error, result: void) => {\n /* istanbul ignore if */\n if (error) {\n reject(error);\n return;\n }\n resolve(result);\n },\n );\n });\n }\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getAssetSymbol(address: string): Promise<string> {\n const contract = new Contract(\n address,\n // Contract ABI fragment containing only the symbol method to fetch the symbol of the contract.\n [\n {\n inputs: [],\n name: 'symbol',\n outputs: [{ name: '_symbol', type: 'string' }],\n stateMutability: 'view',\n type: 'function',\n payable: false,\n },\n ],\n this.provider,\n );\n return contract.symbol();\n }\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n async getAssetName(address: string): Promise<string> {\n const contract = new Contract(\n address,\n // Contract ABI fragment containing only the name method to fetch the name of the contract.\n [\n {\n inputs: [],\n name: 'name',\n outputs: [{ name: '_name', type: 'string' }],\n stateMutability: 'view',\n type: 'function',\n payable: false,\n },\n ],\n this.provider,\n );\n return contract.name();\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - ERC1155 asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private async contractSupportsInterface(\n address: string,\n interfaceId: string,\n ): Promise<boolean> {\n const contract = new Contract(address, abiERC1155, this.provider);\n return contract.supportsInterface(interfaceId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n async getDetails(\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n image: string | undefined;\n name: string | undefined;\n symbol: string | undefined;\n }> {\n const isERC1155 = await this.contractSupportsBase1155Interface(address);\n\n if (!isERC1155) {\n throw new Error(\"This isn't a valid ERC1155 contract\");\n }\n\n let image;\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // Catch block should be kept empty to ignore exceptions, and\n // pass as much information as possible to the return statement\n }\n }\n\n // TODO consider querying to the metadata to get name.\n return {\n standard: ERC1155,\n tokenURI,\n image,\n symbol,\n name,\n };\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,gBAAgB;AAEzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAKpB,IAAM,kBAAN,MAAsB;AAAA,EAG3B,YAAY,UAAwB;AAClC,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,qCACJ,SACkB;AAClB,WAAO,KAAK;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,uCACJ,SACkB;AAClB,WAAO,KAA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A,QACN;AAAA,MACF,IACA;AAAA,IACN,CAAC;AAED,QAAI,UAAU;AACZ,UAAI;AACF,cAAM,WAAW,MAAM,aAAa,QAAQ;AAC5C,cAAM,SAAS,MAAM,SAAS,KAAK;AACnC,gBAAQ,QAAQ;AAChB,YAAI,OAAO,WAAW,SAAS,GAAG;AAChC,kBAAQ,oBAAoB,aAAa,OAAO,IAAI;AAAA,QACtD;AAAA,MACF,QAAQ;AAAA,MAGR;AAAA,IACF;AAGA,WAAO;AAAA,MACL,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/chunk-MZI3SDQN.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/assetsUtil.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _controllerutils = require('@metamask/controller-utils');
|
|
6
|
-
var _utils = require('@metamask/utils');
|
|
7
|
-
var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
|
|
8
|
-
var TOKEN_PRICES_BATCH_SIZE = 30;
|
|
9
|
-
function compareNftMetadata(newNftMetadata, nft) {
|
|
10
|
-
const keys = [
|
|
11
|
-
"image",
|
|
12
|
-
"backgroundColor",
|
|
13
|
-
"imagePreview",
|
|
14
|
-
"imageThumbnail",
|
|
15
|
-
"imageOriginal",
|
|
16
|
-
"animation",
|
|
17
|
-
"animationOriginal",
|
|
18
|
-
"externalLink",
|
|
19
|
-
"tokenURI"
|
|
20
|
-
];
|
|
21
|
-
const differentValues = keys.reduce((value, key) => {
|
|
22
|
-
if (newNftMetadata[key] && newNftMetadata[key] !== nft[key]) {
|
|
23
|
-
return value + 1;
|
|
24
|
-
}
|
|
25
|
-
return value;
|
|
26
|
-
}, 0);
|
|
27
|
-
return differentValues > 0;
|
|
28
|
-
}
|
|
29
|
-
function hasNewCollectionFields(newNftMetadata, nft) {
|
|
30
|
-
const keysNewNftMetadata = Object.keys(newNftMetadata.collection ?? {});
|
|
31
|
-
const keysExistingNft = new Set(Object.keys(nft.collection ?? {}));
|
|
32
|
-
return keysNewNftMetadata.some((key) => !keysExistingNft.has(key));
|
|
33
|
-
}
|
|
34
|
-
var aggregatorNameByKey = {
|
|
35
|
-
aave: "Aave",
|
|
36
|
-
bancor: "Bancor",
|
|
37
|
-
cmc: "CMC",
|
|
38
|
-
cryptocom: "Crypto.com",
|
|
39
|
-
coinGecko: "CoinGecko",
|
|
40
|
-
oneInch: "1inch",
|
|
41
|
-
paraswap: "Paraswap",
|
|
42
|
-
pmm: "PMM",
|
|
43
|
-
zapper: "Zapper",
|
|
44
|
-
zerion: "Zerion",
|
|
45
|
-
zeroEx: "0x",
|
|
46
|
-
synthetix: "Synthetix",
|
|
47
|
-
yearn: "Yearn",
|
|
48
|
-
apeswap: "ApeSwap",
|
|
49
|
-
binanceDex: "BinanceDex",
|
|
50
|
-
pancakeTop100: "PancakeTop100",
|
|
51
|
-
pancakeExtended: "PancakeExtended",
|
|
52
|
-
balancer: "Balancer",
|
|
53
|
-
quickswap: "QuickSwap",
|
|
54
|
-
matcha: "Matcha",
|
|
55
|
-
pangolinDex: "PangolinDex",
|
|
56
|
-
pangolinDexStableCoin: "PangolinDexStableCoin",
|
|
57
|
-
pangolinDexAvaxBridge: "PangolinDexAvaxBridge",
|
|
58
|
-
traderJoe: "TraderJoe",
|
|
59
|
-
airswapLight: "AirswapLight",
|
|
60
|
-
kleros: "Kleros"
|
|
61
|
-
};
|
|
62
|
-
var formatAggregatorNames = (aggregators) => {
|
|
63
|
-
return aggregators.map(
|
|
64
|
-
(key) => aggregatorNameByKey[key] || `${key[0].toUpperCase()}${key.substring(1, key.length)}`
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
var formatIconUrlWithProxy = ({
|
|
68
|
-
chainId,
|
|
69
|
-
tokenAddress
|
|
70
|
-
}) => {
|
|
71
|
-
const chainIdDecimal = _controllerutils.convertHexToDecimal.call(void 0, chainId).toString();
|
|
72
|
-
return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;
|
|
73
|
-
};
|
|
74
|
-
var SupportedTokenDetectionNetworks = /* @__PURE__ */ ((SupportedTokenDetectionNetworks2) => {
|
|
75
|
-
SupportedTokenDetectionNetworks2["mainnet"] = "0x1";
|
|
76
|
-
SupportedTokenDetectionNetworks2["bsc"] = "0x38";
|
|
77
|
-
SupportedTokenDetectionNetworks2["polygon"] = "0x89";
|
|
78
|
-
SupportedTokenDetectionNetworks2["avax"] = "0xa86a";
|
|
79
|
-
SupportedTokenDetectionNetworks2["aurora"] = "0x4e454152";
|
|
80
|
-
SupportedTokenDetectionNetworks2["linea_goerli"] = "0xe704";
|
|
81
|
-
SupportedTokenDetectionNetworks2["linea_mainnet"] = "0xe708";
|
|
82
|
-
SupportedTokenDetectionNetworks2["arbitrum"] = "0xa4b1";
|
|
83
|
-
SupportedTokenDetectionNetworks2["optimism"] = "0xa";
|
|
84
|
-
SupportedTokenDetectionNetworks2["base"] = "0x2105";
|
|
85
|
-
SupportedTokenDetectionNetworks2["zksync"] = "0x144";
|
|
86
|
-
SupportedTokenDetectionNetworks2["cronos"] = "0x19";
|
|
87
|
-
SupportedTokenDetectionNetworks2["celo"] = "0xa4ec";
|
|
88
|
-
SupportedTokenDetectionNetworks2["gnosis"] = "0x64";
|
|
89
|
-
SupportedTokenDetectionNetworks2["fantom"] = "0xfa";
|
|
90
|
-
SupportedTokenDetectionNetworks2["polygon_zkevm"] = "0x44d";
|
|
91
|
-
SupportedTokenDetectionNetworks2["moonbeam"] = "0x504";
|
|
92
|
-
SupportedTokenDetectionNetworks2["moonriver"] = "0x505";
|
|
93
|
-
return SupportedTokenDetectionNetworks2;
|
|
94
|
-
})(SupportedTokenDetectionNetworks || {});
|
|
95
|
-
function isTokenDetectionSupportedForNetwork(chainId) {
|
|
96
|
-
return Object.values(SupportedTokenDetectionNetworks).includes(chainId);
|
|
97
|
-
}
|
|
98
|
-
function isTokenListSupportedForNetwork(chainId) {
|
|
99
|
-
return isTokenDetectionSupportedForNetwork(chainId);
|
|
100
|
-
}
|
|
101
|
-
function removeIpfsProtocolPrefix(ipfsUrl) {
|
|
102
|
-
if (ipfsUrl.startsWith("ipfs://ipfs/")) {
|
|
103
|
-
return ipfsUrl.replace("ipfs://ipfs/", "");
|
|
104
|
-
} else if (ipfsUrl.startsWith("ipfs://")) {
|
|
105
|
-
return ipfsUrl.replace("ipfs://", "");
|
|
106
|
-
}
|
|
107
|
-
throw new Error("this method should not be used with non ipfs urls");
|
|
108
|
-
}
|
|
109
|
-
async function getIpfsCIDv1AndPath(ipfsUrl) {
|
|
110
|
-
const url = removeIpfsProtocolPrefix(ipfsUrl);
|
|
111
|
-
const index = url.indexOf("/");
|
|
112
|
-
const cid = index !== -1 ? url.substring(0, index) : url;
|
|
113
|
-
const path = index !== -1 ? url.substring(index) : void 0;
|
|
114
|
-
const { CID } = await Promise.resolve().then(() => _interopRequireWildcard(require("multiformats")));
|
|
115
|
-
return {
|
|
116
|
-
cid: CID.parse(cid).toV1().toString(),
|
|
117
|
-
path
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async function getFormattedIpfsUrl(ipfsGateway, ipfsUrl, subdomainSupported) {
|
|
121
|
-
const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));
|
|
122
|
-
if (subdomainSupported) {
|
|
123
|
-
const { cid, path } = await getIpfsCIDv1AndPath(ipfsUrl);
|
|
124
|
-
return `${protocol}//${cid}.ipfs.${host}${path ?? ""}`;
|
|
125
|
-
}
|
|
126
|
-
const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);
|
|
127
|
-
return `${origin}/ipfs/${cidAndPath}`;
|
|
128
|
-
}
|
|
129
|
-
function addUrlProtocolPrefix(urlString) {
|
|
130
|
-
if (!urlString.match(/(^http:\/\/)|(^https:\/\/)/u)) {
|
|
131
|
-
return `https://${urlString}`;
|
|
132
|
-
}
|
|
133
|
-
return urlString;
|
|
134
|
-
}
|
|
135
|
-
function ethersBigNumberToBN(bigNumber) {
|
|
136
|
-
return new (0, _bnjs2.default)(_utils.remove0x.call(void 0, bigNumber.toHexString()), "hex");
|
|
137
|
-
}
|
|
138
|
-
function divideIntoBatches(values, { batchSize }) {
|
|
139
|
-
const batches = [];
|
|
140
|
-
for (let i = 0; i < values.length; i += batchSize) {
|
|
141
|
-
batches.push(values.slice(i, i + batchSize));
|
|
142
|
-
}
|
|
143
|
-
return batches;
|
|
144
|
-
}
|
|
145
|
-
async function reduceInBatchesSerially({
|
|
146
|
-
values,
|
|
147
|
-
batchSize,
|
|
148
|
-
eachBatch,
|
|
149
|
-
initialResult
|
|
150
|
-
}) {
|
|
151
|
-
const batches = divideIntoBatches(values, { batchSize });
|
|
152
|
-
let workingResult = initialResult;
|
|
153
|
-
for (const [index, batch] of batches.entries()) {
|
|
154
|
-
workingResult = await eachBatch(workingResult, batch, index);
|
|
155
|
-
}
|
|
156
|
-
const finalResult = workingResult;
|
|
157
|
-
return finalResult;
|
|
158
|
-
}
|
|
159
|
-
async function fetchTokenContractExchangeRates({
|
|
160
|
-
tokenPricesService,
|
|
161
|
-
nativeCurrency,
|
|
162
|
-
tokenAddresses,
|
|
163
|
-
chainId
|
|
164
|
-
}) {
|
|
165
|
-
const isChainIdSupported = tokenPricesService.validateChainIdSupported(chainId);
|
|
166
|
-
const isCurrencySupported = tokenPricesService.validateCurrencySupported(nativeCurrency);
|
|
167
|
-
if (!isChainIdSupported || !isCurrencySupported) {
|
|
168
|
-
return {};
|
|
169
|
-
}
|
|
170
|
-
const tokenPricesByTokenAddress = await reduceInBatchesSerially({
|
|
171
|
-
values: [...tokenAddresses].sort(),
|
|
172
|
-
batchSize: TOKEN_PRICES_BATCH_SIZE,
|
|
173
|
-
eachBatch: async (allTokenPricesByTokenAddress, batch) => {
|
|
174
|
-
const tokenPricesByTokenAddressForBatch = await tokenPricesService.fetchTokenPrices({
|
|
175
|
-
tokenAddresses: batch,
|
|
176
|
-
chainId,
|
|
177
|
-
currency: nativeCurrency
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
...allTokenPricesByTokenAddress,
|
|
181
|
-
...tokenPricesByTokenAddressForBatch
|
|
182
|
-
};
|
|
183
|
-
},
|
|
184
|
-
initialResult: {}
|
|
185
|
-
});
|
|
186
|
-
return Object.entries(tokenPricesByTokenAddress).reduce(
|
|
187
|
-
(obj, [tokenAddress, tokenPrice]) => {
|
|
188
|
-
return {
|
|
189
|
-
...obj,
|
|
190
|
-
[_controllerutils.toChecksumHexAddress.call(void 0, tokenAddress)]: tokenPrice?.price
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
{}
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
exports.TOKEN_PRICES_BATCH_SIZE = TOKEN_PRICES_BATCH_SIZE; exports.compareNftMetadata = compareNftMetadata; exports.hasNewCollectionFields = hasNewCollectionFields; exports.formatAggregatorNames = formatAggregatorNames; exports.formatIconUrlWithProxy = formatIconUrlWithProxy; exports.SupportedTokenDetectionNetworks = SupportedTokenDetectionNetworks; exports.isTokenDetectionSupportedForNetwork = isTokenDetectionSupportedForNetwork; exports.isTokenListSupportedForNetwork = isTokenListSupportedForNetwork; exports.removeIpfsProtocolPrefix = removeIpfsProtocolPrefix; exports.getIpfsCIDv1AndPath = getIpfsCIDv1AndPath; exports.getFormattedIpfsUrl = getFormattedIpfsUrl; exports.addUrlProtocolPrefix = addUrlProtocolPrefix; exports.ethersBigNumberToBN = ethersBigNumberToBN; exports.divideIntoBatches = divideIntoBatches; exports.reduceInBatchesSerially = reduceInBatchesSerially; exports.fetchTokenContractExchangeRates = fetchTokenContractExchangeRates;
|
|
215
|
-
//# sourceMappingURL=chunk-MZI3SDQN.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assetsUtil.ts"],"names":["SupportedTokenDetectionNetworks"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AAUR,IAAM,0BAA0B;AAWhC,SAAS,mBAAmB,gBAA6B,KAAU;AACxE,QAAM,OAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,kBAAkB,KAAK,OAAO,CAAC,OAAO,QAAQ;AAClD,QAAI,eAAe,GAAG,KAAK,eAAe,GAAG,MAAM,IAAI,GAAG,GAAG;AAC3D,aAAO,QAAQ;AAAA,IACjB;AACA,WAAO;AAAA,EACT,GAAG,CAAC;AACJ,SAAO,kBAAkB;AAC3B;AAQO,SAAS,uBACd,gBACA,KACS;AACT,QAAM,qBAAqB,OAAO,KAAK,eAAe,cAAc,CAAC,CAAC;AACtE,QAAM,kBAAkB,IAAI,IAAI,OAAO,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC;AAEjE,SAAO,mBAAmB,KAAK,CAAC,QAAQ,CAAC,gBAAgB,IAAI,GAAG,CAAC;AACnE;AAEA,IAAM,sBAA8C;AAAA,EAClD,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,WAAW;AAAA,EACX,WA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AAO,OAAO,QAAQ,yBAAyB,EAAE;AAAA,IAC/C,CAAC,KAAK,CAAC,cAAc,UAAU,MAAM;AACnC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,qBAAqB,YAAY,CAAC,GAAG,YAAY;AAAA,MACpD;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AACF","sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport {\n convertHexToDecimal,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport type { Nft, NftMetadata } from './NftController';\nimport type { AbstractTokenPricesService } from './token-prices-service';\nimport { type ContractExchangeRates } from './TokenRatesController';\n\n/**\n * The maximum number of token addresses that should be sent to the Price API in\n * a single request.\n */\nexport const TOKEN_PRICES_BATCH_SIZE = 30;\n\n/**\n * Compares nft metadata entries to any nft entry.\n * We need this method when comparing a new fetched nft metadata, in case a entry changed to a defined value,\n * there's a need to update the nft in state.\n *\n * @param newNftMetadata - Nft metadata object.\n * @param nft - Nft object to compare with.\n * @returns Whether there are differences.\n */\nexport function compareNftMetadata(newNftMetadata: NftMetadata, nft: Nft) {\n const keys: (keyof NftMetadata)[] = [\n 'image',\n 'backgroundColor',\n 'imagePreview',\n 'imageThumbnail',\n 'imageOriginal',\n 'animation',\n 'animationOriginal',\n 'externalLink',\n 'tokenURI',\n ];\n const differentValues = keys.reduce((value, key) => {\n if (newNftMetadata[key] && newNftMetadata[key] !== nft[key]) {\n return value + 1;\n }\n return value;\n }, 0);\n return differentValues > 0;\n}\n\n/**\n * Checks whether the existing nft object has all the keys of the new incoming nft metadata object\n * @param newNftMetadata - New nft metadata object\n * @param nft - Existing nft object to compare with\n * @returns Whether the existing nft object has all the new keys from the new Nft metadata object\n */\nexport function hasNewCollectionFields(\n newNftMetadata: NftMetadata,\n nft: Nft,\n): boolean {\n const keysNewNftMetadata = Object.keys(newNftMetadata.collection ?? {});\n const keysExistingNft = new Set(Object.keys(nft.collection ?? {}));\n\n return keysNewNftMetadata.some((key) => !keysExistingNft.has(key));\n}\n\nconst aggregatorNameByKey: Record<string, string> = {\n aave: 'Aave',\n bancor: 'Bancor',\n cmc: 'CMC',\n cryptocom: 'Crypto.com',\n coinGecko: 'CoinGecko',\n oneInch: '1inch',\n paraswap: 'Paraswap',\n pmm: 'PMM',\n zapper: 'Zapper',\n zerion: 'Zerion',\n zeroEx: '0x',\n synthetix: 'Synthetix',\n yearn: 'Yearn',\n apeswap: 'ApeSwap',\n binanceDex: 'BinanceDex',\n pancakeTop100: 'PancakeTop100',\n pancakeExtended: 'PancakeExtended',\n balancer: 'Balancer',\n quickswap: 'QuickSwap',\n matcha: 'Matcha',\n pangolinDex: 'PangolinDex',\n pangolinDexStableCoin: 'PangolinDexStableCoin',\n pangolinDexAvaxBridge: 'PangolinDexAvaxBridge',\n traderJoe: 'TraderJoe',\n airswapLight: 'AirswapLight',\n kleros: 'Kleros',\n};\n\n/**\n * Formats aggregator names to presentable format.\n *\n * @param aggregators - List of token list names in camelcase.\n * @returns Formatted aggregator names.\n */\nexport const formatAggregatorNames = (aggregators: string[]) => {\n return aggregators.map(\n (key) =>\n aggregatorNameByKey[key] ||\n `${key[0].toUpperCase()}${key.substring(1, key.length)}`,\n );\n};\n\n/**\n * Format token list assets to use image proxy from Codefi.\n *\n * @param params - Object that contains chainID and tokenAddress.\n * @param params.chainId - ChainID of network in 0x-prefixed hexadecimal format.\n * @param params.tokenAddress - Address of token in mixed or lowercase.\n * @returns Formatted image url\n */\nexport const formatIconUrlWithProxy = ({\n chainId,\n tokenAddress,\n}: {\n chainId: Hex;\n tokenAddress: string;\n}) => {\n const chainIdDecimal = convertHexToDecimal(chainId).toString();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;\n};\n\n/**\n * Networks where token detection is supported - Values are in hex format\n */\nexport enum SupportedTokenDetectionNetworks {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n mainnet = '0x1', // decimal: 1\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n bsc = '0x38', // decimal: 56\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n polygon = '0x89', // decimal: 137\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n avax = '0xa86a', // decimal: 43114\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n aurora = '0x4e454152', // decimal: 1313161554\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n linea_goerli = '0xe704', // decimal: 59140\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n linea_mainnet = '0xe708', // decimal: 59144\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n arbitrum = '0xa4b1', // decimal: 42161\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n optimism = '0xa', // decimal: 10\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n base = '0x2105', // decimal: 8453\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n zksync = '0x144', // decimal: 324\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n cronos = '0x19', // decimal: 25\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n celo = '0xa4ec', // decimal: 42220\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n gnosis = '0x64', // decimal: 100\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n fantom = '0xfa', // decimal: 250\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n polygon_zkevm = '0x44d', // decimal: 1101\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n moonbeam = '0x504', // decimal: 1284\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n moonriver = '0x505', // decimal: 1285\n}\n\n/**\n * Check if token detection is enabled for certain networks.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports token detection\n */\nexport function isTokenDetectionSupportedForNetwork(chainId: Hex): boolean {\n return Object.values<Hex>(SupportedTokenDetectionNetworks).includes(chainId);\n}\n\n/**\n * Check if token list polling is enabled for a given network.\n * Currently this method is used to support e2e testing for consumers of this package.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports tokenlists\n */\nexport function isTokenListSupportedForNetwork(chainId: Hex): boolean {\n return isTokenDetectionSupportedForNetwork(chainId);\n}\n\n/**\n * Removes IPFS protocol prefix from input string.\n *\n * @param ipfsUrl - An IPFS url (e.g. ipfs://{content id})\n * @returns IPFS content identifier and (possibly) path in a string\n * @throws Will throw if the url passed is not IPFS.\n */\nexport function removeIpfsProtocolPrefix(ipfsUrl: string) {\n if (ipfsUrl.startsWith('ipfs://ipfs/')) {\n return ipfsUrl.replace('ipfs://ipfs/', '');\n } else if (ipfsUrl.startsWith('ipfs://')) {\n return ipfsUrl.replace('ipfs://', '');\n }\n // this method should not be used with non-ipfs urls (i.e. startsWith('ipfs://') === true)\n throw new Error('this method should not be used with non ipfs urls');\n}\n\n/**\n * Extracts content identifier and path from an input string.\n *\n * @param ipfsUrl - An IPFS URL minus the IPFS protocol prefix\n * @returns IFPS content identifier (cid) and sub path as string.\n * @throws Will throw if the url passed is not ipfs.\n */\nexport async function getIpfsCIDv1AndPath(ipfsUrl: string): Promise<{\n cid: string;\n path?: string;\n}> {\n const url = removeIpfsProtocolPrefix(ipfsUrl);\n\n // check if there is a path\n // (CID is everything preceding first forward slash, path is everything after)\n const index = url.indexOf('/');\n const cid = index !== -1 ? url.substring(0, index) : url;\n const path = index !== -1 ? url.substring(index) : undefined;\n\n const { CID } = await import('multiformats');\n // We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)\n // because most cid v0s appear to be incompatible with IPFS subdomains\n return {\n cid: CID.parse(cid).toV1().toString(),\n path,\n };\n}\n\n/**\n * Formats URL correctly for use retrieving assets hosted on IPFS.\n *\n * @param ipfsGateway - The users preferred IPFS gateway (full URL or just host).\n * @param ipfsUrl - The IFPS URL pointed at the asset.\n * @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.\n * @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.\n */\nexport async function getFormattedIpfsUrl(\n ipfsGateway: string,\n ipfsUrl: string,\n subdomainSupported: boolean,\n): Promise<string> {\n const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));\n if (subdomainSupported) {\n const { cid, path } = await getIpfsCIDv1AndPath(ipfsUrl);\n return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;\n }\n const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);\n return `${origin}/ipfs/${cidAndPath}`;\n}\n\n/**\n * Adds URL protocol prefix to input URL string if missing.\n *\n * @param urlString - An IPFS URL.\n * @returns A URL with a https:// prepended.\n */\nexport function addUrlProtocolPrefix(urlString: string): string {\n if (!urlString.match(/(^http:\\/\\/)|(^https:\\/\\/)/u)) {\n return `https://${urlString}`;\n }\n return urlString;\n}\n\n/**\n * Converts an Ethers BigNumber to a BN.\n *\n * @param bigNumber - An Ethers BigNumber instance.\n * @returns A BN object.\n */\nexport function ethersBigNumberToBN(bigNumber: BigNumber): BN {\n return new BN(remove0x(bigNumber.toHexString()), 'hex');\n}\n\n/**\n * Partitions a list of values into groups that are at most `batchSize` in\n * length.\n *\n * @param values - The list of values.\n * @param args - The remaining arguments.\n * @param args.batchSize - The desired maximum number of values per batch.\n * @returns The list of batches.\n */\nexport function divideIntoBatches<Value>(\n values: Value[],\n { batchSize }: { batchSize: number },\n): Value[][] {\n const batches = [];\n for (let i = 0; i < values.length; i += batchSize) {\n batches.push(values.slice(i, i + batchSize));\n }\n return batches;\n}\n\n/**\n * Constructs an object from processing batches of the given values\n * sequentially.\n *\n * @param args - The arguments to this function.\n * @param args.values - A list of values to iterate over.\n * @param args.batchSize - The maximum number of values in each batch.\n * @param args.eachBatch - A function to call for each batch. This function is\n * similar to the function that `Array.prototype.reduce` takes, in that it\n * receives the object that is being built, each batch in the list of batches\n * and the index, and should return an updated version of the object.\n * @param args.initialResult - The initial value of the final data structure,\n * i.e., the value that will be fed into the first call of `eachBatch`.\n * @returns The built object.\n */\nexport async function reduceInBatchesSerially<\n Value,\n Result extends Record<PropertyKey, unknown>,\n>({\n values,\n batchSize,\n eachBatch,\n initialResult,\n}: {\n values: Value[];\n batchSize: number;\n eachBatch: (\n workingResult: Partial<Result>,\n batch: Value[],\n index: number,\n ) => Partial<Result> | Promise<Partial<Result>>;\n initialResult: Partial<Result>;\n}): Promise<Result> {\n const batches = divideIntoBatches(values, { batchSize });\n let workingResult = initialResult;\n for (const [index, batch] of batches.entries()) {\n workingResult = await eachBatch(workingResult, batch, index);\n }\n // There's no way around this — we have to assume that in the end, the result\n // matches the intended type.\n const finalResult = workingResult as Result;\n return finalResult;\n}\n\n/**\n * Retrieves token prices for a set of contract addresses in a specific currency and chainId.\n *\n * @param args - The arguments to function.\n * @param args.tokenPricesService - An object in charge of retrieving token prices.\n * @param args.nativeCurrency - The native currency to request price in.\n * @param args.tokenAddresses - The list of contract addresses.\n * @param args.chainId - The chainId of the tokens.\n * @returns The prices for the requested tokens.\n */\nexport async function fetchTokenContractExchangeRates({\n tokenPricesService,\n nativeCurrency,\n tokenAddresses,\n chainId,\n}: {\n tokenPricesService: AbstractTokenPricesService;\n nativeCurrency: string;\n tokenAddresses: Hex[];\n chainId: Hex;\n}): Promise<ContractExchangeRates> {\n const isChainIdSupported =\n tokenPricesService.validateChainIdSupported(chainId);\n const isCurrencySupported =\n tokenPricesService.validateCurrencySupported(nativeCurrency);\n\n if (!isChainIdSupported || !isCurrencySupported) {\n return {};\n }\n\n const tokenPricesByTokenAddress = await reduceInBatchesSerially<\n Hex,\n Awaited<ReturnType<AbstractTokenPricesService['fetchTokenPrices']>>\n >({\n values: [...tokenAddresses].sort(),\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n eachBatch: async (allTokenPricesByTokenAddress, batch) => {\n const tokenPricesByTokenAddressForBatch =\n await tokenPricesService.fetchTokenPrices({\n tokenAddresses: batch,\n chainId,\n currency: nativeCurrency,\n });\n\n return {\n ...allTokenPricesByTokenAddress,\n ...tokenPricesByTokenAddressForBatch,\n };\n },\n initialResult: {},\n });\n\n return Object.entries(tokenPricesByTokenAddress).reduce(\n (obj, [tokenAddress, tokenPrice]) => {\n return {\n ...obj,\n [toChecksumHexAddress(tokenAddress)]: tokenPrice?.price,\n };\n },\n {},\n );\n}\n"]}
|
package/dist/chunk-OBUR4TXH.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";//# sourceMappingURL=chunk-OBUR4TXH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-RGHTNZQ6.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/constants.ts
|
|
2
|
-
var Source = /* @__PURE__ */ ((Source2) => {
|
|
3
|
-
Source2["Custom"] = "custom";
|
|
4
|
-
Source2["Dapp"] = "dapp";
|
|
5
|
-
Source2["Detected"] = "detected";
|
|
6
|
-
return Source2;
|
|
7
|
-
})(Source || {});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.Source = Source;
|
|
12
|
-
//# sourceMappingURL=chunk-RGHTNZQ6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts"],"names":["Source"],"mappings":";AAAO,IAAK,SAAL,kBAAKA,YAAL;AACL,EAAAA,QAAA,YAAS;AACT,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,cAAW;AAHD,SAAAA;AAAA,GAAA","sourcesContent":["export enum Source {\n Custom = 'custom',\n Dapp = 'dapp',\n Detected = 'detected',\n}\n"]}
|
package/dist/chunk-S5CFNNOM.mjs
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ethersBigNumberToBN
|
|
3
|
-
} from "./chunk-BZEAPSD5.mjs";
|
|
4
|
-
|
|
5
|
-
// src/Standards/ERC20Standard.ts
|
|
6
|
-
import { toUtf8 } from "@ethereumjs/util";
|
|
7
|
-
import { Contract } from "@ethersproject/contracts";
|
|
8
|
-
import { decodeSingle } from "@metamask/abi-utils";
|
|
9
|
-
import { ERC20 } from "@metamask/controller-utils";
|
|
10
|
-
import { abiERC20 } from "@metamask/metamask-eth-abis";
|
|
11
|
-
import { assertIsStrictHexString } from "@metamask/utils";
|
|
12
|
-
var ERC20Standard = class {
|
|
13
|
-
constructor(provider) {
|
|
14
|
-
this.provider = provider;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Get balance or count for current account on specific asset contract.
|
|
18
|
-
*
|
|
19
|
-
* @param address - Asset ERC20 contract address.
|
|
20
|
-
* @param selectedAddress - Current account public address.
|
|
21
|
-
* @returns Promise resolving to BN object containing balance for current account on specific asset contract.
|
|
22
|
-
*/
|
|
23
|
-
async getBalanceOf(address, selectedAddress) {
|
|
24
|
-
const contract = new Contract(address, abiERC20, this.provider);
|
|
25
|
-
const balance = await contract.balanceOf(selectedAddress);
|
|
26
|
-
return ethersBigNumberToBN(balance);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Query for the decimals for a given ERC20 asset.
|
|
30
|
-
*
|
|
31
|
-
* @param address - ERC20 asset contract string.
|
|
32
|
-
* @returns Promise resolving to the 'decimals'.
|
|
33
|
-
*/
|
|
34
|
-
async getTokenDecimals(address) {
|
|
35
|
-
const contract = new Contract(address, abiERC20, this.provider);
|
|
36
|
-
try {
|
|
37
|
-
const decimals = await contract.decimals();
|
|
38
|
-
return decimals.toString();
|
|
39
|
-
} catch (err) {
|
|
40
|
-
if (err instanceof Error && err.message.includes("call revert exception")) {
|
|
41
|
-
throw new Error("Failed to parse token decimals");
|
|
42
|
-
}
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Query for the name for a given ERC20 asset.
|
|
48
|
-
*
|
|
49
|
-
* @param address - ERC20 asset contract string.
|
|
50
|
-
* @returns Promise resolving to the 'name'.
|
|
51
|
-
*/
|
|
52
|
-
async getTokenName(address) {
|
|
53
|
-
const contract = new Contract(address, abiERC20, this.provider);
|
|
54
|
-
try {
|
|
55
|
-
const name = await contract.name();
|
|
56
|
-
return name.toString();
|
|
57
|
-
} catch (err) {
|
|
58
|
-
if (err instanceof Error && err.message.includes("call revert exception")) {
|
|
59
|
-
throw new Error("Failed to parse token name");
|
|
60
|
-
}
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Query for symbol for a given ERC20 asset.
|
|
66
|
-
*
|
|
67
|
-
* @param address - ERC20 asset contract address.
|
|
68
|
-
* @returns Promise resolving to the 'symbol'.
|
|
69
|
-
*/
|
|
70
|
-
async getTokenSymbol(address) {
|
|
71
|
-
const payload = { to: address, data: "0x95d89b41" };
|
|
72
|
-
const result = await this.provider.call(payload);
|
|
73
|
-
assertIsStrictHexString(result);
|
|
74
|
-
try {
|
|
75
|
-
const decoded = decodeSingle("string", result);
|
|
76
|
-
if (decoded?.length > 0) {
|
|
77
|
-
return decoded;
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const utf8 = toUtf8(result);
|
|
83
|
-
if (utf8.length > 0) {
|
|
84
|
-
return utf8;
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
}
|
|
88
|
-
throw new Error("Failed to parse token symbol");
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Query if a contract implements an interface.
|
|
92
|
-
*
|
|
93
|
-
* @param address - Asset contract address.
|
|
94
|
-
* @param userAddress - The public address for the currently active user's account.
|
|
95
|
-
* @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.
|
|
96
|
-
*/
|
|
97
|
-
async getDetails(address, userAddress) {
|
|
98
|
-
const [decimals, symbol, balance] = await Promise.all([
|
|
99
|
-
this.getTokenDecimals(address),
|
|
100
|
-
this.getTokenSymbol(address),
|
|
101
|
-
userAddress ? this.getBalanceOf(address, userAddress) : void 0
|
|
102
|
-
]);
|
|
103
|
-
return {
|
|
104
|
-
decimals,
|
|
105
|
-
symbol,
|
|
106
|
-
balance,
|
|
107
|
-
standard: ERC20
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export {
|
|
113
|
-
ERC20Standard
|
|
114
|
-
};
|
|
115
|
-
//# sourceMappingURL=chunk-S5CFNNOM.mjs.map
|