@metamask/assets-controllers 28.0.0 → 30.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.
- package/CHANGELOG.md +47 -1
- package/README.md +29 -0
- package/dist/AssetsContractController.js +6 -6
- package/dist/AssetsContractController.mjs +5 -5
- package/dist/CurrencyRateController.js +4 -3
- package/dist/CurrencyRateController.mjs +3 -2
- package/dist/NftController.js +3 -3
- package/dist/NftController.mjs +2 -2
- package/dist/NftDetectionController.js +2 -2
- package/dist/NftDetectionController.mjs +1 -1
- package/dist/RatesController/RatesController.js +14 -0
- package/dist/RatesController/RatesController.mjs +14 -0
- package/dist/RatesController/index.js +13 -0
- package/dist/RatesController/index.js.map +1 -0
- package/dist/RatesController/index.mjs +13 -0
- package/dist/RatesController/index.mjs.map +1 -0
- package/dist/RatesController/types.js +1 -0
- package/dist/RatesController/types.js.map +1 -0
- package/dist/RatesController/types.mjs +1 -0
- package/dist/RatesController/types.mjs.map +1 -0
- package/dist/Standards/ERC20Standard.js +3 -3
- package/dist/Standards/ERC20Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +2 -2
- package/dist/TokenDetectionController.js +3 -3
- package/dist/TokenDetectionController.mjs +2 -2
- package/dist/TokenListController.js +4 -4
- package/dist/TokenListController.mjs +3 -3
- package/dist/TokenRatesController.js +6 -4
- package/dist/TokenRatesController.mjs +5 -3
- package/dist/TokensController.js +6 -6
- package/dist/TokensController.mjs +5 -5
- package/dist/assetsUtil.js +2 -2
- package/dist/assetsUtil.mjs +1 -1
- package/dist/{chunk-D3N35ABH.js → chunk-3R43XIIX.js} +17 -6
- package/dist/chunk-3R43XIIX.js.map +1 -0
- package/dist/{chunk-4PAJC7WC.mjs → chunk-46UZDIXW.mjs} +35 -12
- package/dist/chunk-46UZDIXW.mjs.map +1 -0
- package/dist/{chunk-C4JDCQG2.js → chunk-4ODKGWYQ.js} +15 -8
- package/dist/chunk-4ODKGWYQ.js.map +1 -0
- package/dist/{chunk-Q6TLNHYC.js → chunk-5F5EQAX5.js} +7 -7
- package/dist/{chunk-RUPB4ELK.js → chunk-6W5EQ3JQ.js} +56 -42
- package/dist/chunk-6W5EQ3JQ.js.map +1 -0
- package/dist/chunk-7K6PSEAA.js +1 -0
- package/dist/chunk-7K6PSEAA.js.map +1 -0
- package/dist/{chunk-ZM42FNAQ.mjs → chunk-7MMEHAKG.mjs} +7 -7
- package/dist/{chunk-AC5HGIHS.mjs → chunk-ASA5RLBY.mjs} +2 -2
- package/dist/chunk-B5YVX5IO.mjs +202 -0
- package/dist/chunk-B5YVX5IO.mjs.map +1 -0
- package/dist/{chunk-BM7EPTR6.js → chunk-B5YY22QQ.js} +3 -3
- package/dist/{chunk-QWACHXRH.mjs → chunk-B6W4CQOR.mjs} +2 -2
- package/dist/chunk-B6W4CQOR.mjs.map +1 -0
- package/dist/{chunk-GCWWC4X3.js → chunk-BOTVAG4A.js} +5 -5
- package/dist/chunk-CNKVITJO.mjs +66 -0
- package/dist/chunk-CNKVITJO.mjs.map +1 -0
- package/dist/{chunk-KS4MOA2T.mjs → chunk-D3K5MPMW.mjs} +2 -2
- package/dist/{chunk-LRKDZWS6.js → chunk-ELSMS5S7.js} +3 -3
- package/dist/chunk-ELSMS5S7.js.map +1 -0
- package/dist/{chunk-JEGLHDNA.js → chunk-FMZML3V5.js} +15 -9
- package/dist/chunk-FMZML3V5.js.map +1 -0
- package/dist/{chunk-QVSSEGA5.js → chunk-HDI4L2DD.js} +5 -5
- package/dist/chunk-JYHAAA6W.mjs +1 -0
- package/dist/chunk-JYHAAA6W.mjs.map +1 -0
- package/dist/{chunk-KDMDWUVX.mjs → chunk-KOKB6U4Z.mjs} +15 -9
- package/dist/chunk-KOKB6U4Z.mjs.map +1 -0
- package/dist/{chunk-UNKIHWZH.js → chunk-LAU6ZDZR.js} +37 -14
- package/dist/chunk-LAU6ZDZR.js.map +1 -0
- package/dist/{chunk-N5H5KDJZ.mjs → chunk-LZ5ZGQEX.mjs} +2 -2
- package/dist/{chunk-E2SLNUD4.js → chunk-MBCN3MNX.js} +11 -11
- package/dist/{chunk-RDWXY4OF.mjs → chunk-MHN7CJCZ.mjs} +14 -7
- package/dist/chunk-MHN7CJCZ.mjs.map +1 -0
- package/dist/{chunk-CNICDMRI.mjs → chunk-MR6EF4B7.mjs} +2 -2
- package/dist/{chunk-D6BDJYSK.js → chunk-NEXY7SE2.js} +9 -2
- package/dist/chunk-NEXY7SE2.js.map +1 -0
- package/dist/{chunk-ZPAX2HLQ.mjs → chunk-Q5JRBGWO.mjs} +9 -2
- package/dist/chunk-Q5JRBGWO.mjs.map +1 -0
- package/dist/chunk-TTH3ES66.mjs +1 -0
- package/dist/chunk-TTH3ES66.mjs.map +1 -0
- package/dist/{chunk-TGKUZNML.js → chunk-U3DJJN4X.js} +4 -4
- package/dist/chunk-WB6KJX4N.js +66 -0
- package/dist/chunk-WB6KJX4N.js.map +1 -0
- package/dist/{chunk-NHX4QGOD.mjs → chunk-X4FFNQHE.mjs} +53 -39
- package/dist/chunk-X4FFNQHE.mjs.map +1 -0
- package/dist/chunk-XC3SOOGC.js +1 -0
- package/dist/chunk-XC3SOOGC.js.map +1 -0
- package/dist/{chunk-QQAG6ECS.mjs → chunk-XHMM35YT.mjs} +3 -3
- package/dist/{chunk-OSEZFHQ3.mjs → chunk-Y35SM7TO.mjs} +19 -14
- package/dist/chunk-Y35SM7TO.mjs.map +1 -0
- package/dist/chunk-YIFA2HXH.js +202 -0
- package/dist/chunk-YIFA2HXH.js.map +1 -0
- package/dist/{chunk-IURNPMBB.mjs → chunk-Z3OQU4XW.mjs} +17 -6
- package/dist/chunk-Z3OQU4XW.mjs.map +1 -0
- package/dist/{chunk-4FMVFW2T.js → chunk-Z6TBQQE5.js} +20 -15
- package/dist/chunk-Z6TBQQE5.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.js +10 -0
- package/dist/crypto-compare-service/crypto-compare.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +10 -0
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -0
- package/dist/crypto-compare-service/index.js +11 -0
- package/dist/crypto-compare-service/index.js.map +1 -0
- package/dist/crypto-compare-service/index.mjs +11 -0
- package/dist/crypto-compare-service/index.mjs.map +1 -0
- package/dist/index.js +24 -16
- package/dist/index.mjs +25 -17
- package/dist/token-prices-service/codefi-v2.js +4 -2
- package/dist/token-prices-service/codefi-v2.mjs +5 -3
- package/dist/token-prices-service/index.js +2 -2
- package/dist/token-prices-service/index.mjs +1 -1
- package/dist/token-service.js +3 -3
- package/dist/token-service.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/AssetsContractController.d.ts.map +1 -1
- package/dist/types/CurrencyRateController.d.ts +1 -1
- package/dist/types/CurrencyRateController.d.ts.map +1 -1
- package/dist/types/NftController.d.ts +3 -3
- package/dist/types/NftController.d.ts.map +1 -1
- package/dist/types/NftDetectionController.d.ts +5 -1
- package/dist/types/NftDetectionController.d.ts.map +1 -1
- package/dist/types/RatesController/RatesController.d.ts +44 -0
- package/dist/types/RatesController/RatesController.d.ts.map +1 -0
- package/dist/types/RatesController/index.d.ts +3 -0
- package/dist/types/RatesController/index.d.ts.map +1 -0
- package/dist/types/RatesController/types.d.ts +100 -0
- package/dist/types/RatesController/types.d.ts.map +1 -0
- package/dist/types/TokenRatesController.d.ts +26 -4
- package/dist/types/TokenRatesController.d.ts.map +1 -1
- package/dist/types/TokensController.d.ts +1 -1
- package/dist/types/TokensController.d.ts.map +1 -1
- package/dist/types/assetsUtil.d.ts +9 -2
- package/dist/types/assetsUtil.d.ts.map +1 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts +22 -0
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +1 -0
- package/dist/types/crypto-compare-service/index.d.ts +2 -0
- package/dist/types/crypto-compare-service/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts +18 -0
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +1 -1
- package/dist/types/token-prices-service/codefi-v2.d.ts +7 -0
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +1 -1
- package/dist/types/token-service.d.ts +1 -1
- package/dist/types/token-service.d.ts.map +1 -1
- package/package.json +14 -14
- package/dist/chunk-4FMVFW2T.js.map +0 -1
- package/dist/chunk-4PAJC7WC.mjs.map +0 -1
- package/dist/chunk-C4JDCQG2.js.map +0 -1
- package/dist/chunk-D3N35ABH.js.map +0 -1
- package/dist/chunk-D6BDJYSK.js.map +0 -1
- package/dist/chunk-DYH5P3VY.js +0 -35
- package/dist/chunk-DYH5P3VY.js.map +0 -1
- package/dist/chunk-IURNPMBB.mjs.map +0 -1
- package/dist/chunk-JEGLHDNA.js.map +0 -1
- package/dist/chunk-KDMDWUVX.mjs.map +0 -1
- package/dist/chunk-LRKDZWS6.js.map +0 -1
- package/dist/chunk-NHX4QGOD.mjs.map +0 -1
- package/dist/chunk-OSEZFHQ3.mjs.map +0 -1
- package/dist/chunk-PWZE6KJV.mjs +0 -35
- package/dist/chunk-PWZE6KJV.mjs.map +0 -1
- package/dist/chunk-QWACHXRH.mjs.map +0 -1
- package/dist/chunk-RDWXY4OF.mjs.map +0 -1
- package/dist/chunk-RUPB4ELK.js.map +0 -1
- package/dist/chunk-UNKIHWZH.js.map +0 -1
- package/dist/chunk-ZPAX2HLQ.mjs.map +0 -1
- package/dist/crypto-compare.js +0 -8
- package/dist/crypto-compare.mjs +0 -8
- package/dist/types/crypto-compare.d.ts +0 -13
- package/dist/types/crypto-compare.d.ts.map +0 -1
- /package/dist/{crypto-compare.js.map → RatesController/RatesController.js.map} +0 -0
- /package/dist/{crypto-compare.mjs.map → RatesController/RatesController.mjs.map} +0 -0
- /package/dist/{chunk-Q6TLNHYC.js.map → chunk-5F5EQAX5.js.map} +0 -0
- /package/dist/{chunk-ZM42FNAQ.mjs.map → chunk-7MMEHAKG.mjs.map} +0 -0
- /package/dist/{chunk-AC5HGIHS.mjs.map → chunk-ASA5RLBY.mjs.map} +0 -0
- /package/dist/{chunk-BM7EPTR6.js.map → chunk-B5YY22QQ.js.map} +0 -0
- /package/dist/{chunk-GCWWC4X3.js.map → chunk-BOTVAG4A.js.map} +0 -0
- /package/dist/{chunk-KS4MOA2T.mjs.map → chunk-D3K5MPMW.mjs.map} +0 -0
- /package/dist/{chunk-QVSSEGA5.js.map → chunk-HDI4L2DD.js.map} +0 -0
- /package/dist/{chunk-N5H5KDJZ.mjs.map → chunk-LZ5ZGQEX.mjs.map} +0 -0
- /package/dist/{chunk-E2SLNUD4.js.map → chunk-MBCN3MNX.js.map} +0 -0
- /package/dist/{chunk-CNICDMRI.mjs.map → chunk-MR6EF4B7.mjs.map} +0 -0
- /package/dist/{chunk-TGKUZNML.js.map → chunk-U3DJJN4X.js.map} +0 -0
- /package/dist/{chunk-QQAG6ECS.mjs.map → chunk-XHMM35YT.mjs.map} +0 -0
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkZ6TBQQE5js = require('./chunk-Z6TBQQE5.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
var _chunkWB6KJX4Njs = require('./chunk-WB6KJX4N.js');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkNEXY7SE2js = require('./chunk-NEXY7SE2.js');
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
|
|
@@ -28,7 +31,7 @@ async function getCurrencyConversionRate({
|
|
|
28
31
|
}) {
|
|
29
32
|
const includeUSDRate = false;
|
|
30
33
|
try {
|
|
31
|
-
const result = await
|
|
34
|
+
const result = await _chunkWB6KJX4Njs.fetchExchangeRate.call(void 0,
|
|
32
35
|
to,
|
|
33
36
|
from,
|
|
34
37
|
includeUSDRate
|
|
@@ -154,8 +157,7 @@ var TokenRatesController = class extends _pollingcontroller.StaticIntervalPollin
|
|
|
154
157
|
allDetectedTokens: {}
|
|
155
158
|
};
|
|
156
159
|
this.defaultState = {
|
|
157
|
-
|
|
158
|
-
contractExchangeRatesByChainId: {}
|
|
160
|
+
marketData: {}
|
|
159
161
|
};
|
|
160
162
|
this.initialize();
|
|
161
163
|
this.setIntervalLength(interval);
|
|
@@ -180,10 +182,13 @@ var TokenRatesController = class extends _pollingcontroller.StaticIntervalPollin
|
|
|
180
182
|
await this.updateExchangeRates();
|
|
181
183
|
}
|
|
182
184
|
});
|
|
183
|
-
onNetworkStateChange(async ({
|
|
184
|
-
const
|
|
185
|
+
onNetworkStateChange(async ({ selectedNetworkClientId }) => {
|
|
186
|
+
const selectedNetworkClient = getNetworkClientById(
|
|
187
|
+
selectedNetworkClientId
|
|
188
|
+
);
|
|
189
|
+
const { chainId, ticker } = selectedNetworkClient.configuration;
|
|
185
190
|
if (this.config.chainId !== chainId || this.config.nativeCurrency !== ticker) {
|
|
186
|
-
this.update({
|
|
191
|
+
this.update({ ...this.defaultState });
|
|
187
192
|
this.configure({ chainId, nativeCurrency: ticker });
|
|
188
193
|
if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _pollState) === "Active" /* Active */) {
|
|
189
194
|
await this.updateExchangeRates();
|
|
@@ -231,9 +236,6 @@ var TokenRatesController = class extends _pollingcontroller.StaticIntervalPollin
|
|
|
231
236
|
return;
|
|
232
237
|
}
|
|
233
238
|
const tokenAddresses = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getTokenAddresses, getTokenAddresses_fn).call(this, chainId);
|
|
234
|
-
if (tokenAddresses.length === 0) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
239
|
const updateKey = `${chainId}:${nativeCurrency}`;
|
|
238
240
|
if (updateKey in _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessExchangeRateUpdates)) {
|
|
239
241
|
await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessExchangeRateUpdates)[updateKey];
|
|
@@ -246,27 +248,18 @@ var TokenRatesController = class extends _pollingcontroller.StaticIntervalPollin
|
|
|
246
248
|
} = _utils.createDeferredPromise.call(void 0, { suppressUnhandledRejection: true });
|
|
247
249
|
_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessExchangeRateUpdates)[updateKey] = inProgressUpdate;
|
|
248
250
|
try {
|
|
249
|
-
const
|
|
251
|
+
const contractInformations = await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _fetchAndMapExchangeRates, fetchAndMapExchangeRates_fn).call(this, {
|
|
250
252
|
tokenAddresses,
|
|
251
253
|
chainId,
|
|
252
254
|
nativeCurrency
|
|
253
255
|
});
|
|
254
|
-
const
|
|
255
|
-
const updatedContractExchangeRates = chainId === this.config.chainId && nativeCurrency === this.config.nativeCurrency ? newContractExchangeRates : existingContractExchangeRates;
|
|
256
|
-
const existingContractExchangeRatesForChainId = this.state.contractExchangeRatesByChainId[chainId] ?? {};
|
|
257
|
-
const updatedContractExchangeRatesForChainId = {
|
|
258
|
-
...this.state.contractExchangeRatesByChainId,
|
|
256
|
+
const marketData = {
|
|
259
257
|
[chainId]: {
|
|
260
|
-
...
|
|
261
|
-
[nativeCurrency]: {
|
|
262
|
-
...existingContractExchangeRatesForChainId[nativeCurrency],
|
|
263
|
-
...newContractExchangeRates
|
|
264
|
-
}
|
|
258
|
+
...contractInformations ?? {}
|
|
265
259
|
}
|
|
266
260
|
};
|
|
267
261
|
this.update({
|
|
268
|
-
|
|
269
|
-
contractExchangeRatesByChainId: updatedContractExchangeRatesForChainId
|
|
262
|
+
marketData
|
|
270
263
|
});
|
|
271
264
|
updateSucceeded();
|
|
272
265
|
} catch (error) {
|
|
@@ -327,10 +320,11 @@ fetchAndMapExchangeRates_fn = async function({
|
|
|
327
320
|
}) {
|
|
328
321
|
if (!_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokenPricesService).validateChainIdSupported(chainId)) {
|
|
329
322
|
return tokenAddresses.reduce((obj, tokenAddress) => {
|
|
330
|
-
|
|
323
|
+
obj = {
|
|
331
324
|
...obj,
|
|
332
325
|
[tokenAddress]: void 0
|
|
333
326
|
};
|
|
327
|
+
return obj;
|
|
334
328
|
}, {});
|
|
335
329
|
}
|
|
336
330
|
if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokenPricesService).validateCurrencySupported(nativeCurrency)) {
|
|
@@ -351,9 +345,10 @@ fetchAndMapExchangeRatesForSupportedNativeCurrency_fn = async function({
|
|
|
351
345
|
chainId,
|
|
352
346
|
nativeCurrency
|
|
353
347
|
}) {
|
|
354
|
-
|
|
348
|
+
let contractNativeInformations;
|
|
349
|
+
const tokenPricesByTokenAddress = await _chunkNEXY7SE2js.reduceInBatchesSerially.call(void 0, {
|
|
355
350
|
values: [...tokenAddresses].sort(),
|
|
356
|
-
batchSize:
|
|
351
|
+
batchSize: _chunkNEXY7SE2js.TOKEN_PRICES_BATCH_SIZE,
|
|
357
352
|
eachBatch: async (allTokenPricesByTokenAddress, batch) => {
|
|
358
353
|
const tokenPricesByTokenAddressForBatch = await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokenPricesService).fetchTokenPrices({
|
|
359
354
|
tokenAddresses: batch,
|
|
@@ -367,12 +362,27 @@ fetchAndMapExchangeRatesForSupportedNativeCurrency_fn = async function({
|
|
|
367
362
|
},
|
|
368
363
|
initialResult: {}
|
|
369
364
|
});
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
365
|
+
contractNativeInformations = tokenPricesByTokenAddress;
|
|
366
|
+
if (tokenAddresses.length === 0) {
|
|
367
|
+
const contractNativeInformationsNative = await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokenPricesService).fetchTokenPrices({
|
|
368
|
+
tokenAddresses: [],
|
|
369
|
+
chainId,
|
|
370
|
+
currency: nativeCurrency
|
|
371
|
+
});
|
|
372
|
+
contractNativeInformations = {
|
|
373
|
+
[_chunkZ6TBQQE5js.ZERO_ADDRESS]: {
|
|
374
|
+
currency: nativeCurrency,
|
|
375
|
+
...contractNativeInformationsNative[_chunkZ6TBQQE5js.ZERO_ADDRESS]
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return Object.entries(contractNativeInformations).reduce(
|
|
380
|
+
(obj, [tokenAddress, token]) => {
|
|
381
|
+
obj = {
|
|
373
382
|
...obj,
|
|
374
|
-
[tokenAddress]:
|
|
383
|
+
[tokenAddress.toLowerCase()]: { ...token }
|
|
375
384
|
};
|
|
385
|
+
return obj;
|
|
376
386
|
},
|
|
377
387
|
{}
|
|
378
388
|
);
|
|
@@ -383,7 +393,7 @@ fetchAndMapExchangeRatesForUnsupportedNativeCurrency_fn = async function({
|
|
|
383
393
|
nativeCurrency
|
|
384
394
|
}) {
|
|
385
395
|
const [
|
|
386
|
-
|
|
396
|
+
contractExchangeInformations,
|
|
387
397
|
fallbackCurrencyToNativeCurrencyConversionRate
|
|
388
398
|
] = await Promise.all([
|
|
389
399
|
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _fetchAndMapExchangeRatesForSupportedNativeCurrency, fetchAndMapExchangeRatesForSupportedNativeCurrency_fn).call(this, {
|
|
@@ -399,15 +409,19 @@ fetchAndMapExchangeRatesForUnsupportedNativeCurrency_fn = async function({
|
|
|
399
409
|
if (fallbackCurrencyToNativeCurrencyConversionRate === null) {
|
|
400
410
|
return {};
|
|
401
411
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
412
|
+
const updatedContractExchangeRates = Object.entries(
|
|
413
|
+
contractExchangeInformations
|
|
414
|
+
).reduce((acc, [tokenAddress, token]) => {
|
|
415
|
+
acc = {
|
|
416
|
+
...acc,
|
|
417
|
+
[tokenAddress]: {
|
|
418
|
+
...token,
|
|
419
|
+
value: token.value ? token.value * fallbackCurrencyToNativeCurrencyConversionRate : void 0
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
return acc;
|
|
423
|
+
}, {});
|
|
424
|
+
return updatedContractExchangeRates;
|
|
411
425
|
};
|
|
412
426
|
var TokenRatesController_default = TokenRatesController;
|
|
413
427
|
|
|
@@ -415,4 +429,4 @@ var TokenRatesController_default = TokenRatesController;
|
|
|
415
429
|
|
|
416
430
|
|
|
417
431
|
exports.TokenRatesController = TokenRatesController; exports.TokenRatesController_default = TokenRatesController_default;
|
|
418
|
-
//# sourceMappingURL=chunk-
|
|
432
|
+
//# sourceMappingURL=chunk-6W5EQ3JQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/TokenRatesController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,SAAS,yCAAyC;AAElD,SAAS,6BAAuC;AAChD,SAAS,eAAe;AAoHxB,eAAe,0BAA0B;AAAA,EACvC;AAAA,EACA;AACF,GAGG;AACD,QAAM,iBAAiB;AACvB,MAAI;AACF,UAAM,SAAS,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO,OAAO;AAAA,EAChB,SAAS,OAAO;AACd,QACE,iBAAiB,SACjB,MAAM,QAAQ,SAAS,0CAA0C,GACjE;AACA,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR;AACF;AA3JA;AAiKO,IAAM,uBAAN,cAAmC,kCAGxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiCA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+BAA+B,OAAO;AAAA,IAC1C;AAAA,EACF,EAAE,OAAO,CAAC,KAAK,CAAC,cAAc,KAAK,MAAM;AACvC,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,CAAC,YAAY,GAAG;AAAA,QACd,GAAG;AAAA,QACH,OAAO,MAAM,QACT,MAAM,QAAQ,iDACd;AAAA,MACN;AAAA,IACF;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAGF,IAAO,+BAAQ","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport {\n safelyExecute,\n toChecksumHexAddress,\n FALL_BACK_VS_CURRENCY,\n toHex,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkController,\n NetworkState,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';\nimport type { PreferencesState } from '@metamask/preferences-controller';\nimport { createDeferredPromise, type Hex } from '@metamask/utils';\nimport { isEqual } from 'lodash';\n\nimport { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil';\nimport { fetchExchangeRate as fetchNativeCurrencyExchangeRate } from './crypto-compare-service';\nimport type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service';\nimport { ZERO_ADDRESS } from './token-prices-service/codefi-v2';\nimport type { TokensState } from './TokensController';\n\n/**\n * @type Token\n *\n * Token representation\n * @property address - Hex address of the token contract\n * @property decimals - Number of decimals the token uses\n * @property symbol - Symbol of the token\n * @property image - Image of the token, url or bit32 image\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface Token {\n address: string;\n decimals: number;\n symbol: string;\n aggregators?: string[];\n image?: string;\n balanceError?: unknown;\n isERC721?: boolean;\n name?: string;\n}\n\n/**\n * @type TokenRatesConfig\n *\n * Token rates controller configuration\n * @property interval - Polling interval used to fetch new token rates\n * @property nativeCurrency - Current native currency selected to use base of rates\n * @property chainId - Current network chainId\n * @property tokens - List of tokens to track exchange rates for\n * @property threshold - Threshold to invalidate the supportedChains\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TokenRatesConfig extends BaseConfig {\n interval: number;\n nativeCurrency: string;\n chainId: Hex;\n selectedAddress: string;\n allTokens: { [chainId: Hex]: { [key: string]: Token[] } };\n allDetectedTokens: { [chainId: Hex]: { [key: string]: Token[] } };\n threshold: number;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface ContractExchangeRates {\n [address: string]: number | undefined;\n}\n\ntype MarketDataDetails = {\n tokenAddress: `0x${string}`;\n value: number;\n currency: string;\n allTimeHigh: number;\n allTimeLow: number;\n circulatingSupply: number;\n dilutedMarketCap: number;\n high1d: number;\n low1d: number;\n marketCap: number;\n marketCapPercentChange1d: number;\n price: number;\n priceChange1d: number;\n pricePercentChange1d: number;\n pricePercentChange1h: number;\n pricePercentChange1y: number;\n pricePercentChange7d: number;\n pricePercentChange14d: number;\n pricePercentChange30d: number;\n pricePercentChange200d: number;\n totalVolume: number;\n};\n\nexport type ContractMarketData = Record<Hex, MarketDataDetails>;\n\nenum PollState {\n Active = 'Active',\n Inactive = 'Inactive',\n}\n\n/**\n * @type TokenRatesState\n *\n * Token rates controller state\n * @property marketData - Market data for tokens, keyed by chain ID and then token contract address.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TokenRatesState extends BaseState {\n marketData: Record<Hex, Record<Hex, MarketDataDetails>>;\n}\n\n/**\n * Uses the CryptoCompare API to fetch the exchange rate between one currency\n * and another, i.e., the multiplier to apply the amount of one currency in\n * order to convert it to another.\n *\n * @param args - The arguments to this function.\n * @param args.from - The currency to convert from.\n * @param args.to - The currency to convert to.\n * @returns The exchange rate between `fromCurrency` to `toCurrency` if one\n * exists, or null if one does not.\n */\nasync function getCurrencyConversionRate({\n from,\n to,\n}: {\n from: string;\n to: string;\n}) {\n const includeUSDRate = false;\n try {\n const result = await fetchNativeCurrencyExchangeRate(\n to,\n from,\n includeUSDRate,\n );\n return result.conversionRate;\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n ) {\n return null;\n }\n throw error;\n }\n}\n\n/**\n * Controller that passively polls on a set interval for token-to-fiat exchange rates\n * for tokens stored in the TokensController\n */\nexport class TokenRatesController extends StaticIntervalPollingControllerV1<\n TokenRatesConfig,\n TokenRatesState\n> {\n private handle?: ReturnType<typeof setTimeout>;\n\n #pollState = PollState.Inactive;\n\n #tokenPricesService: AbstractTokenPricesService;\n\n #inProcessExchangeRateUpdates: Record<`${Hex}:${string}`, Promise<void>> = {};\n\n /**\n * Name of this controller used during composition\n */\n override name = 'TokenRatesController';\n\n private readonly getNetworkClientById: NetworkController['getNetworkClientById'];\n\n /**\n * Creates a TokenRatesController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The polling interval in ms\n * @param options.threshold - The duration in ms before metadata fetched from CoinGecko is considered stale\n * @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.\n * @param options.chainId - The chain ID of the current network.\n * @param options.ticker - The ticker for the current network.\n * @param options.selectedAddress - The current selected address.\n * @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.\n * @param options.onTokensStateChange - Allows subscribing to token controller state changes.\n * @param options.onNetworkStateChange - Allows subscribing to network state changes.\n * @param options.tokenPricesService - An object in charge of retrieving token prices.\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(\n {\n interval = 3 * 60 * 1000,\n threshold = 6 * 60 * 60 * 1000,\n getNetworkClientById,\n chainId: initialChainId,\n ticker: initialTicker,\n selectedAddress: initialSelectedAddress,\n onPreferencesStateChange,\n onTokensStateChange,\n onNetworkStateChange,\n tokenPricesService,\n }: {\n interval?: number;\n threshold?: number;\n getNetworkClientById: NetworkController['getNetworkClientById'];\n chainId: Hex;\n ticker: string;\n selectedAddress: string;\n onPreferencesStateChange: (\n listener: (preferencesState: PreferencesState) => void,\n ) => void;\n onTokensStateChange: (\n listener: (tokensState: TokensState) => void,\n ) => void;\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n tokenPricesService: AbstractTokenPricesService;\n },\n config?: Partial<TokenRatesConfig>,\n state?: Partial<TokenRatesState>,\n ) {\n super(config, state);\n this.defaultConfig = {\n interval,\n threshold,\n disabled: false,\n nativeCurrency: initialTicker,\n chainId: initialChainId,\n selectedAddress: initialSelectedAddress,\n allTokens: {}, // TODO: initialize these correctly, maybe as part of BaseControllerV2 migration\n allDetectedTokens: {},\n };\n\n this.defaultState = {\n marketData: {},\n };\n this.initialize();\n this.setIntervalLength(interval);\n this.getNetworkClientById = getNetworkClientById;\n this.#tokenPricesService = tokenPricesService;\n\n if (config?.disabled) {\n this.configure({ disabled: true }, false, false);\n }\n\n onPreferencesStateChange(async ({ selectedAddress }) => {\n if (this.config.selectedAddress !== selectedAddress) {\n this.configure({ selectedAddress });\n if (this.#pollState === PollState.Active) {\n await this.updateExchangeRates();\n }\n }\n });\n\n onTokensStateChange(async ({ allTokens, allDetectedTokens }) => {\n const previousTokenAddresses = this.#getTokenAddresses(\n this.config.chainId,\n );\n this.configure({ allTokens, allDetectedTokens });\n const newTokenAddresses = this.#getTokenAddresses(this.config.chainId);\n if (\n !isEqual(previousTokenAddresses, newTokenAddresses) &&\n this.#pollState === PollState.Active\n ) {\n await this.updateExchangeRates();\n }\n });\n\n onNetworkStateChange(async ({ selectedNetworkClientId }) => {\n const selectedNetworkClient = getNetworkClientById(\n selectedNetworkClientId,\n );\n const { chainId, ticker } = selectedNetworkClient.configuration;\n\n if (\n this.config.chainId !== chainId ||\n this.config.nativeCurrency !== ticker\n ) {\n this.update({ ...this.defaultState });\n this.configure({ chainId, nativeCurrency: ticker });\n if (this.#pollState === PollState.Active) {\n await this.updateExchangeRates();\n }\n }\n });\n }\n\n /**\n * Get the user's tokens for the given chain.\n *\n * @param chainId - The chain ID.\n * @returns The list of tokens addresses for the current chain\n */\n #getTokenAddresses(chainId: Hex): Hex[] {\n const { allTokens, allDetectedTokens } = this.config;\n const tokens = allTokens[chainId]?.[this.config.selectedAddress] || [];\n const detectedTokens =\n allDetectedTokens[chainId]?.[this.config.selectedAddress] || [];\n\n return [\n ...new Set(\n [...tokens, ...detectedTokens].map((token) =>\n toHex(toChecksumHexAddress(token.address)),\n ),\n ),\n ].sort();\n }\n\n /**\n * Start (or restart) polling.\n */\n async start() {\n this.#stopPoll();\n this.#pollState = PollState.Active;\n await this.#poll();\n }\n\n /**\n * Stop polling.\n */\n stop() {\n this.#stopPoll();\n this.#pollState = PollState.Inactive;\n }\n\n /**\n * Clear the active polling timer, if present.\n */\n #stopPoll() {\n if (this.handle) {\n clearTimeout(this.handle);\n }\n }\n\n /**\n * Poll for exchange rate updates.\n */\n async #poll() {\n await safelyExecute(() => this.updateExchangeRates());\n\n // Poll using recursive `setTimeout` instead of `setInterval` so that\n // requests don't stack if they take longer than the polling interval\n this.handle = setTimeout(() => {\n this.#poll();\n }, this.config.interval);\n }\n\n /**\n * Updates exchange rates for all tokens.\n */\n async updateExchangeRates() {\n const { chainId, nativeCurrency } = this.config;\n await this.updateExchangeRatesByChainId({\n chainId,\n nativeCurrency,\n });\n }\n\n /**\n * Updates exchange rates for all tokens.\n *\n * @param options - The options to fetch exchange rates.\n * @param options.chainId - The chain ID.\n * @param options.nativeCurrency - The ticker for the chain.\n */\n async updateExchangeRatesByChainId({\n chainId,\n nativeCurrency,\n }: {\n chainId: Hex;\n nativeCurrency: string;\n }) {\n if (this.disabled) {\n return;\n }\n\n const tokenAddresses = this.#getTokenAddresses(chainId);\n\n const updateKey: `${Hex}:${string}` = `${chainId}:${nativeCurrency}`;\n if (updateKey in this.#inProcessExchangeRateUpdates) {\n // This prevents redundant updates\n // This promise is resolved after the in-progress update has finished,\n // and state has been updated.\n await this.#inProcessExchangeRateUpdates[updateKey];\n return;\n }\n\n const {\n promise: inProgressUpdate,\n resolve: updateSucceeded,\n reject: updateFailed,\n } = createDeferredPromise({ suppressUnhandledRejection: true });\n this.#inProcessExchangeRateUpdates[updateKey] = inProgressUpdate;\n\n try {\n const contractInformations = await this.#fetchAndMapExchangeRates({\n tokenAddresses,\n chainId,\n nativeCurrency,\n });\n\n const marketData = {\n [chainId]: {\n ...(contractInformations ?? {}),\n },\n };\n\n this.update({\n marketData,\n });\n updateSucceeded();\n } catch (error: unknown) {\n updateFailed(error);\n throw error;\n } finally {\n delete this.#inProcessExchangeRateUpdates[updateKey];\n }\n }\n\n /**\n * Uses the token prices service to retrieve exchange rates for tokens in a\n * particular currency.\n *\n * If the price API does not support the given chain ID, returns an empty\n * object.\n *\n * If the price API does not support the given currency, retrieves exchange\n * rates in a known currency instead, then converts those rates using the\n * exchange rate between the known currency and desired currency.\n *\n * @param args - The arguments to this function.\n * @param args.tokenAddresses - Addresses for tokens.\n * @param args.chainId - The EIP-155 ID of the chain where the tokens live.\n * @param args.nativeCurrency - The native currency in which to request\n * exchange rates.\n * @returns A map from token address to its exchange rate in the native\n * currency, or an empty map if no exchange rates can be obtained for the\n * chain ID.\n */\n async #fetchAndMapExchangeRates({\n tokenAddresses,\n chainId,\n nativeCurrency,\n }: {\n tokenAddresses: Hex[];\n chainId: Hex;\n nativeCurrency: string;\n }): Promise<ContractMarketData> {\n if (!this.#tokenPricesService.validateChainIdSupported(chainId)) {\n return tokenAddresses.reduce((obj, tokenAddress) => {\n obj = {\n ...obj,\n [tokenAddress]: undefined,\n };\n\n return obj;\n }, {});\n }\n\n if (this.#tokenPricesService.validateCurrencySupported(nativeCurrency)) {\n return await this.#fetchAndMapExchangeRatesForSupportedNativeCurrency({\n tokenAddresses,\n chainId,\n nativeCurrency,\n });\n }\n return await this.#fetchAndMapExchangeRatesForUnsupportedNativeCurrency({\n tokenAddresses,\n nativeCurrency,\n });\n }\n\n /**\n * Updates token rates for the given networkClientId\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.getNetworkClientById(networkClientId);\n await this.updateExchangeRatesByChainId({\n chainId: networkClient.configuration.chainId,\n nativeCurrency: networkClient.configuration.ticker,\n });\n }\n\n /**\n * Retrieves prices in the given currency for the given tokens on the given\n * chain. Ensures that token addresses are checksum addresses.\n *\n * @param args - The arguments to this function.\n * @param args.tokenAddresses - Addresses for tokens.\n * @param args.chainId - The EIP-155 ID of the chain where the tokens live.\n * @param args.nativeCurrency - The native currency in which to request\n * prices.\n * @returns A map of the token addresses (as checksums) to their prices in the\n * native currency.\n */\n async #fetchAndMapExchangeRatesForSupportedNativeCurrency({\n tokenAddresses,\n chainId,\n nativeCurrency,\n }: {\n tokenAddresses: Hex[];\n chainId: Hex;\n nativeCurrency: string;\n }): Promise<ContractMarketData> {\n let contractNativeInformations;\n const tokenPricesByTokenAddress = await reduceInBatchesSerially<\n Hex,\n Awaited<ReturnType<AbstractTokenPricesService['fetchTokenPrices']>>\n >({\n values: [...tokenAddresses].sort(),\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n eachBatch: async (allTokenPricesByTokenAddress, batch) => {\n const tokenPricesByTokenAddressForBatch =\n await this.#tokenPricesService.fetchTokenPrices({\n tokenAddresses: batch,\n chainId,\n currency: nativeCurrency,\n });\n\n return {\n ...allTokenPricesByTokenAddress,\n ...tokenPricesByTokenAddressForBatch,\n };\n },\n initialResult: {},\n });\n contractNativeInformations = tokenPricesByTokenAddress;\n\n // fetch for native token\n if (tokenAddresses.length === 0) {\n const contractNativeInformationsNative =\n await this.#tokenPricesService.fetchTokenPrices({\n tokenAddresses: [],\n chainId,\n currency: nativeCurrency,\n });\n\n contractNativeInformations = {\n [ZERO_ADDRESS]: {\n currency: nativeCurrency,\n ...contractNativeInformationsNative[ZERO_ADDRESS],\n },\n };\n }\n return Object.entries(contractNativeInformations).reduce(\n (obj, [tokenAddress, token]) => {\n obj = {\n ...obj,\n [tokenAddress.toLowerCase()]: { ...token },\n };\n\n return obj;\n },\n {},\n );\n }\n\n /**\n * If the price API does not support a given native currency, then we need to\n * convert it to a fallback currency and feed that currency into the price\n * API, then convert the prices to our desired native currency.\n *\n * @param args - The arguments to this function.\n * @param args.tokenAddresses - Addresses for tokens.\n * @param args.nativeCurrency - The native currency in which to request\n * prices.\n * @returns A map of the token addresses (as checksums) to their prices in the\n * native currency.\n */\n async #fetchAndMapExchangeRatesForUnsupportedNativeCurrency({\n tokenAddresses,\n nativeCurrency,\n }: {\n tokenAddresses: Hex[];\n nativeCurrency: string;\n }): Promise<ContractMarketData> {\n const [\n contractExchangeInformations,\n fallbackCurrencyToNativeCurrencyConversionRate,\n ] = await Promise.all([\n this.#fetchAndMapExchangeRatesForSupportedNativeCurrency({\n tokenAddresses,\n chainId: this.config.chainId,\n nativeCurrency: FALL_BACK_VS_CURRENCY,\n }),\n getCurrencyConversionRate({\n from: FALL_BACK_VS_CURRENCY,\n to: nativeCurrency,\n }),\n ]);\n\n if (fallbackCurrencyToNativeCurrencyConversionRate === null) {\n return {};\n }\n\n const updatedContractExchangeRates = Object.entries(\n contractExchangeInformations,\n ).reduce((acc, [tokenAddress, token]) => {\n acc = {\n ...acc,\n [tokenAddress]: {\n ...token,\n value: token.value\n ? token.value * fallbackCurrencyToNativeCurrencyConversionRate\n : undefined,\n },\n };\n return acc;\n }, {});\n\n return updatedContractExchangeRates;\n }\n}\n\nexport default TokenRatesController;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=chunk-7K6PSEAA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ERC1155Standard
|
|
3
|
-
} from "./chunk-N5H5KDJZ.mjs";
|
|
4
1
|
import {
|
|
5
2
|
ERC20Standard
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-D3K5MPMW.mjs";
|
|
4
|
+
import {
|
|
5
|
+
ERC1155Standard
|
|
6
|
+
} from "./chunk-LZ5ZGQEX.mjs";
|
|
7
7
|
import {
|
|
8
8
|
TOKEN_METADATA_NO_SUPPORT_ERROR,
|
|
9
9
|
fetchTokenMetadata
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Z3OQU4XW.mjs";
|
|
11
11
|
import {
|
|
12
12
|
formatAggregatorNames,
|
|
13
13
|
formatIconUrlWithProxy
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-Q5JRBGWO.mjs";
|
|
15
15
|
|
|
16
16
|
// src/TokensController.ts
|
|
17
17
|
import { Contract } from "@ethersproject/contracts";
|
|
@@ -701,4 +701,4 @@ export {
|
|
|
701
701
|
TokensController,
|
|
702
702
|
TokensController_default
|
|
703
703
|
};
|
|
704
|
-
//# sourceMappingURL=chunk-
|
|
704
|
+
//# sourceMappingURL=chunk-7MMEHAKG.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getFormattedIpfsUrl
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q5JRBGWO.mjs";
|
|
4
4
|
|
|
5
5
|
// src/Standards/NftStandards/ERC721/ERC721Standard.ts
|
|
6
6
|
import { Contract } from "@ethersproject/contracts";
|
|
@@ -175,4 +175,4 @@ var ERC721Standard = class {
|
|
|
175
175
|
export {
|
|
176
176
|
ERC721Standard
|
|
177
177
|
};
|
|
178
|
-
//# sourceMappingURL=chunk-
|
|
178
|
+
//# sourceMappingURL=chunk-ASA5RLBY.mjs.map
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchMultiExchangeRate
|
|
3
|
+
} from "./chunk-CNKVITJO.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__privateAdd,
|
|
6
|
+
__privateGet,
|
|
7
|
+
__privateMethod,
|
|
8
|
+
__privateSet
|
|
9
|
+
} from "./chunk-XUI43LEZ.mjs";
|
|
10
|
+
|
|
11
|
+
// src/RatesController/RatesController.ts
|
|
12
|
+
import { BaseController } from "@metamask/base-controller";
|
|
13
|
+
import { Mutex } from "async-mutex";
|
|
14
|
+
var name = "RatesController";
|
|
15
|
+
var Cryptocurrency = /* @__PURE__ */ ((Cryptocurrency2) => {
|
|
16
|
+
Cryptocurrency2["Btc"] = "btc";
|
|
17
|
+
return Cryptocurrency2;
|
|
18
|
+
})(Cryptocurrency || {});
|
|
19
|
+
var DEFAULT_INTERVAL = 18e4;
|
|
20
|
+
var metadata = {
|
|
21
|
+
fiatCurrency: { persist: true, anonymous: true },
|
|
22
|
+
rates: { persist: true, anonymous: true },
|
|
23
|
+
cryptocurrencies: { persist: true, anonymous: true }
|
|
24
|
+
};
|
|
25
|
+
var defaultState = {
|
|
26
|
+
fiatCurrency: "usd",
|
|
27
|
+
rates: {
|
|
28
|
+
["btc" /* Btc */]: {
|
|
29
|
+
conversionDate: 0,
|
|
30
|
+
conversionRate: "0"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
cryptocurrencies: ["btc" /* Btc */]
|
|
34
|
+
};
|
|
35
|
+
var _mutex, _fetchMultiExchangeRate, _includeUsdRate, _intervalLength, _intervalId, _withLock, withLock_fn, _executePoll, executePoll_fn, _updateRates, updateRates_fn;
|
|
36
|
+
var RatesController = class extends BaseController {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a RatesController instance.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Constructor options.
|
|
41
|
+
* @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.
|
|
42
|
+
* @param options.interval - The polling interval, in milliseconds.
|
|
43
|
+
* @param options.messenger - A reference to the messaging system.
|
|
44
|
+
* @param options.state - Initial state to set on this controller.
|
|
45
|
+
* @param options.fetchMultiExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.
|
|
46
|
+
*/
|
|
47
|
+
constructor({
|
|
48
|
+
interval = DEFAULT_INTERVAL,
|
|
49
|
+
messenger,
|
|
50
|
+
state,
|
|
51
|
+
includeUsdRate,
|
|
52
|
+
fetchMultiExchangeRate: fetchMultiExchangeRate2 = fetchMultiExchangeRate
|
|
53
|
+
}) {
|
|
54
|
+
super({
|
|
55
|
+
name,
|
|
56
|
+
metadata,
|
|
57
|
+
messenger,
|
|
58
|
+
state: { ...defaultState, ...state }
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Executes a function `callback` within a mutex lock to ensure that only one instance of `callback` runs at a time across all invocations of `#withLock`.
|
|
62
|
+
* This method is useful for synchronizing access to a resource or section of code that should not be executed concurrently.
|
|
63
|
+
*
|
|
64
|
+
* @template R - The return type of the function `callback`.
|
|
65
|
+
* @param callback - A callback to execute once the lock is acquired. This callback can be synchronous or asynchronous.
|
|
66
|
+
* @returns A promise that resolves to the result of the function `callback`. The promise is fulfilled once `callback` has completed execution.
|
|
67
|
+
* @example
|
|
68
|
+
* async function criticalLogic() {
|
|
69
|
+
* // Critical logic code goes here.
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* // Execute criticalLogic within a lock.
|
|
73
|
+
* const result = await this.#withLock(criticalLogic);
|
|
74
|
+
*/
|
|
75
|
+
__privateAdd(this, _withLock);
|
|
76
|
+
/**
|
|
77
|
+
* Executes the polling operation to update rates.
|
|
78
|
+
*/
|
|
79
|
+
__privateAdd(this, _executePoll);
|
|
80
|
+
/**
|
|
81
|
+
* Updates the rates by fetching new data.
|
|
82
|
+
*/
|
|
83
|
+
__privateAdd(this, _updateRates);
|
|
84
|
+
__privateAdd(this, _mutex, new Mutex());
|
|
85
|
+
__privateAdd(this, _fetchMultiExchangeRate, void 0);
|
|
86
|
+
__privateAdd(this, _includeUsdRate, void 0);
|
|
87
|
+
__privateAdd(this, _intervalLength, void 0);
|
|
88
|
+
__privateAdd(this, _intervalId, void 0);
|
|
89
|
+
__privateSet(this, _includeUsdRate, includeUsdRate);
|
|
90
|
+
__privateSet(this, _fetchMultiExchangeRate, fetchMultiExchangeRate2);
|
|
91
|
+
__privateSet(this, _intervalLength, interval);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Starts the polling process.
|
|
95
|
+
*/
|
|
96
|
+
async start() {
|
|
97
|
+
if (__privateGet(this, _intervalId)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.messagingSystem.publish(`${name}:pollingStarted`);
|
|
101
|
+
__privateSet(this, _intervalId, setInterval(() => {
|
|
102
|
+
__privateMethod(this, _executePoll, executePoll_fn).call(this).catch(console.error);
|
|
103
|
+
}, __privateGet(this, _intervalLength)));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Stops the polling process.
|
|
107
|
+
*/
|
|
108
|
+
async stop() {
|
|
109
|
+
if (!__privateGet(this, _intervalId)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
clearInterval(__privateGet(this, _intervalId));
|
|
113
|
+
__privateSet(this, _intervalId, void 0);
|
|
114
|
+
this.messagingSystem.publish(`${name}:pollingStopped`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns the current list of cryptocurrency.
|
|
118
|
+
* @returns The cryptocurrency list.
|
|
119
|
+
*/
|
|
120
|
+
getCryptocurrencyList() {
|
|
121
|
+
const { cryptocurrencies } = this.state;
|
|
122
|
+
return cryptocurrencies;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sets the list of supported cryptocurrencies.
|
|
126
|
+
* @param list - The list of supported cryptocurrencies.
|
|
127
|
+
*/
|
|
128
|
+
async setCryptocurrencyList(list) {
|
|
129
|
+
await __privateMethod(this, _withLock, withLock_fn).call(this, () => {
|
|
130
|
+
this.update(() => {
|
|
131
|
+
return {
|
|
132
|
+
...this.state,
|
|
133
|
+
fromCurrencies: list
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sets the internal fiat currency and update rates accordingly.
|
|
140
|
+
* @param fiatCurrency - The fiat currency.
|
|
141
|
+
*/
|
|
142
|
+
async setFiatCurrency(fiatCurrency) {
|
|
143
|
+
if (fiatCurrency === "") {
|
|
144
|
+
throw new Error("The currency can not be an empty string");
|
|
145
|
+
}
|
|
146
|
+
await __privateMethod(this, _withLock, withLock_fn).call(this, () => {
|
|
147
|
+
this.update(() => {
|
|
148
|
+
return {
|
|
149
|
+
...defaultState,
|
|
150
|
+
fiatCurrency
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
await __privateMethod(this, _updateRates, updateRates_fn).call(this);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
_mutex = new WeakMap();
|
|
158
|
+
_fetchMultiExchangeRate = new WeakMap();
|
|
159
|
+
_includeUsdRate = new WeakMap();
|
|
160
|
+
_intervalLength = new WeakMap();
|
|
161
|
+
_intervalId = new WeakMap();
|
|
162
|
+
_withLock = new WeakSet();
|
|
163
|
+
withLock_fn = async function(callback) {
|
|
164
|
+
const releaseLock = await __privateGet(this, _mutex).acquire();
|
|
165
|
+
try {
|
|
166
|
+
return callback();
|
|
167
|
+
} finally {
|
|
168
|
+
releaseLock();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
_executePoll = new WeakSet();
|
|
172
|
+
executePoll_fn = async function() {
|
|
173
|
+
await __privateMethod(this, _updateRates, updateRates_fn).call(this);
|
|
174
|
+
};
|
|
175
|
+
_updateRates = new WeakSet();
|
|
176
|
+
updateRates_fn = async function() {
|
|
177
|
+
await __privateMethod(this, _withLock, withLock_fn).call(this, async () => {
|
|
178
|
+
const { fiatCurrency, cryptocurrencies } = this.state;
|
|
179
|
+
const response = await __privateGet(this, _fetchMultiExchangeRate).call(this, fiatCurrency, cryptocurrencies, __privateGet(this, _includeUsdRate));
|
|
180
|
+
const updatedRates = {};
|
|
181
|
+
for (const [cryptocurrency, values] of Object.entries(response)) {
|
|
182
|
+
updatedRates[cryptocurrency] = {
|
|
183
|
+
conversionDate: Date.now(),
|
|
184
|
+
conversionRate: values[fiatCurrency],
|
|
185
|
+
...__privateGet(this, _includeUsdRate) && { usdConversionRate: values.usd }
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
this.update(() => {
|
|
189
|
+
return {
|
|
190
|
+
...this.state,
|
|
191
|
+
rates: updatedRates
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
name,
|
|
199
|
+
Cryptocurrency,
|
|
200
|
+
RatesController
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=chunk-B5YVX5IO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RatesController/RatesController.ts"],"sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport { Mutex } from 'async-mutex';\n\nimport { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n ConversionRates,\n RatesControllerState,\n RatesControllerOptions,\n RatesControllerMessenger,\n} from './types';\n\nexport const name = 'RatesController';\n\nexport enum Cryptocurrency {\n Btc = 'btc',\n}\n\nconst DEFAULT_INTERVAL = 180000;\n\nconst metadata = {\n fiatCurrency: { persist: true, anonymous: true },\n rates: { persist: true, anonymous: true },\n cryptocurrencies: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n fiatCurrency: 'usd',\n rates: {\n [Cryptocurrency.Btc]: {\n conversionDate: 0,\n conversionRate: '0',\n },\n },\n cryptocurrencies: [Cryptocurrency.Btc],\n};\n\nexport class RatesController extends BaseController<\n typeof name,\n RatesControllerState,\n RatesControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #fetchMultiExchangeRate;\n\n readonly #includeUsdRate;\n\n #intervalLength: number;\n\n #intervalId: NodeJS.Timeout | undefined;\n\n /**\n * Creates a RatesController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchMultiExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n interval = DEFAULT_INTERVAL,\n messenger,\n state,\n includeUsdRate,\n fetchMultiExchangeRate = defaultFetchExchangeRate,\n }: RatesControllerOptions) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#fetchMultiExchangeRate = fetchMultiExchangeRate;\n this.#intervalLength = interval;\n }\n\n /**\n * Executes a function `callback` within a mutex lock to ensure that only one instance of `callback` runs at a time across all invocations of `#withLock`.\n * This method is useful for synchronizing access to a resource or section of code that should not be executed concurrently.\n *\n * @template R - The return type of the function `callback`.\n * @param callback - A callback to execute once the lock is acquired. This callback can be synchronous or asynchronous.\n * @returns A promise that resolves to the result of the function `callback`. The promise is fulfilled once `callback` has completed execution.\n * @example\n * async function criticalLogic() {\n * // Critical logic code goes here.\n * }\n *\n * // Execute criticalLogic within a lock.\n * const result = await this.#withLock(criticalLogic);\n */\n async #withLock<R>(callback: () => R) {\n const releaseLock = await this.#mutex.acquire();\n try {\n return callback();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Executes the polling operation to update rates.\n */\n async #executePoll(): Promise<void> {\n await this.#updateRates();\n }\n\n /**\n * Updates the rates by fetching new data.\n */\n async #updateRates(): Promise<void> {\n await this.#withLock(async () => {\n const { fiatCurrency, cryptocurrencies } = this.state;\n const response: Record<\n Cryptocurrency,\n Record<string, string>\n > = await this.#fetchMultiExchangeRate(\n fiatCurrency,\n cryptocurrencies,\n this.#includeUsdRate,\n );\n\n const updatedRates: ConversionRates = {};\n for (const [cryptocurrency, values] of Object.entries(response)) {\n updatedRates[cryptocurrency] = {\n conversionDate: Date.now(),\n conversionRate: values[fiatCurrency],\n ...(this.#includeUsdRate && { usdConversionRate: values.usd }),\n };\n }\n\n this.update(() => {\n return {\n ...this.state,\n rates: updatedRates,\n };\n });\n });\n }\n\n /**\n * Starts the polling process.\n */\n async start(): Promise<void> {\n if (this.#intervalId) {\n return;\n }\n\n this.messagingSystem.publish(`${name}:pollingStarted`);\n\n this.#intervalId = setInterval(() => {\n this.#executePoll().catch(console.error);\n }, this.#intervalLength);\n }\n\n /**\n * Stops the polling process.\n */\n async stop(): Promise<void> {\n if (!this.#intervalId) {\n return;\n }\n\n clearInterval(this.#intervalId);\n this.#intervalId = undefined;\n this.messagingSystem.publish(`${name}:pollingStopped`);\n }\n\n /**\n * Returns the current list of cryptocurrency.\n * @returns The cryptocurrency list.\n */\n getCryptocurrencyList(): Cryptocurrency[] {\n const { cryptocurrencies } = this.state;\n return cryptocurrencies;\n }\n\n /**\n * Sets the list of supported cryptocurrencies.\n * @param list - The list of supported cryptocurrencies.\n */\n async setCryptocurrencyList(list: Cryptocurrency[]): Promise<void> {\n await this.#withLock(() => {\n this.update(() => {\n return {\n ...this.state,\n fromCurrencies: list,\n };\n });\n });\n }\n\n /**\n * Sets the internal fiat currency and update rates accordingly.\n * @param fiatCurrency - The fiat currency.\n */\n async setFiatCurrency(fiatCurrency: string): Promise<void> {\n if (fiatCurrency === '') {\n throw new Error('The currency can not be an empty string');\n }\n\n await this.#withLock(() => {\n this.update(() => {\n return {\n ...defaultState,\n fiatCurrency,\n };\n });\n });\n await this.#updateRates();\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AAUf,IAAM,OAAO;AAEb,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,SAAM;AADI,SAAAA;AAAA,GAAA;AAIZ,IAAM,mBAAmB;AAEzB,IAAM,WAAW;AAAA,EACf,cAAc,EAAE,SAAS,MAAM,WAAW,KAAK;AAAA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AAGP,UAAM,eAAgC,CAAC;AACvC,eAAW,CAAC,gBAAgB,MAAM,KAAK,OAAO,QAAQ,QAAQ,GAAG;AAC/D,mBAAa,cAAc,IAAI;AAAA,QAC7B,gBAAgB,KAAK,IAAI;AAAA,QACzB,gBAAgB,OAAO,YAAY;AAAA,QACnC,GAAI,mBAAK,oBAAmB,EAAE,mBAAmB,OAAO,IAAI;AAAA,MAC9D;AAAA,IACF;AAEA,SAAK,OAAO,MAAM;AAChB,aAAO;AAAA,QACL,GAAG,KAAK;AAAA,QACR,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["Cryptocurrency","fetchMultiExchangeRate"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNEXY7SE2js = require('./chunk-NEXY7SE2.js');
|
|
4
4
|
|
|
5
5
|
// src/Standards/ERC20Standard.ts
|
|
6
6
|
var _util = require('@ethereumjs/util');
|
|
@@ -23,7 +23,7 @@ var ERC20Standard = class {
|
|
|
23
23
|
async getBalanceOf(address, selectedAddress) {
|
|
24
24
|
const contract = new (0, _contracts.Contract)(address, _metamaskethabis.abiERC20, this.provider);
|
|
25
25
|
const balance = await contract.balanceOf(selectedAddress);
|
|
26
|
-
return
|
|
26
|
+
return _chunkNEXY7SE2js.ethersBigNumberToBN.call(void 0, balance);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Query for the decimals for a given ERC20 asset.
|
|
@@ -112,4 +112,4 @@ var ERC20Standard = class {
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
exports.ERC20Standard = ERC20Standard;
|
|
115
|
-
//# sourceMappingURL=chunk-
|
|
115
|
+
//# sourceMappingURL=chunk-B5YY22QQ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fetchExchangeRate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CNKVITJO.mjs";
|
|
4
4
|
|
|
5
5
|
// src/CurrencyRateController.ts
|
|
6
6
|
import {
|
|
@@ -154,4 +154,4 @@ export {
|
|
|
154
154
|
CurrencyRateController,
|
|
155
155
|
CurrencyRateController_default
|
|
156
156
|
};
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
//# sourceMappingURL=chunk-B6W4CQOR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/CurrencyRateController.ts"],"sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare-service';\n\n/**\n * @type CurrencyRateState\n * @property currencyRates - Object keyed by native currency\n * @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n * @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n * @property currentCurrency - Currently-active ISO 4217 currency code\n * @property usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type GetCurrencyRateState = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions = GetCurrencyRateState;\n\ntype AllowedActions = NetworkControllerGetNetworkClientByIdAction;\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents,\n AllowedActions['type'],\n never\n>;\n\nconst metadata = {\n currentCurrency: { persist: true, anonymous: true },\n currencyRates: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly fetchExchangeRate;\n\n private readonly includeUsdRate;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n messenger,\n state,\n fetchExchangeRate = defaultFetchExchangeRate,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n fetchExchangeRate?: typeof defaultFetchExchangeRate;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.includeUsdRate = includeUsdRate;\n this.setIntervalLength(interval);\n this.fetchExchangeRate = fetchExchangeRate;\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string) {\n const releaseLock = await this.mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n nativeCurrencies.forEach(this.updateExchangeRate.bind(this));\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pair.\n *\n * @param nativeCurrency - The ticker symbol for the chain.\n */\n async updateExchangeRate(nativeCurrency: string): Promise<void> {\n const releaseLock = await this.mutex.acquire();\n const { currentCurrency, currencyRates } = this.state;\n\n let conversionDate: number | null = null;\n let conversionRate: number | null = null;\n let usdConversionRate: number | null = null;\n\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n const nativeCurrencyForExchangeRate = Object.values(\n TESTNET_TICKER_SYMBOLS,\n ).includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY // ETH\n : nativeCurrency;\n\n try {\n if (\n currentCurrency &&\n nativeCurrency &&\n // if either currency is an empty string we can skip the comparison\n // because it will result in an error from the api and ultimately\n // a null conversionRate either way.\n currentCurrency !== '' &&\n nativeCurrency !== ''\n ) {\n const fetchExchangeRateResponse = await this.fetchExchangeRate(\n currentCurrency,\n nativeCurrencyForExchangeRate,\n this.includeUsdRate,\n );\n conversionRate = fetchExchangeRateResponse.conversionRate;\n usdConversionRate = fetchExchangeRateResponse.usdConversionRate;\n conversionDate = Date.now() / 1000;\n }\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n )\n ) {\n throw error;\n }\n } finally {\n try {\n this.update(() => {\n return {\n currencyRates: {\n ...currencyRates,\n [nativeCurrency]: {\n conversionDate,\n conversionRate,\n usdConversionRate,\n },\n },\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n await this.updateExchangeRate(networkClient.configuration.ticker);\n }\n}\n\nexport default CurrencyRateController;\n"],"mappings":";;;;;AAKA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAKP,SAAS,uCAAuC;AAChD,SAAS,aAAa;AAwBtB,IAAM,OAAO;AA0Bb,IAAM,WAAW;AAAA,EACf,iBAAiB,EAAE,SAAS,MAAM,WAAW,KAAK;AAAA,EAClD,eAAe,EAAE,SAAS,MAAM,WAAW,KAAK;AAClD;AAEA,IAAM,eAAe;AAAA,EACnB,iBAAiB;AAAA,EACjB,eAAe;AAAA,IACb,KAAK;AAAA,MACH,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,MAChB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAMO,IAAM,yBAAN,cAAqC,gCAI1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,YAAY;AAAA,IACV,iBAAiB;AAAA,IACjB,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,mBAAAA,qBAAoB;AAAA,EACtB,GAMG;AACD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,EAAE,GAAG,cAAc,GAAG,MAAM;AAAA,IACrC,CAAC;AAlCH,SAAiB,QAAQ,IAAI,MAAM;AAmCjC,SAAK,iBAAiB;AACtB,SAAK,kBAAkB,QAAQ;AAC/B,SAAK,oBAAoBA;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,mBAAmB,iBAAyB;AAChD,UAAM,cAAc,MAAM,KAAK,MAAM,QAAQ;AAC7C,UAAM,mBAAmB,OAAO,KAAK,KAAK,MAAM,aAAa;AAC7D,QAAI;AACF,WAAK,OAAO,MAAM;AAChB,eAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,UAAE;AACA,kBAAY;AAAA,IACd;A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MACA;AAAA,IACF;AACA,UAAM,KAAK,mBAAmB,cAAc,cAAc,MAAM;AAAA,EAClE;AACF;AAEA,IAAO,iCAAQ;","names":["fetchExchangeRate"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkNEXY7SE2js = require('./chunk-NEXY7SE2.js');
|
|
5
5
|
|
|
6
6
|
// src/Standards/NftStandards/ERC1155/ERC1155Standard.ts
|
|
7
7
|
var _contracts = require('@ethersproject/contracts');
|
|
@@ -73,7 +73,7 @@ var ERC1155Standard = class {
|
|
|
73
73
|
async getBalanceOf(contractAddress, address, tokenId) {
|
|
74
74
|
const contract = new (0, _contracts.Contract)(contractAddress, _metamaskethabis.abiERC1155, this.provider);
|
|
75
75
|
const balance = await contract.balanceOf(address, tokenId);
|
|
76
|
-
return
|
|
76
|
+
return _chunkNEXY7SE2js.ethersBigNumberToBN.call(void 0, balance);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Transfer single ERC1155 token.
|
|
@@ -184,7 +184,7 @@ var ERC1155Standard = class {
|
|
|
184
184
|
_controllerutils.safelyExecute.call(void 0, () => this.getAssetName(address)),
|
|
185
185
|
tokenId ? _controllerutils.safelyExecute.call(void 0,
|
|
186
186
|
() => this.getTokenURI(address, tokenId).then(
|
|
187
|
-
(uri) => uri.startsWith("ipfs://") ?
|
|
187
|
+
(uri) => uri.startsWith("ipfs://") ? _chunkNEXY7SE2js.getFormattedIpfsUrl.call(void 0, ipfsGateway, uri, true) : uri
|
|
188
188
|
)
|
|
189
189
|
) : void 0
|
|
190
190
|
]);
|
|
@@ -194,7 +194,7 @@ var ERC1155Standard = class {
|
|
|
194
194
|
const object = await response.json();
|
|
195
195
|
image = object?.image;
|
|
196
196
|
if (image?.startsWith("ipfs://")) {
|
|
197
|
-
image =
|
|
197
|
+
image = _chunkNEXY7SE2js.getFormattedIpfsUrl.call(void 0, ipfsGateway, image, true);
|
|
198
198
|
}
|
|
199
199
|
} catch {
|
|
200
200
|
}
|
|
@@ -212,4 +212,4 @@ var ERC1155Standard = class {
|
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
exports.ERC1155Standard = ERC1155Standard;
|
|
215
|
-
//# sourceMappingURL=chunk-
|
|
215
|
+
//# sourceMappingURL=chunk-BOTVAG4A.js.map
|