@metamask/assets-controllers 25.0.0 → 27.0.0

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.
Files changed (235) hide show
  1. package/CHANGELOG.md +210 -39
  2. package/dist/AccountTrackerController.js +9 -236
  3. package/dist/AccountTrackerController.js.map +1 -1
  4. package/dist/AccountTrackerController.mjs +10 -0
  5. package/dist/AccountTrackerController.mjs.map +1 -0
  6. package/dist/AssetsContractController.js +17 -385
  7. package/dist/AssetsContractController.js.map +1 -1
  8. package/dist/AssetsContractController.mjs +18 -0
  9. package/dist/AssetsContractController.mjs.map +1 -0
  10. package/dist/CurrencyRateController.js +10 -157
  11. package/dist/CurrencyRateController.js.map +1 -1
  12. package/dist/CurrencyRateController.mjs +11 -0
  13. package/dist/CurrencyRateController.mjs.map +1 -0
  14. package/dist/NftController.js +15 -1039
  15. package/dist/NftController.js.map +1 -1
  16. package/dist/NftController.mjs +16 -0
  17. package/dist/NftController.mjs.map +1 -0
  18. package/dist/NftDetectionController.js +12 -215
  19. package/dist/NftDetectionController.js.map +1 -1
  20. package/dist/NftDetectionController.mjs +13 -0
  21. package/dist/NftDetectionController.mjs.map +1 -0
  22. package/dist/Standards/ERC20Standard.js +8 -144
  23. package/dist/Standards/ERC20Standard.js.map +1 -1
  24. package/dist/Standards/ERC20Standard.mjs +9 -0
  25. package/dist/Standards/ERC20Standard.mjs.map +1 -0
  26. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +8 -217
  27. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +1 -1
  28. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +9 -0
  29. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -0
  30. package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +8 -175
  31. package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +1 -1
  32. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +9 -0
  33. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -0
  34. package/dist/TokenBalancesController.js +11 -144
  35. package/dist/TokenBalancesController.js.map +1 -1
  36. package/dist/TokenBalancesController.mjs +12 -0
  37. package/dist/TokenBalancesController.mjs.map +1 -0
  38. package/dist/TokenDetectionController.js +16 -245
  39. package/dist/TokenDetectionController.js.map +1 -1
  40. package/dist/TokenDetectionController.mjs +17 -0
  41. package/dist/TokenDetectionController.mjs.map +1 -0
  42. package/dist/TokenListController.js +13 -250
  43. package/dist/TokenListController.js.map +1 -1
  44. package/dist/TokenListController.mjs +14 -0
  45. package/dist/TokenListController.mjs.map +1 -0
  46. package/dist/TokenRatesController.js +11 -328
  47. package/dist/TokenRatesController.js.map +1 -1
  48. package/dist/TokenRatesController.mjs +12 -0
  49. package/dist/TokenRatesController.mjs.map +1 -0
  50. package/dist/TokensController.js +15 -636
  51. package/dist/TokensController.js.map +1 -1
  52. package/dist/TokensController.mjs +16 -0
  53. package/dist/TokensController.mjs.map +1 -0
  54. package/dist/assetsUtil.js +41 -380
  55. package/dist/assetsUtil.js.map +1 -1
  56. package/dist/assetsUtil.mjs +42 -0
  57. package/dist/assetsUtil.mjs.map +1 -0
  58. package/dist/chunk-23F5W3A2.mjs +157 -0
  59. package/dist/chunk-23F5W3A2.mjs.map +1 -0
  60. package/dist/chunk-27KOXCQK.mjs +1 -0
  61. package/dist/chunk-27KOXCQK.mjs.map +1 -0
  62. package/dist/chunk-3FMWI46J.mjs +361 -0
  63. package/dist/chunk-3FMWI46J.mjs.map +1 -0
  64. package/dist/chunk-3FOTFZIL.mjs +411 -0
  65. package/dist/chunk-3FOTFZIL.mjs.map +1 -0
  66. package/dist/chunk-4LY47RPI.mjs +139 -0
  67. package/dist/chunk-4LY47RPI.mjs.map +1 -0
  68. package/dist/chunk-5C7ZVZNM.mjs +267 -0
  69. package/dist/chunk-5C7ZVZNM.mjs.map +1 -0
  70. package/dist/chunk-64EHFYLM.mjs +245 -0
  71. package/dist/chunk-64EHFYLM.mjs.map +1 -0
  72. package/dist/chunk-6C2ZIK7A.js +245 -0
  73. package/dist/chunk-6C2ZIK7A.js.map +1 -0
  74. package/dist/chunk-6DTCHPBB.mjs +178 -0
  75. package/dist/chunk-6DTCHPBB.mjs.map +1 -0
  76. package/dist/chunk-74IP34EL.js +1177 -0
  77. package/dist/chunk-74IP34EL.js.map +1 -0
  78. package/dist/chunk-BZI7P3TD.js +115 -0
  79. package/dist/chunk-BZI7P3TD.js.map +1 -0
  80. package/dist/chunk-C4PQK53K.js +32 -0
  81. package/dist/chunk-C4PQK53K.js.map +1 -0
  82. package/dist/chunk-CP3HC7AQ.mjs +12 -0
  83. package/dist/chunk-CP3HC7AQ.mjs.map +1 -0
  84. package/dist/chunk-GHZX5DE4.js +215 -0
  85. package/dist/chunk-GHZX5DE4.js.map +1 -0
  86. package/dist/chunk-GMKIOYCB.js +361 -0
  87. package/dist/chunk-GMKIOYCB.js.map +1 -0
  88. package/dist/chunk-H6TOSWUM.js +157 -0
  89. package/dist/chunk-H6TOSWUM.js.map +1 -0
  90. package/dist/chunk-HWFBJFHS.js +284 -0
  91. package/dist/chunk-HWFBJFHS.js.map +1 -0
  92. package/dist/chunk-J2JQQNHN.mjs +115 -0
  93. package/dist/chunk-J2JQQNHN.mjs.map +1 -0
  94. package/dist/chunk-J6HPEQL3.mjs +704 -0
  95. package/dist/chunk-J6HPEQL3.mjs.map +1 -0
  96. package/dist/chunk-JC4WAN2J.mjs +1177 -0
  97. package/dist/chunk-JC4WAN2J.mjs.map +1 -0
  98. package/dist/chunk-LD4GC7OR.js +139 -0
  99. package/dist/chunk-LD4GC7OR.js.map +1 -0
  100. package/dist/chunk-NG2UOKDD.js +178 -0
  101. package/dist/chunk-NG2UOKDD.js.map +1 -0
  102. package/dist/chunk-NGIXA5M5.mjs +418 -0
  103. package/dist/chunk-NGIXA5M5.mjs.map +1 -0
  104. package/dist/chunk-NLNXQHAU.js +704 -0
  105. package/dist/chunk-NLNXQHAU.js.map +1 -0
  106. package/dist/chunk-OBUR4TXH.js +1 -0
  107. package/dist/chunk-OBUR4TXH.js.map +1 -0
  108. package/dist/chunk-PAJTKWEC.mjs +246 -0
  109. package/dist/chunk-PAJTKWEC.mjs.map +1 -0
  110. package/dist/chunk-PRIXT2R6.js +411 -0
  111. package/dist/chunk-PRIXT2R6.js.map +1 -0
  112. package/dist/chunk-PUFSYRJZ.js +74 -0
  113. package/dist/chunk-PUFSYRJZ.js.map +1 -0
  114. package/dist/chunk-QHRPRO5U.mjs +74 -0
  115. package/dist/chunk-QHRPRO5U.mjs.map +1 -0
  116. package/dist/chunk-QR4CX2JT.mjs +284 -0
  117. package/dist/chunk-QR4CX2JT.mjs.map +1 -0
  118. package/dist/chunk-RGHTNZQ6.js +12 -0
  119. package/dist/chunk-RGHTNZQ6.js.map +1 -0
  120. package/dist/chunk-TCO22VIO.mjs +32 -0
  121. package/dist/chunk-TCO22VIO.mjs.map +1 -0
  122. package/dist/chunk-TDKCVCGP.mjs +215 -0
  123. package/dist/chunk-TDKCVCGP.mjs.map +1 -0
  124. package/dist/chunk-UAH5YURZ.js +343 -0
  125. package/dist/chunk-UAH5YURZ.js.map +1 -0
  126. package/dist/chunk-V4ZO3F2S.js +246 -0
  127. package/dist/chunk-V4ZO3F2S.js.map +1 -0
  128. package/dist/chunk-VDJBJAUB.js +418 -0
  129. package/dist/chunk-VDJBJAUB.js.map +1 -0
  130. package/dist/chunk-WRQ7POD7.mjs +343 -0
  131. package/dist/chunk-WRQ7POD7.mjs.map +1 -0
  132. package/dist/chunk-XUI43LEZ.mjs +30 -0
  133. package/dist/chunk-XUI43LEZ.mjs.map +1 -0
  134. package/dist/chunk-YD3NRMFC.js +267 -0
  135. package/dist/chunk-YD3NRMFC.js.map +1 -0
  136. package/dist/chunk-Z4BLTVTB.js +30 -0
  137. package/dist/chunk-Z4BLTVTB.js.map +1 -0
  138. package/dist/constants.js +7 -9
  139. package/dist/constants.js.map +1 -1
  140. package/dist/constants.mjs +8 -0
  141. package/dist/constants.mjs.map +1 -0
  142. package/dist/crypto-compare.js +7 -66
  143. package/dist/crypto-compare.js.map +1 -1
  144. package/dist/crypto-compare.mjs +8 -0
  145. package/dist/crypto-compare.mjs.map +1 -0
  146. package/dist/index.js +72 -36
  147. package/dist/index.js.map +1 -1
  148. package/dist/index.mjs +73 -0
  149. package/dist/index.mjs.map +1 -0
  150. package/dist/token-prices-service/abstract-token-prices-service.js +1 -3
  151. package/dist/token-prices-service/abstract-token-prices-service.js.map +1 -1
  152. package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
  153. package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -0
  154. package/dist/token-prices-service/codefi-v2.js +11 -353
  155. package/dist/token-prices-service/codefi-v2.js.map +1 -1
  156. package/dist/token-prices-service/codefi-v2.mjs +12 -0
  157. package/dist/token-prices-service/codefi-v2.mjs.map +1 -0
  158. package/dist/token-prices-service/index.js +8 -5
  159. package/dist/token-prices-service/index.js.map +1 -1
  160. package/dist/token-prices-service/index.mjs +9 -0
  161. package/dist/token-prices-service/index.mjs.map +1 -0
  162. package/dist/token-service.js +14 -133
  163. package/dist/token-service.js.map +1 -1
  164. package/dist/token-service.mjs +15 -0
  165. package/dist/token-service.mjs.map +1 -0
  166. package/dist/tsconfig.build.tsbuildinfo +1 -0
  167. package/dist/types/AccountTrackerController.d.ts.map +1 -0
  168. package/dist/{AssetsContractController.d.ts → types/AssetsContractController.d.ts} +5 -6
  169. package/dist/types/AssetsContractController.d.ts.map +1 -0
  170. package/dist/types/CurrencyRateController.d.ts.map +1 -0
  171. package/dist/types/NftController.d.ts.map +1 -0
  172. package/dist/types/NftDetectionController.d.ts.map +1 -0
  173. package/dist/{Standards → types/Standards}/ERC20Standard.d.ts +1 -2
  174. package/dist/types/Standards/ERC20Standard.d.ts.map +1 -0
  175. package/dist/{Standards → types/Standards}/NftStandards/ERC1155/ERC1155Standard.d.ts +1 -2
  176. package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +1 -0
  177. package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +1 -0
  178. package/dist/{TokenBalancesController.d.ts → types/TokenBalancesController.d.ts} +12 -10
  179. package/dist/types/TokenBalancesController.d.ts.map +1 -0
  180. package/dist/types/TokenDetectionController.d.ts +111 -0
  181. package/dist/types/TokenDetectionController.d.ts.map +1 -0
  182. package/dist/types/TokenListController.d.ts.map +1 -0
  183. package/dist/types/TokenRatesController.d.ts.map +1 -0
  184. package/dist/{TokensController.d.ts → types/TokensController.d.ts} +26 -19
  185. package/dist/types/TokensController.d.ts.map +1 -0
  186. package/dist/{assetsUtil.d.ts → types/assetsUtil.d.ts} +1 -2
  187. package/dist/types/assetsUtil.d.ts.map +1 -0
  188. package/dist/types/constants.d.ts.map +1 -0
  189. package/dist/types/crypto-compare.d.ts.map +1 -0
  190. package/dist/{index.d.ts → types/index.d.ts} +6 -3
  191. package/dist/types/index.d.ts.map +1 -0
  192. package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +1 -0
  193. package/dist/types/token-prices-service/codefi-v2.d.ts.map +1 -0
  194. package/dist/types/token-prices-service/index.d.ts.map +1 -0
  195. package/dist/types/token-service.d.ts.map +1 -0
  196. package/package.json +30 -13
  197. package/dist/AccountTrackerController.d.ts.map +0 -1
  198. package/dist/AssetsContractController.d.ts.map +0 -1
  199. package/dist/CurrencyRateController.d.ts.map +0 -1
  200. package/dist/NftController.d.ts.map +0 -1
  201. package/dist/NftDetectionController.d.ts.map +0 -1
  202. package/dist/Standards/ERC20Standard.d.ts.map +0 -1
  203. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
  204. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
  205. package/dist/Standards/standards-types.d.ts +0 -15
  206. package/dist/Standards/standards-types.d.ts.map +0 -1
  207. package/dist/Standards/standards-types.js +0 -3
  208. package/dist/Standards/standards-types.js.map +0 -1
  209. package/dist/TokenBalancesController.d.ts.map +0 -1
  210. package/dist/TokenDetectionController.d.ts +0 -88
  211. package/dist/TokenDetectionController.d.ts.map +0 -1
  212. package/dist/TokenListController.d.ts.map +0 -1
  213. package/dist/TokenRatesController.d.ts.map +0 -1
  214. package/dist/TokensController.d.ts.map +0 -1
  215. package/dist/assetsUtil.d.ts.map +0 -1
  216. package/dist/constants.d.ts.map +0 -1
  217. package/dist/crypto-compare.d.ts.map +0 -1
  218. package/dist/index.d.ts.map +0 -1
  219. package/dist/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
  220. package/dist/token-prices-service/codefi-v2.d.ts.map +0 -1
  221. package/dist/token-prices-service/index.d.ts.map +0 -1
  222. package/dist/token-service.d.ts.map +0 -1
  223. /package/dist/{AccountTrackerController.d.ts → types/AccountTrackerController.d.ts} +0 -0
  224. /package/dist/{CurrencyRateController.d.ts → types/CurrencyRateController.d.ts} +0 -0
  225. /package/dist/{NftController.d.ts → types/NftController.d.ts} +0 -0
  226. /package/dist/{NftDetectionController.d.ts → types/NftDetectionController.d.ts} +0 -0
  227. /package/dist/{Standards → types/Standards}/NftStandards/ERC721/ERC721Standard.d.ts +0 -0
  228. /package/dist/{TokenListController.d.ts → types/TokenListController.d.ts} +0 -0
  229. /package/dist/{TokenRatesController.d.ts → types/TokenRatesController.d.ts} +0 -0
  230. /package/dist/{constants.d.ts → types/constants.d.ts} +0 -0
  231. /package/dist/{crypto-compare.d.ts → types/crypto-compare.d.ts} +0 -0
  232. /package/dist/{token-prices-service → types/token-prices-service}/abstract-token-prices-service.d.ts +0 -0
  233. /package/dist/{token-prices-service → types/token-prices-service}/codefi-v2.d.ts +0 -0
  234. /package/dist/{token-prices-service → types/token-prices-service}/index.d.ts +0 -0
  235. /package/dist/{token-service.d.ts → types/token-service.d.ts} +0 -0
