@metamask/core-backend 4.1.0 → 5.1.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 +35 -6
- package/README.md +252 -1
- package/dist/AccountActivityService.cjs +1 -1
- package/dist/AccountActivityService.cjs.map +1 -1
- package/dist/AccountActivityService.mjs +1 -1
- package/dist/AccountActivityService.mjs.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.cjs.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.d.cts +106 -20
- package/dist/BackendWebSocketService-method-action-types.d.cts.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.d.mts +106 -20
- package/dist/BackendWebSocketService-method-action-types.d.mts.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.mjs.map +1 -1
- package/dist/BackendWebSocketService.cjs +5 -3
- package/dist/BackendWebSocketService.cjs.map +1 -1
- package/dist/BackendWebSocketService.d.cts +2 -2
- package/dist/BackendWebSocketService.d.cts.map +1 -1
- package/dist/BackendWebSocketService.d.mts +2 -2
- package/dist/BackendWebSocketService.d.mts.map +1 -1
- package/dist/BackendWebSocketService.mjs +5 -3
- package/dist/BackendWebSocketService.mjs.map +1 -1
- package/dist/api/ApiPlatformClient.cjs +177 -0
- package/dist/api/ApiPlatformClient.cjs.map +1 -0
- package/dist/api/ApiPlatformClient.d.cts +127 -0
- package/dist/api/ApiPlatformClient.d.cts.map +1 -0
- package/dist/api/ApiPlatformClient.d.mts +127 -0
- package/dist/api/ApiPlatformClient.d.mts.map +1 -0
- package/dist/api/ApiPlatformClient.mjs +172 -0
- package/dist/api/ApiPlatformClient.mjs.map +1 -0
- package/dist/api/accounts/client.cjs +492 -0
- package/dist/api/accounts/client.cjs.map +1 -0
- package/dist/api/accounts/client.d.cts +213 -0
- package/dist/api/accounts/client.d.cts.map +1 -0
- package/dist/api/accounts/client.d.mts +213 -0
- package/dist/api/accounts/client.d.mts.map +1 -0
- package/dist/api/accounts/client.mjs +488 -0
- package/dist/api/accounts/client.mjs.map +1 -0
- package/dist/api/accounts/index.cjs +9 -0
- package/dist/api/accounts/index.cjs.map +1 -0
- package/dist/api/accounts/index.d.cts +6 -0
- package/dist/api/accounts/index.d.cts.map +1 -0
- package/dist/api/accounts/index.d.mts +6 -0
- package/dist/api/accounts/index.d.mts.map +1 -0
- package/dist/api/accounts/index.mjs +5 -0
- package/dist/api/accounts/index.mjs.map +1 -0
- package/dist/api/accounts/types.cjs +7 -0
- package/dist/api/accounts/types.cjs.map +1 -0
- package/dist/api/accounts/types.d.cts +195 -0
- package/dist/api/accounts/types.d.cts.map +1 -0
- package/dist/api/accounts/types.d.mts +195 -0
- package/dist/api/accounts/types.d.mts.map +1 -0
- package/dist/api/accounts/types.mjs +6 -0
- package/dist/api/accounts/types.mjs.map +1 -0
- package/dist/api/base-client.cjs +149 -0
- package/dist/api/base-client.cjs.map +1 -0
- package/dist/api/base-client.d.cts +54 -0
- package/dist/api/base-client.d.cts.map +1 -0
- package/dist/api/base-client.d.mts +54 -0
- package/dist/api/base-client.d.mts.map +1 -0
- package/dist/api/base-client.mjs +143 -0
- package/dist/api/base-client.mjs.map +1 -0
- package/dist/api/index.cjs +35 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +18 -0
- package/dist/api/index.d.cts.map +1 -0
- package/dist/api/index.d.mts +18 -0
- package/dist/api/index.d.mts.map +1 -0
- package/dist/api/index.mjs +18 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/prices/client.cjs +521 -0
- package/dist/api/prices/client.cjs.map +1 -0
- package/dist/api/prices/client.d.cts +235 -0
- package/dist/api/prices/client.d.cts.map +1 -0
- package/dist/api/prices/client.d.mts +235 -0
- package/dist/api/prices/client.d.mts.map +1 -0
- package/dist/api/prices/client.mjs +517 -0
- package/dist/api/prices/client.mjs.map +1 -0
- package/dist/api/prices/index.cjs +9 -0
- package/dist/api/prices/index.cjs.map +1 -0
- package/dist/api/prices/index.d.cts +6 -0
- package/dist/api/prices/index.d.cts.map +1 -0
- package/dist/api/prices/index.d.mts +6 -0
- package/dist/api/prices/index.d.mts.map +1 -0
- package/dist/api/prices/index.mjs +5 -0
- package/dist/api/prices/index.mjs.map +1 -0
- package/dist/api/prices/types.cjs +7 -0
- package/dist/api/prices/types.cjs.map +1 -0
- package/dist/api/prices/types.d.cts +61 -0
- package/dist/api/prices/types.d.cts.map +1 -0
- package/dist/api/prices/types.d.mts +61 -0
- package/dist/api/prices/types.d.mts.map +1 -0
- package/dist/api/prices/types.mjs +6 -0
- package/dist/api/prices/types.mjs.map +1 -0
- package/dist/api/shared-types.cjs +93 -0
- package/dist/api/shared-types.cjs.map +1 -0
- package/dist/api/shared-types.d.cts +131 -0
- package/dist/api/shared-types.d.cts.map +1 -0
- package/dist/api/shared-types.d.mts +131 -0
- package/dist/api/shared-types.d.mts.map +1 -0
- package/dist/api/shared-types.mjs +87 -0
- package/dist/api/shared-types.mjs.map +1 -0
- package/dist/api/test-utils.cjs +70 -0
- package/dist/api/test-utils.cjs.map +1 -0
- package/dist/api/test-utils.d.cts +30 -0
- package/dist/api/test-utils.d.cts.map +1 -0
- package/dist/api/test-utils.d.mts +30 -0
- package/dist/api/test-utils.d.mts.map +1 -0
- package/dist/api/test-utils.mjs +64 -0
- package/dist/api/test-utils.mjs.map +1 -0
- package/dist/api/token/client.cjs +342 -0
- package/dist/api/token/client.cjs.map +1 -0
- package/dist/api/token/client.d.cts +193 -0
- package/dist/api/token/client.d.cts.map +1 -0
- package/dist/api/token/client.d.mts +193 -0
- package/dist/api/token/client.d.mts.map +1 -0
- package/dist/api/token/client.mjs +338 -0
- package/dist/api/token/client.mjs.map +1 -0
- package/dist/api/token/index.cjs +9 -0
- package/dist/api/token/index.cjs.map +1 -0
- package/dist/api/token/index.d.cts +6 -0
- package/dist/api/token/index.d.cts.map +1 -0
- package/dist/api/token/index.d.mts +6 -0
- package/dist/api/token/index.d.mts.map +1 -0
- package/dist/api/token/index.mjs +5 -0
- package/dist/api/token/index.mjs.map +1 -0
- package/dist/api/token/types.cjs +7 -0
- package/dist/api/token/types.cjs.map +1 -0
- package/dist/api/token/types.d.cts +75 -0
- package/dist/api/token/types.d.cts.map +1 -0
- package/dist/api/token/types.d.mts +75 -0
- package/dist/api/token/types.d.mts.map +1 -0
- package/dist/api/token/types.mjs +6 -0
- package/dist/api/token/types.mjs.map +1 -0
- package/dist/api/tokens/client.cjs +91 -0
- package/dist/api/tokens/client.cjs.map +1 -0
- package/dist/api/tokens/client.d.cts +45 -0
- package/dist/api/tokens/client.d.cts.map +1 -0
- package/dist/api/tokens/client.d.mts +45 -0
- package/dist/api/tokens/client.d.mts.map +1 -0
- package/dist/api/tokens/client.mjs +87 -0
- package/dist/api/tokens/client.mjs.map +1 -0
- package/dist/api/tokens/index.cjs +9 -0
- package/dist/api/tokens/index.cjs.map +1 -0
- package/dist/api/tokens/index.d.cts +6 -0
- package/dist/api/tokens/index.d.cts.map +1 -0
- package/dist/api/tokens/index.d.mts +6 -0
- package/dist/api/tokens/index.d.mts.map +1 -0
- package/dist/api/tokens/index.mjs +5 -0
- package/dist/api/tokens/index.mjs.map +1 -0
- package/dist/api/tokens/types.cjs +7 -0
- package/dist/api/tokens/types.cjs.map +1 -0
- package/dist/api/tokens/types.d.cts +83 -0
- package/dist/api/tokens/types.d.cts.map +1 -0
- package/dist/api/tokens/types.d.mts +83 -0
- package/dist/api/tokens/types.d.mts.map +1 -0
- package/dist/api/tokens/types.mjs +6 -0
- package/dist/api/tokens/types.mjs.map +1 -0
- package/dist/index.cjs +33 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +21 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -12
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prices API Client - price.api.cx.metamask.io
|
|
4
|
+
*
|
|
5
|
+
* Handles all price-related API calls including:
|
|
6
|
+
* - Supported networks
|
|
7
|
+
* - Exchange rates
|
|
8
|
+
* - Spot prices (v1, v2, v3)
|
|
9
|
+
* - Historical prices
|
|
10
|
+
* - Price graphs
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PricesApiClient = void 0;
|
|
14
|
+
const base_client_1 = require("../base-client.cjs");
|
|
15
|
+
/**
|
|
16
|
+
* Prices API Client.
|
|
17
|
+
* Provides methods for interacting with the Price API.
|
|
18
|
+
*/
|
|
19
|
+
class PricesApiClient extends base_client_1.BaseApiClient {
|
|
20
|
+
// ==========================================================================
|
|
21
|
+
// CACHE MANAGEMENT
|
|
22
|
+
// ==========================================================================
|
|
23
|
+
/**
|
|
24
|
+
* Invalidate all price queries.
|
|
25
|
+
*/
|
|
26
|
+
async invalidatePrices() {
|
|
27
|
+
await this.queryClient.invalidateQueries({
|
|
28
|
+
queryKey: ['prices'],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// ==========================================================================
|
|
32
|
+
// SUPPORTED NETWORKS
|
|
33
|
+
// ==========================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Get price supported networks (v1 endpoint).
|
|
36
|
+
*
|
|
37
|
+
* @param options - Fetch options including cache settings.
|
|
38
|
+
* @returns The supported networks response.
|
|
39
|
+
*/
|
|
40
|
+
async fetchPriceV1SupportedNetworks(options) {
|
|
41
|
+
return this.queryClient.fetchQuery({
|
|
42
|
+
queryKey: ['prices', 'v1SupportedNetworks'],
|
|
43
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v1/supportedNetworks', { signal }),
|
|
44
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.SUPPORTED_NETWORKS,
|
|
45
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.EXTENDED,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get price supported networks in CAIP format (v2 endpoint).
|
|
50
|
+
*
|
|
51
|
+
* @param options - Fetch options including cache settings.
|
|
52
|
+
* @returns The supported networks response.
|
|
53
|
+
*/
|
|
54
|
+
async fetchPriceV2SupportedNetworks(options) {
|
|
55
|
+
return this.queryClient.fetchQuery({
|
|
56
|
+
queryKey: ['prices', 'v2SupportedNetworks'],
|
|
57
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v2/supportedNetworks', { signal }),
|
|
58
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.SUPPORTED_NETWORKS,
|
|
59
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.EXTENDED,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// ==========================================================================
|
|
63
|
+
// EXCHANGE RATES
|
|
64
|
+
// ==========================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Get all exchange rates for a base currency (v1 endpoint).
|
|
67
|
+
*
|
|
68
|
+
* @param baseCurrency - The base currency code.
|
|
69
|
+
* @param options - Fetch options including cache settings.
|
|
70
|
+
* @returns The exchange rates response.
|
|
71
|
+
*/
|
|
72
|
+
async fetchV1ExchangeRates(baseCurrency, options) {
|
|
73
|
+
return this.queryClient.fetchQuery({
|
|
74
|
+
queryKey: ['prices', 'v1ExchangeRates', baseCurrency],
|
|
75
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v1/exchange-rates', {
|
|
76
|
+
signal,
|
|
77
|
+
params: { baseCurrency },
|
|
78
|
+
}),
|
|
79
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.EXCHANGE_RATES,
|
|
80
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get fiat exchange rates (v1 endpoint).
|
|
85
|
+
*
|
|
86
|
+
* @param options - Fetch options including cache settings.
|
|
87
|
+
* @returns The exchange rates response.
|
|
88
|
+
*/
|
|
89
|
+
async fetchV1FiatExchangeRates(options) {
|
|
90
|
+
return this.queryClient.fetchQuery({
|
|
91
|
+
queryKey: ['prices', 'v1FiatExchangeRates'],
|
|
92
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v1/exchange-rates/fiat', { signal }),
|
|
93
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.EXCHANGE_RATES,
|
|
94
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get crypto exchange rates (v1 endpoint).
|
|
99
|
+
*
|
|
100
|
+
* @param options - Fetch options including cache settings.
|
|
101
|
+
* @returns The exchange rates response.
|
|
102
|
+
*/
|
|
103
|
+
async fetchV1CryptoExchangeRates(options) {
|
|
104
|
+
return this.queryClient.fetchQuery({
|
|
105
|
+
queryKey: ['prices', 'v1CryptoExchangeRates'],
|
|
106
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v1/exchange-rates/crypto', { signal }),
|
|
107
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.EXCHANGE_RATES,
|
|
108
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// ==========================================================================
|
|
112
|
+
// V1 SPOT PRICES (CoinGecko ID based)
|
|
113
|
+
// ==========================================================================
|
|
114
|
+
/**
|
|
115
|
+
* Get spot prices by CoinGecko coin IDs (v1 endpoint).
|
|
116
|
+
*
|
|
117
|
+
* @param coinIds - Array of CoinGecko coin IDs.
|
|
118
|
+
* @param options - Fetch options including cache settings.
|
|
119
|
+
* @returns The spot prices by coin ID.
|
|
120
|
+
*/
|
|
121
|
+
async fetchV1SpotPricesByCoinIds(coinIds, options) {
|
|
122
|
+
if (coinIds.length === 0) {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
return this.queryClient.fetchQuery({
|
|
126
|
+
queryKey: [
|
|
127
|
+
'prices',
|
|
128
|
+
'v1SpotPricesByCoinIds',
|
|
129
|
+
{ coinIds: [...coinIds].sort() },
|
|
130
|
+
],
|
|
131
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v1/spot-prices', {
|
|
132
|
+
signal,
|
|
133
|
+
params: { coinIds },
|
|
134
|
+
}),
|
|
135
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
136
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get spot price for a single CoinGecko coin ID (v1 endpoint).
|
|
141
|
+
*
|
|
142
|
+
* @param coinId - The CoinGecko coin ID.
|
|
143
|
+
* @param currency - The currency for prices.
|
|
144
|
+
* @param options - Fetch options including cache settings.
|
|
145
|
+
* @returns The spot price data.
|
|
146
|
+
*/
|
|
147
|
+
async fetchV1SpotPriceByCoinId(coinId, currency = 'usd', options) {
|
|
148
|
+
return this.queryClient.fetchQuery({
|
|
149
|
+
queryKey: ['prices', 'v1SpotPriceByCoinId', coinId, currency],
|
|
150
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/spot-prices/${coinId}`, {
|
|
151
|
+
signal,
|
|
152
|
+
params: { vsCurrency: currency },
|
|
153
|
+
}),
|
|
154
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
155
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// ==========================================================================
|
|
159
|
+
// V1 SPOT PRICES (Token Address based)
|
|
160
|
+
// ==========================================================================
|
|
161
|
+
/**
|
|
162
|
+
* Get spot prices for tokens on a chain (v1 endpoint).
|
|
163
|
+
*
|
|
164
|
+
* @param chainId - The chain ID (hex format).
|
|
165
|
+
* @param tokenAddresses - Array of token addresses.
|
|
166
|
+
* @param queryOptions - Query options.
|
|
167
|
+
* @param queryOptions.currency - The currency for prices.
|
|
168
|
+
* @param queryOptions.includeMarketData - Whether to include market data.
|
|
169
|
+
* @param options - Fetch options including cache settings.
|
|
170
|
+
* @returns The token prices by address.
|
|
171
|
+
*/
|
|
172
|
+
async fetchV1TokenPrices(chainId, tokenAddresses, queryOptions, options) {
|
|
173
|
+
if (tokenAddresses.length === 0) {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
177
|
+
const currency = queryOptions?.currency ?? 'usd';
|
|
178
|
+
return this.queryClient.fetchQuery({
|
|
179
|
+
queryKey: [
|
|
180
|
+
'prices',
|
|
181
|
+
'v1TokenPrices',
|
|
182
|
+
{
|
|
183
|
+
chainId,
|
|
184
|
+
tokenAddresses: [...tokenAddresses].sort(),
|
|
185
|
+
currency,
|
|
186
|
+
includeMarketData: queryOptions?.includeMarketData,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/chains/${chainIdDecimal}/spot-prices`, {
|
|
190
|
+
signal,
|
|
191
|
+
params: {
|
|
192
|
+
tokenAddresses,
|
|
193
|
+
vsCurrency: currency,
|
|
194
|
+
includeMarketData: queryOptions?.includeMarketData,
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
198
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get spot price for a single token (v1 endpoint).
|
|
203
|
+
*
|
|
204
|
+
* @param chainId - The chain ID (hex format).
|
|
205
|
+
* @param tokenAddress - The token address.
|
|
206
|
+
* @param currency - The currency for prices.
|
|
207
|
+
* @param options - Fetch options including cache settings.
|
|
208
|
+
* @returns The market data or undefined.
|
|
209
|
+
*/
|
|
210
|
+
async fetchV1TokenPrice(chainId, tokenAddress, currency = 'usd', options) {
|
|
211
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
212
|
+
try {
|
|
213
|
+
return await this.queryClient.fetchQuery({
|
|
214
|
+
queryKey: ['prices', 'v1TokenPrice', chainId, tokenAddress, currency],
|
|
215
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/chains/${chainIdDecimal}/spot-prices/${tokenAddress}`, {
|
|
216
|
+
signal,
|
|
217
|
+
params: { vsCurrency: currency },
|
|
218
|
+
}),
|
|
219
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
220
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// ==========================================================================
|
|
228
|
+
// V2 SPOT PRICES
|
|
229
|
+
// ==========================================================================
|
|
230
|
+
/**
|
|
231
|
+
* Get spot prices for tokens on a chain with market data (v2 endpoint).
|
|
232
|
+
*
|
|
233
|
+
* @param chainId - The chain ID (hex format).
|
|
234
|
+
* @param tokenAddresses - Array of token addresses.
|
|
235
|
+
* @param queryOptions - Query options.
|
|
236
|
+
* @param queryOptions.currency - The currency for prices.
|
|
237
|
+
* @param queryOptions.includeMarketData - Whether to include market data.
|
|
238
|
+
* @param options - Fetch options including cache settings.
|
|
239
|
+
* @returns The spot prices with market data.
|
|
240
|
+
*/
|
|
241
|
+
async fetchV2SpotPrices(chainId, tokenAddresses, queryOptions, options) {
|
|
242
|
+
if (tokenAddresses.length === 0) {
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
246
|
+
const currency = queryOptions?.currency ?? 'usd';
|
|
247
|
+
const includeMarketData = queryOptions?.includeMarketData ?? true;
|
|
248
|
+
return this.queryClient.fetchQuery({
|
|
249
|
+
queryKey: [
|
|
250
|
+
'prices',
|
|
251
|
+
'v2SpotPrices',
|
|
252
|
+
{
|
|
253
|
+
chainId,
|
|
254
|
+
tokenAddresses: [...tokenAddresses].sort(),
|
|
255
|
+
currency,
|
|
256
|
+
includeMarketData,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v2/chains/${chainIdDecimal}/spot-prices`, {
|
|
260
|
+
signal,
|
|
261
|
+
params: {
|
|
262
|
+
tokenAddresses,
|
|
263
|
+
vsCurrency: currency,
|
|
264
|
+
includeMarketData: queryOptions?.includeMarketData ?? true,
|
|
265
|
+
},
|
|
266
|
+
}),
|
|
267
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
268
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
// ==========================================================================
|
|
272
|
+
// V3 SPOT PRICES (CAIP-19 based)
|
|
273
|
+
// ==========================================================================
|
|
274
|
+
/**
|
|
275
|
+
* Get spot prices by CAIP-19 asset IDs (v3 endpoint).
|
|
276
|
+
*
|
|
277
|
+
* @param assetIds - Array of CAIP-19 asset IDs.
|
|
278
|
+
* @param queryOptions - Query options.
|
|
279
|
+
* @param queryOptions.currency - The currency for prices.
|
|
280
|
+
* @param queryOptions.includeMarketData - Whether to include market data.
|
|
281
|
+
* @param queryOptions.cacheOnly - Whether to use cache only.
|
|
282
|
+
* @param options - Fetch options including cache settings.
|
|
283
|
+
* @returns The spot prices response.
|
|
284
|
+
*/
|
|
285
|
+
async fetchV3SpotPrices(assetIds, queryOptions, options) {
|
|
286
|
+
if (assetIds.length === 0) {
|
|
287
|
+
return {};
|
|
288
|
+
}
|
|
289
|
+
const currency = queryOptions?.currency ?? 'usd';
|
|
290
|
+
const includeMarketData = queryOptions?.includeMarketData ?? true;
|
|
291
|
+
const cacheOnly = queryOptions?.cacheOnly ?? false;
|
|
292
|
+
return this.queryClient.fetchQuery({
|
|
293
|
+
queryKey: [
|
|
294
|
+
'prices',
|
|
295
|
+
'v3SpotPrices',
|
|
296
|
+
{
|
|
297
|
+
assetIds: [...assetIds].sort(),
|
|
298
|
+
currency,
|
|
299
|
+
includeMarketData,
|
|
300
|
+
cacheOnly,
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, '/v3/spot-prices', {
|
|
304
|
+
signal,
|
|
305
|
+
params: {
|
|
306
|
+
assetIds,
|
|
307
|
+
vsCurrency: currency,
|
|
308
|
+
includeMarketData,
|
|
309
|
+
cacheOnly,
|
|
310
|
+
},
|
|
311
|
+
}),
|
|
312
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
313
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
// ==========================================================================
|
|
317
|
+
// V1 HISTORICAL PRICES
|
|
318
|
+
// ==========================================================================
|
|
319
|
+
/**
|
|
320
|
+
* Get historical prices by CoinGecko coin ID (v1 endpoint).
|
|
321
|
+
*
|
|
322
|
+
* @param coinId - The CoinGecko coin ID.
|
|
323
|
+
* @param queryOptions - Query options.
|
|
324
|
+
* @param queryOptions.currency - The currency for prices.
|
|
325
|
+
* @param queryOptions.timePeriod - The time period.
|
|
326
|
+
* @param queryOptions.from - Start timestamp.
|
|
327
|
+
* @param queryOptions.to - End timestamp.
|
|
328
|
+
* @param options - Fetch options including cache settings.
|
|
329
|
+
* @returns The historical prices response.
|
|
330
|
+
*/
|
|
331
|
+
async fetchV1HistoricalPricesByCoinId(coinId, queryOptions, options) {
|
|
332
|
+
return this.queryClient.fetchQuery({
|
|
333
|
+
queryKey: ['prices', 'v1HistoricalByCoinId', coinId, queryOptions],
|
|
334
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/historical-prices/${coinId}`, {
|
|
335
|
+
signal,
|
|
336
|
+
params: {
|
|
337
|
+
vsCurrency: queryOptions?.currency,
|
|
338
|
+
timePeriod: queryOptions?.timePeriod,
|
|
339
|
+
from: queryOptions?.from,
|
|
340
|
+
to: queryOptions?.to,
|
|
341
|
+
},
|
|
342
|
+
}),
|
|
343
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
344
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Get historical prices for tokens on a chain (v1 endpoint).
|
|
349
|
+
*
|
|
350
|
+
* @param chainId - The chain ID (hex format).
|
|
351
|
+
* @param tokenAddresses - Array of token addresses.
|
|
352
|
+
* @param queryOptions - Query options.
|
|
353
|
+
* @param queryOptions.currency - The currency for prices.
|
|
354
|
+
* @param queryOptions.timePeriod - The time period.
|
|
355
|
+
* @param queryOptions.from - Start timestamp.
|
|
356
|
+
* @param queryOptions.to - End timestamp.
|
|
357
|
+
* @param options - Fetch options including cache settings.
|
|
358
|
+
* @returns The historical prices response.
|
|
359
|
+
*/
|
|
360
|
+
async fetchV1HistoricalPricesByTokenAddresses(chainId, tokenAddresses, queryOptions, options) {
|
|
361
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
362
|
+
return this.queryClient.fetchQuery({
|
|
363
|
+
queryKey: [
|
|
364
|
+
'prices',
|
|
365
|
+
'v1HistoricalByTokenAddresses',
|
|
366
|
+
{
|
|
367
|
+
chainId,
|
|
368
|
+
tokenAddresses: [...tokenAddresses].sort(),
|
|
369
|
+
options: queryOptions,
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/chains/${chainIdDecimal}/historical-prices`, {
|
|
373
|
+
signal,
|
|
374
|
+
params: {
|
|
375
|
+
tokenAddresses,
|
|
376
|
+
vsCurrency: queryOptions?.currency,
|
|
377
|
+
timePeriod: queryOptions?.timePeriod,
|
|
378
|
+
from: queryOptions?.from,
|
|
379
|
+
to: queryOptions?.to,
|
|
380
|
+
},
|
|
381
|
+
}),
|
|
382
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
383
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get historical prices for a single token (v1 endpoint).
|
|
388
|
+
*
|
|
389
|
+
* @param chainId - The chain ID (hex format).
|
|
390
|
+
* @param tokenAddress - The token address.
|
|
391
|
+
* @param queryOptions - Query options.
|
|
392
|
+
* @param queryOptions.currency - The currency for prices.
|
|
393
|
+
* @param queryOptions.timeRange - The time range.
|
|
394
|
+
* @param options - Fetch options including cache settings.
|
|
395
|
+
* @returns The historical prices response.
|
|
396
|
+
*/
|
|
397
|
+
async fetchV1HistoricalPrices(chainId, tokenAddress, queryOptions, options) {
|
|
398
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
399
|
+
const currency = queryOptions?.currency ?? 'usd';
|
|
400
|
+
const timeRange = queryOptions?.timeRange ?? '7d';
|
|
401
|
+
return this.queryClient.fetchQuery({
|
|
402
|
+
queryKey: [
|
|
403
|
+
'prices',
|
|
404
|
+
'v1Historical',
|
|
405
|
+
chainId,
|
|
406
|
+
tokenAddress,
|
|
407
|
+
currency,
|
|
408
|
+
timeRange,
|
|
409
|
+
],
|
|
410
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/chains/${chainIdDecimal}/historical-prices/${tokenAddress}`, {
|
|
411
|
+
signal,
|
|
412
|
+
params: {
|
|
413
|
+
vsCurrency: currency,
|
|
414
|
+
timePeriod: timeRange,
|
|
415
|
+
},
|
|
416
|
+
}),
|
|
417
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
418
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
// ==========================================================================
|
|
422
|
+
// V3 HISTORICAL PRICES
|
|
423
|
+
// ==========================================================================
|
|
424
|
+
/**
|
|
425
|
+
* Get historical prices by CAIP-19 asset ID (v3 endpoint).
|
|
426
|
+
*
|
|
427
|
+
* @param chainId - The CAIP-2 chain ID.
|
|
428
|
+
* @param assetType - The asset type portion of CAIP-19.
|
|
429
|
+
* @param queryOptions - Query options.
|
|
430
|
+
* @param queryOptions.currency - The currency for prices.
|
|
431
|
+
* @param queryOptions.timePeriod - The time period.
|
|
432
|
+
* @param queryOptions.from - Start timestamp.
|
|
433
|
+
* @param queryOptions.to - End timestamp.
|
|
434
|
+
* @param queryOptions.interval - Data interval.
|
|
435
|
+
* @param options - Fetch options including cache settings.
|
|
436
|
+
* @returns The historical prices response.
|
|
437
|
+
*/
|
|
438
|
+
async fetchV3HistoricalPrices(chainId, assetType, queryOptions, options) {
|
|
439
|
+
return this.queryClient.fetchQuery({
|
|
440
|
+
queryKey: ['prices', 'v3Historical', chainId, assetType, queryOptions],
|
|
441
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v3/historical-prices/${chainId}/${assetType}`, {
|
|
442
|
+
signal,
|
|
443
|
+
params: {
|
|
444
|
+
vsCurrency: queryOptions?.currency,
|
|
445
|
+
timePeriod: queryOptions?.timePeriod,
|
|
446
|
+
from: queryOptions?.from,
|
|
447
|
+
to: queryOptions?.to,
|
|
448
|
+
interval: queryOptions?.interval,
|
|
449
|
+
},
|
|
450
|
+
}),
|
|
451
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
452
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
// ==========================================================================
|
|
456
|
+
// V1 HISTORICAL PRICE GRAPH
|
|
457
|
+
// ==========================================================================
|
|
458
|
+
/**
|
|
459
|
+
* Get historical price graph data by CoinGecko coin ID (v1 endpoint).
|
|
460
|
+
*
|
|
461
|
+
* @param coinId - The CoinGecko coin ID.
|
|
462
|
+
* @param queryOptions - Query options.
|
|
463
|
+
* @param queryOptions.currency - The currency for prices.
|
|
464
|
+
* @param queryOptions.includeOHLC - Whether to include OHLC data.
|
|
465
|
+
* @param options - Fetch options including cache settings.
|
|
466
|
+
* @returns The historical price graph response.
|
|
467
|
+
*/
|
|
468
|
+
async fetchV1HistoricalPriceGraphByCoinId(coinId, queryOptions, options) {
|
|
469
|
+
const currency = queryOptions?.currency ?? 'usd';
|
|
470
|
+
const includeOHLC = queryOptions?.includeOHLC ?? false;
|
|
471
|
+
return this.queryClient.fetchQuery({
|
|
472
|
+
queryKey: ['prices', 'v1GraphByCoinId', coinId, currency, includeOHLC],
|
|
473
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/historical-prices-graph/${coinId}`, {
|
|
474
|
+
signal,
|
|
475
|
+
params: {
|
|
476
|
+
vsCurrency: currency,
|
|
477
|
+
includeOHLC,
|
|
478
|
+
},
|
|
479
|
+
}),
|
|
480
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
481
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Get historical price graph data by token address (v1 endpoint).
|
|
486
|
+
*
|
|
487
|
+
* @param chainId - The chain ID (hex format).
|
|
488
|
+
* @param tokenAddress - The token address.
|
|
489
|
+
* @param queryOptions - Query options.
|
|
490
|
+
* @param queryOptions.currency - The currency for prices.
|
|
491
|
+
* @param queryOptions.includeOHLC - Whether to include OHLC data.
|
|
492
|
+
* @param options - Fetch options including cache settings.
|
|
493
|
+
* @returns The historical price graph response.
|
|
494
|
+
*/
|
|
495
|
+
async fetchV1HistoricalPriceGraphByTokenAddress(chainId, tokenAddress, queryOptions, options) {
|
|
496
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
497
|
+
const currency = queryOptions?.currency ?? 'usd';
|
|
498
|
+
const includeOHLC = queryOptions?.includeOHLC ?? false;
|
|
499
|
+
return this.queryClient.fetchQuery({
|
|
500
|
+
queryKey: [
|
|
501
|
+
'prices',
|
|
502
|
+
'v1GraphByTokenAddress',
|
|
503
|
+
chainId,
|
|
504
|
+
tokenAddress,
|
|
505
|
+
currency,
|
|
506
|
+
includeOHLC,
|
|
507
|
+
],
|
|
508
|
+
queryFn: ({ signal }) => this.fetch(base_client_1.API_URLS.PRICES, `/v1/chains/${chainIdDecimal}/historical-prices-graph/${tokenAddress}`, {
|
|
509
|
+
signal,
|
|
510
|
+
params: {
|
|
511
|
+
vsCurrency: currency,
|
|
512
|
+
includeOHLC,
|
|
513
|
+
},
|
|
514
|
+
}),
|
|
515
|
+
staleTime: options?.staleTime ?? base_client_1.STALE_TIMES.PRICES,
|
|
516
|
+
gcTime: options?.gcTime ?? base_client_1.GC_TIMES.DEFAULT,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
exports.PricesApiClient = PricesApiClient;
|
|
521
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.cjs","sourceRoot":"","sources":["../../../src/api/prices/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAYH,oDAAgF;AAOhF;;;GAGG;AACH,MAAa,eAAgB,SAAQ,2BAAa;IAChD,6EAA6E;IAC7E,mBAAmB;IACnB,6EAA6E;IAE7E;;OAEG;IACH,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC;YACvC,QAAQ,EAAE,CAAC,QAAQ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AM;gBACN,MAAM,EAAE;oBACN,UAAU,EAAE,QAAQ;oBACpB,WAAW;iBACZ;aACF,CACF;YACH,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,yBAAW,CAAC,MAAM;YACnD,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,sBAAQ,CAAC,OAAO;SAC5C,CAAC,CAAC;IACL,CAAC;CACF;AA1rBD,0CA0rBC","sourcesContent":["/**\n * Prices API Client - price.api.cx.metamask.io\n *\n * Handles all price-related API calls including:\n * - Supported networks\n * - Exchange rates\n * - Spot prices (v1, v2, v3)\n * - Historical prices\n * - Price graphs\n */\n\nimport type { QueryFunctionContext } from '@tanstack/query-core';\n\nimport type {\n CoinGeckoSpotPrice,\n V1ExchangeRatesResponse,\n PriceSupportedNetworksResponse,\n V1HistoricalPricesResponse,\n V3SpotPricesResponse,\n V3HistoricalPricesResponse,\n} from './types';\nimport { BaseApiClient, API_URLS, STALE_TIMES, GC_TIMES } from '../base-client';\nimport type {\n FetchOptions,\n SupportedCurrency,\n MarketDataDetails,\n} from '../shared-types';\n\n/**\n * Prices API Client.\n * Provides methods for interacting with the Price API.\n */\nexport class PricesApiClient extends BaseApiClient {\n // ==========================================================================\n // CACHE MANAGEMENT\n // ==========================================================================\n\n /**\n * Invalidate all price queries.\n */\n async invalidatePrices(): Promise<void> {\n await this.queryClient.invalidateQueries({\n queryKey: ['prices'],\n });\n }\n\n // ==========================================================================\n // SUPPORTED NETWORKS\n // ==========================================================================\n\n /**\n * Get price supported networks (v1 endpoint).\n *\n * @param options - Fetch options including cache settings.\n * @returns The supported networks response.\n */\n async fetchPriceV1SupportedNetworks(\n options?: FetchOptions,\n ): Promise<PriceSupportedNetworksResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1SupportedNetworks'],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<PriceSupportedNetworksResponse>(\n API_URLS.PRICES,\n '/v1/supportedNetworks',\n { signal },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.SUPPORTED_NETWORKS,\n gcTime: options?.gcTime ?? GC_TIMES.EXTENDED,\n });\n }\n\n /**\n * Get price supported networks in CAIP format (v2 endpoint).\n *\n * @param options - Fetch options including cache settings.\n * @returns The supported networks response.\n */\n async fetchPriceV2SupportedNetworks(\n options?: FetchOptions,\n ): Promise<PriceSupportedNetworksResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v2SupportedNetworks'],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<PriceSupportedNetworksResponse>(\n API_URLS.PRICES,\n '/v2/supportedNetworks',\n { signal },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.SUPPORTED_NETWORKS,\n gcTime: options?.gcTime ?? GC_TIMES.EXTENDED,\n });\n }\n\n // ==========================================================================\n // EXCHANGE RATES\n // ==========================================================================\n\n /**\n * Get all exchange rates for a base currency (v1 endpoint).\n *\n * @param baseCurrency - The base currency code.\n * @param options - Fetch options including cache settings.\n * @returns The exchange rates response.\n */\n async fetchV1ExchangeRates(\n baseCurrency: string,\n options?: FetchOptions,\n ): Promise<V1ExchangeRatesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1ExchangeRates', baseCurrency],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1ExchangeRatesResponse>(\n API_URLS.PRICES,\n '/v1/exchange-rates',\n {\n signal,\n params: { baseCurrency },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.EXCHANGE_RATES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get fiat exchange rates (v1 endpoint).\n *\n * @param options - Fetch options including cache settings.\n * @returns The exchange rates response.\n */\n async fetchV1FiatExchangeRates(\n options?: FetchOptions,\n ): Promise<V1ExchangeRatesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1FiatExchangeRates'],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1ExchangeRatesResponse>(\n API_URLS.PRICES,\n '/v1/exchange-rates/fiat',\n { signal },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.EXCHANGE_RATES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get crypto exchange rates (v1 endpoint).\n *\n * @param options - Fetch options including cache settings.\n * @returns The exchange rates response.\n */\n async fetchV1CryptoExchangeRates(\n options?: FetchOptions,\n ): Promise<V1ExchangeRatesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1CryptoExchangeRates'],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1ExchangeRatesResponse>(\n API_URLS.PRICES,\n '/v1/exchange-rates/crypto',\n { signal },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.EXCHANGE_RATES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // V1 SPOT PRICES (CoinGecko ID based)\n // ==========================================================================\n\n /**\n * Get spot prices by CoinGecko coin IDs (v1 endpoint).\n *\n * @param coinIds - Array of CoinGecko coin IDs.\n * @param options - Fetch options including cache settings.\n * @returns The spot prices by coin ID.\n */\n async fetchV1SpotPricesByCoinIds(\n coinIds: string[],\n options?: FetchOptions,\n ): Promise<Record<string, CoinGeckoSpotPrice>> {\n if (coinIds.length === 0) {\n return {};\n }\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v1SpotPricesByCoinIds',\n { coinIds: [...coinIds].sort() },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<Record<string, CoinGeckoSpotPrice>>(\n API_URLS.PRICES,\n '/v1/spot-prices',\n {\n signal,\n params: { coinIds },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get spot price for a single CoinGecko coin ID (v1 endpoint).\n *\n * @param coinId - The CoinGecko coin ID.\n * @param currency - The currency for prices.\n * @param options - Fetch options including cache settings.\n * @returns The spot price data.\n */\n async fetchV1SpotPriceByCoinId(\n coinId: string,\n currency: SupportedCurrency = 'usd',\n options?: FetchOptions,\n ): Promise<CoinGeckoSpotPrice> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1SpotPriceByCoinId', coinId, currency],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<CoinGeckoSpotPrice>(\n API_URLS.PRICES,\n `/v1/spot-prices/${coinId}`,\n {\n signal,\n params: { vsCurrency: currency },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // V1 SPOT PRICES (Token Address based)\n // ==========================================================================\n\n /**\n * Get spot prices for tokens on a chain (v1 endpoint).\n *\n * @param chainId - The chain ID (hex format).\n * @param tokenAddresses - Array of token addresses.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.includeMarketData - Whether to include market data.\n * @param options - Fetch options including cache settings.\n * @returns The token prices by address.\n */\n async fetchV1TokenPrices(\n chainId: string,\n tokenAddresses: string[],\n queryOptions?: {\n currency?: SupportedCurrency;\n includeMarketData?: boolean;\n },\n options?: FetchOptions,\n ): Promise<Record<string, Record<string, number>>> {\n if (tokenAddresses.length === 0) {\n return {};\n }\n const chainIdDecimal = parseInt(chainId, 16);\n const currency = queryOptions?.currency ?? 'usd';\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v1TokenPrices',\n {\n chainId,\n tokenAddresses: [...tokenAddresses].sort(),\n currency,\n includeMarketData: queryOptions?.includeMarketData,\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<Record<string, Record<string, number>>>(\n API_URLS.PRICES,\n `/v1/chains/${chainIdDecimal}/spot-prices`,\n {\n signal,\n params: {\n tokenAddresses,\n vsCurrency: currency,\n includeMarketData: queryOptions?.includeMarketData,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get spot price for a single token (v1 endpoint).\n *\n * @param chainId - The chain ID (hex format).\n * @param tokenAddress - The token address.\n * @param currency - The currency for prices.\n * @param options - Fetch options including cache settings.\n * @returns The market data or undefined.\n */\n async fetchV1TokenPrice(\n chainId: string,\n tokenAddress: string,\n currency: SupportedCurrency = 'usd',\n options?: FetchOptions,\n ): Promise<MarketDataDetails | undefined> {\n const chainIdDecimal = parseInt(chainId, 16);\n try {\n return await this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1TokenPrice', chainId, tokenAddress, currency],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<MarketDataDetails>(\n API_URLS.PRICES,\n `/v1/chains/${chainIdDecimal}/spot-prices/${tokenAddress}`,\n {\n signal,\n params: { vsCurrency: currency },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n } catch {\n return undefined;\n }\n }\n\n // ==========================================================================\n // V2 SPOT PRICES\n // ==========================================================================\n\n /**\n * Get spot prices for tokens on a chain with market data (v2 endpoint).\n *\n * @param chainId - The chain ID (hex format).\n * @param tokenAddresses - Array of token addresses.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.includeMarketData - Whether to include market data.\n * @param options - Fetch options including cache settings.\n * @returns The spot prices with market data.\n */\n async fetchV2SpotPrices(\n chainId: string,\n tokenAddresses: string[],\n queryOptions?: {\n currency?: SupportedCurrency;\n includeMarketData?: boolean;\n },\n options?: FetchOptions,\n ): Promise<Record<string, MarketDataDetails>> {\n if (tokenAddresses.length === 0) {\n return {};\n }\n const chainIdDecimal = parseInt(chainId, 16);\n const currency = queryOptions?.currency ?? 'usd';\n const includeMarketData = queryOptions?.includeMarketData ?? true;\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v2SpotPrices',\n {\n chainId,\n tokenAddresses: [...tokenAddresses].sort(),\n currency,\n includeMarketData,\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<Record<string, MarketDataDetails>>(\n API_URLS.PRICES,\n `/v2/chains/${chainIdDecimal}/spot-prices`,\n {\n signal,\n params: {\n tokenAddresses,\n vsCurrency: currency,\n includeMarketData: queryOptions?.includeMarketData ?? true,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // V3 SPOT PRICES (CAIP-19 based)\n // ==========================================================================\n\n /**\n * Get spot prices by CAIP-19 asset IDs (v3 endpoint).\n *\n * @param assetIds - Array of CAIP-19 asset IDs.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.includeMarketData - Whether to include market data.\n * @param queryOptions.cacheOnly - Whether to use cache only.\n * @param options - Fetch options including cache settings.\n * @returns The spot prices response.\n */\n async fetchV3SpotPrices(\n assetIds: string[],\n queryOptions?: {\n currency?: SupportedCurrency;\n includeMarketData?: boolean;\n cacheOnly?: boolean;\n },\n options?: FetchOptions,\n ): Promise<V3SpotPricesResponse> {\n if (assetIds.length === 0) {\n return {};\n }\n const currency = queryOptions?.currency ?? 'usd';\n const includeMarketData = queryOptions?.includeMarketData ?? true;\n const cacheOnly = queryOptions?.cacheOnly ?? false;\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v3SpotPrices',\n {\n assetIds: [...assetIds].sort(),\n currency,\n includeMarketData,\n cacheOnly,\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V3SpotPricesResponse>(API_URLS.PRICES, '/v3/spot-prices', {\n signal,\n params: {\n assetIds,\n vsCurrency: currency,\n includeMarketData,\n cacheOnly,\n },\n }),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // V1 HISTORICAL PRICES\n // ==========================================================================\n\n /**\n * Get historical prices by CoinGecko coin ID (v1 endpoint).\n *\n * @param coinId - The CoinGecko coin ID.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.timePeriod - The time period.\n * @param queryOptions.from - Start timestamp.\n * @param queryOptions.to - End timestamp.\n * @param options - Fetch options including cache settings.\n * @returns The historical prices response.\n */\n async fetchV1HistoricalPricesByCoinId(\n coinId: string,\n queryOptions?: {\n currency?: SupportedCurrency;\n timePeriod?: string;\n from?: number;\n to?: number;\n },\n options?: FetchOptions,\n ): Promise<V1HistoricalPricesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1HistoricalByCoinId', coinId, queryOptions],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1HistoricalPricesResponse>(\n API_URLS.PRICES,\n `/v1/historical-prices/${coinId}`,\n {\n signal,\n params: {\n vsCurrency: queryOptions?.currency,\n timePeriod: queryOptions?.timePeriod,\n from: queryOptions?.from,\n to: queryOptions?.to,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get historical prices for tokens on a chain (v1 endpoint).\n *\n * @param chainId - The chain ID (hex format).\n * @param tokenAddresses - Array of token addresses.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.timePeriod - The time period.\n * @param queryOptions.from - Start timestamp.\n * @param queryOptions.to - End timestamp.\n * @param options - Fetch options including cache settings.\n * @returns The historical prices response.\n */\n async fetchV1HistoricalPricesByTokenAddresses(\n chainId: string,\n tokenAddresses: string[],\n queryOptions?: {\n currency?: SupportedCurrency;\n timePeriod?: string;\n from?: number;\n to?: number;\n },\n options?: FetchOptions,\n ): Promise<V1HistoricalPricesResponse> {\n const chainIdDecimal = parseInt(chainId, 16);\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v1HistoricalByTokenAddresses',\n {\n chainId,\n tokenAddresses: [...tokenAddresses].sort(),\n options: queryOptions,\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1HistoricalPricesResponse>(\n API_URLS.PRICES,\n `/v1/chains/${chainIdDecimal}/historical-prices`,\n {\n signal,\n params: {\n tokenAddresses,\n vsCurrency: queryOptions?.currency,\n timePeriod: queryOptions?.timePeriod,\n from: queryOptions?.from,\n to: queryOptions?.to,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get historical prices for a single token (v1 endpoint).\n *\n * @param chainId - The chain ID (hex format).\n * @param tokenAddress - The token address.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.timeRange - The time range.\n * @param options - Fetch options including cache settings.\n * @returns The historical prices response.\n */\n async fetchV1HistoricalPrices(\n chainId: string,\n tokenAddress: string,\n queryOptions?: { currency?: SupportedCurrency; timeRange?: string },\n options?: FetchOptions,\n ): Promise<V1HistoricalPricesResponse> {\n const chainIdDecimal = parseInt(chainId, 16);\n const currency = queryOptions?.currency ?? 'usd';\n const timeRange = queryOptions?.timeRange ?? '7d';\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v1Historical',\n chainId,\n tokenAddress,\n currency,\n timeRange,\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1HistoricalPricesResponse>(\n API_URLS.PRICES,\n `/v1/chains/${chainIdDecimal}/historical-prices/${tokenAddress}`,\n {\n signal,\n params: {\n vsCurrency: currency,\n timePeriod: timeRange,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // V3 HISTORICAL PRICES\n // ==========================================================================\n\n /**\n * Get historical prices by CAIP-19 asset ID (v3 endpoint).\n *\n * @param chainId - The CAIP-2 chain ID.\n * @param assetType - The asset type portion of CAIP-19.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.timePeriod - The time period.\n * @param queryOptions.from - Start timestamp.\n * @param queryOptions.to - End timestamp.\n * @param queryOptions.interval - Data interval.\n * @param options - Fetch options including cache settings.\n * @returns The historical prices response.\n */\n async fetchV3HistoricalPrices(\n chainId: string,\n assetType: string,\n queryOptions?: {\n currency?: SupportedCurrency;\n timePeriod?: string;\n from?: number;\n to?: number;\n interval?: '5m' | 'hourly' | 'daily';\n },\n options?: FetchOptions,\n ): Promise<V3HistoricalPricesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v3Historical', chainId, assetType, queryOptions],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V3HistoricalPricesResponse>(\n API_URLS.PRICES,\n `/v3/historical-prices/${chainId}/${assetType}`,\n {\n signal,\n params: {\n vsCurrency: queryOptions?.currency,\n timePeriod: queryOptions?.timePeriod,\n from: queryOptions?.from,\n to: queryOptions?.to,\n interval: queryOptions?.interval,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // V1 HISTORICAL PRICE GRAPH\n // ==========================================================================\n\n /**\n * Get historical price graph data by CoinGecko coin ID (v1 endpoint).\n *\n * @param coinId - The CoinGecko coin ID.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.includeOHLC - Whether to include OHLC data.\n * @param options - Fetch options including cache settings.\n * @returns The historical price graph response.\n */\n async fetchV1HistoricalPriceGraphByCoinId(\n coinId: string,\n queryOptions?: { currency?: SupportedCurrency; includeOHLC?: boolean },\n options?: FetchOptions,\n ): Promise<V3HistoricalPricesResponse> {\n const currency = queryOptions?.currency ?? 'usd';\n const includeOHLC = queryOptions?.includeOHLC ?? false;\n return this.queryClient.fetchQuery({\n queryKey: ['prices', 'v1GraphByCoinId', coinId, currency, includeOHLC],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V3HistoricalPricesResponse>(\n API_URLS.PRICES,\n `/v1/historical-prices-graph/${coinId}`,\n {\n signal,\n params: {\n vsCurrency: currency,\n includeOHLC,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get historical price graph data by token address (v1 endpoint).\n *\n * @param chainId - The chain ID (hex format).\n * @param tokenAddress - The token address.\n * @param queryOptions - Query options.\n * @param queryOptions.currency - The currency for prices.\n * @param queryOptions.includeOHLC - Whether to include OHLC data.\n * @param options - Fetch options including cache settings.\n * @returns The historical price graph response.\n */\n async fetchV1HistoricalPriceGraphByTokenAddress(\n chainId: string,\n tokenAddress: string,\n queryOptions?: { currency?: SupportedCurrency; includeOHLC?: boolean },\n options?: FetchOptions,\n ): Promise<V3HistoricalPricesResponse> {\n const chainIdDecimal = parseInt(chainId, 16);\n const currency = queryOptions?.currency ?? 'usd';\n const includeOHLC = queryOptions?.includeOHLC ?? false;\n return this.queryClient.fetchQuery({\n queryKey: [\n 'prices',\n 'v1GraphByTokenAddress',\n chainId,\n tokenAddress,\n currency,\n includeOHLC,\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V3HistoricalPricesResponse>(\n API_URLS.PRICES,\n `/v1/chains/${chainIdDecimal}/historical-prices-graph/${tokenAddress}`,\n {\n signal,\n params: {\n vsCurrency: currency,\n includeOHLC,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.PRICES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n}\n"]}
|