@metamask/assets-controllers 90.0.0 → 92.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 +52 -1
- package/dist/CurrencyRateController.cjs +3 -3
- package/dist/CurrencyRateController.cjs.map +1 -1
- package/dist/CurrencyRateController.d.cts.map +1 -1
- package/dist/CurrencyRateController.d.mts.map +1 -1
- package/dist/CurrencyRateController.mjs +3 -3
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +48 -10
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +2 -1
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +2 -1
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs +49 -11
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +12 -7
- package/dist/TokenDetectionController.cjs.map +1 -1
- package/dist/TokenDetectionController.d.cts +2 -1
- package/dist/TokenDetectionController.d.cts.map +1 -1
- package/dist/TokenDetectionController.d.mts +2 -1
- package/dist/TokenDetectionController.d.mts.map +1 -1
- package/dist/TokenDetectionController.mjs +12 -7
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +82 -278
- package/dist/TokenRatesController.cjs.map +1 -1
- package/dist/TokenRatesController.d.cts +9 -35
- package/dist/TokenRatesController.d.cts.map +1 -1
- package/dist/TokenRatesController.d.mts +9 -35
- package/dist/TokenRatesController.d.mts.map +1 -1
- package/dist/TokenRatesController.mjs +83 -279
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +2 -3
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +2 -3
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.cts +2 -2
- package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.mts +2 -2
- package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
- package/dist/assetsUtil.cjs +11 -5
- package/dist/assetsUtil.cjs.map +1 -1
- package/dist/assetsUtil.d.cts +2 -2
- package/dist/assetsUtil.d.cts.map +1 -1
- package/dist/assetsUtil.d.mts +2 -2
- package/dist/assetsUtil.d.mts.map +1 -1
- package/dist/assetsUtil.mjs +11 -5
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +8 -8
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts +2 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts +2 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs +8 -8
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs +18 -8
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts +4 -2
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts +4 -2
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs +18 -8
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.cts +17 -43
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +17 -43
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +177 -109
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +47 -10
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +47 -10
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +177 -109
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/dist/token-service.cjs +6 -4
- package/dist/token-service.cjs.map +1 -1
- package/dist/token-service.d.cts +3 -1
- package/dist/token-service.d.cts.map +1 -1
- package/dist/token-service.d.mts +3 -1
- package/dist/token-service.d.mts.map +1 -1
- package/dist/token-service.mjs +6 -4
- package/dist/token-service.mjs.map +1 -1
- package/package.json +14 -24
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedEvmAccountChangeEvent } from "@metamask/accounts-controller";
|
|
2
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
2
|
import type { Messenger } from "@metamask/messenger";
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
3
|
+
import type { NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
4
|
+
import type { Hex } from "@metamask/utils";
|
|
6
5
|
import type { AbstractTokenPricesService } from "./token-prices-service/abstract-token-prices-service.cjs";
|
|
7
6
|
import type { TokensControllerGetStateAction, TokensControllerStateChangeEvent } from "./TokensController.cjs";
|
|
8
7
|
/**
|
|
@@ -58,14 +57,18 @@ export type MarketDataDetails = {
|
|
|
58
57
|
* Represents a mapping of token contract addresses to their market data.
|
|
59
58
|
*/
|
|
60
59
|
export type ContractMarketData = Record<Hex, MarketDataDetails>;
|
|
60
|
+
type ChainIdAndNativeCurrency = {
|
|
61
|
+
chainId: Hex;
|
|
62
|
+
nativeCurrency: string;
|
|
63
|
+
};
|
|
61
64
|
/**
|
|
62
65
|
* The external actions available to the {@link TokenRatesController}.
|
|
63
66
|
*/
|
|
64
|
-
export type AllowedActions = TokensControllerGetStateAction |
|
|
67
|
+
export type AllowedActions = TokensControllerGetStateAction | NetworkControllerGetStateAction;
|
|
65
68
|
/**
|
|
66
69
|
* The external events available to the {@link TokenRatesController}.
|
|
67
70
|
*/
|
|
68
|
-
export type AllowedEvents = TokensControllerStateChangeEvent | NetworkControllerStateChangeEvent
|
|
71
|
+
export type AllowedEvents = TokensControllerStateChangeEvent | NetworkControllerStateChangeEvent;
|
|
69
72
|
/**
|
|
70
73
|
* The name of the {@link TokenRatesController}.
|
|
71
74
|
*/
|
|
@@ -156,41 +159,12 @@ export declare class TokenRatesController extends TokenRatesController_base<type
|
|
|
156
159
|
* Blocks controller from making network calls
|
|
157
160
|
*/
|
|
158
161
|
disable(): void;
|
|
159
|
-
/**
|
|
160
|
-
* Start (or restart) polling.
|
|
161
|
-
*
|
|
162
|
-
* @param chainId - The chain ID.
|
|
163
|
-
* @param nativeCurrency - The native currency.
|
|
164
|
-
*/
|
|
165
|
-
start(chainId: Hex, nativeCurrency: string): Promise<void>;
|
|
166
|
-
/**
|
|
167
|
-
* Stop polling.
|
|
168
|
-
*/
|
|
169
|
-
stop(): void;
|
|
170
|
-
/**
|
|
171
|
-
* Updates exchange rates for all tokens.
|
|
172
|
-
*
|
|
173
|
-
* @param chainIdAndNativeCurrency - The chain ID and native currency.
|
|
174
|
-
*/
|
|
175
|
-
updateExchangeRates(chainIdAndNativeCurrency: {
|
|
176
|
-
chainId: Hex;
|
|
177
|
-
nativeCurrency: string;
|
|
178
|
-
}[]): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
-
* Updates exchange rates for all tokens.
|
|
181
|
-
*
|
|
182
|
-
* @param chainIds - The chain IDs.
|
|
183
|
-
* @returns A promise that resolves when all chain updates complete.
|
|
184
|
-
*/
|
|
185
162
|
/**
|
|
186
163
|
* Updates exchange rates for all tokens.
|
|
187
164
|
*
|
|
188
165
|
* @param chainIdAndNativeCurrency - The chain ID and native currency.
|
|
189
166
|
*/
|
|
190
|
-
|
|
191
|
-
chainId: Hex;
|
|
192
|
-
nativeCurrency: string;
|
|
193
|
-
}[]): Promise<void>;
|
|
167
|
+
updateExchangeRates(chainIdAndNativeCurrency: ChainIdAndNativeCurrency[]): Promise<void>;
|
|
194
168
|
/**
|
|
195
169
|
* Updates token rates for the given networkClientId
|
|
196
170
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenRatesController.d.cts","sourceRoot":"","sources":["../src/TokenRatesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"TokenRatesController.d.cts","sourceRoot":"","sources":["../src/TokenRatesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,+BAA+B,EAC/B,iCAAiC,EAClC,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,0BAA0B,EAAE,iEAA6D;AAEvG,OAAO,KAAK,EACV,8BAA8B,EAC9B,gCAAg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B,EAC3B,QAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE;QACD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,kBAAkB,EAAE,0BAA0B,CAAC;QAC/C,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;KAC5C;IA2HD;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,IAAI,IAAI;IAkBf;;;;OAIG;IACG,mBAAmB,CACvB,wBAAwB,EAAE,wBAAwB,EAAE,GACnD,OAAO,CAAC,IAAI,CAAC;IAsLhB;;;;;OAKG;IACG,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvE;;OAEG;IACH,UAAU;CAKX;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedEvmAccountChangeEvent } from "@metamask/accounts-controller";
|
|
2
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
2
|
import type { Messenger } from "@metamask/messenger";
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
3
|
+
import type { NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
4
|
+
import type { Hex } from "@metamask/utils";
|
|
6
5
|
import type { AbstractTokenPricesService } from "./token-prices-service/abstract-token-prices-service.mjs";
|
|
7
6
|
import type { TokensControllerGetStateAction, TokensControllerStateChangeEvent } from "./TokensController.mjs";
|
|
8
7
|
/**
|
|
@@ -58,14 +57,18 @@ export type MarketDataDetails = {
|
|
|
58
57
|
* Represents a mapping of token contract addresses to their market data.
|
|
59
58
|
*/
|
|
60
59
|
export type ContractMarketData = Record<Hex, MarketDataDetails>;
|
|
60
|
+
type ChainIdAndNativeCurrency = {
|
|
61
|
+
chainId: Hex;
|
|
62
|
+
nativeCurrency: string;
|
|
63
|
+
};
|
|
61
64
|
/**
|
|
62
65
|
* The external actions available to the {@link TokenRatesController}.
|
|
63
66
|
*/
|
|
64
|
-
export type AllowedActions = TokensControllerGetStateAction |
|
|
67
|
+
export type AllowedActions = TokensControllerGetStateAction | NetworkControllerGetStateAction;
|
|
65
68
|
/**
|
|
66
69
|
* The external events available to the {@link TokenRatesController}.
|
|
67
70
|
*/
|
|
68
|
-
export type AllowedEvents = TokensControllerStateChangeEvent | NetworkControllerStateChangeEvent
|
|
71
|
+
export type AllowedEvents = TokensControllerStateChangeEvent | NetworkControllerStateChangeEvent;
|
|
69
72
|
/**
|
|
70
73
|
* The name of the {@link TokenRatesController}.
|
|
71
74
|
*/
|
|
@@ -156,41 +159,12 @@ export declare class TokenRatesController extends TokenRatesController_base<type
|
|
|
156
159
|
* Blocks controller from making network calls
|
|
157
160
|
*/
|
|
158
161
|
disable(): void;
|
|
159
|
-
/**
|
|
160
|
-
* Start (or restart) polling.
|
|
161
|
-
*
|
|
162
|
-
* @param chainId - The chain ID.
|
|
163
|
-
* @param nativeCurrency - The native currency.
|
|
164
|
-
*/
|
|
165
|
-
start(chainId: Hex, nativeCurrency: string): Promise<void>;
|
|
166
|
-
/**
|
|
167
|
-
* Stop polling.
|
|
168
|
-
*/
|
|
169
|
-
stop(): void;
|
|
170
|
-
/**
|
|
171
|
-
* Updates exchange rates for all tokens.
|
|
172
|
-
*
|
|
173
|
-
* @param chainIdAndNativeCurrency - The chain ID and native currency.
|
|
174
|
-
*/
|
|
175
|
-
updateExchangeRates(chainIdAndNativeCurrency: {
|
|
176
|
-
chainId: Hex;
|
|
177
|
-
nativeCurrency: string;
|
|
178
|
-
}[]): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
-
* Updates exchange rates for all tokens.
|
|
181
|
-
*
|
|
182
|
-
* @param chainIds - The chain IDs.
|
|
183
|
-
* @returns A promise that resolves when all chain updates complete.
|
|
184
|
-
*/
|
|
185
162
|
/**
|
|
186
163
|
* Updates exchange rates for all tokens.
|
|
187
164
|
*
|
|
188
165
|
* @param chainIdAndNativeCurrency - The chain ID and native currency.
|
|
189
166
|
*/
|
|
190
|
-
|
|
191
|
-
chainId: Hex;
|
|
192
|
-
nativeCurrency: string;
|
|
193
|
-
}[]): Promise<void>;
|
|
167
|
+
updateExchangeRates(chainIdAndNativeCurrency: ChainIdAndNativeCurrency[]): Promise<void>;
|
|
194
168
|
/**
|
|
195
169
|
* Updates token rates for the given networkClientId
|
|
196
170
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenRatesController.d.mts","sourceRoot":"","sources":["../src/TokenRatesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"TokenRatesController.d.mts","sourceRoot":"","sources":["../src/TokenRatesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,+BAA+B,EAC/B,iCAAiC,EAClC,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,0BAA0B,EAAE,iEAA6D;AAEvG,OAAO,KAAK,EACV,8BAA8B,EAC9B,gCAAgC,EAEjC,+BAA2B;AAE5B;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CA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;OAEG;IACH,OAAO,IAAI,IAAI;IAkBf;;;;OAIG;IACG,mBAAmB,CACvB,wBAAwB,EAAE,wBAAwB,EAAE,GACnD,OAAO,CAAC,IAAI,CAAC;IAsLhB;;;;;OAKG;IACG,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvE;;OAEG;IACH,UAAU;CAKX;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -9,20 +9,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _TokenRatesController_instances,
|
|
13
|
-
import {
|
|
12
|
+
var _TokenRatesController_instances, _TokenRatesController_tokenPricesService, _TokenRatesController_disabled, _TokenRatesController_allTokens, _TokenRatesController_allDetectedTokens, _TokenRatesController_subscribeToTokensStateChange, _TokenRatesController_subscribeToNetworkStateChange, _TokenRatesController_getTokenAddresses, _TokenRatesController_getTokensControllerState, _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency, _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency;
|
|
13
|
+
import { toChecksumHexAddress } from "@metamask/controller-utils";
|
|
14
14
|
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
15
|
-
import { createDeferredPromise } from "@metamask/utils";
|
|
16
15
|
import $lodash from "lodash";
|
|
17
16
|
const { isEqual } = $lodash;
|
|
18
17
|
import { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from "./assetsUtil.mjs";
|
|
19
18
|
import { getNativeTokenAddress } from "./token-prices-service/codefi-v2.mjs";
|
|
20
19
|
const DEFAULT_INTERVAL = 180000;
|
|
21
|
-
var PollState;
|
|
22
|
-
(function (PollState) {
|
|
23
|
-
PollState["Active"] = "Active";
|
|
24
|
-
PollState["Inactive"] = "Inactive";
|
|
25
|
-
})(PollState || (PollState = {}));
|
|
26
20
|
/**
|
|
27
21
|
* The name of the {@link TokenRatesController}.
|
|
28
22
|
*/
|
|
@@ -68,18 +62,13 @@ export class TokenRatesController extends StaticIntervalPollingController() {
|
|
|
68
62
|
metadata: tokenRatesControllerMetadata,
|
|
69
63
|
});
|
|
70
64
|
_TokenRatesController_instances.add(this);
|
|
71
|
-
_TokenRatesController_handle.set(this, void 0);
|
|
72
|
-
_TokenRatesController_pollState.set(this, PollState.Inactive);
|
|
73
65
|
_TokenRatesController_tokenPricesService.set(this, void 0);
|
|
74
|
-
_TokenRatesController_inProcessExchangeRateUpdates.set(this, {});
|
|
75
66
|
_TokenRatesController_disabled.set(this, void 0);
|
|
76
|
-
_TokenRatesController_interval.set(this, void 0);
|
|
77
67
|
_TokenRatesController_allTokens.set(this, void 0);
|
|
78
68
|
_TokenRatesController_allDetectedTokens.set(this, void 0);
|
|
79
69
|
this.setIntervalLength(interval);
|
|
80
70
|
__classPrivateFieldSet(this, _TokenRatesController_tokenPricesService, tokenPricesService, "f");
|
|
81
71
|
__classPrivateFieldSet(this, _TokenRatesController_disabled, disabled, "f");
|
|
82
|
-
__classPrivateFieldSet(this, _TokenRatesController_interval, interval, "f");
|
|
83
72
|
const { allTokens, allDetectedTokens } = __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getTokensControllerState).call(this);
|
|
84
73
|
__classPrivateFieldSet(this, _TokenRatesController_allTokens, allTokens, "f");
|
|
85
74
|
__classPrivateFieldSet(this, _TokenRatesController_allDetectedTokens, allDetectedTokens, "f");
|
|
@@ -98,99 +87,52 @@ export class TokenRatesController extends StaticIntervalPollingController() {
|
|
|
98
87
|
disable() {
|
|
99
88
|
__classPrivateFieldSet(this, _TokenRatesController_disabled, true, "f");
|
|
100
89
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Start (or restart) polling.
|
|
103
|
-
*
|
|
104
|
-
* @param chainId - The chain ID.
|
|
105
|
-
* @param nativeCurrency - The native currency.
|
|
106
|
-
*/
|
|
107
|
-
async start(chainId, nativeCurrency) {
|
|
108
|
-
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_stopPoll).call(this);
|
|
109
|
-
__classPrivateFieldSet(this, _TokenRatesController_pollState, PollState.Active, "f");
|
|
110
|
-
await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_poll).call(this, chainId, nativeCurrency);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Stop polling.
|
|
114
|
-
*/
|
|
115
|
-
stop() {
|
|
116
|
-
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_stopPoll).call(this);
|
|
117
|
-
__classPrivateFieldSet(this, _TokenRatesController_pollState, PollState.Inactive, "f");
|
|
118
|
-
}
|
|
119
90
|
/**
|
|
120
91
|
* Updates exchange rates for all tokens.
|
|
121
92
|
*
|
|
122
93
|
* @param chainIdAndNativeCurrency - The chain ID and native currency.
|
|
123
94
|
*/
|
|
124
95
|
async updateExchangeRates(chainIdAndNativeCurrency) {
|
|
125
|
-
await this.updateExchangeRatesByChainId(chainIdAndNativeCurrency);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Updates exchange rates for all tokens.
|
|
129
|
-
*
|
|
130
|
-
* @param chainIds - The chain IDs.
|
|
131
|
-
* @returns A promise that resolves when all chain updates complete.
|
|
132
|
-
*/
|
|
133
|
-
/**
|
|
134
|
-
* Updates exchange rates for all tokens.
|
|
135
|
-
*
|
|
136
|
-
* @param chainIdAndNativeCurrency - The chain ID and native currency.
|
|
137
|
-
*/
|
|
138
|
-
async updateExchangeRatesByChainId(chainIdAndNativeCurrency) {
|
|
139
96
|
if (__classPrivateFieldGet(this, _TokenRatesController_disabled, "f")) {
|
|
140
97
|
return;
|
|
141
98
|
}
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
// Each promise returns an object with the market data for the chain.
|
|
162
|
-
const marketData = {
|
|
163
|
-
[chainId]: {
|
|
164
|
-
...(contractInformations ?? {}),
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
updateSucceeded();
|
|
168
|
-
return marketData;
|
|
99
|
+
const marketData = {};
|
|
100
|
+
const assetsByNativeCurrency = {};
|
|
101
|
+
const unsupportedAssetsByNativeCurrency = {};
|
|
102
|
+
for (const { chainId, nativeCurrency } of chainIdAndNativeCurrency) {
|
|
103
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").validateChainIdSupported(chainId)) {
|
|
104
|
+
for (const tokenAddress of __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_getTokenAddresses).call(this, chainId)) {
|
|
105
|
+
if (__classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").validateCurrencySupported(nativeCurrency)) {
|
|
106
|
+
(assetsByNativeCurrency[nativeCurrency] ?? (assetsByNativeCurrency[nativeCurrency] = [])).push({
|
|
107
|
+
chainId,
|
|
108
|
+
tokenAddress,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
(unsupportedAssetsByNativeCurrency[nativeCurrency] ?? (unsupportedAssetsByNativeCurrency[nativeCurrency] = [])).push({
|
|
113
|
+
chainId,
|
|
114
|
+
tokenAddress,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
169
118
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const results = await Promise.allSettled(updatePromises);
|
|
181
|
-
// Merge all successful market data updates into one object.
|
|
182
|
-
const combinedMarketData = results.reduce((acc, result) => {
|
|
183
|
-
if (result.status === 'fulfilled' && result.value) {
|
|
184
|
-
acc = { ...acc, ...result.value };
|
|
119
|
+
}
|
|
120
|
+
const promises = [
|
|
121
|
+
...Object.entries(assetsByNativeCurrency).map(([nativeCurrency, assets]) => __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency).call(this, assets, nativeCurrency, marketData)),
|
|
122
|
+
...Object.entries(unsupportedAssetsByNativeCurrency).map(([nativeCurrency, assets]) => __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency).call(this, assets, nativeCurrency, marketData)),
|
|
123
|
+
];
|
|
124
|
+
await Promise.allSettled(promises);
|
|
125
|
+
const chainIds = new Set(Object.values(chainIdAndNativeCurrency).map((chain) => chain.chainId));
|
|
126
|
+
for (const chainId of chainIds) {
|
|
127
|
+
if (!marketData[chainId]) {
|
|
128
|
+
marketData[chainId] = {};
|
|
185
129
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// Call this.update only once with the combined market data to reduce the number of state changes and re-renders
|
|
189
|
-
if (Object.keys(combinedMarketData).length > 0) {
|
|
130
|
+
}
|
|
131
|
+
if (Object.keys(marketData).length > 0) {
|
|
190
132
|
this.update((state) => {
|
|
191
133
|
state.marketData = {
|
|
192
134
|
...state.marketData,
|
|
193
|
-
...
|
|
135
|
+
...marketData,
|
|
194
136
|
};
|
|
195
137
|
});
|
|
196
138
|
}
|
|
@@ -215,7 +157,7 @@ export class TokenRatesController extends StaticIntervalPollingController() {
|
|
|
215
157
|
});
|
|
216
158
|
return acc;
|
|
217
159
|
}, []);
|
|
218
|
-
await this.
|
|
160
|
+
await this.updateExchangeRates(chainIdAndNativeCurrency);
|
|
219
161
|
}
|
|
220
162
|
/**
|
|
221
163
|
* Reset the controller state to the default state.
|
|
@@ -226,7 +168,7 @@ export class TokenRatesController extends StaticIntervalPollingController() {
|
|
|
226
168
|
});
|
|
227
169
|
}
|
|
228
170
|
}
|
|
229
|
-
|
|
171
|
+
_TokenRatesController_tokenPricesService = new WeakMap(), _TokenRatesController_disabled = new WeakMap(), _TokenRatesController_allTokens = new WeakMap(), _TokenRatesController_allDetectedTokens = new WeakMap(), _TokenRatesController_instances = new WeakSet(), _TokenRatesController_subscribeToTokensStateChange = function _TokenRatesController_subscribeToTokensStateChange() {
|
|
230
172
|
this.messenger.subscribe('TokensController:stateChange',
|
|
231
173
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
232
174
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
@@ -257,24 +199,12 @@ _TokenRatesController_handle = new WeakMap(), _TokenRatesController_pollState =
|
|
|
257
199
|
});
|
|
258
200
|
return acc;
|
|
259
201
|
}, []);
|
|
260
|
-
await this.
|
|
202
|
+
await this.updateExchangeRates(chainIdAndNativeCurrency);
|
|
261
203
|
}, ({ allTokens, allDetectedTokens }) => {
|
|
262
204
|
return { allTokens, allDetectedTokens };
|
|
263
205
|
});
|
|
264
206
|
}, _TokenRatesController_subscribeToNetworkStateChange = function _TokenRatesController_subscribeToNetworkStateChange() {
|
|
265
|
-
this.messenger.subscribe('NetworkController:stateChange',
|
|
266
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
267
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
268
|
-
async ({ networkConfigurationsByChainId }, patches) => {
|
|
269
|
-
const chainIdAndNativeCurrency = Object.values(networkConfigurationsByChainId).map(({ chainId, nativeCurrency }) => {
|
|
270
|
-
return {
|
|
271
|
-
chainId: chainId,
|
|
272
|
-
nativeCurrency,
|
|
273
|
-
};
|
|
274
|
-
});
|
|
275
|
-
if (__classPrivateFieldGet(this, _TokenRatesController_pollState, "f") === PollState.Active) {
|
|
276
|
-
await this.updateExchangeRates(chainIdAndNativeCurrency);
|
|
277
|
-
}
|
|
207
|
+
this.messenger.subscribe('NetworkController:stateChange', (_state, patches) => {
|
|
278
208
|
// Remove state for deleted networks
|
|
279
209
|
for (const patch of patches) {
|
|
280
210
|
if (patch.op === 'remove' &&
|
|
@@ -290,189 +220,63 @@ _TokenRatesController_handle = new WeakMap(), _TokenRatesController_pollState =
|
|
|
290
220
|
const getTokens = (allTokens) => Object.values(allTokens ?? {}).flatMap((tokens) => tokens.map(({ address }) => toChecksumHexAddress(address)));
|
|
291
221
|
const tokenAddresses = getTokens(__classPrivateFieldGet(this, _TokenRatesController_allTokens, "f")[chainId]);
|
|
292
222
|
const detectedTokenAddresses = getTokens(__classPrivateFieldGet(this, _TokenRatesController_allDetectedTokens, "f")[chainId]);
|
|
293
|
-
return [
|
|
223
|
+
return [
|
|
224
|
+
...new Set([
|
|
225
|
+
...tokenAddresses,
|
|
226
|
+
...detectedTokenAddresses,
|
|
227
|
+
getNativeTokenAddress(chainId),
|
|
228
|
+
]),
|
|
229
|
+
].sort();
|
|
294
230
|
}, _TokenRatesController_getTokensControllerState = function _TokenRatesController_getTokensControllerState() {
|
|
295
231
|
const { allTokens, allDetectedTokens } = this.messenger.call('TokensController:getState');
|
|
296
232
|
return {
|
|
297
233
|
allTokens,
|
|
298
234
|
allDetectedTokens,
|
|
299
235
|
};
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
}, _TokenRatesController_poll =
|
|
305
|
-
/**
|
|
306
|
-
* Poll for exchange rate updates.
|
|
307
|
-
*
|
|
308
|
-
* @param chainId - The chain ID.
|
|
309
|
-
* @param nativeCurrency - The native currency.
|
|
310
|
-
*/
|
|
311
|
-
async function _TokenRatesController_poll(chainId, nativeCurrency) {
|
|
312
|
-
await safelyExecute(() => this.updateExchangeRates([{ chainId, nativeCurrency }]));
|
|
313
|
-
// Poll using recursive `setTimeout` instead of `setInterval` so that
|
|
314
|
-
// requests don't stack if they take longer than the polling interval
|
|
315
|
-
__classPrivateFieldSet(this, _TokenRatesController_handle, setTimeout(() => {
|
|
316
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
317
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
318
|
-
__classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_poll).call(this, chainId, nativeCurrency);
|
|
319
|
-
}, __classPrivateFieldGet(this, _TokenRatesController_interval, "f")), "f");
|
|
320
|
-
}, _TokenRatesController_fetchAndMapExchangeRates =
|
|
321
|
-
/**
|
|
322
|
-
* Uses the token prices service to retrieve exchange rates for tokens in a
|
|
323
|
-
* particular currency.
|
|
324
|
-
*
|
|
325
|
-
* If the price API does not support the given chain ID, returns an empty
|
|
326
|
-
* object.
|
|
327
|
-
*
|
|
328
|
-
* If the price API does not support the given currency, retrieves exchange
|
|
329
|
-
* rates in a known currency instead, then converts those rates using the
|
|
330
|
-
* exchange rate between the known currency and desired currency.
|
|
331
|
-
*
|
|
332
|
-
* @param args - The arguments to this function.
|
|
333
|
-
* @param args.tokenAddresses - Addresses for tokens.
|
|
334
|
-
* @param args.chainId - The EIP-155 ID of the chain where the tokens live.
|
|
335
|
-
* @param args.nativeCurrency - The native currency in which to request
|
|
336
|
-
* exchange rates.
|
|
337
|
-
* @returns A map from token address to its exchange rate in the native
|
|
338
|
-
* currency, or an empty map if no exchange rates can be obtained for the
|
|
339
|
-
* chain ID.
|
|
340
|
-
*/
|
|
341
|
-
async function _TokenRatesController_fetchAndMapExchangeRates({ tokenAddresses, chainId, nativeCurrency, }) {
|
|
342
|
-
if (!__classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").validateChainIdSupported(chainId)) {
|
|
343
|
-
return tokenAddresses.reduce((obj, tokenAddress) => {
|
|
344
|
-
obj = {
|
|
345
|
-
...obj,
|
|
346
|
-
[tokenAddress]: undefined,
|
|
347
|
-
};
|
|
348
|
-
return obj;
|
|
349
|
-
}, {});
|
|
350
|
-
}
|
|
351
|
-
if (__classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").validateCurrencySupported(nativeCurrency)) {
|
|
352
|
-
return await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency).call(this, {
|
|
353
|
-
tokenAddresses,
|
|
354
|
-
chainId,
|
|
355
|
-
nativeCurrency,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
return await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency).call(this, {
|
|
359
|
-
chainId,
|
|
360
|
-
tokenAddresses,
|
|
361
|
-
nativeCurrency,
|
|
362
|
-
});
|
|
363
|
-
}, _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency =
|
|
364
|
-
/**
|
|
365
|
-
* Retrieves prices in the given currency for the given tokens on the given
|
|
366
|
-
* chain. Ensures that token addresses are checksum addresses.
|
|
367
|
-
*
|
|
368
|
-
* @param args - The arguments to this function.
|
|
369
|
-
* @param args.tokenAddresses - Addresses for tokens.
|
|
370
|
-
* @param args.chainId - The EIP-155 ID of the chain where the tokens live.
|
|
371
|
-
* @param args.nativeCurrency - The native currency in which to request
|
|
372
|
-
* prices.
|
|
373
|
-
* @returns A map of the token addresses (as checksums) to their prices in the
|
|
374
|
-
* native currency.
|
|
375
|
-
*/
|
|
376
|
-
async function _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency({ tokenAddresses, chainId, nativeCurrency, }) {
|
|
377
|
-
let contractNativeInformations;
|
|
378
|
-
const tokenPricesByTokenAddress = await reduceInBatchesSerially({
|
|
379
|
-
values: [...tokenAddresses].sort(),
|
|
236
|
+
}, _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency = async function _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency(assets, currency, marketData = {}) {
|
|
237
|
+
return await reduceInBatchesSerially({
|
|
238
|
+
values: assets,
|
|
380
239
|
batchSize: TOKEN_PRICES_BATCH_SIZE,
|
|
381
|
-
eachBatch: async (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
currency
|
|
240
|
+
eachBatch: async (partialMarketData, assetsBatch) => {
|
|
241
|
+
var _a;
|
|
242
|
+
const batchMarketData = await __classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").fetchTokenPrices({
|
|
243
|
+
assets: assetsBatch,
|
|
244
|
+
currency,
|
|
386
245
|
});
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
246
|
+
for (const tokenPrice of batchMarketData) {
|
|
247
|
+
(partialMarketData[_a = tokenPrice.chainId] ?? (partialMarketData[_a] = {}))[tokenPrice.tokenAddress] = tokenPrice;
|
|
248
|
+
}
|
|
249
|
+
return partialMarketData;
|
|
391
250
|
},
|
|
392
|
-
initialResult:
|
|
393
|
-
});
|
|
394
|
-
contractNativeInformations = tokenPricesByTokenAddress;
|
|
395
|
-
// fetch for native token
|
|
396
|
-
if (tokenAddresses.length === 0) {
|
|
397
|
-
const contractNativeInformationsNative = await __classPrivateFieldGet(this, _TokenRatesController_tokenPricesService, "f").fetchTokenPrices({
|
|
398
|
-
tokenAddresses: [],
|
|
399
|
-
chainId,
|
|
400
|
-
currency: nativeCurrency,
|
|
401
|
-
});
|
|
402
|
-
contractNativeInformations = {
|
|
403
|
-
[getNativeTokenAddress(chainId)]: {
|
|
404
|
-
currency: nativeCurrency,
|
|
405
|
-
...contractNativeInformationsNative[getNativeTokenAddress(chainId)],
|
|
406
|
-
},
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
return Object.entries(contractNativeInformations).reduce((obj, [tokenAddress, token]) => {
|
|
410
|
-
obj = {
|
|
411
|
-
...obj,
|
|
412
|
-
[tokenAddress]: { ...token },
|
|
413
|
-
};
|
|
414
|
-
return obj;
|
|
415
|
-
}, {});
|
|
416
|
-
}, _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency =
|
|
417
|
-
/**
|
|
418
|
-
* If the price API does not support a given native currency, then we need to
|
|
419
|
-
* convert it to a fallback currency and feed that currency into the price
|
|
420
|
-
* API, then convert the prices to our desired native currency.
|
|
421
|
-
*
|
|
422
|
-
* @param args - The arguments to this function.
|
|
423
|
-
* @param args.chainId - The chain id to fetch prices for.
|
|
424
|
-
* @param args.tokenAddresses - Addresses for tokens.
|
|
425
|
-
* @param args.nativeCurrency - The native currency in which to request
|
|
426
|
-
* prices.
|
|
427
|
-
* @returns A map of the token addresses (as checksums) to their prices in the
|
|
428
|
-
* native currency.
|
|
429
|
-
*/
|
|
430
|
-
async function _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency({ chainId, tokenAddresses, nativeCurrency, }) {
|
|
431
|
-
const nativeTokenAddress = getNativeTokenAddress(chainId);
|
|
432
|
-
// Step -1: First fetch native token priced in USD
|
|
433
|
-
const nativeTokenPriceMap = await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency).call(this, {
|
|
434
|
-
tokenAddresses: [], // special-case: returns only native token
|
|
435
|
-
chainId,
|
|
436
|
-
nativeCurrency: 'usd',
|
|
251
|
+
initialResult: marketData,
|
|
437
252
|
});
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
chainId,
|
|
442
|
-
nativeCurrency: 'usd',
|
|
443
|
-
});
|
|
444
|
-
const nativeTokenInfo = nativeTokenPriceMap[nativeTokenAddress];
|
|
445
|
-
const nativeTokenPriceInUSD = nativeTokenInfo?.price;
|
|
446
|
-
if (!nativeTokenPriceInUSD || nativeTokenPriceInUSD === 0) {
|
|
447
|
-
// If we can't price the native token in the fallback currency,
|
|
448
|
-
// we can't safely convert; return empty so callers know there is no data.
|
|
449
|
-
return {};
|
|
450
|
-
}
|
|
451
|
-
// Step -3: Convert USD prices to native currency
|
|
253
|
+
}, _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency = async function _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency(assets, currency, marketData) {
|
|
254
|
+
// Step -1: Then fetch all tracked tokens priced in USD
|
|
255
|
+
const marketDataInUSD = await __classPrivateFieldGet(this, _TokenRatesController_instances, "m", _TokenRatesController_fetchAndMapExchangeRatesForSupportedNativeCurrency).call(this, assets, 'usd');
|
|
452
256
|
// Formula: price_in_native = token_usd / native_usd
|
|
453
|
-
const convertUSDToNative = (valueInUSD) => valueInUSD
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
257
|
+
const convertUSDToNative = (valueInUSD, nativeTokenPriceInUSD) => valueInUSD / nativeTokenPriceInUSD;
|
|
258
|
+
// Step -2: Convert USD prices to native currency
|
|
259
|
+
for (const [chainId, marketDataByTokenAddress] of Object.entries(marketDataInUSD)) {
|
|
260
|
+
const nativeTokenPriceInUSD = marketDataByTokenAddress[getNativeTokenAddress(chainId)]?.price;
|
|
261
|
+
// Return here if it's null, undefined or 0
|
|
262
|
+
if (!nativeTokenPriceInUSD) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
for (const [tokenAddress, tokenData] of Object.entries(marketDataByTokenAddress)) {
|
|
266
|
+
(marketData[chainId] ?? (marketData[chainId] = {}))[tokenAddress] = {
|
|
461
267
|
...tokenData,
|
|
462
|
-
currency
|
|
463
|
-
price: convertUSDToNative(tokenData.price),
|
|
464
|
-
marketCap: convertUSDToNative(tokenData.marketCap),
|
|
465
|
-
allTimeHigh: convertUSDToNative(tokenData.allTimeHigh),
|
|
466
|
-
allTimeLow: convertUSDToNative(tokenData.allTimeLow),
|
|
467
|
-
totalVolume: convertUSDToNative(tokenData.totalVolume),
|
|
468
|
-
high1d: convertUSDToNative(tokenData.high1d),
|
|
469
|
-
low1d: convertUSDToNative(tokenData.low1d),
|
|
470
|
-
dilutedMarketCap: convertUSDToNative(tokenData.dilutedMarketCap),
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
}, {});
|
|
475
|
-
return tokenPricesInNative;
|
|
268
|
+
currency,
|
|
269
|
+
price: convertUSDToNative(tokenData.price, nativeTokenPriceInUSD),
|
|
270
|
+
marketCap: convertUSDToNative(tokenData.marketCap, nativeTokenPriceInUSD),
|
|
271
|
+
allTimeHigh: convertUSDToNative(tokenData.allTimeHigh, nativeTokenPriceInUSD),
|
|
272
|
+
allTimeLow: convertUSDToNative(tokenData.allTimeLow, nativeTokenPriceInUSD),
|
|
273
|
+
totalVolume: convertUSDToNative(tokenData.totalVolume, nativeTokenPriceInUSD),
|
|
274
|
+
high1d: convertUSDToNative(tokenData.high1d, nativeTokenPriceInUSD),
|
|
275
|
+
low1d: convertUSDToNative(tokenData.low1d, nativeTokenPriceInUSD),
|
|
276
|
+
dilutedMarketCap: convertUSDToNative(tokenData.dilutedMarketCap, nativeTokenPriceInUSD),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
476
280
|
};
|
|
477
281
|
export default TokenRatesController;
|
|
478
282
|
//# sourceMappingURL=TokenRatesController.mjs.map
|