@@ -1,145 +1,9 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ERC20Standard = void 0;
13
- const contracts_1 = require("@ethersproject/contracts");
14
- const abi_utils_1 = require("@metamask/abi-utils");
15
- const controller_utils_1 = require("@metamask/controller-utils");
16
- const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
17
- const utils_1 = require("@metamask/utils");
18
- const ethereumjs_util_1 = require("ethereumjs-util");
19
- const assetsUtil_1 = require("../assetsUtil");
20
- class ERC20Standard {
21
- constructor(provider) {
22
- this.provider = provider;
23
- }
24
- /**
25
- * Get balance or count for current account on specific asset contract.
26
- *
27
- * @param address - Asset ERC20 contract address.
28
- * @param selectedAddress - Current account public address.
29
- * @returns Promise resolving to BN object containing balance for current account on specific asset contract.
30
- */
31
- getBalanceOf(address, selectedAddress) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC20, this.provider);
34
- const balance = yield contract.balanceOf(selectedAddress);
35
- return (0, assetsUtil_1.ethersBigNumberToBN)(balance);
36
- });
37
- }
38
- /**
39
- * Query for the decimals for a given ERC20 asset.
40
- *
41
- * @param address - ERC20 asset contract string.
42
- * @returns Promise resolving to the 'decimals'.
43
- */
44
- getTokenDecimals(address) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC20, this.provider);
47
- try {
48
- const decimals = yield contract.decimals();
49
- return decimals.toString();
50
- // TODO: Replace `any` with type
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- }
53
- catch (err) {
54
- // Mirror previous implementation
55
- if (err.message.includes('call revert exception')) {
56
- throw new Error('Failed to parse token decimals');
57
- }
58
- throw err;
59
- }
60
- });
61
- }
62
- /**
63
- * Query for the name for a given ERC20 asset.
64
- *
65
- * @param address - ERC20 asset contract string.
66
- * @returns Promise resolving to the 'name'.
67
- */
68
- getTokenName(address) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC20, this.provider);
71
- try {
72
- const name = yield contract.name();
73
- return name.toString();
74
- // TODO: Replace `any` with type
75
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
- }
77
- catch (err) {
78
- // Mirror previous implementation
79
- if (err.message.includes('call revert exception')) {
80
- throw new Error('Failed to parse token name');
81
- }
82
- throw err;
83
- }
84
- });
85
- }
86
- /**
87
- * Query for symbol for a given ERC20 asset.
88
- *
89
- * @param address - ERC20 asset contract address.
90
- * @returns Promise resolving to the 'symbol'.
91
- */
92
- getTokenSymbol(address) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- // Signature for calling `symbol()`
95
- const payload = { to: address, data: '0x95d89b41' };
96
- const result = yield this.provider.call(payload);
97
- (0, utils_1.assertIsStrictHexString)(result);
98
- // Parse as string - treat empty string as failure
99
- try {
100
- const decoded = (0, abi_utils_1.decodeSingle)('string', result);
101
- if ((decoded === null || decoded === void 0 ? void 0 : decoded.length) > 0) {
102
- return decoded;
103
- }
104
- }
105
- catch (_a) {
106
- // Ignore error
107
- }
108
- // Parse as bytes - treat empty string as failure
109
- try {
110
- const utf8 = (0, ethereumjs_util_1.toUtf8)(result);
111
- if (utf8.length > 0) {
112
- return utf8;
113
- }
114
- }
115
- catch (_b) {
116
- // Ignore error
117
- }
118
- throw new Error('Failed to parse token symbol');
119
- });
120
- }
121
- /**
122
- * Query if a contract implements an interface.
123
- *
124
- * @param address - Asset contract address.
125
- * @param userAddress - The public address for the currently active user's account.
126
- * @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.
127
- */
128
- getDetails(address, userAddress) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- const [decimals, symbol, balance] = yield Promise.all([
131
- this.getTokenDecimals(address),
132
- this.getTokenSymbol(address),
133
- userAddress ? this.getBalanceOf(address, userAddress) : undefined,
134
- ]);
135
- return {
136
- decimals,
137
- symbol,
138
- balance,
139
- standard: controller_utils_1.ERC20,
140
- };
141
- });
142
- }
143
- }
144
- exports.ERC20Standard = ERC20Standard;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkBZI7P3TDjs = require('../chunk-BZI7P3TD.js');
4
+ require('../chunk-YD3NRMFC.js');
5
+ require('../chunk-Z4BLTVTB.js');
6
+
7
+
8
+ exports.ERC20Standard = _chunkBZI7P3TDjs.ERC20Standard;
145
9
  //# sourceMappingURL=ERC20Standard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ERC20Standard.js","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wDAAoD;AAEpD,mDAAmD;AACnD,iEAAmD;AACnD,mEAAuD;AACvD,2CAA0D;AAC1D,qDAAyC;AAGzC,8CAAoD;AAEpD,MAAa,aAAa;IAGxB,YAAY,QAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACG,YAAY,CAAC,OAAe,EAAE,eAAuB;;YACzD,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,EAAE,4BAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAChE,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;YAC1D,OAAO,IAAA,gCAAmB,EAAC,OAAO,CAAC,CAAC;QACtC,CAAC;KAAA;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,OAAe;;YACpC,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,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AClD,IAAI;gBACF,MAAM,OAAO,GAAG,IAAA,wBAAY,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;gBAC/C,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,IAAG,CAAC,EAAE;oBACvB,OAAO,OAAO,CAAC;iBAChB;aACF;YAAC,WAAM;gBACN,eAAe;aAChB;YAED,iDAAiD;YACjD,IAAI;gBACF,MAAM,IAAI,GAAG,IAAA,wBAAM,EAAC,MAAM,CAAC,CAAC;gBAC5B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;oBACnB,OAAO,IAAI,CAAC;iBACb;aACF;YAAC,WAAM;gBACN,eAAe;aAChB;YAED,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;KAAA;IAED;;;;;;OAMG;IACG,UAAU,CACd,OAAe,EACf,WAAoB;;YAOpB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACpD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;gBAC9B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;gBAC5B,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;aAClE,CAAC,CAAC;YACH,OAAO;gBACL,QAAQ;gBACR,MAAM;gBACN,OAAO;gBACP,QAAQ,EAAE,wBAAK;aAChB,CAAC;QACJ,CAAC;KAAA;CACF;AA9HD,sCA8HC","sourcesContent":["import { 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 { toUtf8 } from 'ethereumjs-util';\nimport type { BN } from 'ethereumjs-util';\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 // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n // Mirror previous implementation\n if (err.message.includes('call revert exception')) {\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 // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n // Mirror previous implementation\n if (err.message.includes('call revert exception')) {\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
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import {
2
+ ERC20Standard
3
+ } from "../chunk-J2JQQNHN.mjs";
4
+ import "../chunk-5C7ZVZNM.mjs";
5
+ import "../chunk-XUI43LEZ.mjs";
6
+ export {
7
+ ERC20Standard
8
+ };
9
+ //# sourceMappingURL=ERC20Standard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,218 +1,9 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ERC1155Standard = void 0;
13
- const contracts_1 = require("@ethersproject/contracts");
14
- const controller_utils_1 = require("@metamask/controller-utils");
15
- const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
16
- const assetsUtil_1 = require("../../../assetsUtil");
17
- class ERC1155Standard {
18
- constructor(provider) {
19
- this.provider = provider;
20
- }
21
- /**
22
- * Query if contract implements ERC1155 URI Metadata interface.
23
- *
24
- * @param address - ERC1155 asset contract address.
25
- * @returns Promise resolving to whether the contract implements ERC1155 URI Metadata interface.
26
- */
27
- contractSupportsURIMetadataInterface(address) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- return this.contractSupportsInterface(address, controller_utils_1.ERC1155_METADATA_URI_INTERFACE_ID);
30
- });
31
- }
32
- /**
33
- * Query if contract implements ERC1155 Token Receiver interface.
34
- *
35
- * @param address - ERC1155 asset contract address.
36
- * @returns Promise resolving to whether the contract implements ERC1155 Token Receiver interface.
37
- */
38
- contractSupportsTokenReceiverInterface(address) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- return this.contractSupportsInterface(address, controller_utils_1.ERC1155_TOKEN_RECEIVER_INTERFACE_ID);
41
- });
42
- }
43
- /**
44
- * Query if contract implements ERC1155 interface.
45
- *
46
- * @param address - ERC1155 asset contract address.
47
- * @returns Promise resolving to whether the contract implements the base ERC1155 interface.
48
- */
49
- contractSupportsBase1155Interface(address) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- return this.contractSupportsInterface(address, controller_utils_1.ERC1155_INTERFACE_ID);
52
- });
53
- }
54
- /**
55
- * Query for tokenURI for a given asset.
56
- *
57
- * @param address - ERC1155 asset contract address.
58
- * @param tokenId - ERC1155 asset identifier.
59
- * @returns Promise resolving to the 'tokenURI'.
60
- */
61
- getTokenURI(address, tokenId) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC1155, this.provider);
64
- return contract.uri(tokenId);
65
- });
66
- }
67
- /**
68
- * Query for balance of a given ERC1155 token.
69
- *
70
- * @param contractAddress - ERC1155 asset contract address.
71
- * @param address - Wallet public address.
72
- * @param tokenId - ERC1155 asset identifier.
73
- * @returns Promise resolving to the 'balanceOf'.
74
- */
75
- getBalanceOf(contractAddress, address, tokenId) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const contract = new contracts_1.Contract(contractAddress, metamask_eth_abis_1.abiERC1155, this.provider);
78
- const balance = yield contract.balanceOf(address, tokenId);
79
- return (0, assetsUtil_1.ethersBigNumberToBN)(balance);
80
- });
81
- }
82
- /**
83
- * Transfer single ERC1155 token.
84
- * When minting/creating tokens, the from arg MUST be set to 0x0 (i.e. zero address).
85
- * When burning/destroying tokens, the to arg MUST be set to 0x0 (i.e. zero address).
86
- *
87
- * @param operator - ERC1155 token address.
88
- * @param from - ERC1155 token holder.
89
- * @param to - ERC1155 token recipient.
90
- * @param id - ERC1155 token id.
91
- * @param value - Number of tokens to be sent.
92
- * @returns Promise resolving to the 'transferSingle'.
93
- */
94
- transferSingle(operator, from, to, id, value) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const contract = new contracts_1.Contract(operator, metamask_eth_abis_1.abiERC1155, this.provider);
97
- return new Promise((resolve, reject) => {
98
- contract.transferSingle(operator, from, to, id, value, (error, result) => {
99
- /* istanbul ignore if */
100
- if (error) {
101
- reject(error);
102
- return;
103
- }
104
- resolve(result);
105
- });
106
- });
107
- });
108
- }
109
- /**
110
- * Query for symbol for a given asset.
111
- *
112
- * @param address - ERC1155 asset contract address.
113
- * @returns Promise resolving to the 'symbol'.
114
- */
115
- getAssetSymbol(address) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- const contract = new contracts_1.Contract(address,
118
- // Contract ABI fragment containing only the symbol method to fetch the symbol of the contract.
119
- [
120
- {
121
- inputs: [],
122
- name: 'symbol',
123
- outputs: [{ name: '_symbol', type: 'string' }],
124
- stateMutability: 'view',
125
- type: 'function',
126
- payable: false,
127
- },
128
- ], this.provider);
129
- return contract.symbol();
130
- });
131
- }
132
- /**
133
- * Query for name for a given asset.
134
- *
135
- * @param address - ERC1155 asset contract address.
136
- * @returns Promise resolving to the 'name'.
137
- */
138
- getAssetName(address) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- const contract = new contracts_1.Contract(address,
141
- // Contract ABI fragment containing only the name method to fetch the name of the contract.
142
- [
143
- {
144
- inputs: [],
145
- name: 'name',
146
- outputs: [{ name: '_name', type: 'string' }],
147
- stateMutability: 'view',
148
- type: 'function',
149
- payable: false,
150
- },
151
- ], this.provider);
152
- return contract.name();
153
- });
154
- }
155
- /**
156
- * Query if a contract implements an interface.
157
- *
158
- * @param address - ERC1155 asset contract address.
159
- * @param interfaceId - Interface identifier.
160
- * @returns Promise resolving to whether the contract implements `interfaceID`.
161
- */
162
- contractSupportsInterface(address, interfaceId) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC1155, this.provider);
165
- return contract.supportsInterface(interfaceId);
166
- });
167
- }
168
- /**
169
- * Query if a contract implements an interface.
170
- *
171
- * @param address - Asset contract address.
172
- * @param ipfsGateway - The user's preferred IPFS gateway.
173
- * @param tokenId - tokenId of a given token in the contract.
174
- * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.
175
- */
176
- getDetails(address, ipfsGateway, tokenId) {
177
- return __awaiter(this, void 0, void 0, function* () {
178
- const isERC1155 = yield this.contractSupportsBase1155Interface(address);
179
- if (!isERC1155) {
180
- throw new Error("This isn't a valid ERC1155 contract");
181
- }
182
- let image;
183
- const [symbol, name, tokenURI] = yield Promise.all([
184
- (0, controller_utils_1.safelyExecute)(() => this.getAssetSymbol(address)),
185
- (0, controller_utils_1.safelyExecute)(() => this.getAssetName(address)),
186
- tokenId
187
- ? (0, controller_utils_1.safelyExecute)(() => this.getTokenURI(address, tokenId).then((uri) => uri.startsWith('ipfs://')
188
- ? (0, assetsUtil_1.getFormattedIpfsUrl)(ipfsGateway, uri, true)
189
- : uri))
190
- : undefined,
191
- ]);
192
- if (tokenURI) {
193
- try {
194
- const response = yield (0, controller_utils_1.timeoutFetch)(tokenURI);
195
- const object = yield response.json();
196
- image = object === null || object === void 0 ? void 0 : object.image;
197
- if (image === null || image === void 0 ? void 0 : image.startsWith('ipfs://')) {
198
- image = (0, assetsUtil_1.getFormattedIpfsUrl)(ipfsGateway, image, true);
199
- }
200
- }
201
- catch (_a) {
202
- // Catch block should be kept empty to ignore exceptions, and
203
- // pass as much information as possible to the return statement
204
- }
205
- }
206
- // TODO consider querying to the metadata to get name.
207
- return {
208
- standard: controller_utils_1.ERC1155,
209
- tokenURI,
210
- image,
211
- symbol,
212
- name,
213
- };
214
- });
215
- }
216
- }
217
- exports.ERC1155Standard = ERC1155Standard;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkGHZX5DE4js = require('../../../chunk-GHZX5DE4.js');
4
+ require('../../../chunk-YD3NRMFC.js');
5
+ require('../../../chunk-Z4BLTVTB.js');
6
+
7
+
8
+ exports.ERC1155Standard = _chunkGHZX5DE4js.ERC1155Standard;
218
9
  //# sourceMappingURL=ERC1155Standard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ERC1155Standard.js","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC1155/ERC1155Standard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wDAAoD;AAEpD,iEAOoC;AACpC,mEAAyD;AAGzD,oDAA+E;AAE/E,MAAa,eAAe;IAG1B,YAAY,QAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACG,oCAAoC,CACxC,OAAe;;YAEf,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,oDAAiC,CAClC,CAAC;QACJ,CAAC;KAAA;IAED;;;;;OAKG;IACG,sCAAsC,CAC1C,OAAe;;YAEf,OAAO,IAAI,CAAC,yBAA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E,IAAI,CAAC,CAAC;qBACvD;iBACF;gBAAC,WAAM;oBACN,6DAA6D;oBAC7D,+DAA+D;iBAChE;aACF;YAED,sDAAsD;YACtD,OAAO;gBACL,QAAQ,EAAE,0BAAO;gBACjB,QAAQ;gBACR,KAAK;gBACL,MAAM;gBACN,IAAI;aACL,CAAC;QACJ,CAAC;KAAA;CACF;AArPD,0CAqPC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n ERC1155,\n ERC1155_INTERFACE_ID,\n ERC1155_METADATA_URI_INTERFACE_ID,\n ERC1155_TOKEN_RECEIVER_INTERFACE_ID,\n safelyExecute,\n timeoutFetch,\n} from '@metamask/controller-utils';\nimport { abiERC1155 } from '@metamask/metamask-eth-abis';\nimport type { BN } from 'ethereumjs-util';\n\nimport { getFormattedIpfsUrl, ethersBigNumberToBN } from '../../../assetsUtil';\n\nexport class ERC1155Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC1155 URI Metadata interface.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC1155 URI Metadata interface.\n */\n async contractSupportsURIMetadataInterface(\n address: string,\n ): Promise<boolean> {\n return this.contractSupportsInterface(\n address,\n ERC1155_METADATA_URI_INTERFACE_ID,\n );\n }\n\n /**\n * Query if contract implements ERC1155 Token Receiver interface.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC1155 Token Receiver interface.\n */\n async contractSupportsTokenReceiverInterface(\n address: string,\n ): Promise<boolean> {\n return this.contractSupportsInterface(\n address,\n ERC1155_TOKEN_RECEIVER_INTERFACE_ID,\n );\n }\n\n /**\n * Query if contract implements ERC1155 interface.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to whether the contract implements the base ERC1155 interface.\n */\n async contractSupportsBase1155Interface(address: string): Promise<boolean> {\n return this.contractSupportsInterface(address, ERC1155_INTERFACE_ID);\n }\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @param tokenId - ERC1155 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n async getTokenURI(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC1155, this.provider);\n return contract.uri(tokenId);\n }\n\n /**\n * Query for balance of a given ERC1155 token.\n *\n * @param contractAddress - ERC1155 asset contract address.\n * @param address - Wallet public address.\n * @param tokenId - ERC1155 asset identifier.\n * @returns Promise resolving to the 'balanceOf'.\n */\n async getBalanceOf(\n contractAddress: string,\n address: string,\n tokenId: string,\n ): Promise<BN> {\n const contract = new Contract(contractAddress, abiERC1155, this.provider);\n const balance = await contract.balanceOf(address, tokenId);\n return ethersBigNumberToBN(balance);\n }\n\n /**\n * Transfer single ERC1155 token.\n * When minting/creating tokens, the from arg MUST be set to 0x0 (i.e. zero address).\n * When burning/destroying tokens, the to arg MUST be set to 0x0 (i.e. zero address).\n *\n * @param operator - ERC1155 token address.\n * @param from - ERC1155 token holder.\n * @param to - ERC1155 token recipient.\n * @param id - ERC1155 token id.\n * @param value - Number of tokens to be sent.\n * @returns Promise resolving to the 'transferSingle'.\n */\n async transferSingle(\n operator: string,\n from: string,\n to: string,\n id: string,\n value: string,\n ): Promise<void> {\n const contract = new Contract(operator, abiERC1155, this.provider);\n return new Promise<void>((resolve, reject) => {\n contract.transferSingle(\n operator,\n from,\n to,\n id,\n value,\n (error: Error, result: void) => {\n /* istanbul ignore if */\n if (error) {\n reject(error);\n return;\n }\n resolve(result);\n },\n );\n });\n }\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getAssetSymbol(address: string): Promise<string> {\n const contract = new Contract(\n address,\n // Contract ABI fragment containing only the symbol method to fetch the symbol of the contract.\n [\n {\n inputs: [],\n name: 'symbol',\n outputs: [{ name: '_symbol', type: 'string' }],\n stateMutability: 'view',\n type: 'function',\n payable: false,\n },\n ],\n this.provider,\n );\n return contract.symbol();\n }\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n async getAssetName(address: string): Promise<string> {\n const contract = new Contract(\n address,\n // Contract ABI fragment containing only the name method to fetch the name of the contract.\n [\n {\n inputs: [],\n name: 'name',\n outputs: [{ name: '_name', type: 'string' }],\n stateMutability: 'view',\n type: 'function',\n payable: false,\n },\n ],\n this.provider,\n );\n return contract.name();\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - ERC1155 asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private async contractSupportsInterface(\n address: string,\n interfaceId: string,\n ): Promise<boolean> {\n const contract = new Contract(address, abiERC1155, this.provider);\n return contract.supportsInterface(interfaceId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n async getDetails(\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n image: string | undefined;\n name: string | undefined;\n symbol: string | undefined;\n }> {\n const isERC1155 = await this.contractSupportsBase1155Interface(address);\n\n if (!isERC1155) {\n throw new Error(\"This isn't a valid ERC1155 contract\");\n }\n\n let image;\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // Catch block should be kept empty to ignore exceptions, and\n // pass as much information as possible to the return statement\n }\n }\n\n // TODO consider querying to the metadata to get name.\n return {\n standard: ERC1155,\n tokenURI,\n image,\n symbol,\n name,\n };\n }\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import {
