@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,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC721Standard = void 0;
|
|
4
|
+
const contracts_1 = require("@ethersproject/contracts");
|
|
5
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
6
|
+
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
7
|
+
const assetsUtil_1 = require("../../../assetsUtil.cjs");
|
|
8
|
+
class ERC721Standard {
|
|
9
|
+
constructor(provider) {
|
|
10
|
+
/**
|
|
11
|
+
* Query if contract implements ERC721Metadata interface.
|
|
12
|
+
*
|
|
13
|
+
* @param address - ERC721 asset contract address.
|
|
14
|
+
* @returns Promise resolving to whether the contract implements ERC721Metadata interface.
|
|
15
|
+
*/
|
|
16
|
+
this.contractSupportsMetadataInterface = async (address) => {
|
|
17
|
+
return this.contractSupportsInterface(address, controller_utils_1.ERC721_METADATA_INTERFACE_ID);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Query if contract implements ERC721Enumerable interface.
|
|
21
|
+
*
|
|
22
|
+
* @param address - ERC721 asset contract address.
|
|
23
|
+
* @returns Promise resolving to whether the contract implements ERC721Enumerable interface.
|
|
24
|
+
*/
|
|
25
|
+
this.contractSupportsEnumerableInterface = async (address) => {
|
|
26
|
+
return this.contractSupportsInterface(address, controller_utils_1.ERC721_ENUMERABLE_INTERFACE_ID);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Query if contract implements ERC721 interface.
|
|
30
|
+
*
|
|
31
|
+
* @param address - ERC721 asset contract address.
|
|
32
|
+
* @returns Promise resolving to whether the contract implements ERC721 interface.
|
|
33
|
+
*/
|
|
34
|
+
this.contractSupportsBase721Interface = async (address) => {
|
|
35
|
+
return this.contractSupportsInterface(address, controller_utils_1.ERC721_INTERFACE_ID);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Enumerate assets assigned to an owner.
|
|
39
|
+
*
|
|
40
|
+
* @param address - ERC721 asset contract address.
|
|
41
|
+
* @param selectedAddress - Current account public address.
|
|
42
|
+
* @param index - An NFT counter less than `balanceOf(selectedAddress)`.
|
|
43
|
+
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
|
|
44
|
+
*/
|
|
45
|
+
this.getNftTokenId = async (address, selectedAddress, index) => {
|
|
46
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
|
|
47
|
+
return contract.tokenOfOwnerByIndex(selectedAddress, index);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Query for tokenURI for a given asset.
|
|
51
|
+
*
|
|
52
|
+
* @param address - ERC721 asset contract address.
|
|
53
|
+
* @param tokenId - ERC721 asset identifier.
|
|
54
|
+
* @returns Promise resolving to the 'tokenURI'.
|
|
55
|
+
*/
|
|
56
|
+
this.getTokenURI = async (address, tokenId) => {
|
|
57
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
|
|
58
|
+
const supportsMetadata = await this.contractSupportsMetadataInterface(address);
|
|
59
|
+
if (!supportsMetadata) {
|
|
60
|
+
// Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.
|
|
61
|
+
// This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).
|
|
62
|
+
// As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.
|
|
63
|
+
console.error('Contract does not support ERC721 metadata interface.');
|
|
64
|
+
}
|
|
65
|
+
return contract.tokenURI(tokenId);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Query for name for a given asset.
|
|
69
|
+
*
|
|
70
|
+
* @param address - ERC721 asset contract address.
|
|
71
|
+
* @returns Promise resolving to the 'name'.
|
|
72
|
+
*/
|
|
73
|
+
this.getAssetName = async (address) => {
|
|
74
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
|
|
75
|
+
return contract.name();
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Query for symbol for a given asset.
|
|
79
|
+
*
|
|
80
|
+
* @param address - ERC721 asset contract address.
|
|
81
|
+
* @returns Promise resolving to the 'symbol'.
|
|
82
|
+
*/
|
|
83
|
+
this.getAssetSymbol = async (address) => {
|
|
84
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
|
|
85
|
+
return contract.symbol();
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Query if a contract implements an interface.
|
|
89
|
+
*
|
|
90
|
+
* @param address - Asset contract address.
|
|
91
|
+
* @param interfaceId - Interface identifier.
|
|
92
|
+
* @returns Promise resolving to whether the contract implements `interfaceID`.
|
|
93
|
+
*/
|
|
94
|
+
this.contractSupportsInterface = async (address, interfaceId) => {
|
|
95
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
|
|
96
|
+
try {
|
|
97
|
+
return await contract.supportsInterface(interfaceId);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
// Mirror previous implementation
|
|
101
|
+
if (err instanceof Error &&
|
|
102
|
+
err.message.includes('call revert exception')) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Query if a contract implements an interface.
|
|
110
|
+
*
|
|
111
|
+
* @param address - Asset contract address.
|
|
112
|
+
* @param ipfsGateway - The user's preferred IPFS gateway.
|
|
113
|
+
* @param tokenId - tokenId of a given token in the contract.
|
|
114
|
+
* @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.
|
|
115
|
+
*/
|
|
116
|
+
this.getDetails = async (address, ipfsGateway, tokenId) => {
|
|
117
|
+
const isERC721 = await this.contractSupportsBase721Interface(address);
|
|
118
|
+
if (!isERC721) {
|
|
119
|
+
throw new Error("This isn't a valid ERC721 contract");
|
|
120
|
+
}
|
|
121
|
+
const [symbol, name, tokenURI] = await Promise.all([
|
|
122
|
+
(0, controller_utils_1.safelyExecute)(() => this.getAssetSymbol(address)),
|
|
123
|
+
(0, controller_utils_1.safelyExecute)(() => this.getAssetName(address)),
|
|
124
|
+
tokenId
|
|
125
|
+
? (0, controller_utils_1.safelyExecute)(() => this.getTokenURI(address, tokenId).then((uri) => uri.startsWith('ipfs://')
|
|
126
|
+
? (0, assetsUtil_1.getFormattedIpfsUrl)(ipfsGateway, uri, true)
|
|
127
|
+
: uri))
|
|
128
|
+
: undefined,
|
|
129
|
+
]);
|
|
130
|
+
let image;
|
|
131
|
+
if (tokenURI) {
|
|
132
|
+
try {
|
|
133
|
+
const response = await (0, controller_utils_1.timeoutFetch)(tokenURI);
|
|
134
|
+
const object = await response.json();
|
|
135
|
+
image = object?.image;
|
|
136
|
+
if (image?.startsWith('ipfs://')) {
|
|
137
|
+
image = (0, assetsUtil_1.getFormattedIpfsUrl)(ipfsGateway, image, true);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// ignore
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
standard: controller_utils_1.ERC721,
|
|
146
|
+
tokenURI,
|
|
147
|
+
symbol,
|
|
148
|
+
name,
|
|
149
|
+
image,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
this.provider = provider;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Query for owner for a given ERC721 asset.
|
|
156
|
+
*
|
|
157
|
+
* @param address - ERC721 asset contract address.
|
|
158
|
+
* @param tokenId - ERC721 asset identifier.
|
|
159
|
+
* @returns Promise resolving to the owner address.
|
|
160
|
+
*/
|
|
161
|
+
async getOwnerOf(address, tokenId) {
|
|
162
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
|
|
163
|
+
return contract.ownerOf(tokenId);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ERC721Standard = ERC721Standard;
|
|
167
|
+
//# sourceMappingURL=ERC721Standard.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC721Standard.cjs","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AAEpD,iEAOoC;AACpC,mEAAwD;AAExD,wDAA0D;AAE1D,MAAa,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAAiC,GAAG,KAAK,EACvC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,+CAA4B,CAC7B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,wCAAmC,GAAG,KAAK,EACzC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,iDAA8B,CAC/B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,qCAAgC,GAAG,KAAK,EACtC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,sCAAmB,CAAC,CAAC;QACtE,CAAC,CAAC;QAEF;;;;;;;WAOG;QACH,kBAAa,GAAG,KAAK,EACnB,OAAe,EACf,eAAuB,EACvB,KAAa,EACI,EAAE;YACnB,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,EAAE,6BAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjE,OAAO,QAAQ,CAAC,mBAAmB,CAAC,eAAe,EAAE,KAAK,CAAC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AAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACrC,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC;oBACtB,IAAI,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE;wBAChC,KAAK,GAAG,IAAA,gCAAmB,EAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;qBACvD;iBACF;gBAAC,MAAM;oBACN,SAAS;iBACV;aACF;YAED,OAAO;gBACL,QAAQ,EAAE,yBAAM;gBAChB,QAAQ;gBACR,MAAM;gBACN,IAAI;gBACJ,KAAK;aACN,CAAC;QACJ,CAAC,CAAC;QA1MA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAwGD;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAAe;QAC/C,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,EAAE,6BAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CAwFF;AA/MD,wCA+MC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata = await this.contractSupportsMetadataInterface(\n address,\n );\n if (!supportsMetadata) {\n // Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.\n // This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).\n // As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.\n console.error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\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 getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\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 let image;\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 // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Web3Provider } from
|
|
1
|
+
import type { Web3Provider } from "@ethersproject/providers";
|
|
2
2
|
export declare class ERC721Standard {
|
|
3
3
|
private readonly provider;
|
|
4
4
|
constructor(provider: Web3Provider);
|
|
@@ -86,4 +86,4 @@ export declare class ERC721Standard {
|
|
|
86
86
|
image: string | undefined;
|
|
87
87
|
}>;
|
|
88
88
|
}
|
|
89
|
-
//# sourceMappingURL=ERC721Standard.d.
|
|
89
|
+
//# sourceMappingURL=ERC721Standard.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC721Standard.d.cts","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,iCAAiC;AAa7D,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,QAAQ,EAAE,YAAY;IAIlC;;;;;OAKG;IACH,iCAAiC,YACtB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,mCAAmC,YACxB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,gCAAgC,YACrB,MAAM,KACd,QAAQ,OAAO,CAAC,CAEjB;IAEF;;;;;;;OAOG;IACH,aAAa,YACF,MAAM,mBACE,MAAM,SAChB,MAAM,KACZ,QAAQ,MAAM,CAAC,CAGhB;IAEF;;;;;;OAMG;IACH,WAAW,YAAmB,MAAM,WAAW,MAAM,KAAG,QAAQ,MAAM,CAAC,CAYrE;IAEF;;;;;OAKG;IACH,YAAY,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGrD;IAEF;;;;;OAKG;IACH,cAAc,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGvD;IAEF;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAiBxC;IAEF;;;;;;;OAOG;IACH,UAAU,YACC,MAAM,eACF,MAAM,YACT,MAAM;kBAEN,MAAM;kBACN,MAAM,GAAG,SAAS;gBACpB,MAAM,GAAG,SAAS;cACpB,MAAM,GAAG,SAAS;eACjB,MAAM,GAAG,SAAS;OA0CzB;CACH"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Web3Provider } from "@ethersproject/providers";
|
|
2
|
+
export declare class ERC721Standard {
|
|
3
|
+
private readonly provider;
|
|
4
|
+
constructor(provider: Web3Provider);
|
|
5
|
+
/**
|
|
6
|
+
* Query if contract implements ERC721Metadata interface.
|
|
7
|
+
*
|
|
8
|
+
* @param address - ERC721 asset contract address.
|
|
9
|
+
* @returns Promise resolving to whether the contract implements ERC721Metadata interface.
|
|
10
|
+
*/
|
|
11
|
+
contractSupportsMetadataInterface: (address: string) => Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Query if contract implements ERC721Enumerable interface.
|
|
14
|
+
*
|
|
15
|
+
* @param address - ERC721 asset contract address.
|
|
16
|
+
* @returns Promise resolving to whether the contract implements ERC721Enumerable interface.
|
|
17
|
+
*/
|
|
18
|
+
contractSupportsEnumerableInterface: (address: string) => Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Query if contract implements ERC721 interface.
|
|
21
|
+
*
|
|
22
|
+
* @param address - ERC721 asset contract address.
|
|
23
|
+
* @returns Promise resolving to whether the contract implements ERC721 interface.
|
|
24
|
+
*/
|
|
25
|
+
contractSupportsBase721Interface: (address: string) => Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Enumerate assets assigned to an owner.
|
|
28
|
+
*
|
|
29
|
+
* @param address - ERC721 asset contract address.
|
|
30
|
+
* @param selectedAddress - Current account public address.
|
|
31
|
+
* @param index - An NFT counter less than `balanceOf(selectedAddress)`.
|
|
32
|
+
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
|
|
33
|
+
*/
|
|
34
|
+
getNftTokenId: (address: string, selectedAddress: string, index: number) => Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Query for tokenURI for a given asset.
|
|
37
|
+
*
|
|
38
|
+
* @param address - ERC721 asset contract address.
|
|
39
|
+
* @param tokenId - ERC721 asset identifier.
|
|
40
|
+
* @returns Promise resolving to the 'tokenURI'.
|
|
41
|
+
*/
|
|
42
|
+
getTokenURI: (address: string, tokenId: string) => Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Query for name for a given asset.
|
|
45
|
+
*
|
|
46
|
+
* @param address - ERC721 asset contract address.
|
|
47
|
+
* @returns Promise resolving to the 'name'.
|
|
48
|
+
*/
|
|
49
|
+
getAssetName: (address: string) => Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Query for symbol for a given asset.
|
|
52
|
+
*
|
|
53
|
+
* @param address - ERC721 asset contract address.
|
|
54
|
+
* @returns Promise resolving to the 'symbol'.
|
|
55
|
+
*/
|
|
56
|
+
getAssetSymbol: (address: string) => Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Query for owner for a given ERC721 asset.
|
|
59
|
+
*
|
|
60
|
+
* @param address - ERC721 asset contract address.
|
|
61
|
+
* @param tokenId - ERC721 asset identifier.
|
|
62
|
+
* @returns Promise resolving to the owner address.
|
|
63
|
+
*/
|
|
64
|
+
getOwnerOf(address: string, tokenId: string): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Query if a contract implements an interface.
|
|
67
|
+
*
|
|
68
|
+
* @param address - Asset contract address.
|
|
69
|
+
* @param interfaceId - Interface identifier.
|
|
70
|
+
* @returns Promise resolving to whether the contract implements `interfaceID`.
|
|
71
|
+
*/
|
|
72
|
+
private readonly contractSupportsInterface;
|
|
73
|
+
/**
|
|
74
|
+
* Query if a contract implements an interface.
|
|
75
|
+
*
|
|
76
|
+
* @param address - Asset contract address.
|
|
77
|
+
* @param ipfsGateway - The user's preferred IPFS gateway.
|
|
78
|
+
* @param tokenId - tokenId of a given token in the contract.
|
|
79
|
+
* @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.
|
|
80
|
+
*/
|
|
81
|
+
getDetails: (address: string, ipfsGateway: string, tokenId?: string) => Promise<{
|
|
82
|
+
standard: string;
|
|
83
|
+
tokenURI: string | undefined;
|
|
84
|
+
symbol: string | undefined;
|
|
85
|
+
name: string | undefined;
|
|
86
|
+
image: string | undefined;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=ERC721Standard.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC721Standard.d.mts","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,iCAAiC;AAa7D,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,QAAQ,EAAE,YAAY;IAIlC;;;;;OAKG;IACH,iCAAiC,YACtB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,mCAAmC,YACxB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,gCAAgC,YACrB,MAAM,KACd,QAAQ,OAAO,CAAC,CAEjB;IAEF;;;;;;;OAOG;IACH,aAAa,YACF,MAAM,mBACE,MAAM,SAChB,MAAM,KACZ,QAAQ,MAAM,CAAC,CAGhB;IAEF;;;;;;OAMG;IACH,WAAW,YAAmB,MAAM,WAAW,MAAM,KAAG,QAAQ,MAAM,CAAC,CAYrE;IAEF;;;;;OAKG;IACH,YAAY,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGrD;IAEF;;;;;OAKG;IACH,cAAc,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGvD;IAEF;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAiBxC;IAEF;;;;;;;OAOG;IACH,UAAU,YACC,MAAM,eACF,MAAM,YACT,MAAM;kBAEN,MAAM;kBACN,MAAM,GAAG,SAAS;gBACpB,MAAM,GAAG,SAAS;cACpB,MAAM,GAAG,SAAS;eACjB,MAAM,GAAG,SAAS;OA0CzB;CACH"}
|
|
@@ -1,9 +1,163 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
import "../../../
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Contract } from "@ethersproject/contracts";
|
|
2
|
+
import { timeoutFetch, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721, safelyExecute } from "@metamask/controller-utils";
|
|
3
|
+
import { abiERC721 } from "@metamask/metamask-eth-abis";
|
|
4
|
+
import { getFormattedIpfsUrl } from "../../../assetsUtil.mjs";
|
|
5
|
+
export class ERC721Standard {
|
|
6
|
+
constructor(provider) {
|
|
7
|
+
/**
|
|
8
|
+
* Query if contract implements ERC721Metadata interface.
|
|
9
|
+
*
|
|
10
|
+
* @param address - ERC721 asset contract address.
|
|
11
|
+
* @returns Promise resolving to whether the contract implements ERC721Metadata interface.
|
|
12
|
+
*/
|
|
13
|
+
this.contractSupportsMetadataInterface = async (address) => {
|
|
14
|
+
return this.contractSupportsInterface(address, ERC721_METADATA_INTERFACE_ID);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Query if contract implements ERC721Enumerable interface.
|
|
18
|
+
*
|
|
19
|
+
* @param address - ERC721 asset contract address.
|
|
20
|
+
* @returns Promise resolving to whether the contract implements ERC721Enumerable interface.
|
|
21
|
+
*/
|
|
22
|
+
this.contractSupportsEnumerableInterface = async (address) => {
|
|
23
|
+
return this.contractSupportsInterface(address, ERC721_ENUMERABLE_INTERFACE_ID);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Query if contract implements ERC721 interface.
|
|
27
|
+
*
|
|
28
|
+
* @param address - ERC721 asset contract address.
|
|
29
|
+
* @returns Promise resolving to whether the contract implements ERC721 interface.
|
|
30
|
+
*/
|
|
31
|
+
this.contractSupportsBase721Interface = async (address) => {
|
|
32
|
+
return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Enumerate assets assigned to an owner.
|
|
36
|
+
*
|
|
37
|
+
* @param address - ERC721 asset contract address.
|
|
38
|
+
* @param selectedAddress - Current account public address.
|
|
39
|
+
* @param index - An NFT counter less than `balanceOf(selectedAddress)`.
|
|
40
|
+
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
|
|
41
|
+
*/
|
|
42
|
+
this.getNftTokenId = async (address, selectedAddress, index) => {
|
|
43
|
+
const contract = new Contract(address, abiERC721, this.provider);
|
|
44
|
+
return contract.tokenOfOwnerByIndex(selectedAddress, index);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Query for tokenURI for a given asset.
|
|
48
|
+
*
|
|
49
|
+
* @param address - ERC721 asset contract address.
|
|
50
|
+
* @param tokenId - ERC721 asset identifier.
|
|
51
|
+
* @returns Promise resolving to the 'tokenURI'.
|
|
52
|
+
*/
|
|
53
|
+
this.getTokenURI = async (address, tokenId) => {
|
|
54
|
+
const contract = new Contract(address, abiERC721, this.provider);
|
|
55
|
+
const supportsMetadata = await this.contractSupportsMetadataInterface(address);
|
|
56
|
+
if (!supportsMetadata) {
|
|
57
|
+
// Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.
|
|
58
|
+
// This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).
|
|
59
|
+
// As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.
|
|
60
|
+
console.error('Contract does not support ERC721 metadata interface.');
|
|
61
|
+
}
|
|
62
|
+
return contract.tokenURI(tokenId);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Query for name for a given asset.
|
|
66
|
+
*
|
|
67
|
+
* @param address - ERC721 asset contract address.
|
|
68
|
+
* @returns Promise resolving to the 'name'.
|
|
69
|
+
*/
|
|
70
|
+
this.getAssetName = async (address) => {
|
|
71
|
+
const contract = new Contract(address, abiERC721, this.provider);
|
|
72
|
+
return contract.name();
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Query for symbol for a given asset.
|
|
76
|
+
*
|
|
77
|
+
* @param address - ERC721 asset contract address.
|
|
78
|
+
* @returns Promise resolving to the 'symbol'.
|
|
79
|
+
*/
|
|
80
|
+
this.getAssetSymbol = async (address) => {
|
|
81
|
+
const contract = new Contract(address, abiERC721, this.provider);
|
|
82
|
+
return contract.symbol();
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Query if a contract implements an interface.
|
|
86
|
+
*
|
|
87
|
+
* @param address - Asset contract address.
|
|
88
|
+
* @param interfaceId - Interface identifier.
|
|
89
|
+
* @returns Promise resolving to whether the contract implements `interfaceID`.
|
|
90
|
+
*/
|
|
91
|
+
this.contractSupportsInterface = async (address, interfaceId) => {
|
|
92
|
+
const contract = new Contract(address, abiERC721, this.provider);
|
|
93
|
+
try {
|
|
94
|
+
return await contract.supportsInterface(interfaceId);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
// Mirror previous implementation
|
|
98
|
+
if (err instanceof Error &&
|
|
99
|
+
err.message.includes('call revert exception')) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Query if a contract implements an interface.
|
|
107
|
+
*
|
|
108
|
+
* @param address - Asset contract address.
|
|
109
|
+
* @param ipfsGateway - The user's preferred IPFS gateway.
|
|
110
|
+
* @param tokenId - tokenId of a given token in the contract.
|
|
111
|
+
* @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.
|
|
112
|
+
*/
|
|
113
|
+
this.getDetails = async (address, ipfsGateway, tokenId) => {
|
|
114
|
+
const isERC721 = await this.contractSupportsBase721Interface(address);
|
|
115
|
+
if (!isERC721) {
|
|
116
|
+
throw new Error("This isn't a valid ERC721 contract");
|
|
117
|
+
}
|
|
118
|
+
const [symbol, name, tokenURI] = await Promise.all([
|
|
119
|
+
safelyExecute(() => this.getAssetSymbol(address)),
|
|
120
|
+
safelyExecute(() => this.getAssetName(address)),
|
|
121
|
+
tokenId
|
|
122
|
+
? safelyExecute(() => this.getTokenURI(address, tokenId).then((uri) => uri.startsWith('ipfs://')
|
|
123
|
+
? getFormattedIpfsUrl(ipfsGateway, uri, true)
|
|
124
|
+
: uri))
|
|
125
|
+
: undefined,
|
|
126
|
+
]);
|
|
127
|
+
let image;
|
|
128
|
+
if (tokenURI) {
|
|
129
|
+
try {
|
|
130
|
+
const response = await timeoutFetch(tokenURI);
|
|
131
|
+
const object = await response.json();
|
|
132
|
+
image = object?.image;
|
|
133
|
+
if (image?.startsWith('ipfs://')) {
|
|
134
|
+
image = getFormattedIpfsUrl(ipfsGateway, image, true);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// ignore
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
standard: ERC721,
|
|
143
|
+
tokenURI,
|
|
144
|
+
symbol,
|
|
145
|
+
name,
|
|
146
|
+
image,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
this.provider = provider;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Query for owner for a given ERC721 asset.
|
|
153
|
+
*
|
|
154
|
+
* @param address - ERC721 asset contract address.
|
|
155
|
+
* @param tokenId - ERC721 asset identifier.
|
|
156
|
+
* @returns Promise resolving to the owner address.
|
|
157
|
+
*/
|
|
158
|
+
async getOwnerOf(address, tokenId) {
|
|
159
|
+
const contract = new Contract(address, abiERC721, this.provider);
|
|
160
|
+
return contract.ownerOf(tokenId);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
9
163
|
//# sourceMappingURL=ERC721Standard.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"ERC721Standard.mjs","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AAEpD,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,MAAM,EACN,aAAa,EACd,mCAAmC;AACpC,OAAO,EAAE,SAAS,EAAE,oCAAoC;AAExD,OAAO,EAAE,mBAAmB,EAAE,gCAA4B;AAE1D,MAAM,OAAO,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAAiC,GAAG,KAAK,EACvC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,4BAA4B,CAC7B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,wCAAmC,GAAG,KAAK,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CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,CACjB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAC9C,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;wBACvB,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC;wBAC7C,CAAC,CAAC,GAAG,CACR,CACF;oBACH,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;YAEH,IAAI,KAAK,CAAC;YACV,IAAI,QAAQ,EAAE;gBACZ,IAAI;oBACF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;oBAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACrC,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC;oBACtB,IAAI,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE;wBAChC,KAAK,GAAG,mBAAmB,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;qBACvD;iBACF;gBAAC,MAAM;oBACN,SAAS;iBACV;aACF;YAED,OAAO;gBACL,QAAQ,EAAE,MAAM;gBAChB,QAAQ;gBACR,MAAM;gBACN,IAAI;gBACJ,KAAK;aACN,CAAC;QACJ,CAAC,CAAC;QA1MA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAwGD;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAAe;QAC/C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CAwFF","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata = await this.contractSupportsMetadataInterface(\n address,\n );\n if (!supportsMetadata) {\n // Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.\n // This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).\n // As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.\n console.error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\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 getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\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 let image;\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 // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _TokenBalancesController_handle, _TokenBalancesController_interval, _TokenBalancesController_tokens, _TokenBalancesController_disabled;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TokenBalancesController = exports.getDefaultTokenBalancesState = void 0;
|
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
+
const DEFAULT_INTERVAL = 180000;
|
|
19
|
+
const controllerName = 'TokenBalancesController';
|
|
20
|
+
const metadata = {
|
|
21
|
+
contractBalances: { persist: true, anonymous: false },
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Get the default TokenBalancesController state.
|
|
25
|
+
*
|
|
26
|
+
* @returns The default TokenBalancesController state.
|
|
27
|
+
*/
|
|
28
|
+
function getDefaultTokenBalancesState() {
|
|
29
|
+
return {
|
|
30
|
+
contractBalances: {},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.getDefaultTokenBalancesState = getDefaultTokenBalancesState;
|
|
34
|
+
/**
|
|
35
|
+
* Controller that passively polls on a set interval token balances
|
|
36
|
+
* for tokens stored in the TokensController
|
|
37
|
+
*/
|
|
38
|
+
class TokenBalancesController extends base_controller_1.BaseController {
|
|
39
|
+
/**
|
|
40
|
+
* Construct a Token Balances Controller.
|
|
41
|
+
*
|
|
42
|
+
* @param options - The controller options.
|
|
43
|
+
* @param options.interval - Polling interval used to fetch new token balances.
|
|
44
|
+
* @param options.tokens - List of tokens to track balances for.
|
|
45
|
+
* @param options.disabled - If set to true, all tracked tokens contract balances updates are blocked.
|
|
46
|
+
* @param options.state - Initial state to set on this controller.
|
|
47
|
+
* @param options.messenger - The controller restricted messenger.
|
|
48
|
+
*/
|
|
49
|
+
constructor({ interval = DEFAULT_INTERVAL, tokens = [], disabled = false, messenger, state = {}, }) {
|
|
50
|
+
super({
|
|
51
|
+
name: controllerName,
|
|
52
|
+
metadata,
|
|
53
|
+
messenger,
|
|
54
|
+
state: {
|
|
55
|
+
...getDefaultTokenBalancesState(),
|
|
56
|
+
...state,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
_TokenBalancesController_handle.set(this, void 0);
|
|
60
|
+
_TokenBalancesController_interval.set(this, void 0);
|
|
61
|
+
_TokenBalancesController_tokens.set(this, void 0);
|
|
62
|
+
_TokenBalancesController_disabled.set(this, void 0);
|
|
63
|
+
__classPrivateFieldSet(this, _TokenBalancesController_disabled, disabled, "f");
|
|
64
|
+
__classPrivateFieldSet(this, _TokenBalancesController_interval, interval, "f");
|
|
65
|
+
__classPrivateFieldSet(this, _TokenBalancesController_tokens, tokens, "f");
|
|
66
|
+
this.messagingSystem.subscribe('TokensController:stateChange', ({ tokens: newTokens, detectedTokens }) => {
|
|
67
|
+
__classPrivateFieldSet(this, _TokenBalancesController_tokens, [...newTokens, ...detectedTokens], "f");
|
|
68
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
70
|
+
this.updateBalances();
|
|
71
|
+
});
|
|
72
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
74
|
+
this.poll();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Allows controller to update tracked tokens contract balances.
|
|
78
|
+
*/
|
|
79
|
+
enable() {
|
|
80
|
+
__classPrivateFieldSet(this, _TokenBalancesController_disabled, false, "f");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Blocks controller from updating tracked tokens contract balances.
|
|
84
|
+
*/
|
|
85
|
+
disable() {
|
|
86
|
+
__classPrivateFieldSet(this, _TokenBalancesController_disabled, true, "f");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Starts a new polling interval.
|
|
90
|
+
*
|
|
91
|
+
* @param interval - Polling interval used to fetch new token balances.
|
|
92
|
+
*/
|
|
93
|
+
async poll(interval) {
|
|
94
|
+
if (interval) {
|
|
95
|
+
__classPrivateFieldSet(this, _TokenBalancesController_interval, interval, "f");
|
|
96
|
+
}
|
|
97
|
+
if (__classPrivateFieldGet(this, _TokenBalancesController_handle, "f")) {
|
|
98
|
+
clearTimeout(__classPrivateFieldGet(this, _TokenBalancesController_handle, "f"));
|
|
99
|
+
}
|
|
100
|
+
await (0, controller_utils_1.safelyExecute)(() => this.updateBalances());
|
|
101
|
+
__classPrivateFieldSet(this, _TokenBalancesController_handle, setTimeout(() => {
|
|
102
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
104
|
+
this.poll(__classPrivateFieldGet(this, _TokenBalancesController_interval, "f"));
|
|
105
|
+
}, __classPrivateFieldGet(this, _TokenBalancesController_interval, "f")), "f");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Updates balances for all tokens.
|
|
109
|
+
*/
|
|
110
|
+
async updateBalances() {
|
|
111
|
+
if (__classPrivateFieldGet(this, _TokenBalancesController_disabled, "f")) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const selectedInternalAccount = this.messagingSystem.call('AccountsController:getSelectedAccount');
|
|
115
|
+
const newContractBalances = {};
|
|
116
|
+
for (const token of __classPrivateFieldGet(this, _TokenBalancesController_tokens, "f")) {
|
|
117
|
+
const { address } = token;
|
|
118
|
+
try {
|
|
119
|
+
const balance = await this.messagingSystem.call('AssetsContractController:getERC20BalanceOf', address, selectedInternalAccount.address);
|
|
120
|
+
newContractBalances[address] = (0, controller_utils_1.toHex)(balance);
|
|
121
|
+
token.hasBalanceError = false;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
newContractBalances[address] = (0, controller_utils_1.toHex)(0);
|
|
125
|
+
token.hasBalanceError = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this.update((state) => {
|
|
129
|
+
state.contractBalances = newContractBalances;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.TokenBalancesController = TokenBalancesController;
|
|
134
|
+
_TokenBalancesController_handle = new WeakMap(), _TokenBalancesController_interval = new WeakMap(), _TokenBalancesController_tokens = new WeakMap(), _TokenBalancesController_disabled = new WeakMap();
|
|
135
|
+
exports.default = TokenBalancesController;
|
|
136
|
+
//# sourceMappingURL=TokenBalancesController.cjs.map
|