@metamask/assets-controllers 38.0.0 → 38.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -1
- package/dist/AccountTrackerController.cjs +245 -0
- package/dist/AccountTrackerController.cjs.map +1 -0
- package/dist/{types/AccountTrackerController.d.ts → AccountTrackerController.d.cts} +6 -6
- package/dist/AccountTrackerController.d.cts.map +1 -0
- package/dist/AccountTrackerController.d.mts +112 -0
- package/dist/AccountTrackerController.d.mts.map +1 -0
- package/dist/AccountTrackerController.mjs +244 -8
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/AssetsContractController.cjs +389 -0
- package/dist/AssetsContractController.cjs.map +1 -0
- package/dist/{types/AssetsContractController.d.ts → AssetsContractController.d.cts} +9 -9
- package/dist/AssetsContractController.d.cts.map +1 -0
- package/dist/AssetsContractController.d.mts +277 -0
- package/dist/AssetsContractController.d.mts.map +1 -0
- package/dist/AssetsContractController.mjs +387 -16
- package/dist/AssetsContractController.mjs.map +1 -1
- package/dist/CurrencyRateController.cjs +156 -0
- package/dist/CurrencyRateController.cjs.map +1 -0
- package/dist/{types/CurrencyRateController.d.ts → CurrencyRateController.d.cts} +5 -5
- package/dist/CurrencyRateController.d.cts.map +1 -0
- package/dist/CurrencyRateController.d.mts +80 -0
- package/dist/CurrencyRateController.d.mts.map +1 -0
- package/dist/CurrencyRateController.mjs +150 -10
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/NftController.cjs +1159 -0
- package/dist/NftController.cjs.map +1 -0
- package/dist/{types/NftController.d.ts → NftController.d.cts} +11 -11
- package/dist/NftController.d.cts.map +1 -0
- package/dist/NftController.d.mts +424 -0
- package/dist/NftController.d.mts.map +1 -0
- package/dist/NftController.mjs +1156 -12
- package/dist/NftController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs +237 -0
- package/dist/NftDetectionController.cjs.map +1 -0
- package/dist/{types/NftDetectionController.d.ts → NftDetectionController.d.cts} +9 -9
- package/dist/NftDetectionController.d.cts.map +1 -0
- package/dist/NftDetectionController.d.mts +368 -0
- package/dist/NftDetectionController.d.mts.map +1 -0
- package/dist/NftDetectionController.mjs +231 -14
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/RatesController/RatesController.cjs +189 -0
- package/dist/RatesController/RatesController.cjs.map +1 -0
- package/dist/{types/RatesController/RatesController.d.ts → RatesController/RatesController.d.cts} +3 -3
- package/dist/RatesController/RatesController.d.cts.map +1 -0
- package/dist/RatesController/RatesController.d.mts +44 -0
- package/dist/RatesController/RatesController.d.mts.map +1 -0
- package/dist/RatesController/RatesController.mjs +183 -12
- package/dist/RatesController/RatesController.mjs.map +1 -1
- package/dist/RatesController/index.cjs +7 -0
- package/dist/RatesController/index.cjs.map +1 -0
- package/dist/{types/RatesController/index.d.ts → RatesController/index.d.cts} +3 -3
- package/dist/RatesController/index.d.cts.map +1 -0
- package/dist/RatesController/index.d.mts +3 -0
- package/dist/RatesController/index.d.mts.map +1 -0
- package/dist/RatesController/index.mjs +1 -12
- package/dist/RatesController/index.mjs.map +1 -1
- package/dist/RatesController/types.cjs +3 -0
- package/dist/RatesController/types.cjs.map +1 -0
- package/dist/{types/RatesController/types.d.ts → RatesController/types.d.cts} +4 -4
- package/dist/RatesController/types.d.cts.map +1 -0
- package/dist/RatesController/types.d.mts +100 -0
- package/dist/RatesController/types.d.mts.map +1 -0
- package/dist/RatesController/types.mjs +1 -0
- package/dist/RatesController/types.mjs.map +1 -1
- package/dist/Standards/ERC20Standard.cjs +124 -0
- package/dist/Standards/ERC20Standard.cjs.map +1 -0
- package/dist/{types/Standards/ERC20Standard.d.ts → Standards/ERC20Standard.d.cts} +3 -3
- package/dist/Standards/ERC20Standard.d.cts.map +1 -0
- package/dist/Standards/ERC20Standard.d.mts +49 -0
- package/dist/Standards/ERC20Standard.d.mts.map +1 -0
- package/dist/Standards/ERC20Standard.mjs +121 -8
- package/dist/Standards/ERC20Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs +189 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs.map +1 -0
- package/dist/{types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts → Standards/NftStandards/ERC1155/ERC1155Standard.d.cts} +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.cts.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts +95 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +184 -8
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +167 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -0
- package/dist/{types/Standards/NftStandards/ERC721/ERC721Standard.d.ts → Standards/NftStandards/ERC721/ERC721Standard.d.cts} +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.cts.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts +89 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +162 -8
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +136 -0
- package/dist/TokenBalancesController.cjs.map +1 -0
- package/dist/{types/TokenBalancesController.d.ts → TokenBalancesController.d.cts} +7 -7
- package/dist/TokenBalancesController.d.cts.map +1 -0
- package/dist/TokenBalancesController.d.mts +82 -0
- package/dist/TokenBalancesController.d.mts.map +1 -0
- package/dist/TokenBalancesController.mjs +129 -10
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +369 -0
- package/dist/TokenDetectionController.cjs.map +1 -0
- package/dist/{types/TokenDetectionController.d.ts → TokenDetectionController.d.cts} +10 -10
- package/dist/TokenDetectionController.d.cts.map +1 -0
- package/dist/TokenDetectionController.d.mts +109 -0
- package/dist/TokenDetectionController.d.mts.map +1 -0
- package/dist/TokenDetectionController.mjs +366 -15
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenListController.cjs +274 -0
- package/dist/TokenListController.cjs.map +1 -0
- package/dist/{types/TokenListController.d.ts → TokenListController.d.cts} +5 -5
- package/dist/TokenListController.d.cts.map +1 -0
- package/dist/TokenListController.d.mts +117 -0
- package/dist/TokenListController.d.mts.map +1 -0
- package/dist/TokenListController.mjs +267 -12
- package/dist/TokenListController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +452 -0
- package/dist/TokenRatesController.cjs.map +1 -0
- package/dist/{types/TokenRatesController.d.ts → TokenRatesController.d.cts} +8 -8
- package/dist/TokenRatesController.d.cts.map +1 -0
- package/dist/TokenRatesController.d.mts +170 -0
- package/dist/TokenRatesController.d.mts.map +1 -0
- package/dist/TokenRatesController.mjs +446 -16
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokensController.cjs +678 -0
- package/dist/TokensController.cjs.map +1 -0
- package/dist/{types/TokensController.d.ts → TokensController.d.cts} +9 -9
- package/dist/TokensController.d.cts.map +1 -0
- package/dist/TokensController.d.mts +165 -0
- package/dist/TokensController.d.mts.map +1 -0
- package/dist/TokensController.mjs +675 -14
- package/dist/TokensController.mjs.map +1 -1
- package/dist/assetsUtil.cjs +358 -0
- package/dist/assetsUtil.cjs.map +1 -0
- package/dist/{types/assetsUtil.d.ts → assetsUtil.d.cts} +7 -7
- package/dist/assetsUtil.d.cts.map +1 -0
- package/dist/assetsUtil.d.mts +177 -0
- package/dist/assetsUtil.d.mts.map +1 -0
- package/dist/assetsUtil.mjs +343 -36
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/constants.cjs +10 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +6 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +6 -7
- package/dist/constants.mjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.cjs +119 -0
- package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -0
- package/dist/{types/crypto-compare-service/crypto-compare.d.ts → crypto-compare-service/crypto-compare.d.cts} +1 -1
- package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.d.mts +22 -0
- package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +113 -9
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
- package/dist/crypto-compare-service/index.cjs +7 -0
- package/dist/crypto-compare-service/index.cjs.map +1 -0
- package/dist/crypto-compare-service/index.d.cts +2 -0
- package/dist/crypto-compare-service/index.d.cts.map +1 -0
- package/dist/crypto-compare-service/index.d.mts +2 -0
- package/dist/crypto-compare-service/index.d.mts.map +1 -0
- package/dist/crypto-compare-service/index.mjs +1 -10
- package/dist/crypto-compare-service/index.mjs.map +1 -1
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/index.d.ts → index.d.cts} +24 -24
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -80
- package/dist/index.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs +3 -0
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -0
- package/dist/{types/token-prices-service/abstract-token-prices-service.d.ts → token-prices-service/abstract-token-prices-service.d.cts} +2 -2
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +79 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +352 -0
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -0
- package/dist/{types/token-prices-service/codefi-v2.d.ts → token-prices-service/codefi-v2.d.cts} +3 -3
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -0
- package/dist/token-prices-service/codefi-v2.d.mts +97 -0
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -0
- package/dist/token-prices-service/codefi-v2.mjs +347 -12
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/dist/token-prices-service/index.cjs +7 -0
- package/dist/token-prices-service/index.cjs.map +1 -0
- package/dist/token-prices-service/index.d.cts +3 -0
- package/dist/token-prices-service/index.d.cts.map +1 -0
- package/dist/token-prices-service/index.d.mts +3 -0
- package/dist/token-prices-service/index.d.mts.map +1 -0
- package/dist/token-prices-service/index.mjs +1 -10
- package/dist/token-prices-service/index.mjs.map +1 -1
- package/dist/token-service.cjs +130 -0
- package/dist/token-service.cjs.map +1 -0
- package/dist/{types/token-service.d.ts → token-service.d.cts} +2 -2
- package/dist/token-service.d.cts.map +1 -0
- package/dist/token-service.d.mts +31 -0
- package/dist/token-service.d.mts.map +1 -0
- package/dist/token-service.mjs +124 -14
- package/dist/token-service.mjs.map +1 -1
- package/package.json +20 -15
- package/dist/AccountTrackerController.js +0 -10
- package/dist/AccountTrackerController.js.map +0 -1
- package/dist/AssetsContractController.js +0 -18
- package/dist/AssetsContractController.js.map +0 -1
- package/dist/CurrencyRateController.js +0 -12
- package/dist/CurrencyRateController.js.map +0 -1
- package/dist/NftController.js +0 -14
- package/dist/NftController.js.map +0 -1
- package/dist/NftDetectionController.js +0 -16
- package/dist/NftDetectionController.js.map +0 -1
- package/dist/RatesController/RatesController.js +0 -14
- package/dist/RatesController/RatesController.js.map +0 -1
- package/dist/RatesController/index.js +0 -13
- package/dist/RatesController/index.js.map +0 -1
- package/dist/RatesController/types.js +0 -1
- package/dist/RatesController/types.js.map +0 -1
- package/dist/Standards/ERC20Standard.js +0 -9
- package/dist/Standards/ERC20Standard.js.map +0 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +0 -9
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +0 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +0 -9
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +0 -1
- package/dist/TokenBalancesController.js +0 -12
- package/dist/TokenBalancesController.js.map +0 -1
- package/dist/TokenDetectionController.js +0 -17
- package/dist/TokenDetectionController.js.map +0 -1
- package/dist/TokenListController.js +0 -14
- package/dist/TokenListController.js.map +0 -1
- package/dist/TokenRatesController.js +0 -18
- package/dist/TokenRatesController.js.map +0 -1
- package/dist/TokensController.js +0 -16
- package/dist/TokensController.js.map +0 -1
- package/dist/assetsUtil.js +0 -38
- package/dist/assetsUtil.js.map +0 -1
- package/dist/chunk-27KOXCQK.mjs +0 -1
- package/dist/chunk-27KOXCQK.mjs.map +0 -1
- package/dist/chunk-2TZK6YZA.js +0 -1405
- package/dist/chunk-2TZK6YZA.js.map +0 -1
- package/dist/chunk-3LPQTUGG.js +0 -434
- package/dist/chunk-3LPQTUGG.js.map +0 -1
- package/dist/chunk-3QDXAE2D.mjs +0 -178
- package/dist/chunk-3QDXAE2D.mjs.map +0 -1
- package/dist/chunk-46KUC5FH.mjs +0 -434
- package/dist/chunk-46KUC5FH.mjs.map +0 -1
- package/dist/chunk-4QZESU46.mjs +0 -530
- package/dist/chunk-4QZESU46.mjs.map +0 -1
- package/dist/chunk-5QLC2MHV.js +0 -215
- package/dist/chunk-5QLC2MHV.js.map +0 -1
- package/dist/chunk-7K6PSEAA.js +0 -1
- package/dist/chunk-7K6PSEAA.js.map +0 -1
- package/dist/chunk-AX522TDL.mjs +0 -85
- package/dist/chunk-AX522TDL.mjs.map +0 -1
- package/dist/chunk-AZSIKIMK.mjs +0 -429
- package/dist/chunk-AZSIKIMK.mjs.map +0 -1
- package/dist/chunk-BBCZM5P4.js +0 -300
- package/dist/chunk-BBCZM5P4.js.map +0 -1
- package/dist/chunk-BZEAPSD5.mjs +0 -215
- package/dist/chunk-BZEAPSD5.mjs.map +0 -1
- package/dist/chunk-C7LNCQXM.mjs +0 -300
- package/dist/chunk-C7LNCQXM.mjs.map +0 -1
- package/dist/chunk-CP3HC7AQ.mjs +0 -12
- package/dist/chunk-CP3HC7AQ.mjs.map +0 -1
- package/dist/chunk-FWKV5FGP.mjs +0 -71
- package/dist/chunk-FWKV5FGP.mjs.map +0 -1
- package/dist/chunk-GDFLKKDY.js +0 -71
- package/dist/chunk-GDFLKKDY.js.map +0 -1
- package/dist/chunk-GW6RE66P.mjs +0 -210
- package/dist/chunk-GW6RE66P.mjs.map +0 -1
- package/dist/chunk-HVOIBGYN.js +0 -282
- package/dist/chunk-HVOIBGYN.js.map +0 -1
- package/dist/chunk-ISK2VSBB.js +0 -178
- package/dist/chunk-ISK2VSBB.js.map +0 -1
- package/dist/chunk-JCR4H6YL.js +0 -115
- package/dist/chunk-JCR4H6YL.js.map +0 -1
- package/dist/chunk-JJX7TMH5.mjs +0 -135
- package/dist/chunk-JJX7TMH5.mjs.map +0 -1
- package/dist/chunk-JMZ7KWJS.js +0 -157
- package/dist/chunk-JMZ7KWJS.js.map +0 -1
- package/dist/chunk-JYHAAA6W.mjs +0 -1
- package/dist/chunk-JYHAAA6W.mjs.map +0 -1
- package/dist/chunk-K7A3EOIM.js +0 -85
- package/dist/chunk-K7A3EOIM.js.map +0 -1
- package/dist/chunk-KPBNX6GP.mjs +0 -215
- package/dist/chunk-KPBNX6GP.mjs.map +0 -1
- package/dist/chunk-LKVWPNXY.js +0 -429
- package/dist/chunk-LKVWPNXY.js.map +0 -1
- package/dist/chunk-MZI3SDQN.js +0 -215
- package/dist/chunk-MZI3SDQN.js.map +0 -1
- package/dist/chunk-NDUMUEE6.js +0 -812
- package/dist/chunk-NDUMUEE6.js.map +0 -1
- package/dist/chunk-OBUR4TXH.js +0 -1
- package/dist/chunk-OBUR4TXH.js.map +0 -1
- package/dist/chunk-RGHTNZQ6.js +0 -12
- package/dist/chunk-RGHTNZQ6.js.map +0 -1
- package/dist/chunk-S5CFNNOM.mjs +0 -115
- package/dist/chunk-S5CFNNOM.mjs.map +0 -1
- package/dist/chunk-SK2B36Q4.mjs +0 -1405
- package/dist/chunk-SK2B36Q4.mjs.map +0 -1
- package/dist/chunk-TFLYM4PY.mjs +0 -291
- package/dist/chunk-TFLYM4PY.mjs.map +0 -1
- package/dist/chunk-TIFLP53R.js +0 -210
- package/dist/chunk-TIFLP53R.js.map +0 -1
- package/dist/chunk-TTH3ES66.mjs +0 -1
- package/dist/chunk-TTH3ES66.mjs.map +0 -1
- package/dist/chunk-UKXD6WUT.mjs +0 -157
- package/dist/chunk-UKXD6WUT.mjs.map +0 -1
- package/dist/chunk-UUF4E7OG.js +0 -530
- package/dist/chunk-UUF4E7OG.js.map +0 -1
- package/dist/chunk-V6DNVROD.js +0 -348
- package/dist/chunk-V6DNVROD.js.map +0 -1
- package/dist/chunk-XC3SOOGC.js +0 -1
- package/dist/chunk-XC3SOOGC.js.map +0 -1
- package/dist/chunk-XMQA5NLX.mjs +0 -812
- package/dist/chunk-XMQA5NLX.mjs.map +0 -1
- package/dist/chunk-XQO3EG4J.mjs +0 -348
- package/dist/chunk-XQO3EG4J.mjs.map +0 -1
- package/dist/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-XUI43LEZ.mjs.map +0 -1
- package/dist/chunk-YGGUAMHV.js +0 -135
- package/dist/chunk-YGGUAMHV.js.map +0 -1
- package/dist/chunk-Z4BLTVTB.js +0 -30
- package/dist/chunk-Z4BLTVTB.js.map +0 -1
- package/dist/chunk-Z7RMCHD4.mjs +0 -282
- package/dist/chunk-Z7RMCHD4.mjs.map +0 -1
- package/dist/chunk-ZAR4BIOC.js +0 -291
- package/dist/chunk-ZAR4BIOC.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/crypto-compare-service/crypto-compare.js +0 -10
- package/dist/crypto-compare-service/crypto-compare.js.map +0 -1
- package/dist/crypto-compare-service/index.js +0 -11
- package/dist/crypto-compare-service/index.js.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.js +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.js.map +0 -1
- package/dist/token-prices-service/codefi-v2.js +0 -14
- package/dist/token-prices-service/codefi-v2.js.map +0 -1
- package/dist/token-prices-service/index.js +0 -11
- package/dist/token-prices-service/index.js.map +0 -1
- package/dist/token-service.js +0 -15
- package/dist/token-service.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/AccountTrackerController.d.ts.map +0 -1
- package/dist/types/AssetsContractController.d.ts.map +0 -1
- package/dist/types/CurrencyRateController.d.ts.map +0 -1
- package/dist/types/NftController.d.ts.map +0 -1
- package/dist/types/NftDetectionController.d.ts.map +0 -1
- package/dist/types/RatesController/RatesController.d.ts.map +0 -1
- package/dist/types/RatesController/index.d.ts.map +0 -1
- package/dist/types/RatesController/types.d.ts.map +0 -1
- package/dist/types/Standards/ERC20Standard.d.ts.map +0 -1
- package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
- package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
- package/dist/types/TokenBalancesController.d.ts.map +0 -1
- package/dist/types/TokenDetectionController.d.ts.map +0 -1
- package/dist/types/TokenListController.d.ts.map +0 -1
- package/dist/types/TokenRatesController.d.ts.map +0 -1
- package/dist/types/TokensController.d.ts.map +0 -1
- package/dist/types/assetsUtil.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +0 -1
- package/dist/types/crypto-compare-service/index.d.ts +0 -2
- package/dist/types/crypto-compare-service/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +0 -1
- package/dist/types/token-prices-service/index.d.ts +0 -3
- package/dist/types/token-prices-service/index.d.ts.map +0 -1
- package/dist/types/token-service.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/RatesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA0B","sourcesContent":["export { RatesController, Cryptocurrency } from './RatesController';\nexport type {\n RatesControllerState,\n RatesControllerEvents,\n RatesControllerActions,\n RatesControllerMessenger,\n RatesControllerGetStateAction,\n RatesControllerStateChangeEvent,\n RatesControllerPollingStartedEvent,\n RatesControllerPollingStoppedEvent,\n} from './types';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a string that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate. For this field we use string as the data type to avoid potential rounding\n * errors and precision loss.\n * The `usdConversionRate` provides the conversion rate to USD as a string, or `null` if the\n * conversion rate to USD is not available. We also use string for the same reason as stated before.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: string;\n conversionDate: number;\n usdConversionRate?: string;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = RestrictedControllerMessenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents,\n never,\n never\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from
|
|
3
|
-
import type { name as ratesControllerName, Cryptocurrency } from
|
|
1
|
+
import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
+
import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.cjs";
|
|
3
|
+
import type { name as ratesControllerName, Cryptocurrency } from "./RatesController.cjs";
|
|
4
4
|
/**
|
|
5
5
|
* Represents the conversion rates from one currency to others, including the conversion date.
|
|
6
6
|
* The `conversionRate` field is a string that maps a cryptocurrency code (e.g., "BTC") to its
|
|
@@ -97,4 +97,4 @@ export type RatesControllerOptions = {
|
|
|
97
97
|
*/
|
|
98
98
|
fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;
|
|
99
99
|
};
|
|
100
|
-
//# sourceMappingURL=types.d.
|
|
100
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AACpG,OAAO,KAAK,EACV,IAAI,IAAI,mBAAmB,EAC3B,cAAc,EACf,8BAA0B;AAE3B;;;;;;;;GAQG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAA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S,EAAE,wBAAwB,CAAC;IACpC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACtC;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,wBAAwB,CAAC;CAC1D,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
+
import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.mjs";
|
|
3
|
+
import type { name as ratesControllerName, Cryptocurrency } from "./RatesController.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Represents the conversion rates from one currency to others, including the conversion date.
|
|
6
|
+
* The `conversionRate` field is a string that maps a cryptocurrency code (e.g., "BTC") to its
|
|
7
|
+
* conversion rate. For this field we use string as the data type to avoid potential rounding
|
|
8
|
+
* errors and precision loss.
|
|
9
|
+
* The `usdConversionRate` provides the conversion rate to USD as a string, or `null` if the
|
|
10
|
+
* conversion rate to USD is not available. We also use string for the same reason as stated before.
|
|
11
|
+
* The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.
|
|
12
|
+
*/
|
|
13
|
+
export type Rate = {
|
|
14
|
+
conversionRate: string;
|
|
15
|
+
conversionDate: number;
|
|
16
|
+
usdConversionRate?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Represents the conversion rates for multiple cryptocurrencies.
|
|
20
|
+
* Each key is a string representing the cryptocurrency symbol (e.g., "BTC", "SOL"),
|
|
21
|
+
* and its value is a `Rate` object containing conversion rates from that cryptocurrency
|
|
22
|
+
* to a fiat currencies and an optional USD rate.
|
|
23
|
+
*/
|
|
24
|
+
export type ConversionRates = Record<string, Rate>;
|
|
25
|
+
/**
|
|
26
|
+
* Represents the state structure for the RatesController.
|
|
27
|
+
*/
|
|
28
|
+
export type RatesControllerState = {
|
|
29
|
+
/**
|
|
30
|
+
* The fiat currency in which conversion rates are expressed
|
|
31
|
+
* (i.e., the "to" currency).
|
|
32
|
+
*/
|
|
33
|
+
fiatCurrency: string;
|
|
34
|
+
/**
|
|
35
|
+
* The conversion rates for multiple cryptocurrencies.
|
|
36
|
+
*/
|
|
37
|
+
rates: ConversionRates;
|
|
38
|
+
/**
|
|
39
|
+
* A list of supported cryptocurrency symbols.
|
|
40
|
+
* (i.e., the "from" currencies).
|
|
41
|
+
*/
|
|
42
|
+
cryptocurrencies: Cryptocurrency[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Type definition for RatesController state change events.
|
|
46
|
+
*/
|
|
47
|
+
export type RatesControllerStateChangeEvent = ControllerStateChangeEvent<typeof ratesControllerName, RatesControllerState>;
|
|
48
|
+
/**
|
|
49
|
+
* Type definition for the RatesController polling started event.
|
|
50
|
+
*/
|
|
51
|
+
export type RatesControllerPollingStartedEvent = {
|
|
52
|
+
type: `${typeof ratesControllerName}:pollingStarted`;
|
|
53
|
+
payload: [];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Type definition for the RatesController polling stopped event.
|
|
57
|
+
*/
|
|
58
|
+
export type RatesControllerPollingStoppedEvent = {
|
|
59
|
+
type: `${typeof ratesControllerName}:pollingStopped`;
|
|
60
|
+
payload: [];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Defines the events that the RatesController can emit.
|
|
64
|
+
*/
|
|
65
|
+
export type RatesControllerEvents = RatesControllerStateChangeEvent | RatesControllerPollingStartedEvent | RatesControllerPollingStoppedEvent;
|
|
66
|
+
export type RatesControllerGetStateAction = ControllerGetStateAction<typeof ratesControllerName, RatesControllerState>;
|
|
67
|
+
/**
|
|
68
|
+
* Defines the actions that can be performed to get the state of the RatesController.
|
|
69
|
+
*/
|
|
70
|
+
export type RatesControllerActions = RatesControllerGetStateAction;
|
|
71
|
+
/**
|
|
72
|
+
* Defines the actions that the RatesController can perform.
|
|
73
|
+
*/
|
|
74
|
+
export type RatesControllerMessenger = RestrictedControllerMessenger<typeof ratesControllerName, RatesControllerActions, RatesControllerEvents, never, never>;
|
|
75
|
+
/**
|
|
76
|
+
* The options required to initialize a RatesController.
|
|
77
|
+
*/
|
|
78
|
+
export type RatesControllerOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* Whether to include USD rates in the conversion rates.
|
|
81
|
+
*/
|
|
82
|
+
includeUsdRate: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The polling interval in milliseconds.
|
|
85
|
+
*/
|
|
86
|
+
interval?: number;
|
|
87
|
+
/**
|
|
88
|
+
* The messenger instance for communication.
|
|
89
|
+
*/
|
|
90
|
+
messenger: RatesControllerMessenger;
|
|
91
|
+
/**
|
|
92
|
+
* The initial state of the controller.
|
|
93
|
+
*/
|
|
94
|
+
state?: Partial<RatesControllerState>;
|
|
95
|
+
/**
|
|
96
|
+
* The function to fetch exchange rates.
|
|
97
|
+
*/
|
|
98
|
+
fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AACpG,OAAO,KAAK,EACV,IAAI,IAAI,mBAAmB,EAC3B,cAAc,EACf,8BAA0B;AAE3B;;;;;;;;GAQG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEnD;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,OAAO,wBAAwB,CAAC;CAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a string that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate. For this field we use string as the data type to avoid potential rounding\n * errors and precision loss.\n * The `usdConversionRate` provides the conversion rate to USD as a string, or `null` if the\n * conversion rate to USD is not available. We also use string for the same reason as stated before.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: string;\n conversionDate: number;\n usdConversionRate?: string;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = RestrictedControllerMessenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents,\n never,\n never\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC20Standard = void 0;
|
|
4
|
+
const util_1 = require("@ethereumjs/util");
|
|
5
|
+
const contracts_1 = require("@ethersproject/contracts");
|
|
6
|
+
const abi_utils_1 = require("@metamask/abi-utils");
|
|
7
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
8
|
+
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
9
|
+
const utils_1 = require("@metamask/utils");
|
|
10
|
+
const assetsUtil_1 = require("../assetsUtil.cjs");
|
|
11
|
+
class ERC20Standard {
|
|
12
|
+
constructor(provider) {
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get balance or count for current account on specific asset contract.
|
|
17
|
+
*
|
|
18
|
+
* @param address - Asset ERC20 contract address.
|
|
19
|
+
* @param selectedAddress - Current account public address.
|
|
20
|
+
* @returns Promise resolving to BN object containing balance for current account on specific asset contract.
|
|
21
|
+
*/
|
|
22
|
+
async getBalanceOf(address, selectedAddress) {
|
|
23
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC20, this.provider);
|
|
24
|
+
const balance = await contract.balanceOf(selectedAddress);
|
|
25
|
+
return (0, assetsUtil_1.ethersBigNumberToBN)(balance);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Query for the decimals for a given ERC20 asset.
|
|
29
|
+
*
|
|
30
|
+
* @param address - ERC20 asset contract string.
|
|
31
|
+
* @returns Promise resolving to the 'decimals'.
|
|
32
|
+
*/
|
|
33
|
+
async getTokenDecimals(address) {
|
|
34
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC20, this.provider);
|
|
35
|
+
try {
|
|
36
|
+
const decimals = await contract.decimals();
|
|
37
|
+
return decimals.toString();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
// Mirror previous implementation
|
|
41
|
+
if (err instanceof Error &&
|
|
42
|
+
err.message.includes('call revert exception')) {
|
|
43
|
+
throw new Error('Failed to parse token decimals');
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Query for the name for a given ERC20 asset.
|
|
50
|
+
*
|
|
51
|
+
* @param address - ERC20 asset contract string.
|
|
52
|
+
* @returns Promise resolving to the 'name'.
|
|
53
|
+
*/
|
|
54
|
+
async getTokenName(address) {
|
|
55
|
+
const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC20, this.provider);
|
|
56
|
+
try {
|
|
57
|
+
const name = await contract.name();
|
|
58
|
+
return name.toString();
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
// Mirror previous implementation
|
|
62
|
+
if (err instanceof Error &&
|
|
63
|
+
err.message.includes('call revert exception')) {
|
|
64
|
+
throw new Error('Failed to parse token name');
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Query for symbol for a given ERC20 asset.
|
|
71
|
+
*
|
|
72
|
+
* @param address - ERC20 asset contract address.
|
|
73
|
+
* @returns Promise resolving to the 'symbol'.
|
|
74
|
+
*/
|
|
75
|
+
async getTokenSymbol(address) {
|
|
76
|
+
// Signature for calling `symbol()`
|
|
77
|
+
const payload = { to: address, data: '0x95d89b41' };
|
|
78
|
+
const result = await this.provider.call(payload);
|
|
79
|
+
(0, utils_1.assertIsStrictHexString)(result);
|
|
80
|
+
// Parse as string - treat empty string as failure
|
|
81
|
+
try {
|
|
82
|
+
const decoded = (0, abi_utils_1.decodeSingle)('string', result);
|
|
83
|
+
if (decoded?.length > 0) {
|
|
84
|
+
return decoded;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Ignore error
|
|
89
|
+
}
|
|
90
|
+
// Parse as bytes - treat empty string as failure
|
|
91
|
+
try {
|
|
92
|
+
const utf8 = (0, util_1.toUtf8)(result);
|
|
93
|
+
if (utf8.length > 0) {
|
|
94
|
+
return utf8;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Ignore error
|
|
99
|
+
}
|
|
100
|
+
throw new Error('Failed to parse token symbol');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Query if a contract implements an interface.
|
|
104
|
+
*
|
|
105
|
+
* @param address - Asset contract address.
|
|
106
|
+
* @param userAddress - The public address for the currently active user's account.
|
|
107
|
+
* @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.
|
|
108
|
+
*/
|
|
109
|
+
async getDetails(address, userAddress) {
|
|
110
|
+
const [decimals, symbol, balance] = await Promise.all([
|
|
111
|
+
this.getTokenDecimals(address),
|
|
112
|
+
this.getTokenSymbol(address),
|
|
113
|
+
userAddress ? this.getBalanceOf(address, userAddress) : undefined,
|
|
114
|
+
]);
|
|
115
|
+
return {
|
|
116
|
+
decimals,
|
|
117
|
+
symbol,
|
|
118
|
+
balance,
|
|
119
|
+
standard: controller_utils_1.ERC20,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.ERC20Standard = ERC20Standard;
|
|
124
|
+
//# sourceMappingURL=ERC20Standard.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC20Standard.cjs","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAC1C,wDAAoD;AAEpD,mDAAmD;AACnD,iEAAmD;AACnD,mEAAuD;AACvD,2CAA0D;AAG1D,kDAAoD;AAEpD,MAAa,aAAa;IAGxB,YAAY,QAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,eAAuB;QACzD,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,EAAE,4BAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QAC1D,OAAO,IAAA,gCAAmB,EAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,gBAAgB,CAAC,OAAe;QACpC,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,EAAE,4BAAQ,EAAE,IAAI,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C,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,OAAO,EAAE,MAAM,GAAG,CAAC,EAAE;gBACvB,OAAO,OAAO,CAAC;aAChB;SACF;QAAC,MAAM;YACN,eAAe;SAChB;QAED,iDAAiD;QACjD,IAAI;YACF,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC;YAC5B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnB,OAAO,IAAI,CAAC;aACb;SACF;QAAC,MAAM;YACN,eAAe;SAChB;QAED,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CACd,OAAe,EACf,WAAoB;QAOpB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACpD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAC5B,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;SAClE,CAAC,CAAC;QACH,OAAO;YACL,QAAQ;YACR,MAAM;YACN,OAAO;YACP,QAAQ,EAAE,wBAAK;SAChB,CAAC;IACJ,CAAC;CACF;AAhID,sCAgIC","sourcesContent":["import { toUtf8 } from '@ethereumjs/util';\nimport { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport { decodeSingle } from '@metamask/abi-utils';\nimport { ERC20 } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { assertIsStrictHexString } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { ethersBigNumberToBN } from '../assetsUtil';\n\nexport class ERC20Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Get balance or count for current account on specific asset contract.\n *\n * @param address - Asset ERC20 contract address.\n * @param selectedAddress - Current account public address.\n * @returns Promise resolving to BN object containing balance for current account on specific asset contract.\n */\n async getBalanceOf(address: string, selectedAddress: string): Promise<BN> {\n const contract = new Contract(address, abiERC20, this.provider);\n const balance = await contract.balanceOf(selectedAddress);\n return ethersBigNumberToBN(balance);\n }\n\n /**\n * Query for the decimals for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'decimals'.\n */\n async getTokenDecimals(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const decimals = await contract.decimals();\n return decimals.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token decimals');\n }\n throw err;\n }\n }\n\n /**\n * Query for the name for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'name'.\n */\n async getTokenName(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const name = await contract.name();\n return name.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token name');\n }\n throw err;\n }\n }\n\n /**\n * Query for symbol for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getTokenSymbol(address: string): Promise<string> {\n // Signature for calling `symbol()`\n const payload = { to: address, data: '0x95d89b41' };\n const result = await this.provider.call(payload);\n assertIsStrictHexString(result);\n // Parse as string - treat empty string as failure\n try {\n const decoded = decodeSingle('string', result);\n if (decoded?.length > 0) {\n return decoded;\n }\n } catch {\n // Ignore error\n }\n\n // Parse as bytes - treat empty string as failure\n try {\n const utf8 = toUtf8(result);\n if (utf8.length > 0) {\n return utf8;\n }\n } catch {\n // Ignore error\n }\n\n throw new Error('Failed to parse token symbol');\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param userAddress - The public address for the currently active user's account.\n * @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.\n */\n async getDetails(\n address: string,\n userAddress?: string,\n ): Promise<{\n standard: string;\n symbol: string | undefined;\n decimals: string | undefined;\n balance: BN | undefined;\n }> {\n const [decimals, symbol, balance] = await Promise.all([\n this.getTokenDecimals(address),\n this.getTokenSymbol(address),\n userAddress ? this.getBalanceOf(address, userAddress) : undefined,\n ]);\n return {\n decimals,\n symbol,\n balance,\n standard: ERC20,\n };\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Web3Provider } from
|
|
2
|
-
import type BN from
|
|
1
|
+
import type { Web3Provider } from "@ethersproject/providers";
|
|
2
|
+
import type BN from "bn.js";
|
|
3
3
|
export declare class ERC20Standard {
|
|
4
4
|
private readonly provider;
|
|
5
5
|
constructor(provider: Web3Provider);
|
|
@@ -46,4 +46,4 @@ export declare class ERC20Standard {
|
|
|
46
46
|
balance: BN | undefined;
|
|
47
47
|
}>;
|
|
48
48
|
}
|
|
49
|
-
//# sourceMappingURL=ERC20Standard.d.
|
|
49
|
+
//# sourceMappingURL=ERC20Standard.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC20Standard.d.cts","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,iCAAiC;AAK7D,OAAO,KAAK,EAAE,cAAc;AAI5B,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,QAAQ,EAAE,YAAY;IAIlC;;;;;;OAMG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAMzE;;;;;OAKG;IACG,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBxD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBpD;;;;;OAKG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BtD;;;;;;OAMG;IACG,UAAU,CACd,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,EAAE,GAAG,SAAS,CAAC;KACzB,CAAC;CAaH"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Web3Provider } from "@ethersproject/providers";
|
|
2
|
+
import type BN from "bn.js";
|
|
3
|
+
export declare class ERC20Standard {
|
|
4
|
+
private readonly provider;
|
|
5
|
+
constructor(provider: Web3Provider);
|
|
6
|
+
/**
|
|
7
|
+
* Get balance or count for current account on specific asset contract.
|
|
8
|
+
*
|
|
9
|
+
* @param address - Asset ERC20 contract address.
|
|
10
|
+
* @param selectedAddress - Current account public address.
|
|
11
|
+
* @returns Promise resolving to BN object containing balance for current account on specific asset contract.
|
|
12
|
+
*/
|
|
13
|
+
getBalanceOf(address: string, selectedAddress: string): Promise<BN>;
|
|
14
|
+
/**
|
|
15
|
+
* Query for the decimals for a given ERC20 asset.
|
|
16
|
+
*
|
|
17
|
+
* @param address - ERC20 asset contract string.
|
|
18
|
+
* @returns Promise resolving to the 'decimals'.
|
|
19
|
+
*/
|
|
20
|
+
getTokenDecimals(address: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Query for the name for a given ERC20 asset.
|
|
23
|
+
*
|
|
24
|
+
* @param address - ERC20 asset contract string.
|
|
25
|
+
* @returns Promise resolving to the 'name'.
|
|
26
|
+
*/
|
|
27
|
+
getTokenName(address: string): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Query for symbol for a given ERC20 asset.
|
|
30
|
+
*
|
|
31
|
+
* @param address - ERC20 asset contract address.
|
|
32
|
+
* @returns Promise resolving to the 'symbol'.
|
|
33
|
+
*/
|
|
34
|
+
getTokenSymbol(address: string): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Query if a contract implements an interface.
|
|
37
|
+
*
|
|
38
|
+
* @param address - Asset contract address.
|
|
39
|
+
* @param userAddress - The public address for the currently active user's account.
|
|
40
|
+
* @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.
|
|
41
|
+
*/
|
|
42
|
+
getDetails(address: string, userAddress?: string): Promise<{
|
|
43
|
+
standard: string;
|
|
44
|
+
symbol: string | undefined;
|
|
45
|
+
decimals: string | undefined;
|
|
46
|
+
balance: BN | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ERC20Standard.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC20Standard.d.mts","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,iCAAiC;AAK7D,OAAO,KAAK,EAAE,cAAc;AAI5B,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,QAAQ,EAAE,YAAY;IAIlC;;;;;;OAMG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAMzE;;;;;OAKG;IACG,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBxD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBpD;;;;;OAKG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BtD;;;;;;OAMG;IACG,UAAU,CACd,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,EAAE,GAAG,SAAS,CAAC;KACzB,CAAC;CAaH"}
|
|
@@ -1,9 +1,122 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
import "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
1
|
+
import $ethereumjsutil from "@ethereumjs/util";
|
|
2
|
+
const { toUtf8 } = $ethereumjsutil;
|
|
3
|
+
import { Contract } from "@ethersproject/contracts";
|
|
4
|
+
import $metamaskabiutils from "@metamask/abi-utils";
|
|
5
|
+
const { decodeSingle } = $metamaskabiutils;
|
|
6
|
+
import { ERC20 } from "@metamask/controller-utils";
|
|
7
|
+
import { abiERC20 } from "@metamask/metamask-eth-abis";
|
|
8
|
+
import { assertIsStrictHexString } from "@metamask/utils";
|
|
9
|
+
import { ethersBigNumberToBN } from "../assetsUtil.mjs";
|
|
10
|
+
export class ERC20Standard {
|
|
11
|
+
constructor(provider) {
|
|
12
|
+
this.provider = provider;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get balance or count for current account on specific asset contract.
|
|
16
|
+
*
|
|
17
|
+
* @param address - Asset ERC20 contract address.
|
|
18
|
+
* @param selectedAddress - Current account public address.
|
|
19
|
+
* @returns Promise resolving to BN object containing balance for current account on specific asset contract.
|
|
20
|
+
*/
|
|
21
|
+
async getBalanceOf(address, selectedAddress) {
|
|
22
|
+
const contract = new Contract(address, abiERC20, this.provider);
|
|
23
|
+
const balance = await contract.balanceOf(selectedAddress);
|
|
24
|
+
return ethersBigNumberToBN(balance);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Query for the decimals for a given ERC20 asset.
|
|
28
|
+
*
|
|
29
|
+
* @param address - ERC20 asset contract string.
|
|
30
|
+
* @returns Promise resolving to the 'decimals'.
|
|
31
|
+
*/
|
|
32
|
+
async getTokenDecimals(address) {
|
|
33
|
+
const contract = new Contract(address, abiERC20, this.provider);
|
|
34
|
+
try {
|
|
35
|
+
const decimals = await contract.decimals();
|
|
36
|
+
return decimals.toString();
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
// Mirror previous implementation
|
|
40
|
+
if (err instanceof Error &&
|
|
41
|
+
err.message.includes('call revert exception')) {
|
|
42
|
+
throw new Error('Failed to parse token decimals');
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Query for the name for a given ERC20 asset.
|
|
49
|
+
*
|
|
50
|
+
* @param address - ERC20 asset contract string.
|
|
51
|
+
* @returns Promise resolving to the 'name'.
|
|
52
|
+
*/
|
|
53
|
+
async getTokenName(address) {
|
|
54
|
+
const contract = new Contract(address, abiERC20, this.provider);
|
|
55
|
+
try {
|
|
56
|
+
const name = await contract.name();
|
|
57
|
+
return name.toString();
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
// Mirror previous implementation
|
|
61
|
+
if (err instanceof Error &&
|
|
62
|
+
err.message.includes('call revert exception')) {
|
|
63
|
+
throw new Error('Failed to parse token name');
|
|
64
|
+
}
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Query for symbol for a given ERC20 asset.
|
|
70
|
+
*
|
|
71
|
+
* @param address - ERC20 asset contract address.
|
|
72
|
+
* @returns Promise resolving to the 'symbol'.
|
|
73
|
+
*/
|
|
74
|
+
async getTokenSymbol(address) {
|
|
75
|
+
// Signature for calling `symbol()`
|
|
76
|
+
const payload = { to: address, data: '0x95d89b41' };
|
|
77
|
+
const result = await this.provider.call(payload);
|
|
78
|
+
assertIsStrictHexString(result);
|
|
79
|
+
// Parse as string - treat empty string as failure
|
|
80
|
+
try {
|
|
81
|
+
const decoded = decodeSingle('string', result);
|
|
82
|
+
if (decoded?.length > 0) {
|
|
83
|
+
return decoded;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Ignore error
|
|
88
|
+
}
|
|
89
|
+
// Parse as bytes - treat empty string as failure
|
|
90
|
+
try {
|
|
91
|
+
const utf8 = toUtf8(result);
|
|
92
|
+
if (utf8.length > 0) {
|
|
93
|
+
return utf8;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Ignore error
|
|
98
|
+
}
|
|
99
|
+
throw new Error('Failed to parse token symbol');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Query if a contract implements an interface.
|
|
103
|
+
*
|
|
104
|
+
* @param address - Asset contract address.
|
|
105
|
+
* @param userAddress - The public address for the currently active user's account.
|
|
106
|
+
* @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.
|
|
107
|
+
*/
|
|
108
|
+
async getDetails(address, userAddress) {
|
|
109
|
+
const [decimals, symbol, balance] = await Promise.all([
|
|
110
|
+
this.getTokenDecimals(address),
|
|
111
|
+
this.getTokenSymbol(address),
|
|
112
|
+
userAddress ? this.getBalanceOf(address, userAddress) : undefined,
|
|
113
|
+
]);
|
|
114
|
+
return {
|
|
115
|
+
decimals,
|
|
116
|
+
symbol,
|
|
117
|
+
balance,
|
|
118
|
+
standard: ERC20,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
9
122
|
//# sourceMappingURL=ERC20Standard.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"ERC20Standard.mjs","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":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AE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACpD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAC5B,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;SAClE,CAAC,CAAC;QACH,OAAO;YACL,QAAQ;YACR,MAAM;YACN,OAAO;YACP,QAAQ,EAAE,KAAK;SAChB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { toUtf8 } from '@ethereumjs/util';\nimport { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport { decodeSingle } from '@metamask/abi-utils';\nimport { ERC20 } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { assertIsStrictHexString } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { ethersBigNumberToBN } from '../assetsUtil';\n\nexport class ERC20Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Get balance or count for current account on specific asset contract.\n *\n * @param address - Asset ERC20 contract address.\n * @param selectedAddress - Current account public address.\n * @returns Promise resolving to BN object containing balance for current account on specific asset contract.\n */\n async getBalanceOf(address: string, selectedAddress: string): Promise<BN> {\n const contract = new Contract(address, abiERC20, this.provider);\n const balance = await contract.balanceOf(selectedAddress);\n return ethersBigNumberToBN(balance);\n }\n\n /**\n * Query for the decimals for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'decimals'.\n */\n async getTokenDecimals(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const decimals = await contract.decimals();\n return decimals.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token decimals');\n }\n throw err;\n }\n }\n\n /**\n * Query for the name for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'name'.\n */\n async getTokenName(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const name = await contract.name();\n return name.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token name');\n }\n throw err;\n }\n }\n\n /**\n * Query for symbol for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getTokenSymbol(address: string): Promise<string> {\n // Signature for calling `symbol()`\n const payload = { to: address, data: '0x95d89b41' };\n const result = await this.provider.call(payload);\n assertIsStrictHexString(result);\n // Parse as string - treat empty string as failure\n try {\n const decoded = decodeSingle('string', result);\n if (decoded?.length > 0) {\n return decoded;\n }\n } catch {\n // Ignore error\n }\n\n // Parse as bytes - treat empty string as failure\n try {\n const utf8 = toUtf8(result);\n if (utf8.length > 0) {\n return utf8;\n }\n } catch {\n // Ignore error\n }\n\n throw new Error('Failed to parse token symbol');\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param userAddress - The public address for the currently active user's account.\n * @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.\n */\n async getDetails(\n address: string,\n userAddress?: string,\n ): Promise<{\n standard: string;\n symbol: string | undefined;\n decimals: string | undefined;\n balance: BN | undefined;\n }> {\n const [decimals, symbol, balance] = await Promise.all([\n this.getTokenDecimals(address),\n this.getTokenSymbol(address),\n userAddress ? this.getBalanceOf(address, userAddress) : undefined,\n ]);\n return {\n decimals,\n symbol,\n balance,\n standard: ERC20,\n };\n }\n}\n"]}
|