2
+ ERC1155Standard
3
+ } from "../../../chunk-TDKCVCGP.mjs";
4
+ import "../../../chunk-5C7ZVZNM.mjs";
5
+ import "../../../chunk-XUI43LEZ.mjs";
6
+ export {
7
+ ERC1155Standard
8
+ };
9
+ //# sourceMappingURL=ERC1155Standard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,176 +1,9 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ERC721Standard = void 0;
13
- const contracts_1 = require("@ethersproject/contracts");
14
- const controller_utils_1 = require("@metamask/controller-utils");
15
- const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
16
- const assetsUtil_1 = require("../../../assetsUtil");
17
- class ERC721Standard {
18
- constructor(provider) {
19
- /**
20
- * Query if contract implements ERC721Metadata interface.
21
- *
22
- * @param address - ERC721 asset contract address.
23
- * @returns Promise resolving to whether the contract implements ERC721Metadata interface.
24
- */
25
- this.contractSupportsMetadataInterface = (address) => __awaiter(this, void 0, void 0, function* () {
26
- return this.contractSupportsInterface(address, controller_utils_1.ERC721_METADATA_INTERFACE_ID);
27
- });
28
- /**
29
- * Query if contract implements ERC721Enumerable interface.
30
- *
31
- * @param address - ERC721 asset contract address.
32
- * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.
33
- */
34
- this.contractSupportsEnumerableInterface = (address) => __awaiter(this, void 0, void 0, function* () {
35
- return this.contractSupportsInterface(address, controller_utils_1.ERC721_ENUMERABLE_INTERFACE_ID);
36
- });
37
- /**
38
- * Query if contract implements ERC721 interface.
39
- *
40
- * @param address - ERC721 asset contract address.
41
- * @returns Promise resolving to whether the contract implements ERC721 interface.
42
- */
43
- this.contractSupportsBase721Interface = (address) => __awaiter(this, void 0, void 0, function* () {
44
- return this.contractSupportsInterface(address, controller_utils_1.ERC721_INTERFACE_ID);
45
- });
46
- /**
47
- * Enumerate assets assigned to an owner.
48
- *
49
- * @param address - ERC721 asset contract address.
50
- * @param selectedAddress - Current account public address.
51
- * @param index - An NFT counter less than `balanceOf(selectedAddress)`.
52
- * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
53
- */
54
- this.getNftTokenId = (address, selectedAddress, index) => __awaiter(this, void 0, void 0, function* () {
55
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
56
- return contract.tokenOfOwnerByIndex(selectedAddress, index);
57
- });
58
- /**
59
- * Query for tokenURI for a given asset.
60
- *
61
- * @param address - ERC721 asset contract address.
62
- * @param tokenId - ERC721 asset identifier.
63
- * @returns Promise resolving to the 'tokenURI'.
64
- */
65
- this.getTokenURI = (address, tokenId) => __awaiter(this, void 0, void 0, function* () {
66
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
67
- const supportsMetadata = yield this.contractSupportsMetadataInterface(address);
68
- if (!supportsMetadata) {
69
- throw new Error('Contract does not support ERC721 metadata interface.');
70
- }
71
- return contract.tokenURI(tokenId);
72
- });
73
- /**
74
- * Query for name for a given asset.
75
- *
76
- * @param address - ERC721 asset contract address.
77
- * @returns Promise resolving to the 'name'.
78
- */
79
- this.getAssetName = (address) => __awaiter(this, void 0, void 0, function* () {
80
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
81
- return contract.name();
82
- });
83
- /**
84
- * Query for symbol for a given asset.
85
- *
86
- * @param address - ERC721 asset contract address.
87
- * @returns Promise resolving to the 'symbol'.
88
- */
89
- this.getAssetSymbol = (address) => __awaiter(this, void 0, void 0, function* () {
90
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
91
- return contract.symbol();
92
- });
93
- /**
94
- * Query if a contract implements an interface.
95
- *
96
- * @param address - Asset contract address.
97
- * @param interfaceId - Interface identifier.
98
- * @returns Promise resolving to whether the contract implements `interfaceID`.
99
- */
100
- this.contractSupportsInterface = (address, interfaceId) => __awaiter(this, void 0, void 0, function* () {
101
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
102
- try {
103
- return yield contract.supportsInterface(interfaceId);
104
- // TODO: Replace `any` with type
105
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
- }
107
- catch (err) {
108
- // Mirror previous implementation
109
- if (err.message.includes('call revert exception')) {
110
- return false;
111
- }
112
- throw err;
113
- }
114
- });
115
- /**
116
- * Query if a contract implements an interface.
117
- *
118
- * @param address - Asset contract address.
119
- * @param ipfsGateway - The user's preferred IPFS gateway.
120
- * @param tokenId - tokenId of a given token in the contract.
121
- * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.
122
- */
123
- this.getDetails = (address, ipfsGateway, tokenId) => __awaiter(this, void 0, void 0, function* () {
124
- const isERC721 = yield this.contractSupportsBase721Interface(address);
125
- if (!isERC721) {
126
- throw new Error("This isn't a valid ERC721 contract");
127
- }
128
- const [symbol, name, tokenURI] = yield Promise.all([
129
- (0, controller_utils_1.safelyExecute)(() => this.getAssetSymbol(address)),
130
- (0, controller_utils_1.safelyExecute)(() => this.getAssetName(address)),
131
- tokenId
132
- ? (0, controller_utils_1.safelyExecute)(() => this.getTokenURI(address, tokenId).then((uri) => uri.startsWith('ipfs://')
133
- ? (0, assetsUtil_1.getFormattedIpfsUrl)(ipfsGateway, uri, true)
134
- : uri))
135
- : undefined,
136
- ]);
137
- let image;
138
- if (tokenURI) {
139
- try {
140
- const response = yield (0, controller_utils_1.timeoutFetch)(tokenURI);
141
- const object = yield response.json();
142
- image = object === null || object === void 0 ? void 0 : object.image;
143
- if (image === null || image === void 0 ? void 0 : image.startsWith('ipfs://')) {
144
- image = (0, assetsUtil_1.getFormattedIpfsUrl)(ipfsGateway, image, true);
145
- }
146
- }
147
- catch (_a) {
148
- // ignore
149
- }
150
- }
151
- return {
152
- standard: controller_utils_1.ERC721,
153
- tokenURI,
154
- symbol,
155
- name,
156
- image,
157
- };
158
- });
159
- this.provider = provider;
160
- }
161
- /**
162
- * Query for owner for a given ERC721 asset.
163
- *
164
- * @param address - ERC721 asset contract address.
165
- * @param tokenId - ERC721 asset identifier.
166
- * @returns Promise resolving to the owner address.
167
- */
168
- getOwnerOf(address, tokenId) {
169
- return __awaiter(this, void 0, void 0, function* () {
170
- const contract = new contracts_1.Contract(address, metamask_eth_abis_1.abiERC721, this.provider);
171
- return contract.ownerOf(tokenId);
172
- });
173
- }
174
- }
175
- exports.ERC721Standard = ERC721Standard;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkNG2UOKDDjs = require('../../../chunk-NG2UOKDD.js');
4
+ require('../../../chunk-YD3NRMFC.js');
5
+ require('../../../chunk-Z4BLTVTB.js');
6
+
7
+
8
+ exports.ERC721Standard = _chunkNG2UOKDDjs.ERC721Standard;
176
9
  //# sourceMappingURL=ERC721Standard.js.map