@metamask/core-backend 5.0.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 +25 -1
- 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.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 +8 -11
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts API Client - accounts.api.cx.metamask.io
|
|
3
|
+
*
|
|
4
|
+
* Handles all account-related API calls including:
|
|
5
|
+
* - Supported networks
|
|
6
|
+
* - Active networks
|
|
7
|
+
* - Balances (v2, v4, v5)
|
|
8
|
+
* - Transactions
|
|
9
|
+
* - Relationships
|
|
10
|
+
* - NFTs
|
|
11
|
+
* - Token discovery
|
|
12
|
+
*/
|
|
13
|
+
import { BaseApiClient, API_URLS, STALE_TIMES, GC_TIMES, HttpError } from "../base-client.mjs";
|
|
14
|
+
/**
|
|
15
|
+
* Accounts API Client.
|
|
16
|
+
* Provides methods for interacting with the Accounts API.
|
|
17
|
+
*/
|
|
18
|
+
export class AccountsApiClient extends BaseApiClient {
|
|
19
|
+
// ==========================================================================
|
|
20
|
+
// CACHE MANAGEMENT
|
|
21
|
+
// ==========================================================================
|
|
22
|
+
/**
|
|
23
|
+
* Invalidate all balance queries.
|
|
24
|
+
*/
|
|
25
|
+
async invalidateBalances() {
|
|
26
|
+
await this.queryClient.invalidateQueries({
|
|
27
|
+
queryKey: ['accounts', 'balances'],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Invalidate all account queries.
|
|
32
|
+
*/
|
|
33
|
+
async invalidateAccounts() {
|
|
34
|
+
await this.queryClient.invalidateQueries({
|
|
35
|
+
queryKey: ['accounts'],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// ==========================================================================
|
|
39
|
+
// SUPPORTED NETWORKS
|
|
40
|
+
// ==========================================================================
|
|
41
|
+
/**
|
|
42
|
+
* Get list of supported networks (v1 endpoint).
|
|
43
|
+
*
|
|
44
|
+
* @param options - Fetch options including cache settings.
|
|
45
|
+
* @returns The list of supported networks.
|
|
46
|
+
*/
|
|
47
|
+
async fetchV1SupportedNetworks(options) {
|
|
48
|
+
return this.queryClient.fetchQuery({
|
|
49
|
+
queryKey: ['accounts', 'v1SupportedNetworks'],
|
|
50
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v1/supportedNetworks', { signal }),
|
|
51
|
+
staleTime: options?.staleTime ?? STALE_TIMES.SUPPORTED_NETWORKS,
|
|
52
|
+
gcTime: options?.gcTime ?? GC_TIMES.EXTENDED,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get list of supported networks (v2 endpoint).
|
|
57
|
+
*
|
|
58
|
+
* @param options - Fetch options including cache settings.
|
|
59
|
+
* @returns The list of supported networks.
|
|
60
|
+
*/
|
|
61
|
+
async fetchV2SupportedNetworks(options) {
|
|
62
|
+
return this.queryClient.fetchQuery({
|
|
63
|
+
queryKey: ['accounts', 'v2SupportedNetworks'],
|
|
64
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v2/supportedNetworks', { signal }),
|
|
65
|
+
staleTime: options?.staleTime ?? STALE_TIMES.SUPPORTED_NETWORKS,
|
|
66
|
+
gcTime: options?.gcTime ?? GC_TIMES.EXTENDED,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// ==========================================================================
|
|
70
|
+
// ACTIVE NETWORKS
|
|
71
|
+
// ==========================================================================
|
|
72
|
+
/**
|
|
73
|
+
* Get active networks by CAIP-10 account IDs (v2 endpoint).
|
|
74
|
+
*
|
|
75
|
+
* @param accountIds - Array of CAIP-10 account IDs.
|
|
76
|
+
* @param queryOptions - Query filter options.
|
|
77
|
+
* @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.
|
|
78
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
79
|
+
* @param options - Fetch options including cache settings.
|
|
80
|
+
* @returns The active networks response.
|
|
81
|
+
*/
|
|
82
|
+
async fetchV2ActiveNetworks(accountIds, queryOptions, options) {
|
|
83
|
+
return this.queryClient.fetchQuery({
|
|
84
|
+
queryKey: [
|
|
85
|
+
'accounts',
|
|
86
|
+
'v2ActiveNetworks',
|
|
87
|
+
{
|
|
88
|
+
accountIds: [...accountIds].sort(),
|
|
89
|
+
options: queryOptions && {
|
|
90
|
+
...queryOptions,
|
|
91
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
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
|
+
}),
|
|
103
|
+
staleTime: options?.staleTime ?? STALE_TIMES.NETWORKS,
|
|
104
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// ==========================================================================
|
|
108
|
+
// BALANCES
|
|
109
|
+
// ==========================================================================
|
|
110
|
+
/**
|
|
111
|
+
* Get account balances for a single address (v2 endpoint).
|
|
112
|
+
*
|
|
113
|
+
* @param address - The account address.
|
|
114
|
+
* @param queryOptions - Query filter options.
|
|
115
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
116
|
+
* @param options - Fetch options including cache settings.
|
|
117
|
+
* @returns The account balances response.
|
|
118
|
+
*/
|
|
119
|
+
async fetchV2Balances(address, queryOptions, options) {
|
|
120
|
+
return this.queryClient.fetchQuery({
|
|
121
|
+
queryKey: [
|
|
122
|
+
'accounts',
|
|
123
|
+
'balances',
|
|
124
|
+
'v2',
|
|
125
|
+
{
|
|
126
|
+
address,
|
|
127
|
+
options: queryOptions && {
|
|
128
|
+
...queryOptions,
|
|
129
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/balances`, {
|
|
134
|
+
signal,
|
|
135
|
+
params: { networks: queryOptions?.networks },
|
|
136
|
+
}),
|
|
137
|
+
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
138
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get account balances with additional options (v2 endpoint).
|
|
143
|
+
*
|
|
144
|
+
* @param address - The account address.
|
|
145
|
+
* @param queryOptions - Query filter options.
|
|
146
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
147
|
+
* @param queryOptions.filterSupportedTokens - Whether to filter supported tokens.
|
|
148
|
+
* @param queryOptions.includeTokenAddresses - Token addresses to include.
|
|
149
|
+
* @param queryOptions.includeStakedAssets - Whether to include staked assets.
|
|
150
|
+
* @param options - Fetch options including cache settings.
|
|
151
|
+
* @returns The account balances response.
|
|
152
|
+
*/
|
|
153
|
+
async fetchV2BalancesWithOptions(address, queryOptions, options) {
|
|
154
|
+
return this.queryClient.fetchQuery({
|
|
155
|
+
queryKey: [
|
|
156
|
+
'accounts',
|
|
157
|
+
'balances',
|
|
158
|
+
'v2',
|
|
159
|
+
{
|
|
160
|
+
address,
|
|
161
|
+
options: queryOptions && {
|
|
162
|
+
...queryOptions,
|
|
163
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
164
|
+
includeTokenAddresses: queryOptions.includeTokenAddresses &&
|
|
165
|
+
[...queryOptions.includeTokenAddresses].sort(),
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
],
|
|
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
|
+
}),
|
|
178
|
+
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
179
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get balances for multiple accounts (v4 endpoint).
|
|
184
|
+
*
|
|
185
|
+
* @param accountAddresses - Array of account addresses.
|
|
186
|
+
* @param queryOptions - Query filter options.
|
|
187
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
188
|
+
* @param options - Fetch options including cache settings.
|
|
189
|
+
* @returns The multi-account balances response.
|
|
190
|
+
*/
|
|
191
|
+
async fetchV4MultiAccountBalances(accountAddresses, queryOptions, options) {
|
|
192
|
+
return this.queryClient.fetchQuery({
|
|
193
|
+
queryKey: [
|
|
194
|
+
'accounts',
|
|
195
|
+
'balances',
|
|
196
|
+
'v4',
|
|
197
|
+
{
|
|
198
|
+
accountAddresses: [...accountAddresses].sort(),
|
|
199
|
+
options: queryOptions && {
|
|
200
|
+
...queryOptions,
|
|
201
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v4/multiaccount/balances', {
|
|
206
|
+
signal,
|
|
207
|
+
params: {
|
|
208
|
+
accountAddresses,
|
|
209
|
+
networks: queryOptions?.networks,
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,
|
|
213
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get balances for multiple accounts using CAIP-10 IDs (v5 endpoint).
|
|
218
|
+
*
|
|
219
|
+
* @param accountIds - Array of CAIP-10 account IDs.
|
|
220
|
+
* @param queryOptions - Query filter options.
|
|
221
|
+
* @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.
|
|
222
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
223
|
+
* @param queryOptions.includeStakedAssets - Whether to include staked assets.
|
|
224
|
+
* @param options - Fetch options including cache settings.
|
|
225
|
+
* @returns The multi-account balances response.
|
|
226
|
+
*/
|
|
227
|
+
async fetchV5MultiAccountBalances(accountIds, queryOptions, options) {
|
|
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
|
+
});
|
|
253
|
+
}
|
|
254
|
+
// ==========================================================================
|
|
255
|
+
// TRANSACTIONS
|
|
256
|
+
// ==========================================================================
|
|
257
|
+
/**
|
|
258
|
+
* Get a specific transaction by hash (v1 endpoint).
|
|
259
|
+
*
|
|
260
|
+
* @param chainId - The chain ID.
|
|
261
|
+
* @param txHash - The transaction hash.
|
|
262
|
+
* @param queryOptions - Query filter options.
|
|
263
|
+
* @param queryOptions.includeLogs - Whether to include logs.
|
|
264
|
+
* @param queryOptions.includeValueTransfers - Whether to include value transfers.
|
|
265
|
+
* @param queryOptions.includeTxMetadata - Whether to include transaction metadata.
|
|
266
|
+
* @param queryOptions.lang - Language for metadata.
|
|
267
|
+
* @param options - Fetch options including cache settings.
|
|
268
|
+
* @returns The transaction details.
|
|
269
|
+
*/
|
|
270
|
+
async fetchV1TransactionByHash(chainId, txHash, queryOptions, options) {
|
|
271
|
+
return this.queryClient.fetchQuery({
|
|
272
|
+
queryKey: [
|
|
273
|
+
'accounts',
|
|
274
|
+
'transactions',
|
|
275
|
+
'v1ByHash',
|
|
276
|
+
{ chainId, txHash, options: queryOptions },
|
|
277
|
+
],
|
|
278
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v1/networks/${chainId}/transactions/${txHash}`, {
|
|
279
|
+
signal,
|
|
280
|
+
params: {
|
|
281
|
+
includeLogs: queryOptions?.includeLogs,
|
|
282
|
+
includeValueTransfers: queryOptions?.includeValueTransfers,
|
|
283
|
+
includeTxMetadata: queryOptions?.includeTxMetadata,
|
|
284
|
+
lang: queryOptions?.lang,
|
|
285
|
+
},
|
|
286
|
+
}),
|
|
287
|
+
staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,
|
|
288
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get account transactions (v1 endpoint).
|
|
293
|
+
*
|
|
294
|
+
* @param address - The account address.
|
|
295
|
+
* @param queryOptions - Query filter options.
|
|
296
|
+
* @param queryOptions.chainIds - Chain IDs to filter by.
|
|
297
|
+
* @param queryOptions.cursor - Pagination cursor.
|
|
298
|
+
* @param queryOptions.startTimestamp - Start timestamp filter.
|
|
299
|
+
* @param queryOptions.endTimestamp - End timestamp filter.
|
|
300
|
+
* @param queryOptions.sortDirection - Sort direction (ASC/DESC).
|
|
301
|
+
* @param options - Fetch options including cache settings.
|
|
302
|
+
* @returns The account transactions response.
|
|
303
|
+
*/
|
|
304
|
+
async fetchV1AccountTransactions(address, queryOptions, options) {
|
|
305
|
+
return this.queryClient.fetchQuery({
|
|
306
|
+
queryKey: [
|
|
307
|
+
'accounts',
|
|
308
|
+
'transactions',
|
|
309
|
+
'v1Account',
|
|
310
|
+
{
|
|
311
|
+
address,
|
|
312
|
+
options: queryOptions && {
|
|
313
|
+
...queryOptions,
|
|
314
|
+
chainIds: queryOptions.chainIds && [...queryOptions.chainIds].sort(),
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
],
|
|
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
|
+
}),
|
|
328
|
+
staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,
|
|
329
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get multi-account transactions (v4 endpoint).
|
|
334
|
+
*
|
|
335
|
+
* @param accountIds - Array of CAIP-10 account IDs.
|
|
336
|
+
* @param queryOptions - Query filter options.
|
|
337
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
338
|
+
* @param queryOptions.cursor - Pagination cursor.
|
|
339
|
+
* @param queryOptions.sortDirection - Sort direction (ASC/DESC).
|
|
340
|
+
* @param queryOptions.includeLogs - Whether to include logs.
|
|
341
|
+
* @param queryOptions.includeValueTransfers - Whether to include value transfers.
|
|
342
|
+
* @param queryOptions.includeTxMetadata - Whether to include transaction metadata.
|
|
343
|
+
* @param options - Fetch options including cache settings.
|
|
344
|
+
* @returns The multi-account transactions response.
|
|
345
|
+
*/
|
|
346
|
+
async fetchV4MultiAccountTransactions(accountIds, queryOptions, options) {
|
|
347
|
+
return this.queryClient.fetchQuery({
|
|
348
|
+
queryKey: [
|
|
349
|
+
'accounts',
|
|
350
|
+
'transactions',
|
|
351
|
+
'v4MultiAccount',
|
|
352
|
+
{
|
|
353
|
+
accountIds: [...accountIds].sort(),
|
|
354
|
+
options: queryOptions && {
|
|
355
|
+
...queryOptions,
|
|
356
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, '/v4/multiaccount/transactions', {
|
|
361
|
+
signal,
|
|
362
|
+
params: {
|
|
363
|
+
accountIds,
|
|
364
|
+
networks: queryOptions?.networks,
|
|
365
|
+
cursor: queryOptions?.cursor,
|
|
366
|
+
sortDirection: queryOptions?.sortDirection,
|
|
367
|
+
includeLogs: queryOptions?.includeLogs,
|
|
368
|
+
includeValueTransfers: queryOptions?.includeValueTransfers,
|
|
369
|
+
includeTxMetadata: queryOptions?.includeTxMetadata,
|
|
370
|
+
},
|
|
371
|
+
}),
|
|
372
|
+
staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,
|
|
373
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
// ==========================================================================
|
|
377
|
+
// RELATIONSHIPS
|
|
378
|
+
// ==========================================================================
|
|
379
|
+
/**
|
|
380
|
+
* Get account address relationship (v1 endpoint).
|
|
381
|
+
*
|
|
382
|
+
* @param chainId - The chain ID.
|
|
383
|
+
* @param from - The from address.
|
|
384
|
+
* @param to - The to address.
|
|
385
|
+
* @param options - Fetch options including cache settings.
|
|
386
|
+
* @returns The account relationship result.
|
|
387
|
+
*/
|
|
388
|
+
async fetchV1AccountRelationship(chainId, from, to, options) {
|
|
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
|
+
});
|
|
416
|
+
}
|
|
417
|
+
// ==========================================================================
|
|
418
|
+
// NFTs
|
|
419
|
+
// ==========================================================================
|
|
420
|
+
/**
|
|
421
|
+
* Get NFTs owned by an account (v2 endpoint).
|
|
422
|
+
*
|
|
423
|
+
* @param address - The account address.
|
|
424
|
+
* @param queryOptions - Query filter options.
|
|
425
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
426
|
+
* @param queryOptions.cursor - Pagination cursor.
|
|
427
|
+
* @param options - Fetch options including cache settings.
|
|
428
|
+
* @returns The NFTs response.
|
|
429
|
+
*/
|
|
430
|
+
async fetchV2AccountNfts(address, queryOptions, options) {
|
|
431
|
+
return this.queryClient.fetchQuery({
|
|
432
|
+
queryKey: [
|
|
433
|
+
'accounts',
|
|
434
|
+
'v2Nfts',
|
|
435
|
+
{
|
|
436
|
+
address,
|
|
437
|
+
options: queryOptions && {
|
|
438
|
+
...queryOptions,
|
|
439
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
],
|
|
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
|
+
}),
|
|
450
|
+
staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,
|
|
451
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
// ==========================================================================
|
|
455
|
+
// TOKEN DISCOVERY
|
|
456
|
+
// ==========================================================================
|
|
457
|
+
/**
|
|
458
|
+
* Get ERC20 tokens detected for an account (v2 endpoint).
|
|
459
|
+
*
|
|
460
|
+
* @param address - The account address.
|
|
461
|
+
* @param queryOptions - Query filter options.
|
|
462
|
+
* @param queryOptions.networks - Networks to filter by.
|
|
463
|
+
* @param options - Fetch options including cache settings.
|
|
464
|
+
* @returns The tokens response.
|
|
465
|
+
*/
|
|
466
|
+
async fetchV2AccountTokens(address, queryOptions, options) {
|
|
467
|
+
return this.queryClient.fetchQuery({
|
|
468
|
+
queryKey: [
|
|
469
|
+
'accounts',
|
|
470
|
+
'v2Tokens',
|
|
471
|
+
{
|
|
472
|
+
address,
|
|
473
|
+
options: queryOptions && {
|
|
474
|
+
...queryOptions,
|
|
475
|
+
networks: queryOptions.networks && [...queryOptions.networks].sort(),
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
queryFn: ({ signal }) => this.fetch(API_URLS.ACCOUNTS, `/v2/accounts/${address}/tokens`, {
|
|
480
|
+
signal,
|
|
481
|
+
params: { networks: queryOptions?.networks },
|
|
482
|
+
}),
|
|
483
|
+
staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,
|
|
484
|
+
gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","sourceRoot":"","sources":["../../../src/api/accounts/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAkBH,OAAO,EACL,aAAa,EACb,QAAQ,EACR,WAAW,EACX,QAAQ,EAC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SAAS,EAChC;gBACE,MAAM;gBACN,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE;aAC7C,CACF;YACH,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,WAAW,CAAC,OAAO;YACpD,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,QAAQ,CAAC,OAAO;SAC5C,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Accounts API Client - accounts.api.cx.metamask.io\n *\n * Handles all account-related API calls including:\n * - Supported networks\n * - Active networks\n * - Balances (v2, v4, v5)\n * - Transactions\n * - Relationships\n * - NFTs\n * - Token discovery\n */\n\nimport type { QueryFunctionContext } from '@tanstack/query-core';\n\nimport type {\n V1SupportedNetworksResponse,\n V2SupportedNetworksResponse,\n V2ActiveNetworksResponse,\n V2BalancesResponse,\n V4BalancesResponse,\n V5BalancesResponse,\n V1TransactionByHashResponse,\n V1AccountTransactionsResponse,\n V4MultiAccountTransactionsResponse,\n V1AccountRelationshipResult,\n V2NftsResponse,\n V2TokensResponse,\n} from './types';\nimport {\n BaseApiClient,\n API_URLS,\n STALE_TIMES,\n GC_TIMES,\n HttpError,\n} from '../base-client';\nimport type { FetchOptions } from '../shared-types';\n\n/**\n * Accounts API Client.\n * Provides methods for interacting with the Accounts API.\n */\nexport class AccountsApiClient extends BaseApiClient {\n // ==========================================================================\n // CACHE MANAGEMENT\n // ==========================================================================\n\n /**\n * Invalidate all balance queries.\n */\n async invalidateBalances(): Promise<void> {\n await this.queryClient.invalidateQueries({\n queryKey: ['accounts', 'balances'],\n });\n }\n\n /**\n * Invalidate all account queries.\n */\n async invalidateAccounts(): Promise<void> {\n await this.queryClient.invalidateQueries({\n queryKey: ['accounts'],\n });\n }\n\n // ==========================================================================\n // SUPPORTED NETWORKS\n // ==========================================================================\n\n /**\n * Get list of supported networks (v1 endpoint).\n *\n * @param options - Fetch options including cache settings.\n * @returns The list of supported networks.\n */\n async fetchV1SupportedNetworks(\n options?: FetchOptions,\n ): Promise<V1SupportedNetworksResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['accounts', 'v1SupportedNetworks'],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1SupportedNetworksResponse>(\n API_URLS.ACCOUNTS,\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 list of supported networks (v2 endpoint).\n *\n * @param options - Fetch options including cache settings.\n * @returns The list of supported networks.\n */\n async fetchV2SupportedNetworks(\n options?: FetchOptions,\n ): Promise<V2SupportedNetworksResponse> {\n return this.queryClient.fetchQuery({\n queryKey: ['accounts', 'v2SupportedNetworks'],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V2SupportedNetworksResponse>(\n API_URLS.ACCOUNTS,\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 // ACTIVE NETWORKS\n // ==========================================================================\n\n /**\n * Get active networks by CAIP-10 account IDs (v2 endpoint).\n *\n * @param accountIds - Array of CAIP-10 account IDs.\n * @param queryOptions - Query filter options.\n * @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.\n * @param queryOptions.networks - Networks to filter by.\n * @param options - Fetch options including cache settings.\n * @returns The active networks response.\n */\n async fetchV2ActiveNetworks(\n accountIds: string[],\n queryOptions?: { filterMMListTokens?: boolean; networks?: string[] },\n options?: FetchOptions,\n ): Promise<V2ActiveNetworksResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'v2ActiveNetworks',\n {\n accountIds: [...accountIds].sort(),\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V2ActiveNetworksResponse>(\n API_URLS.ACCOUNTS,\n '/v2/activeNetworks',\n {\n signal,\n params: {\n accountIds,\n filterMMListTokens: queryOptions?.filterMMListTokens,\n networks: queryOptions?.networks,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.NETWORKS,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // BALANCES\n // ==========================================================================\n\n /**\n * Get account balances for a single address (v2 endpoint).\n *\n * @param address - The account address.\n * @param queryOptions - Query filter options.\n * @param queryOptions.networks - Networks to filter by.\n * @param options - Fetch options including cache settings.\n * @returns The account balances response.\n */\n async fetchV2Balances(\n address: string,\n queryOptions?: { networks?: number[] },\n options?: FetchOptions,\n ): Promise<V2BalancesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'balances',\n 'v2',\n {\n address,\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V2BalancesResponse>(\n API_URLS.ACCOUNTS,\n `/v2/accounts/${address}/balances`,\n {\n signal,\n params: { networks: queryOptions?.networks },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get account balances with additional options (v2 endpoint).\n *\n * @param address - The account address.\n * @param queryOptions - Query filter options.\n * @param queryOptions.networks - Networks to filter by.\n * @param queryOptions.filterSupportedTokens - Whether to filter supported tokens.\n * @param queryOptions.includeTokenAddresses - Token addresses to include.\n * @param queryOptions.includeStakedAssets - Whether to include staked assets.\n * @param options - Fetch options including cache settings.\n * @returns The account balances response.\n */\n async fetchV2BalancesWithOptions(\n address: string,\n queryOptions?: {\n networks?: number[];\n filterSupportedTokens?: boolean;\n includeTokenAddresses?: string[];\n includeStakedAssets?: boolean;\n },\n options?: FetchOptions,\n ): Promise<V2BalancesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'balances',\n 'v2',\n {\n address,\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n includeTokenAddresses:\n queryOptions.includeTokenAddresses &&\n [...queryOptions.includeTokenAddresses].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V2BalancesResponse>(\n API_URLS.ACCOUNTS,\n `/v2/accounts/${address}/balances`,\n {\n signal,\n params: {\n networks: queryOptions?.networks,\n filterSupportedTokens: queryOptions?.filterSupportedTokens,\n includeTokenAddresses: queryOptions?.includeTokenAddresses,\n includeStakedAssets: queryOptions?.includeStakedAssets,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get balances for multiple accounts (v4 endpoint).\n *\n * @param accountAddresses - Array of account addresses.\n * @param queryOptions - Query filter options.\n * @param queryOptions.networks - Networks to filter by.\n * @param options - Fetch options including cache settings.\n * @returns The multi-account balances response.\n */\n async fetchV4MultiAccountBalances(\n accountAddresses: string[],\n queryOptions?: { networks?: number[] },\n options?: FetchOptions,\n ): Promise<V4BalancesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'balances',\n 'v4',\n {\n accountAddresses: [...accountAddresses].sort(),\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V4BalancesResponse>(\n API_URLS.ACCOUNTS,\n '/v4/multiaccount/balances',\n {\n signal,\n params: {\n accountAddresses,\n networks: queryOptions?.networks,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get balances for multiple accounts using CAIP-10 IDs (v5 endpoint).\n *\n * @param accountIds - Array of CAIP-10 account IDs.\n * @param queryOptions - Query filter options.\n * @param queryOptions.filterMMListTokens - Whether to filter MM list tokens.\n * @param queryOptions.networks - Networks to filter by.\n * @param queryOptions.includeStakedAssets - Whether to include staked assets.\n * @param options - Fetch options including cache settings.\n * @returns The multi-account balances response.\n */\n async fetchV5MultiAccountBalances(\n accountIds: string[],\n queryOptions?: {\n filterMMListTokens?: boolean;\n networks?: string[];\n includeStakedAssets?: boolean;\n },\n options?: FetchOptions,\n ): Promise<V5BalancesResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'balances',\n 'v5',\n {\n accountIds: [...accountIds].sort(),\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V5BalancesResponse>(\n API_URLS.ACCOUNTS,\n '/v5/multiaccount/balances',\n {\n signal,\n params: {\n accountIds,\n networks: queryOptions?.networks,\n filterMMListTokens: queryOptions?.filterMMListTokens,\n includeStakedAssets: queryOptions?.includeStakedAssets,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.BALANCES,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // TRANSACTIONS\n // ==========================================================================\n\n /**\n * Get a specific transaction by hash (v1 endpoint).\n *\n * @param chainId - The chain ID.\n * @param txHash - The transaction hash.\n * @param queryOptions - Query filter options.\n * @param queryOptions.includeLogs - Whether to include logs.\n * @param queryOptions.includeValueTransfers - Whether to include value transfers.\n * @param queryOptions.includeTxMetadata - Whether to include transaction metadata.\n * @param queryOptions.lang - Language for metadata.\n * @param options - Fetch options including cache settings.\n * @returns The transaction details.\n */\n async fetchV1TransactionByHash(\n chainId: number,\n txHash: string,\n queryOptions?: {\n includeLogs?: boolean;\n includeValueTransfers?: boolean;\n includeTxMetadata?: boolean;\n lang?: string;\n },\n options?: FetchOptions,\n ): Promise<V1TransactionByHashResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'transactions',\n 'v1ByHash',\n { chainId, txHash, options: queryOptions },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1TransactionByHashResponse>(\n API_URLS.ACCOUNTS,\n `/v1/networks/${chainId}/transactions/${txHash}`,\n {\n signal,\n params: {\n includeLogs: queryOptions?.includeLogs,\n includeValueTransfers: queryOptions?.includeValueTransfers,\n includeTxMetadata: queryOptions?.includeTxMetadata,\n lang: queryOptions?.lang,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get account transactions (v1 endpoint).\n *\n * @param address - The account address.\n * @param queryOptions - Query filter options.\n * @param queryOptions.chainIds - Chain IDs to filter by.\n * @param queryOptions.cursor - Pagination cursor.\n * @param queryOptions.startTimestamp - Start timestamp filter.\n * @param queryOptions.endTimestamp - End timestamp filter.\n * @param queryOptions.sortDirection - Sort direction (ASC/DESC).\n * @param options - Fetch options including cache settings.\n * @returns The account transactions response.\n */\n async fetchV1AccountTransactions(\n address: string,\n queryOptions?: {\n chainIds?: string[];\n cursor?: string;\n startTimestamp?: number;\n endTimestamp?: number;\n sortDirection?: 'ASC' | 'DESC';\n },\n options?: FetchOptions,\n ): Promise<V1AccountTransactionsResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'transactions',\n 'v1Account',\n {\n address,\n options: queryOptions && {\n ...queryOptions,\n chainIds:\n queryOptions.chainIds && [...queryOptions.chainIds].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V1AccountTransactionsResponse>(\n API_URLS.ACCOUNTS,\n `/v1/accounts/${address}/transactions`,\n {\n signal,\n params: {\n networks: queryOptions?.chainIds,\n cursor: queryOptions?.cursor,\n startTimestamp: queryOptions?.startTimestamp,\n endTimestamp: queryOptions?.endTimestamp,\n sortDirection: queryOptions?.sortDirection,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n /**\n * Get multi-account transactions (v4 endpoint).\n *\n * @param accountIds - Array of CAIP-10 account IDs.\n * @param queryOptions - Query filter options.\n * @param queryOptions.networks - Networks to filter by.\n * @param queryOptions.cursor - Pagination cursor.\n * @param queryOptions.sortDirection - Sort direction (ASC/DESC).\n * @param queryOptions.includeLogs - Whether to include logs.\n * @param queryOptions.includeValueTransfers - Whether to include value transfers.\n * @param queryOptions.includeTxMetadata - Whether to include transaction metadata.\n * @param options - Fetch options including cache settings.\n * @returns The multi-account transactions response.\n */\n async fetchV4MultiAccountTransactions(\n accountIds: string[],\n queryOptions?: {\n networks?: string[];\n cursor?: string;\n sortDirection?: 'ASC' | 'DESC';\n includeLogs?: boolean;\n includeValueTransfers?: boolean;\n includeTxMetadata?: boolean;\n },\n options?: FetchOptions,\n ): Promise<V4MultiAccountTransactionsResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'transactions',\n 'v4MultiAccount',\n {\n accountIds: [...accountIds].sort(),\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V4MultiAccountTransactionsResponse>(\n API_URLS.ACCOUNTS,\n '/v4/multiaccount/transactions',\n {\n signal,\n params: {\n accountIds,\n networks: queryOptions?.networks,\n cursor: queryOptions?.cursor,\n sortDirection: queryOptions?.sortDirection,\n includeLogs: queryOptions?.includeLogs,\n includeValueTransfers: queryOptions?.includeValueTransfers,\n includeTxMetadata: queryOptions?.includeTxMetadata,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.TRANSACTIONS,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // RELATIONSHIPS\n // ==========================================================================\n\n /**\n * Get account address relationship (v1 endpoint).\n *\n * @param chainId - The chain ID.\n * @param from - The from address.\n * @param to - The to address.\n * @param options - Fetch options including cache settings.\n * @returns The account relationship result.\n */\n async fetchV1AccountRelationship(\n chainId: number,\n from: string,\n to: string,\n options?: FetchOptions,\n ): Promise<V1AccountRelationshipResult> {\n return this.queryClient.fetchQuery({\n queryKey: ['accounts', 'v1Relationship', chainId, from, to],\n queryFn: async ({ signal }: QueryFunctionContext) => {\n try {\n return await this.fetch<V1AccountRelationshipResult>(\n API_URLS.ACCOUNTS,\n `/v1/networks/${chainId}/accounts/${from}/relationships/${to}`,\n { signal },\n );\n } catch (error) {\n if (error instanceof HttpError && typeof error.body === 'object') {\n const body = error.body as {\n error?: { code?: string; message?: string };\n } | null;\n if (\n body?.error &&\n typeof body.error === 'object' &&\n typeof body.error.code === 'string' &&\n typeof body.error.message === 'string'\n ) {\n return {\n error: {\n code: body.error.code,\n message: body.error.message,\n },\n };\n }\n }\n throw error;\n }\n },\n staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // NFTs\n // ==========================================================================\n\n /**\n * Get NFTs owned by an account (v2 endpoint).\n *\n * @param address - The account address.\n * @param queryOptions - Query filter options.\n * @param queryOptions.networks - Networks to filter by.\n * @param queryOptions.cursor - Pagination cursor.\n * @param options - Fetch options including cache settings.\n * @returns The NFTs response.\n */\n async fetchV2AccountNfts(\n address: string,\n queryOptions?: { networks?: number[]; cursor?: string },\n options?: FetchOptions,\n ): Promise<V2NftsResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'v2Nfts',\n {\n address,\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V2NftsResponse>(\n API_URLS.ACCOUNTS,\n `/v2/accounts/${address}/nfts`,\n {\n signal,\n params: {\n networks: queryOptions?.networks,\n cursor: queryOptions?.cursor,\n },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n\n // ==========================================================================\n // TOKEN DISCOVERY\n // ==========================================================================\n\n /**\n * Get ERC20 tokens detected for an account (v2 endpoint).\n *\n * @param address - The account address.\n * @param queryOptions - Query filter options.\n * @param queryOptions.networks - Networks to filter by.\n * @param options - Fetch options including cache settings.\n * @returns The tokens response.\n */\n async fetchV2AccountTokens(\n address: string,\n queryOptions?: { networks?: number[] },\n options?: FetchOptions,\n ): Promise<V2TokensResponse> {\n return this.queryClient.fetchQuery({\n queryKey: [\n 'accounts',\n 'v2Tokens',\n {\n address,\n options: queryOptions && {\n ...queryOptions,\n networks:\n queryOptions.networks && [...queryOptions.networks].sort(),\n },\n },\n ],\n queryFn: ({ signal }: QueryFunctionContext) =>\n this.fetch<V2TokensResponse>(\n API_URLS.ACCOUNTS,\n `/v2/accounts/${address}/tokens`,\n {\n signal,\n params: { networks: queryOptions?.networks },\n },\n ),\n staleTime: options?.staleTime ?? STALE_TIMES.DEFAULT,\n gcTime: options?.gcTime ?? GC_TIMES.DEFAULT,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Accounts API barrel export.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AccountsApiClient = void 0;
|
|
7
|
+
var client_1 = require("./client.cjs");
|
|
8
|
+
Object.defineProperty(exports, "AccountsApiClient", { enumerable: true, get: function () { return client_1.AccountsApiClient; } });
|
|
9
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/api/accounts/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uCAA6C;AAApC,2GAAA,iBAAiB,OAAA","sourcesContent":["/**\n * Accounts API barrel export.\n */\n\nexport { AccountsApiClient } from './client';\nexport type {\n V5BalanceItem,\n V5BalancesResponse,\n V2BalanceItem,\n V2BalancesResponse,\n V4BalancesResponse,\n V1SupportedNetworksResponse,\n V2SupportedNetworksResponse,\n V2ActiveNetworksResponse,\n V1TransactionByHashResponse,\n V1AccountTransactionsResponse,\n V4MultiAccountTransactionsResponse,\n ValueTransfer,\n V1AccountRelationshipResult,\n NftItem,\n V2NftsResponse,\n TokenDiscoveryItem,\n V2TokensResponse,\n} from './types';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts API barrel export.
|
|
3
|
+
*/
|
|
4
|
+
export { AccountsApiClient } from "./client.cjs";
|
|
5
|
+
export type { V5BalanceItem, V5BalancesResponse, V2BalanceItem, V2BalancesResponse, V4BalancesResponse, V1SupportedNetworksResponse, V2SupportedNetworksResponse, V2ActiveNetworksResponse, V1TransactionByHashResponse, V1AccountTransactionsResponse, V4MultiAccountTransactionsResponse, ValueTransfer, V1AccountRelationshipResult, NftItem, V2NftsResponse, TokenDiscoveryItem, V2TokensResponse, } from "./types.cjs";
|
|
6
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/api/accounts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,qBAAiB;AAC7C,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,6BAA6B,EAC7B,kCAAkC,EAClC,aAAa,EACb,2BAA2B,EAC3B,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,oBAAgB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts API barrel export.
|
|
3
|
+
*/
|
|
4
|
+
export { AccountsApiClient } from "./client.mjs";
|
|
5
|
+
export type { V5BalanceItem, V5BalancesResponse, V2BalanceItem, V2BalancesResponse, V4BalancesResponse, V1SupportedNetworksResponse, V2SupportedNetworksResponse, V2ActiveNetworksResponse, V1TransactionByHashResponse, V1AccountTransactionsResponse, V4MultiAccountTransactionsResponse, ValueTransfer, V1AccountRelationshipResult, NftItem, V2NftsResponse, TokenDiscoveryItem, V2TokensResponse, } from "./types.mjs";
|
|
6
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/api/accounts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,qBAAiB;AAC7C,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,6BAA6B,EAC7B,kCAAkC,EAClC,aAAa,EACb,2BAA2B,EAC3B,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,oBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/api/accounts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,qBAAiB","sourcesContent":["/**\n * Accounts API barrel export.\n */\n\nexport { AccountsApiClient } from './client';\nexport type {\n V5BalanceItem,\n V5BalancesResponse,\n V2BalanceItem,\n V2BalancesResponse,\n V4BalancesResponse,\n V1SupportedNetworksResponse,\n V2SupportedNetworksResponse,\n V2ActiveNetworksResponse,\n V1TransactionByHashResponse,\n V1AccountTransactionsResponse,\n V4MultiAccountTransactionsResponse,\n ValueTransfer,\n V1AccountRelationshipResult,\n NftItem,\n V2NftsResponse,\n TokenDiscoveryItem,\n V2TokensResponse,\n} from './types';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/api/accounts/types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * Accounts API types for the API Platform Client.\n * API: accounts.api.cx.metamask.io\n */\n\nimport type { PageInfo } from '../shared-types';\n\n// ============================================================================\n// BALANCE TYPES\n// ============================================================================\n\n/** V5 Balance Item from Accounts API */\nexport type V5BalanceItem = {\n object: 'token';\n symbol: string;\n name: string;\n type: 'native' | 'erc20';\n decimals: number;\n assetId: string;\n balance: string;\n accountId: string;\n};\n\n/** V5 Multi-account balances response */\nexport type V5BalancesResponse = {\n count: number;\n unprocessedNetworks: string[];\n balances: V5BalanceItem[];\n};\n\n/** V2 Balance item */\nexport type V2BalanceItem = {\n object: string;\n type?: string;\n timestamp?: string;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n chainId: number;\n balance: string;\n accountAddress?: string;\n};\n\n/** V2 Balances response */\nexport type V2BalancesResponse = {\n count: number;\n balances: V2BalanceItem[];\n unprocessedNetworks: number[];\n};\n\n/** V4 Multi-account balances response */\nexport type V4BalancesResponse = {\n count: number;\n balances: V2BalanceItem[];\n unprocessedNetworks: number[];\n};\n\n// ============================================================================\n// SUPPORTED NETWORKS TYPES\n// ============================================================================\n\n/** V1 Supported networks response */\nexport type V1SupportedNetworksResponse = {\n supportedNetworks: number[];\n};\n\n/** V2 Supported networks response */\nexport type V2SupportedNetworksResponse = {\n fullSupport: number[];\n partialSupport: {\n balances: number[];\n };\n};\n\n/** Active networks response */\nexport type V2ActiveNetworksResponse = {\n activeNetworks: string[];\n};\n\n// ============================================================================\n// TRANSACTION TYPES\n// ============================================================================\n\n/** Transaction by hash response */\nexport type V1TransactionByHashResponse = {\n hash: string;\n timestamp: string;\n chainId: number;\n blockNumber: number;\n blockHash: string;\n gas: number;\n gasUsed: number;\n gasPrice: string;\n effectiveGasPrice: string;\n nonce: number;\n cumulativeGasUsed: number;\n methodId?: string;\n value: string;\n to: string;\n from: string;\n isError?: boolean;\n valueTransfers?: {\n from: string;\n to: string;\n amount: string;\n decimal: number;\n contractAddress: string;\n symbol: string;\n name: string;\n transferType: string;\n }[];\n logs?: {\n data: string;\n topics: string[];\n address: string;\n logIndex: number;\n }[];\n transactionType?: string;\n transactionCategory?: string;\n transactionProtocol?: string;\n};\n\n/** Account transactions response */\nexport type V1AccountTransactionsResponse = {\n data: V1TransactionByHashResponse[];\n pageInfo: PageInfo;\n};\n\n/** V4 Multi-account transactions response */\nexport type V4MultiAccountTransactionsResponse = {\n unprocessedNetworks: string[];\n pageInfo: {\n count: number;\n hasNextPage: boolean;\n endCursor?: string;\n };\n data: V1TransactionByHashResponse[];\n};\n\n// ============================================================================\n// RELATIONSHIP TYPES\n// ============================================================================\n\n/**\n * Value transfer within a transaction\n */\nexport type ValueTransfer = {\n from: string;\n to: string;\n amount: string;\n decimal: number;\n transferType: string;\n};\n\n/**\n * Account address relationship result from v1 endpoint\n */\nexport type V1AccountRelationshipResult = {\n /** Transaction hash of the relationship */\n txHash?: string;\n /** Chain ID */\n chainId?: number;\n /** Number of interactions */\n count?: number;\n /** Transaction data details */\n data?: {\n hash: string;\n timestamp: string;\n chainId: number;\n blockNumber: number;\n blockHash: string;\n gas: number;\n gasUsed: number;\n gasPrice: string;\n effectiveGasPrice: string;\n nonce: number;\n cumulativeGasUsed: number;\n methodId: string;\n value: string;\n to: string;\n from: string;\n isError: boolean;\n valueTransfers: ValueTransfer[];\n logs: unknown[];\n transactionType: string;\n transactionCategory: string;\n readable: string;\n textFunctionSignature: string;\n };\n /** Error information when relationship lookup fails */\n error?: {\n code: string;\n message: string;\n };\n};\n\n// ============================================================================\n// NFT TYPES\n// ============================================================================\n\n/** NFT item */\nexport type NftItem = {\n tokenId: string;\n contractAddress: string;\n chainId: number;\n name?: string;\n description?: string;\n imageUrl?: string;\n attributes?: Record<string, unknown>[];\n};\n\n/** NFTs response */\nexport type V2NftsResponse = {\n data: NftItem[];\n pageInfo: PageInfo;\n};\n\n// ============================================================================\n// TOKEN DISCOVERY TYPES\n// ============================================================================\n\n/** Token discovery item */\nexport type TokenDiscoveryItem = {\n address: string;\n chainId: number;\n symbol: string;\n name: string;\n decimals: number;\n balance?: string;\n};\n\n/** Tokens response */\nexport type V2TokensResponse = {\n data: TokenDiscoveryItem[];\n};\n"]}
|