@metamask-previews/core-backend 5.1.1-preview-e7b1aa6 → 5.1.1-preview-27e39dd44
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 +0 -23
- package/README.md +55 -60
- package/dist/api/accounts/client.cjs +163 -358
- package/dist/api/accounts/client.cjs.map +1 -1
- package/dist/api/accounts/client.d.cts +12 -198
- package/dist/api/accounts/client.d.cts.map +1 -1
- package/dist/api/accounts/client.d.mts +12 -198
- package/dist/api/accounts/client.d.mts.map +1 -1
- package/dist/api/accounts/client.mjs +164 -359
- package/dist/api/accounts/client.mjs.map +1 -1
- package/dist/api/index.cjs +1 -2
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.d.cts +1 -1
- package/dist/api/index.d.cts.map +1 -1
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.mts.map +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/api/prices/client.cjs +140 -398
- package/dist/api/prices/client.cjs.map +1 -1
- package/dist/api/prices/client.d.cts +3 -215
- package/dist/api/prices/client.d.cts.map +1 -1
- package/dist/api/prices/client.d.mts +3 -215
- package/dist/api/prices/client.d.mts.map +1 -1
- package/dist/api/prices/client.mjs +140 -398
- package/dist/api/prices/client.mjs.map +1 -1
- package/dist/api/shared-types.cjs +1 -18
- package/dist/api/shared-types.cjs.map +1 -1
- package/dist/api/shared-types.d.cts +3 -23
- package/dist/api/shared-types.d.cts.map +1 -1
- package/dist/api/shared-types.d.mts +3 -23
- package/dist/api/shared-types.d.mts.map +1 -1
- package/dist/api/shared-types.mjs +0 -16
- package/dist/api/shared-types.mjs.map +1 -1
- package/dist/api/token/client.cjs +77 -232
- package/dist/api/token/client.cjs.map +1 -1
- package/dist/api/token/client.d.cts +0 -165
- package/dist/api/token/client.d.cts.map +1 -1
- package/dist/api/token/client.d.mts +0 -165
- package/dist/api/token/client.d.mts.map +1 -1
- package/dist/api/token/client.mjs +77 -232
- package/dist/api/token/client.mjs.map +1 -1
- package/dist/api/tokens/client.cjs +23 -64
- package/dist/api/tokens/client.cjs.map +1 -1
- package/dist/api/tokens/client.d.cts +0 -24
- package/dist/api/tokens/client.d.cts.map +1 -1
- package/dist/api/tokens/client.d.mts +0 -24
- package/dist/api/tokens/client.d.mts.map +1 -1
- package/dist/api/tokens/client.mjs +23 -64
- package/dist/api/tokens/client.mjs.map +1 -1
- package/dist/index.cjs +1 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/dist/ApiPlatformClientService-method-action-types.cjs +0 -7
- package/dist/ApiPlatformClientService-method-action-types.cjs.map +0 -1
- package/dist/ApiPlatformClientService-method-action-types.d.cts +0 -21
- package/dist/ApiPlatformClientService-method-action-types.d.cts.map +0 -1
- package/dist/ApiPlatformClientService-method-action-types.d.mts +0 -21
- package/dist/ApiPlatformClientService-method-action-types.d.mts.map +0 -1
- package/dist/ApiPlatformClientService-method-action-types.mjs +0 -6
- package/dist/ApiPlatformClientService-method-action-types.mjs.map +0 -1
- package/dist/ApiPlatformClientService.cjs +0 -82
- package/dist/ApiPlatformClientService.cjs.map +0 -1
- package/dist/ApiPlatformClientService.d.cts +0 -86
- package/dist/ApiPlatformClientService.d.cts.map +0 -1
- package/dist/ApiPlatformClientService.d.mts +0 -86
- package/dist/ApiPlatformClientService.d.mts.map +0 -1
- package/dist/ApiPlatformClientService.mjs +0 -78
- package/dist/ApiPlatformClientService.mjs.map +0 -1
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
* - NFTs
|
|
11
11
|
* - Token discovery
|
|
12
12
|
*/
|
|
13
|
-
import { BaseApiClient, API_URLS, STALE_TIMES, GC_TIMES } from "../base-client.mjs";
|
|
14
|
-
import { getQueryOptionsOverrides } from "../shared-types.mjs";
|
|
13
|
+
import { BaseApiClient, API_URLS, STALE_TIMES, GC_TIMES, HttpError } from "../base-client.mjs";
|
|
15
14
|
/**
|
|
16
15
|
* Accounts API Client.
|
|
17
16
|
* Provides methods for interacting with the Accounts API.
|
|
@@ -40,68 +39,48 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
40
39
|
// SUPPORTED NETWORKS
|
|
41
40
|
// ==========================================================================
|
|
42
41
|
/**
|
|
43
|
-
*
|
|
42
|
+
* Get list of supported networks (v1 endpoint).
|
|
44
43
|
*
|
|
45
44
|
* @param options - Fetch options including cache settings.
|
|
46
|
-
* @returns
|
|
45
|
+
* @returns The list of supported networks.
|
|
47
46
|
*/
|
|
48
|
-
|
|
49
|
-
return {
|
|
47
|
+
async fetchV1SupportedNetworks(options) {
|
|
48
|
+
return this.queryClient.fetchQuery({
|
|
50
49
|
queryKey: ['accounts', 'v1SupportedNetworks'],
|
|
51
50
|
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v1/supportedNetworks', { signal }),
|
|
52
|
-
...getQueryOptionsOverrides(options),
|
|
53
51
|
staleTime: options?.staleTime ?? STALE_TIMES.SUPPORTED_NETWORKS,
|
|
54
52
|
gcTime: options?.gcTime ?? GC_TIMES.EXTENDED,
|
|
55
|
-
};
|
|
53
|
+
});
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
|
-
* Get list of supported networks (
|
|
56
|
+
* Get list of supported networks (v2 endpoint).
|
|
59
57
|
*
|
|
60
58
|
* @param options - Fetch options including cache settings.
|
|
61
59
|
* @returns The list of supported networks.
|
|
62
60
|
*/
|
|
63
|
-
async
|
|
64
|
-
return this.queryClient.fetchQuery(
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns the TanStack Query options object for v2 supported networks.
|
|
68
|
-
*
|
|
69
|
-
* @param options - Fetch options including cache settings.
|
|
70
|
-
* @returns TanStack Query options for use with useQuery, useSuspenseQuery, etc.
|
|
71
|
-
*/
|
|
72
|
-
getV2SupportedNetworksQueryOptions(options) {
|
|
73
|
-
return {
|
|
61
|
+
async fetchV2SupportedNetworks(options) {
|
|
62
|
+
return this.queryClient.fetchQuery({
|
|
74
63
|
queryKey: ['accounts', 'v2SupportedNetworks'],
|
|
75
64
|
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v2/supportedNetworks', { signal }),
|
|
76
|
-
...getQueryOptionsOverrides(options),
|
|
77
65
|
staleTime: options?.staleTime ?? STALE_TIMES.SUPPORTED_NETWORKS,
|
|
78
66
|
gcTime: options?.gcTime ?? GC_TIMES.EXTENDED,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get list of supported networks (v2 endpoint).
|
|
83
|
-
*
|
|
84
|
-
* @param options - Fetch options including cache settings.
|
|
85
|
-
* @returns The list of supported networks.
|
|
86
|
-
*/
|
|
87
|
-
async fetchV2SupportedNetworks(options) {
|
|
88
|
-
return this.queryClient.fetchQuery(this.getV2SupportedNetworksQueryOptions(options));
|
|
67
|
+
});
|
|
89
68
|
}
|
|
90
69
|
// ==========================================================================
|
|
91
70
|
// ACTIVE NETWORKS
|
|
92
71
|
// ==========================================================================
|
|
93
72
|
/**
|
|
94
|
-
*
|
|
73
|
+
* Get active networks by CAIP-10 account IDs (v2 endpoint).
|
|
95
74
|
*
|
|
96
75
|
* @param accountIds - Array of CAIP-10 account IDs.
|
|
97
76
|
* @param queryOptions - Query filter options.
|
|
98
77
|
* @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.
|
|
99
78
|
* @param queryOptions.networks - Networks to filter by.
|
|
100
79
|
* @param options - Fetch options including cache settings.
|
|
101
|
-
* @returns
|
|
80
|
+
* @returns The active networks response.
|
|
102
81
|
*/
|
|
103
|
-
|
|
104
|
-
return {
|
|
82
|
+
async fetchV2ActiveNetworks(accountIds, queryOptions, options) {
|
|
83
|
+
return this.queryClient.fetchQuery({
|
|
105
84
|
queryKey: [
|
|
106
85
|
'accounts',
|
|
107
86
|
'v2ActiveNetworks',
|
|
@@ -113,57 +92,32 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
113
92
|
},
|
|
114
93
|
},
|
|
115
94
|
],
|
|
116
|
-
queryFn:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
filterMMListTokens: queryOptions?.filterMMListTokens,
|
|
125
|
-
networks: queryOptions?.networks,
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
...getQueryOptionsOverrides(options),
|
|
95
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v2/activeNetworks', {
|
|
96
|
+
signal,
|
|
97
|
+
params: {
|
|
98
|
+
accountIds,
|
|
99
|
+
filterMMListTokens: queryOptions?.filterMMListTokens,
|
|
100
|
+
networks: queryOptions?.networks,
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
130
103
|
staleTime: options?.staleTime ?? STALE_TIMES.NETWORKS,
|
|
131
104
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Get active networks by CAIP-10 account IDs (v2 endpoint).
|
|
136
|
-
*
|
|
137
|
-
* @param accountIds - Array of CAIP-10 account IDs.
|
|
138
|
-
* @param queryOptions - Query filter options.
|
|
139
|
-
* @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.
|
|
140
|
-
* @param queryOptions.networks - Networks to filter by.
|
|
141
|
-
* @param options - Fetch options including cache settings.
|
|
142
|
-
* @returns The active networks response.
|
|
143
|
-
*/
|
|
144
|
-
async fetchV2ActiveNetworks(accountIds, queryOptions, options) {
|
|
145
|
-
if (accountIds.length === 0) {
|
|
146
|
-
return { activeNetworks: [] };
|
|
147
|
-
}
|
|
148
|
-
return this.queryClient.fetchQuery(this.getV2ActiveNetworksQueryOptions(accountIds, queryOptions, options));
|
|
105
|
+
});
|
|
149
106
|
}
|
|
150
107
|
// ==========================================================================
|
|
151
108
|
// BALANCES
|
|
152
109
|
// ==========================================================================
|
|
153
110
|
/**
|
|
154
|
-
*
|
|
111
|
+
* Get account balances for a single address (v2 endpoint).
|
|
155
112
|
*
|
|
156
113
|
* @param address - The account address.
|
|
157
114
|
* @param queryOptions - Query filter options.
|
|
158
115
|
* @param queryOptions.networks - Networks to filter by.
|
|
159
|
-
* @param queryOptions.filterSupportedTokens - Whether to filter supported tokens.
|
|
160
|
-
* @param queryOptions.includeTokenAddresses - Token addresses to include.
|
|
161
|
-
* @param queryOptions.includeStakedAssets - Whether to include staked assets.
|
|
162
116
|
* @param options - Fetch options including cache settings.
|
|
163
|
-
* @returns
|
|
117
|
+
* @returns The account balances response.
|
|
164
118
|
*/
|
|
165
|
-
|
|
166
|
-
return {
|
|
119
|
+
async fetchV2Balances(address, queryOptions, options) {
|
|
120
|
+
return this.queryClient.fetchQuery({
|
|
167
121
|
queryKey: [
|
|
168
122
|
'accounts',
|
|
169
123
|
'balances',
|
|
@@ -173,32 +127,19 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
173
127
|
options: queryOptions && {
|
|
174
128
|
...queryOptions,
|
|
175
129
|
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
176
|
-
includeTokenAddresses: queryOptions.includeTokenAddresses &&
|
|
177
|
-
[...queryOptions.includeTokenAddresses].sort(),
|
|
178
130
|
},
|
|
179
131
|
},
|
|
180
132
|
],
|
|
181
|
-
queryFn:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/balances`, {
|
|
186
|
-
signal,
|
|
187
|
-
params: {
|
|
188
|
-
networks: queryOptions?.networks,
|
|
189
|
-
filterSupportedTokens: queryOptions?.filterSupportedTokens,
|
|
190
|
-
includeTokenAddresses: queryOptions?.includeTokenAddresses,
|
|
191
|
-
includeStakedAssets: queryOptions?.includeStakedAssets,
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
...getQueryOptionsOverrides(options),
|
|
133
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/balances`, {
|
|
134
|
+
signal,
|
|
135
|
+
params: { networks: queryOptions?.networks },
|
|
136
|
+
}),
|
|
196
137
|
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
197
138
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
198
|
-
};
|
|
139
|
+
});
|
|
199
140
|
}
|
|
200
141
|
/**
|
|
201
|
-
* Get account balances
|
|
142
|
+
* Get account balances with additional options (v2 endpoint).
|
|
202
143
|
*
|
|
203
144
|
* @param address - The account address.
|
|
204
145
|
* @param queryOptions - Query filter options.
|
|
@@ -209,51 +150,34 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
209
150
|
* @param options - Fetch options including cache settings.
|
|
210
151
|
* @returns The account balances response.
|
|
211
152
|
*/
|
|
212
|
-
async
|
|
213
|
-
|
|
214
|
-
return { count: 0, balances: [], unprocessedNetworks: [] };
|
|
215
|
-
}
|
|
216
|
-
return this.queryClient.fetchQuery(this.getV2BalancesQueryOptions(address, queryOptions, options));
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Returns the TanStack Query options object for v4 multi-account balances.
|
|
220
|
-
*
|
|
221
|
-
* @param accountAddresses - Array of account addresses.
|
|
222
|
-
* @param queryOptions - Query filter options.
|
|
223
|
-
* @param queryOptions.networks - Networks to filter by.
|
|
224
|
-
* @param options - Fetch options including cache settings.
|
|
225
|
-
* @returns TanStack Query options for use with useQuery, useSuspenseQuery, etc.
|
|
226
|
-
*/
|
|
227
|
-
getV4MultiAccountBalancesQueryOptions(accountAddresses, queryOptions, options) {
|
|
228
|
-
return {
|
|
153
|
+
async fetchV2BalancesWithOptions(address, queryOptions, options) {
|
|
154
|
+
return this.queryClient.fetchQuery({
|
|
229
155
|
queryKey: [
|
|
230
156
|
'accounts',
|
|
231
157
|
'balances',
|
|
232
|
-
'
|
|
158
|
+
'v2',
|
|
233
159
|
{
|
|
234
|
-
|
|
160
|
+
address,
|
|
235
161
|
options: queryOptions && {
|
|
236
162
|
...queryOptions,
|
|
237
163
|
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
164
|
+
includeTokenAddresses: queryOptions.includeTokenAddresses &&
|
|
165
|
+
[...queryOptions.includeTokenAddresses].sort(),
|
|
238
166
|
},
|
|
239
167
|
},
|
|
240
168
|
],
|
|
241
|
-
queryFn:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
},
|
|
253
|
-
...getQueryOptionsOverrides(options),
|
|
169
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/balances`, {
|
|
170
|
+
signal,
|
|
171
|
+
params: {
|
|
172
|
+
networks: queryOptions?.networks,
|
|
173
|
+
filterSupportedTokens: queryOptions?.filterSupportedTokens,
|
|
174
|
+
includeTokenAddresses: queryOptions?.includeTokenAddresses,
|
|
175
|
+
includeStakedAssets: queryOptions?.includeStakedAssets,
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
254
178
|
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
255
179
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
256
|
-
};
|
|
180
|
+
});
|
|
257
181
|
}
|
|
258
182
|
/**
|
|
259
183
|
* Get balances for multiple accounts (v4 endpoint).
|
|
@@ -265,54 +189,29 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
265
189
|
* @returns The multi-account balances response.
|
|
266
190
|
*/
|
|
267
191
|
async fetchV4MultiAccountBalances(accountAddresses, queryOptions, options) {
|
|
268
|
-
|
|
269
|
-
return { count: 0, balances: [], unprocessedNetworks: [] };
|
|
270
|
-
}
|
|
271
|
-
return this.queryClient.fetchQuery(this.getV4MultiAccountBalancesQueryOptions(accountAddresses, queryOptions, options));
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Returns the TanStack Query options object for v5 multi-account balances.
|
|
275
|
-
*
|
|
276
|
-
* @param accountIds - Array of CAIP-10 account IDs.
|
|
277
|
-
* @param queryOptions - Query filter options.
|
|
278
|
-
* @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.
|
|
279
|
-
* @param queryOptions.networks - Networks to filter by.
|
|
280
|
-
* @param queryOptions.includeStakedAssets - Whether to include staked assets.
|
|
281
|
-
* @param options - Fetch options including cache settings.
|
|
282
|
-
* @returns TanStack Query options for use with useQuery, useSuspenseQuery, etc.
|
|
283
|
-
*/
|
|
284
|
-
getV5MultiAccountBalancesQueryOptions(accountIds, queryOptions, options) {
|
|
285
|
-
return {
|
|
192
|
+
return this.queryClient.fetchQuery({
|
|
286
193
|
queryKey: [
|
|
287
194
|
'accounts',
|
|
288
195
|
'balances',
|
|
289
|
-
'
|
|
196
|
+
'v4',
|
|
290
197
|
{
|
|
291
|
-
|
|
198
|
+
accountAddresses: [...accountAddresses].sort(),
|
|
292
199
|
options: queryOptions && {
|
|
293
200
|
...queryOptions,
|
|
294
201
|
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
295
202
|
},
|
|
296
203
|
},
|
|
297
204
|
],
|
|
298
|
-
queryFn:
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
accountIds,
|
|
306
|
-
networks: queryOptions?.networks,
|
|
307
|
-
filterMMListTokens: queryOptions?.filterMMListTokens,
|
|
308
|
-
includeStakedAssets: queryOptions?.includeStakedAssets,
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
},
|
|
312
|
-
...getQueryOptionsOverrides(options),
|
|
205
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v4/multiaccount/balances', {
|
|
206
|
+
signal,
|
|
207
|
+
params: {
|
|
208
|
+
accountAddresses,
|
|
209
|
+
networks: queryOptions?.networks,
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
313
212
|
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
314
213
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
315
|
-
};
|
|
214
|
+
});
|
|
316
215
|
}
|
|
317
216
|
/**
|
|
318
217
|
* Get balances for multiple accounts using CAIP-10 IDs (v5 endpoint).
|
|
@@ -326,16 +225,37 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
326
225
|
* @returns The multi-account balances response.
|
|
327
226
|
*/
|
|
328
227
|
async fetchV5MultiAccountBalances(accountIds, queryOptions, options) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
228
|
+
return this.queryClient.fetchQuery({
|
|
229
|
+
queryKey: [
|
|
230
|
+
'accounts',
|
|
231
|
+
'balances',
|
|
232
|
+
'v5',
|
|
233
|
+
{
|
|
234
|
+
accountIds: [...accountIds].sort(),
|
|
235
|
+
options: queryOptions && {
|
|
236
|
+
...queryOptions,
|
|
237
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v5/multiaccount/balances', {
|
|
242
|
+
signal,
|
|
243
|
+
params: {
|
|
244
|
+
accountIds,
|
|
245
|
+
networks: queryOptions?.networks,
|
|
246
|
+
filterMMListTokens: queryOptions?.filterMMListTokens,
|
|
247
|
+
includeStakedAssets: queryOptions?.includeStakedAssets,
|
|
248
|
+
},
|
|
249
|
+
}),
|
|
250
|
+
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
251
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
252
|
+
});
|
|
333
253
|
}
|
|
334
254
|
// ==========================================================================
|
|
335
255
|
// TRANSACTIONS
|
|
336
256
|
// ==========================================================================
|
|
337
257
|
/**
|
|
338
|
-
*
|
|
258
|
+
* Get a specific transaction by hash (v1 endpoint).
|
|
339
259
|
*
|
|
340
260
|
* @param chainId - The chain ID.
|
|
341
261
|
* @param txHash - The transaction hash.
|
|
@@ -345,10 +265,10 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
345
265
|
* @param queryOptions.includeTxMetadata - Whether to include transaction metadata.
|
|
346
266
|
* @param queryOptions.lang - Language for metadata.
|
|
347
267
|
* @param options - Fetch options including cache settings.
|
|
348
|
-
* @returns
|
|
268
|
+
* @returns The transaction details.
|
|
349
269
|
*/
|
|
350
|
-
|
|
351
|
-
return {
|
|
270
|
+
async fetchV1TransactionByHash(chainId, txHash, queryOptions, options) {
|
|
271
|
+
return this.queryClient.fetchQuery({
|
|
352
272
|
queryKey: [
|
|
353
273
|
'accounts',
|
|
354
274
|
'transactions',
|
|
@@ -364,29 +284,12 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
364
284
|
lang: queryOptions?.lang,
|
|
365
285
|
},
|
|
366
286
|
}),
|
|
367
|
-
...getQueryOptionsOverrides(options),
|
|
368
287
|
staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,
|
|
369
288
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Get a specific transaction by hash (v1 endpoint).
|
|
374
|
-
*
|
|
375
|
-
* @param chainId - The chain ID.
|
|
376
|
-
* @param txHash - The transaction hash.
|
|
377
|
-
* @param queryOptions - Query filter options.
|
|
378
|
-
* @param queryOptions.includeLogs - Whether to include logs.
|
|
379
|
-
* @param queryOptions.includeValueTransfers - Whether to include value transfers.
|
|
380
|
-
* @param queryOptions.includeTxMetadata - Whether to include transaction metadata.
|
|
381
|
-
* @param queryOptions.lang - Language for metadata.
|
|
382
|
-
* @param options - Fetch options including cache settings.
|
|
383
|
-
* @returns The transaction details.
|
|
384
|
-
*/
|
|
385
|
-
async fetchV1TransactionByHash(chainId, txHash, queryOptions, options) {
|
|
386
|
-
return this.queryClient.fetchQuery(this.getV1TransactionByHashQueryOptions(chainId, txHash, queryOptions, options));
|
|
289
|
+
});
|
|
387
290
|
}
|
|
388
291
|
/**
|
|
389
|
-
*
|
|
292
|
+
* Get account transactions (v1 endpoint).
|
|
390
293
|
*
|
|
391
294
|
* @param address - The account address.
|
|
392
295
|
* @param queryOptions - Query filter options.
|
|
@@ -396,10 +299,10 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
396
299
|
* @param queryOptions.endTimestamp - End timestamp filter.
|
|
397
300
|
* @param queryOptions.sortDirection - Sort direction (ASC/DESC).
|
|
398
301
|
* @param options - Fetch options including cache settings.
|
|
399
|
-
* @returns
|
|
302
|
+
* @returns The account transactions response.
|
|
400
303
|
*/
|
|
401
|
-
|
|
402
|
-
return {
|
|
304
|
+
async fetchV1AccountTransactions(address, queryOptions, options) {
|
|
305
|
+
return this.queryClient.fetchQuery({
|
|
403
306
|
queryKey: [
|
|
404
307
|
'accounts',
|
|
405
308
|
'transactions',
|
|
@@ -412,75 +315,42 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
412
315
|
},
|
|
413
316
|
},
|
|
414
317
|
],
|
|
415
|
-
queryFn:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
endTimestamp: queryOptions?.endTimestamp,
|
|
426
|
-
sortDirection: queryOptions?.sortDirection,
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
},
|
|
430
|
-
...getQueryOptionsOverrides(options),
|
|
318
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v1/accounts/${address}/transactions`, {
|
|
319
|
+
signal,
|
|
320
|
+
params: {
|
|
321
|
+
networks: queryOptions?.chainIds,
|
|
322
|
+
cursor: queryOptions?.cursor,
|
|
323
|
+
startTimestamp: queryOptions?.startTimestamp,
|
|
324
|
+
endTimestamp: queryOptions?.endTimestamp,
|
|
325
|
+
sortDirection: queryOptions?.sortDirection,
|
|
326
|
+
},
|
|
327
|
+
}),
|
|
431
328
|
staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,
|
|
432
329
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
433
|
-
};
|
|
330
|
+
});
|
|
434
331
|
}
|
|
435
332
|
/**
|
|
436
|
-
* Get account transactions (
|
|
333
|
+
* Get multi-account transactions (v4 endpoint).
|
|
437
334
|
*
|
|
438
|
-
* @param
|
|
335
|
+
* @param accountIds - Array of CAIP-10 account IDs.
|
|
439
336
|
* @param queryOptions - Query filter options.
|
|
440
|
-
* @param queryOptions.
|
|
337
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
441
338
|
* @param queryOptions.cursor - Pagination cursor.
|
|
442
|
-
* @param queryOptions.startTimestamp - Start timestamp filter.
|
|
443
|
-
* @param queryOptions.endTimestamp - End timestamp filter.
|
|
444
|
-
* @param queryOptions.sortDirection - Sort direction (ASC/DESC).
|
|
445
|
-
* @param options - Fetch options including cache settings.
|
|
446
|
-
* @returns The account transactions response.
|
|
447
|
-
*/
|
|
448
|
-
async fetchV1AccountTransactions(address, queryOptions, options) {
|
|
449
|
-
if (address === '') {
|
|
450
|
-
return { data: [], pageInfo: { count: 0, hasNextPage: false } };
|
|
451
|
-
}
|
|
452
|
-
return this.queryClient.fetchQuery(this.getV1AccountTransactionsQueryOptions(address, queryOptions, options));
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Returns the TanStack Query options object for v4 multi-account transactions.
|
|
456
|
-
* Use this with `queryClient.fetchQuery()`, `useQuery()`, `useInfiniteQuery()`,
|
|
457
|
-
* `useSuspenseQuery()`, etc. for flexibility across query permutations.
|
|
458
|
-
*
|
|
459
|
-
* @param accountAddresses - Array of CAIP-10 account addresses.
|
|
460
|
-
* @param queryOptions - Query filter options.
|
|
461
|
-
* @param queryOptions.networks - Comma-separated CAIP-2 network IDs.
|
|
462
|
-
* @param queryOptions.startTimestamp - Start timestamp (epoch) from which to return results.
|
|
463
|
-
* @param queryOptions.endTimestamp - End timestamp (epoch) for which to return results.
|
|
464
|
-
* @param queryOptions.cursor - Pagination cursor (deprecated, use after).
|
|
465
|
-
* @param queryOptions.limit - Maximum number of transactions to request (default 50).
|
|
466
|
-
* @param queryOptions.after - JWT containing the endCursor for the query.
|
|
467
|
-
* @param queryOptions.before - JWT containing the startCursor for the query.
|
|
468
339
|
* @param queryOptions.sortDirection - Sort direction (ASC/DESC).
|
|
469
340
|
* @param queryOptions.includeLogs - Whether to include logs.
|
|
341
|
+
* @param queryOptions.includeValueTransfers - Whether to include value transfers.
|
|
470
342
|
* @param queryOptions.includeTxMetadata - Whether to include transaction metadata.
|
|
471
|
-
* @param queryOptions.maxLogsPerTx - Maximum number of logs per transaction.
|
|
472
|
-
* @param queryOptions.lang - Language for transaction category (default "en").
|
|
473
343
|
* @param options - Fetch options including cache settings.
|
|
474
|
-
* @returns
|
|
344
|
+
* @returns The multi-account transactions response.
|
|
475
345
|
*/
|
|
476
|
-
|
|
477
|
-
return {
|
|
346
|
+
async fetchV4MultiAccountTransactions(accountIds, queryOptions, options) {
|
|
347
|
+
return this.queryClient.fetchQuery({
|
|
478
348
|
queryKey: [
|
|
479
349
|
'accounts',
|
|
480
350
|
'transactions',
|
|
481
351
|
'v4MultiAccount',
|
|
482
352
|
{
|
|
483
|
-
|
|
353
|
+
accountIds: [...accountIds].sort(),
|
|
484
354
|
options: queryOptions && {
|
|
485
355
|
...queryOptions,
|
|
486
356
|
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
@@ -490,70 +360,22 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
490
360
|
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v4/multiaccount/transactions', {
|
|
491
361
|
signal,
|
|
492
362
|
params: {
|
|
493
|
-
|
|
363
|
+
accountIds,
|
|
494
364
|
networks: queryOptions?.networks,
|
|
495
|
-
startTimestamp: queryOptions?.startTimestamp,
|
|
496
|
-
endTimestamp: queryOptions?.endTimestamp,
|
|
497
365
|
cursor: queryOptions?.cursor,
|
|
498
|
-
limit: queryOptions?.limit,
|
|
499
|
-
after: queryOptions?.after,
|
|
500
|
-
before: queryOptions?.before,
|
|
501
366
|
sortDirection: queryOptions?.sortDirection,
|
|
502
367
|
includeLogs: queryOptions?.includeLogs,
|
|
368
|
+
includeValueTransfers: queryOptions?.includeValueTransfers,
|
|
503
369
|
includeTxMetadata: queryOptions?.includeTxMetadata,
|
|
504
|
-
maxLogsPerTx: queryOptions?.maxLogsPerTx,
|
|
505
|
-
lang: queryOptions?.lang,
|
|
506
370
|
},
|
|
507
371
|
}),
|
|
508
|
-
...getQueryOptionsOverrides(options),
|
|
509
372
|
staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,
|
|
510
373
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Get multi-account transactions (v4 endpoint).
|
|
515
|
-
*
|
|
516
|
-
* @param accountAddresses - Array of CAIP-10 account addresses.
|
|
517
|
-
* @param queryOptions - Query filter options.
|
|
518
|
-
* @param queryOptions.networks - Comma-separated CAIP-2 network IDs.
|
|
519
|
-
* @param queryOptions.startTimestamp - Start timestamp (epoch) from which to return results.
|
|
520
|
-
* @param queryOptions.endTimestamp - End timestamp (epoch) for which to return results.
|
|
521
|
-
* @param queryOptions.cursor - Pagination cursor (deprecated, use after).
|
|
522
|
-
* @param queryOptions.limit - Maximum number of transactions to request (default 50).
|
|
523
|
-
* @param queryOptions.after - JWT containing the endCursor for the query.
|
|
524
|
-
* @param queryOptions.before - JWT containing the startCursor for the query.
|
|
525
|
-
* @param queryOptions.sortDirection - Sort direction (ASC/DESC).
|
|
526
|
-
* @param queryOptions.includeLogs - Whether to include logs.
|
|
527
|
-
* @param queryOptions.includeTxMetadata - Whether to include transaction metadata.
|
|
528
|
-
* @param queryOptions.maxLogsPerTx - Maximum number of logs per transaction.
|
|
529
|
-
* @param queryOptions.lang - Language for transaction category (default "en").
|
|
530
|
-
* @param options - Fetch options including cache settings.
|
|
531
|
-
* @returns The multi-account transactions response.
|
|
532
|
-
*/
|
|
533
|
-
async fetchV4MultiAccountTransactions(accountAddresses, queryOptions, options) {
|
|
534
|
-
return this.queryClient.fetchQuery(this.getV4MultiAccountTransactionsQueryOptions(accountAddresses, queryOptions, options));
|
|
374
|
+
});
|
|
535
375
|
}
|
|
536
376
|
// ==========================================================================
|
|
537
377
|
// RELATIONSHIPS
|
|
538
378
|
// ==========================================================================
|
|
539
|
-
/**
|
|
540
|
-
* Returns the TanStack Query options object for v1 account relationship.
|
|
541
|
-
*
|
|
542
|
-
* @param chainId - The chain ID.
|
|
543
|
-
* @param from - The from address.
|
|
544
|
-
* @param to - The to address.
|
|
545
|
-
* @param options - Fetch options including cache settings.
|
|
546
|
-
* @returns TanStack Query options for use with useQuery, useSuspenseQuery, etc.
|
|
547
|
-
*/
|
|
548
|
-
getV1AccountRelationshipQueryOptions(chainId, from, to, options) {
|
|
549
|
-
return {
|
|
550
|
-
queryKey: ['accounts', 'v1Relationship', chainId, from, to],
|
|
551
|
-
queryFn: async ({ signal, }) => this.fetch(API_URLS.ACCOUNTS, `/v1/networks/${chainId}/accounts/${from}/relationships/${to}`, { signal }),
|
|
552
|
-
...getQueryOptionsOverrides(options),
|
|
553
|
-
staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,
|
|
554
|
-
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
379
|
/**
|
|
558
380
|
* Get account address relationship (v1 endpoint).
|
|
559
381
|
*
|
|
@@ -564,23 +386,49 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
564
386
|
* @returns The account relationship result.
|
|
565
387
|
*/
|
|
566
388
|
async fetchV1AccountRelationship(chainId, from, to, options) {
|
|
567
|
-
return this.queryClient.fetchQuery(
|
|
389
|
+
return this.queryClient.fetchQuery({
|
|
390
|
+
queryKey: ['accounts', 'v1Relationship', chainId, from, to],
|
|
391
|
+
queryFn: async ({ signal }) => {
|
|
392
|
+
try {
|
|
393
|
+
return await this.fetch(API_URLS.ACCOUNTS, `/v1/networks/${chainId}/accounts/${from}/relationships/${to}`, { signal });
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
if (error instanceof HttpError && typeof error.body === 'object') {
|
|
397
|
+
const body = error.body;
|
|
398
|
+
if (body?.error &&
|
|
399
|
+
typeof body.error === 'object' &&
|
|
400
|
+
typeof body.error.code === 'string' &&
|
|
401
|
+
typeof body.error.message === 'string') {
|
|
402
|
+
return {
|
|
403
|
+
error: {
|
|
404
|
+
code: body.error.code,
|
|
405
|
+
message: body.error.message,
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,
|
|
414
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
415
|
+
});
|
|
568
416
|
}
|
|
569
417
|
// ==========================================================================
|
|
570
418
|
// NFTs
|
|
571
419
|
// ==========================================================================
|
|
572
420
|
/**
|
|
573
|
-
*
|
|
421
|
+
* Get NFTs owned by an account (v2 endpoint).
|
|
574
422
|
*
|
|
575
423
|
* @param address - The account address.
|
|
576
424
|
* @param queryOptions - Query filter options.
|
|
577
425
|
* @param queryOptions.networks - Networks to filter by.
|
|
578
426
|
* @param queryOptions.cursor - Pagination cursor.
|
|
579
427
|
* @param options - Fetch options including cache settings.
|
|
580
|
-
* @returns
|
|
428
|
+
* @returns The NFTs response.
|
|
581
429
|
*/
|
|
582
|
-
|
|
583
|
-
return {
|
|
430
|
+
async fetchV2AccountNfts(address, queryOptions, options) {
|
|
431
|
+
return this.queryClient.fetchQuery({
|
|
584
432
|
queryKey: [
|
|
585
433
|
'accounts',
|
|
586
434
|
'v2Nfts',
|
|
@@ -592,53 +440,31 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
592
440
|
},
|
|
593
441
|
},
|
|
594
442
|
],
|
|
595
|
-
queryFn:
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
networks: queryOptions?.networks,
|
|
603
|
-
cursor: queryOptions?.cursor,
|
|
604
|
-
},
|
|
605
|
-
});
|
|
606
|
-
},
|
|
607
|
-
...getQueryOptionsOverrides(options),
|
|
443
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/nfts`, {
|
|
444
|
+
signal,
|
|
445
|
+
params: {
|
|
446
|
+
networks: queryOptions?.networks,
|
|
447
|
+
cursor: queryOptions?.cursor,
|
|
448
|
+
},
|
|
449
|
+
}),
|
|
608
450
|
staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,
|
|
609
451
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Get NFTs owned by an account (v2 endpoint).
|
|
614
|
-
*
|
|
615
|
-
* @param address - The account address.
|
|
616
|
-
* @param queryOptions - Query filter options.
|
|
617
|
-
* @param queryOptions.networks - Networks to filter by.
|
|
618
|
-
* @param queryOptions.cursor - Pagination cursor.
|
|
619
|
-
* @param options - Fetch options including cache settings.
|
|
620
|
-
* @returns The NFTs response.
|
|
621
|
-
*/
|
|
622
|
-
async fetchV2AccountNfts(address, queryOptions, options) {
|
|
623
|
-
if (address === '') {
|
|
624
|
-
return { data: [], pageInfo: { count: 0, hasNextPage: false } };
|
|
625
|
-
}
|
|
626
|
-
return this.queryClient.fetchQuery(this.getV2AccountNftsQueryOptions(address, queryOptions, options));
|
|
452
|
+
});
|
|
627
453
|
}
|
|
628
454
|
// ==========================================================================
|
|
629
455
|
// TOKEN DISCOVERY
|
|
630
456
|
// ==========================================================================
|
|
631
457
|
/**
|
|
632
|
-
*
|
|
458
|
+
* Get ERC20 tokens detected for an account (v2 endpoint).
|
|
633
459
|
*
|
|
634
460
|
* @param address - The account address.
|
|
635
461
|
* @param queryOptions - Query filter options.
|
|
636
462
|
* @param queryOptions.networks - Networks to filter by.
|
|
637
463
|
* @param options - Fetch options including cache settings.
|
|
638
|
-
* @returns
|
|
464
|
+
* @returns The tokens response.
|
|
639
465
|
*/
|
|
640
|
-
|
|
641
|
-
return {
|
|
466
|
+
async fetchV2AccountTokens(address, queryOptions, options) {
|
|
467
|
+
return this.queryClient.fetchQuery({
|
|
642
468
|
queryKey: [
|
|
643
469
|
'accounts',
|
|
644
470
|
'v2Tokens',
|
|
@@ -650,34 +476,13 @@ export class AccountsApiClient extends BaseApiClient {
|
|
|
650
476
|
},
|
|
651
477
|
},
|
|
652
478
|
],
|
|
653
|
-
queryFn:
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
return this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/tokens`, {
|
|
658
|
-
signal,
|
|
659
|
-
params: { networks: queryOptions?.networks },
|
|
660
|
-
});
|
|
661
|
-
},
|
|
662
|
-
...getQueryOptionsOverrides(options),
|
|
479
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/tokens`, {
|
|
480
|
+
signal,
|
|
481
|
+
params: { networks: queryOptions?.networks },
|
|
482
|
+
}),
|
|
663
483
|
staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,
|
|
664
484
|
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Get ERC20 tokens detected for an account (v2 endpoint).
|
|
669
|
-
*
|
|
670
|
-
* @param address - The account address.
|
|
671
|
-
* @param queryOptions - Query filter options.
|
|
672
|
-
* @param queryOptions.networks - Networks to filter by.
|
|
673
|
-
* @param options - Fetch options including cache settings.
|
|
674
|
-
* @returns The tokens response.
|
|
675
|
-
*/
|
|
676
|
-
async fetchV2AccountTokens(address, queryOptions, options) {
|
|
677
|
-
if (address === '') {
|
|
678
|
-
return { data: [] };
|
|
679
|
-
}
|
|
680
|
-
return this.queryClient.fetchQuery(this.getV2AccountTokensQueryOptions(address, queryOptions, options));
|
|
485
|
+
});
|
|
681
486
|
}
|
|
682
487
|
}
|
|
683
488
|
//# sourceMappingURL=client.mjs.map
|