@coinbase/agentkit 0.10.3 → 0.10.4
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/README.md +47 -10
- package/dist/action-providers/across/acrossActionProvider.js +2 -4
- package/dist/action-providers/across/acrossActionProvider.test.js +10 -5
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +5 -7
- package/dist/action-providers/clanker/utils.d.ts +2 -1
- package/dist/action-providers/clanker/utils.js +2 -2
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +2 -2
- package/dist/action-providers/spl/splActionProvider.js +12 -13
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +2 -2
- package/dist/action-providers/sushi/constants.d.ts +35 -0
- package/dist/action-providers/sushi/constants.js +7 -0
- package/dist/action-providers/sushi/index.d.ts +4 -0
- package/dist/action-providers/sushi/index.js +20 -0
- package/dist/action-providers/sushi/sushiDataActionProvider.d.ts +32 -0
- package/dist/action-providers/sushi/sushiDataActionProvider.js +113 -0
- package/dist/action-providers/sushi/sushiDataSchemas.d.ts +11 -0
- package/dist/action-providers/sushi/sushiDataSchemas.js +16 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.d.ts +40 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.js +386 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.test.js +392 -0
- package/dist/action-providers/sushi/sushiRouterSchemas.d.ts +36 -0
- package/dist/action-providers/sushi/sushiRouterSchemas.js +55 -0
- package/dist/action-providers/vaultsfyi/constants.d.ts +8 -12
- package/dist/action-providers/vaultsfyi/constants.js +47 -13
- package/dist/action-providers/vaultsfyi/schemas.d.ts +120 -65
- package/dist/action-providers/vaultsfyi/schemas.js +72 -38
- package/dist/action-providers/vaultsfyi/sdk.d.ts +8 -0
- package/dist/action-providers/vaultsfyi/sdk.js +15 -0
- package/dist/action-providers/vaultsfyi/utils.d.ts +151 -55
- package/dist/action-providers/vaultsfyi/utils.js +29 -75
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +55 -16
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +413 -217
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +509 -316
- package/dist/action-providers/x402/constants.d.ts +67 -0
- package/dist/action-providers/x402/constants.js +37 -0
- package/dist/action-providers/x402/schemas.d.ts +45 -5
- package/dist/action-providers/x402/schemas.js +81 -11
- package/dist/action-providers/x402/utils.d.ts +85 -10
- package/dist/action-providers/x402/utils.js +302 -35
- package/dist/action-providers/x402/x402ActionProvider.d.ts +15 -1
- package/dist/action-providers/x402/x402ActionProvider.js +230 -179
- package/dist/action-providers/x402/x402ActionProvider.test.js +222 -262
- package/dist/action-providers/zora/zoraActionProvider.js +4 -5
- package/package.json +10 -7
- package/dist/action-providers/vaultsfyi/api/actions.d.ts +0 -41
- package/dist/action-providers/vaultsfyi/api/actions.js +0 -28
- package/dist/action-providers/vaultsfyi/api/historicalData.d.ts +0 -31
- package/dist/action-providers/vaultsfyi/api/historicalData.js +0 -44
- package/dist/action-providers/vaultsfyi/api/types.d.ts +0 -34
- package/dist/action-providers/vaultsfyi/api/types.js +0 -2
- package/dist/action-providers/vaultsfyi/api/vaults.d.ts +0 -66
- package/dist/action-providers/vaultsfyi/api/vaults.js +0 -57
|
@@ -1,59 +1,308 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getX402Networks = getX402Networks;
|
|
4
|
+
exports.getNetworkId = getNetworkId;
|
|
5
|
+
exports.fetchAllDiscoveryResources = fetchAllDiscoveryResources;
|
|
6
|
+
exports.filterByNetwork = filterByNetwork;
|
|
7
|
+
exports.filterByDescription = filterByDescription;
|
|
8
|
+
exports.filterByX402Version = filterByX402Version;
|
|
9
|
+
exports.filterByKeyword = filterByKeyword;
|
|
10
|
+
exports.filterByMaxPrice = filterByMaxPrice;
|
|
11
|
+
exports.formatSimplifiedResources = formatSimplifiedResources;
|
|
4
12
|
exports.handleHttpError = handleHttpError;
|
|
5
13
|
exports.formatPaymentOption = formatPaymentOption;
|
|
6
14
|
exports.isUsdcAsset = isUsdcAsset;
|
|
7
15
|
exports.convertWholeUnitsToAtomic = convertWholeUnitsToAtomic;
|
|
16
|
+
exports.buildUrlWithParams = buildUrlWithParams;
|
|
8
17
|
const utils_1 = require("../erc20/utils");
|
|
9
18
|
const constants_1 = require("../erc20/constants");
|
|
10
19
|
const viem_1 = require("viem");
|
|
11
20
|
const wallet_providers_1 = require("../../wallet-providers");
|
|
21
|
+
const constants_2 = require("./constants");
|
|
12
22
|
/**
|
|
13
|
-
*
|
|
23
|
+
* Returns array of matching network identifiers (both v1 and v2 CAIP-2 formats).
|
|
24
|
+
* Used for filtering discovery results that may contain either format.
|
|
25
|
+
*
|
|
26
|
+
* @param network - The network object
|
|
27
|
+
* @returns Array of network identifiers that match the wallet's network
|
|
28
|
+
*/
|
|
29
|
+
function getX402Networks(network) {
|
|
30
|
+
const networkId = network.networkId;
|
|
31
|
+
if (!networkId) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return constants_2.NETWORK_MAPPINGS[networkId] ?? [networkId];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets network ID from a CAIP-2 or v1 network identifier.
|
|
38
|
+
*
|
|
39
|
+
* @param network - The x402 network identifier (e.g., "eip155:8453" for v2 or "base" for v1)
|
|
40
|
+
* @returns The network ID (e.g., "base-mainnet") or the original if not found
|
|
41
|
+
*/
|
|
42
|
+
function getNetworkId(network) {
|
|
43
|
+
for (const [agentKitId, formats] of Object.entries(constants_2.NETWORK_MAPPINGS)) {
|
|
44
|
+
if (formats.includes(network)) {
|
|
45
|
+
return agentKitId;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return network;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fetches a URL with retry logic and exponential backoff for rate limiting.
|
|
52
|
+
*
|
|
53
|
+
* @param url - The URL to fetch
|
|
54
|
+
* @param maxRetries - Maximum number of retries (default 3)
|
|
55
|
+
* @param initialDelayMs - Initial delay in milliseconds (default 1000)
|
|
56
|
+
* @returns The fetch Response
|
|
57
|
+
*/
|
|
58
|
+
async function fetchWithRetry(url, maxRetries = 3, initialDelayMs = 1000) {
|
|
59
|
+
let lastError = null;
|
|
60
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
61
|
+
const response = await fetch(url);
|
|
62
|
+
if (response.ok) {
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
if (response.status === 429 && attempt < maxRetries) {
|
|
66
|
+
const delayMs = initialDelayMs * Math.pow(2, attempt);
|
|
67
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
lastError = new Error(`Discovery API error: ${response.status} ${response.statusText}`);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
throw lastError ?? new Error("Failed to fetch after retries");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Fetches all resources from the discovery API with pagination.
|
|
77
|
+
*
|
|
78
|
+
* @param discoveryUrl - The base URL for discovery
|
|
79
|
+
* @param pageSize - Number of resources per page (default 100)
|
|
80
|
+
* @returns Array of all discovered resources
|
|
81
|
+
*/
|
|
82
|
+
async function fetchAllDiscoveryResources(discoveryUrl, pageSize = 1000) {
|
|
83
|
+
const allResources = [];
|
|
84
|
+
let offset = 0;
|
|
85
|
+
let hasMore = true;
|
|
86
|
+
while (hasMore) {
|
|
87
|
+
const url = new URL(discoveryUrl);
|
|
88
|
+
url.searchParams.set("limit", pageSize.toString());
|
|
89
|
+
url.searchParams.set("offset", offset.toString());
|
|
90
|
+
const response = await fetchWithRetry(url.toString());
|
|
91
|
+
const data = await response.json();
|
|
92
|
+
const resources = data.resources ?? data.items ?? [];
|
|
93
|
+
if (resources.length === 0) {
|
|
94
|
+
hasMore = false;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
allResources.push(...resources);
|
|
98
|
+
offset += resources.length;
|
|
99
|
+
// Stop when getting fewer resources than requested (last page)
|
|
100
|
+
if (resources.length < pageSize) {
|
|
101
|
+
hasMore = false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return allResources;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Filters resources by network compatibility.
|
|
109
|
+
* Matches resources that accept any of the wallet's network identifiers (v1 or v2 format).
|
|
110
|
+
*
|
|
111
|
+
* @param resources - Array of discovery resources
|
|
112
|
+
* @param walletNetworks - Array of network identifiers to match
|
|
113
|
+
* @returns Filtered array of resources
|
|
14
114
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
115
|
+
function filterByNetwork(resources, walletNetworks) {
|
|
116
|
+
return resources.filter(resource => {
|
|
117
|
+
const accepts = resource.accepts ?? [];
|
|
118
|
+
return accepts.some(option => walletNetworks.includes(option.network));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
19
121
|
/**
|
|
20
|
-
*
|
|
122
|
+
* Extracts description from a resource based on its x402 version.
|
|
123
|
+
* - v1: description is in accepts[].description
|
|
124
|
+
* - v2: description is in metadata.description
|
|
21
125
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* @returns The
|
|
24
|
-
* @throws Error if the network is not supported
|
|
126
|
+
* @param resource - The discovery resource
|
|
127
|
+
* @returns The description string or empty string if not found
|
|
25
128
|
*/
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
return network.networkId;
|
|
129
|
+
function getResourceDescription(resource) {
|
|
130
|
+
if (resource.x402Version === 2) {
|
|
131
|
+
const metadataDesc = resource.metadata?.description;
|
|
132
|
+
return typeof metadataDesc === "string" ? metadataDesc : "";
|
|
133
|
+
}
|
|
134
|
+
// v1: look in accepts[].description
|
|
135
|
+
const accepts = resource.accepts ?? [];
|
|
136
|
+
for (const option of accepts) {
|
|
137
|
+
if (option.description?.trim()) {
|
|
138
|
+
return option.description;
|
|
139
|
+
}
|
|
38
140
|
}
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Filters resources by having a valid description.
|
|
145
|
+
* Removes resources with empty or default descriptions.
|
|
146
|
+
* Supports both v1 (accepts[].description) and v2 (metadata.description) formats.
|
|
147
|
+
*
|
|
148
|
+
* @param resources - Array of discovery resources
|
|
149
|
+
* @returns Filtered array of resources with valid descriptions
|
|
150
|
+
*/
|
|
151
|
+
function filterByDescription(resources) {
|
|
152
|
+
return resources.filter(resource => {
|
|
153
|
+
const desc = getResourceDescription(resource).trim();
|
|
154
|
+
return desc && desc !== "" && desc !== "Access to protected content";
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Filters resources by x402 protocol version.
|
|
159
|
+
* Uses the x402Version field on the resource.
|
|
160
|
+
*
|
|
161
|
+
* @param resources - Array of discovery resources
|
|
162
|
+
* @param allowedVersions - Array of allowed versions (default: [1, 2])
|
|
163
|
+
* @returns Filtered array of resources matching the allowed versions
|
|
164
|
+
*/
|
|
165
|
+
function filterByX402Version(resources, allowedVersions = [1, 2]) {
|
|
166
|
+
return resources.filter(resource => {
|
|
167
|
+
const version = resource.x402Version;
|
|
168
|
+
if (version === undefined) {
|
|
169
|
+
return true; // Include resources without version info
|
|
170
|
+
}
|
|
171
|
+
return allowedVersions.includes(version);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Filters resources by keyword appearing in description or URL.
|
|
176
|
+
* Case-insensitive search.
|
|
177
|
+
* Supports both v1 (accepts[].description) and v2 (metadata.description) formats.
|
|
178
|
+
*
|
|
179
|
+
* @param resources - Array of discovery resources
|
|
180
|
+
* @param keyword - The keyword to search for in descriptions and URLs
|
|
181
|
+
* @returns Filtered array of resources with matching descriptions or URLs
|
|
182
|
+
*/
|
|
183
|
+
function filterByKeyword(resources, keyword) {
|
|
184
|
+
const lowerKeyword = keyword.toLowerCase();
|
|
185
|
+
return resources.filter(resource => {
|
|
186
|
+
// Check description (version-aware)
|
|
187
|
+
const desc = getResourceDescription(resource).toLowerCase();
|
|
188
|
+
if (desc.includes(lowerKeyword)) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
// Also check the URL for keyword matches
|
|
192
|
+
const url = (resource.resource ?? resource.url ?? "").toLowerCase();
|
|
193
|
+
if (url.includes(lowerKeyword)) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Filters resources by maximum USDC price.
|
|
201
|
+
*
|
|
202
|
+
* @param resources - Array of discovery resources
|
|
203
|
+
* @param maxUsdcPrice - Maximum price in whole USDC units
|
|
204
|
+
* @param walletProvider - Wallet provider for asset identification
|
|
205
|
+
* @param walletNetworks - Array of network identifiers to match
|
|
206
|
+
* @returns Filtered array of resources within price limit
|
|
207
|
+
*/
|
|
208
|
+
async function filterByMaxPrice(resources, maxUsdcPrice, walletProvider, walletNetworks) {
|
|
209
|
+
const filtered = [];
|
|
210
|
+
for (const resource of resources) {
|
|
211
|
+
const accepts = resource.accepts ?? [];
|
|
212
|
+
let shouldInclude = false;
|
|
213
|
+
for (const option of accepts) {
|
|
214
|
+
if (!walletNetworks.includes(option.network)) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (!option.asset) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
// Check if this is a USDC asset
|
|
221
|
+
if (!isUsdcAsset(option.asset, walletProvider)) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
// Get the amount (supports both v1 maxAmountRequired and v2 amount/price)
|
|
225
|
+
const amountStr = option.maxAmountRequired ?? option.amount ?? option.price;
|
|
226
|
+
if (!amountStr) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const maxUsdcPriceAtomic = await convertWholeUnitsToAtomic(maxUsdcPrice, option.asset, walletProvider);
|
|
231
|
+
if (maxUsdcPriceAtomic) {
|
|
232
|
+
const resourceAmount = BigInt(amountStr);
|
|
233
|
+
const maxAmount = BigInt(maxUsdcPriceAtomic);
|
|
234
|
+
if (resourceAmount <= maxAmount) {
|
|
235
|
+
shouldInclude = true;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// Skip if conversion fails
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (shouldInclude) {
|
|
246
|
+
filtered.push(resource);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return filtered;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Formats resources into simplified output for LLM consumption.
|
|
253
|
+
*
|
|
254
|
+
* @param resources - Array of discovery resources
|
|
255
|
+
* @param walletNetworks - Array of network identifiers to match for price extraction
|
|
256
|
+
* @param walletProvider - Wallet provider for formatting
|
|
257
|
+
* @returns Array of simplified resources with url, price, description
|
|
258
|
+
*/
|
|
259
|
+
async function formatSimplifiedResources(resources, walletNetworks, walletProvider) {
|
|
260
|
+
const simplified = [];
|
|
261
|
+
for (const resource of resources) {
|
|
262
|
+
const accepts = resource.accepts ?? [];
|
|
263
|
+
const matchingOption = accepts.find(opt => walletNetworks.includes(opt.network));
|
|
264
|
+
if (!matchingOption) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
// Extract URL: v1 and v2 both use resource.resource, but v2 docs show resource.url
|
|
268
|
+
const url = resource.resource ?? resource.url ?? "";
|
|
269
|
+
// Extract description (version-aware via helper)
|
|
270
|
+
const description = getResourceDescription(resource);
|
|
271
|
+
let price = "Unknown";
|
|
272
|
+
// Get the amount (supports both v1 and v2 formats)
|
|
273
|
+
const amountStr = matchingOption.maxAmountRequired ?? matchingOption.amount ?? matchingOption.price;
|
|
274
|
+
if (amountStr && matchingOption.asset) {
|
|
275
|
+
price = await formatPaymentOption({
|
|
276
|
+
asset: matchingOption.asset,
|
|
277
|
+
maxAmountRequired: amountStr,
|
|
278
|
+
network: matchingOption.network,
|
|
279
|
+
}, walletProvider);
|
|
280
|
+
}
|
|
281
|
+
simplified.push({
|
|
282
|
+
url,
|
|
283
|
+
price,
|
|
284
|
+
description,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return simplified;
|
|
39
288
|
}
|
|
40
289
|
/**
|
|
41
290
|
* Helper method to handle HTTP errors consistently.
|
|
42
291
|
*
|
|
43
|
-
* @param error - The
|
|
292
|
+
* @param error - The error to handle
|
|
44
293
|
* @param url - The URL that was being accessed when the error occurred
|
|
45
294
|
* @returns A JSON string containing formatted error details
|
|
46
295
|
*/
|
|
47
296
|
function handleHttpError(error, url) {
|
|
48
|
-
if (error
|
|
297
|
+
if (error instanceof Response) {
|
|
49
298
|
return JSON.stringify({
|
|
50
299
|
error: true,
|
|
51
|
-
message: `HTTP ${error.
|
|
52
|
-
details: error.
|
|
300
|
+
message: `HTTP ${error.status} error when accessing ${url}`,
|
|
301
|
+
details: error.statusText,
|
|
53
302
|
suggestion: "Check if the URL is correct and the API is available.",
|
|
54
303
|
}, null, 2);
|
|
55
304
|
}
|
|
56
|
-
if (error.
|
|
305
|
+
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
57
306
|
return JSON.stringify({
|
|
58
307
|
error: true,
|
|
59
308
|
message: `Network error when accessing ${url}`,
|
|
@@ -61,10 +310,11 @@ function handleHttpError(error, url) {
|
|
|
61
310
|
suggestion: "Check your internet connection and verify the API endpoint is accessible.",
|
|
62
311
|
}, null, 2);
|
|
63
312
|
}
|
|
313
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
314
|
return JSON.stringify({
|
|
65
315
|
error: true,
|
|
66
316
|
message: `Error making request to ${url}`,
|
|
67
|
-
details:
|
|
317
|
+
details: message,
|
|
68
318
|
suggestion: "Please check the request parameters and try again.",
|
|
69
319
|
}, null, 2);
|
|
70
320
|
}
|
|
@@ -92,7 +342,7 @@ async function formatPaymentOption(option, walletProvider) {
|
|
|
92
342
|
if (asset.toLowerCase() === address.toLowerCase()) {
|
|
93
343
|
const decimals = symbol === "USDC" || symbol === "EURC" ? 6 : 18;
|
|
94
344
|
const formattedAmount = (0, viem_1.formatUnits)(BigInt(maxAmountRequired), decimals);
|
|
95
|
-
return `${formattedAmount} ${symbol} on ${network}
|
|
345
|
+
return `${formattedAmount} ${symbol} on ${getNetworkId(network)}`;
|
|
96
346
|
}
|
|
97
347
|
}
|
|
98
348
|
}
|
|
@@ -101,7 +351,7 @@ async function formatPaymentOption(option, walletProvider) {
|
|
|
101
351
|
const tokenDetails = await (0, utils_1.getTokenDetails)(walletProvider, asset);
|
|
102
352
|
if (tokenDetails) {
|
|
103
353
|
const formattedAmount = (0, viem_1.formatUnits)(BigInt(maxAmountRequired), tokenDetails.decimals);
|
|
104
|
-
return `${formattedAmount} ${tokenDetails.name} on ${network}
|
|
354
|
+
return `${formattedAmount} ${tokenDetails.name} on ${getNetworkId(network)}`;
|
|
105
355
|
}
|
|
106
356
|
}
|
|
107
357
|
catch {
|
|
@@ -111,15 +361,15 @@ async function formatPaymentOption(option, walletProvider) {
|
|
|
111
361
|
if (isSvmNetwork && walletProvider instanceof wallet_providers_1.SvmWalletProvider) {
|
|
112
362
|
// Check if the asset is USDC on Solana networks
|
|
113
363
|
const networkId = walletNetwork.networkId;
|
|
114
|
-
const usdcAddress = SOLANA_USDC_ADDRESSES[networkId];
|
|
364
|
+
const usdcAddress = constants_2.SOLANA_USDC_ADDRESSES[networkId];
|
|
115
365
|
if (usdcAddress && asset === usdcAddress) {
|
|
116
366
|
// USDC has 6 decimals on Solana
|
|
117
367
|
const formattedAmount = (0, viem_1.formatUnits)(BigInt(maxAmountRequired), 6);
|
|
118
|
-
return `${formattedAmount} USDC on ${network}
|
|
368
|
+
return `${formattedAmount} USDC on ${getNetworkId(network)}`;
|
|
119
369
|
}
|
|
120
370
|
}
|
|
121
371
|
// Fallback to original format for non-EVM/SVM networks or when token details can't be fetched
|
|
122
|
-
return `${asset} ${maxAmountRequired} on ${network}
|
|
372
|
+
return `${asset} ${maxAmountRequired} on ${getNetworkId(network)}`;
|
|
123
373
|
}
|
|
124
374
|
/**
|
|
125
375
|
* Checks if an asset is USDC on any supported network.
|
|
@@ -141,7 +391,7 @@ function isUsdcAsset(asset, walletProvider) {
|
|
|
141
391
|
}
|
|
142
392
|
if (isSvmNetwork && walletProvider instanceof wallet_providers_1.SvmWalletProvider) {
|
|
143
393
|
const networkId = walletNetwork.networkId;
|
|
144
|
-
const usdcAddress = SOLANA_USDC_ADDRESSES[networkId];
|
|
394
|
+
const usdcAddress = constants_2.SOLANA_USDC_ADDRESSES[networkId];
|
|
145
395
|
if (usdcAddress) {
|
|
146
396
|
return asset === usdcAddress;
|
|
147
397
|
}
|
|
@@ -186,7 +436,7 @@ async function convertWholeUnitsToAtomic(wholeUnits, asset, walletProvider) {
|
|
|
186
436
|
if (isSvmNetwork && walletProvider instanceof wallet_providers_1.SvmWalletProvider) {
|
|
187
437
|
// Check if the asset is USDC on Solana networks
|
|
188
438
|
const networkId = walletNetwork.networkId;
|
|
189
|
-
const usdcAddress = SOLANA_USDC_ADDRESSES[networkId];
|
|
439
|
+
const usdcAddress = constants_2.SOLANA_USDC_ADDRESSES[networkId];
|
|
190
440
|
if (usdcAddress && asset === usdcAddress) {
|
|
191
441
|
// USDC has 6 decimals on Solana
|
|
192
442
|
return (0, viem_1.parseUnits)(wholeUnits.toString(), 6).toString();
|
|
@@ -195,3 +445,20 @@ async function convertWholeUnitsToAtomic(wholeUnits, asset, walletProvider) {
|
|
|
195
445
|
// Fallback to 18 decimals for unknown tokens or non-EVM/SVM networks
|
|
196
446
|
return (0, viem_1.parseUnits)(wholeUnits.toString(), 18).toString();
|
|
197
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* Builds a URL with query parameters appended.
|
|
450
|
+
*
|
|
451
|
+
* @param baseUrl - The base URL
|
|
452
|
+
* @param queryParams - Optional query parameters to append
|
|
453
|
+
* @returns URL string with query parameters
|
|
454
|
+
*/
|
|
455
|
+
function buildUrlWithParams(baseUrl, queryParams) {
|
|
456
|
+
if (!queryParams || Object.keys(queryParams).length === 0) {
|
|
457
|
+
return baseUrl;
|
|
458
|
+
}
|
|
459
|
+
const url = new URL(baseUrl);
|
|
460
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
461
|
+
url.searchParams.append(key, value);
|
|
462
|
+
});
|
|
463
|
+
return url.toString();
|
|
464
|
+
}
|
|
@@ -16,7 +16,7 @@ export declare class X402ActionProvider extends ActionProvider<WalletProvider> {
|
|
|
16
16
|
* Discovers available x402 services with optional filtering.
|
|
17
17
|
*
|
|
18
18
|
* @param walletProvider - The wallet provider to use for network filtering
|
|
19
|
-
* @param args - Optional filters: maxUsdcPrice
|
|
19
|
+
* @param args - Optional filters: discoveryUrl, maxUsdcPrice
|
|
20
20
|
* @returns JSON string with the list of services (filtered by network and description)
|
|
21
21
|
*/
|
|
22
22
|
discoverX402Services(walletProvider: WalletProvider, args: z.infer<typeof ListX402ServicesSchema>): Promise<string>;
|
|
@@ -51,5 +51,19 @@ export declare class X402ActionProvider extends ActionProvider<WalletProvider> {
|
|
|
51
51
|
* @returns True if the network is supported, false otherwise
|
|
52
52
|
*/
|
|
53
53
|
supportsNetwork: (network: Network) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Creates an x402 client configured for the given wallet provider.
|
|
56
|
+
*
|
|
57
|
+
* @param walletProvider - The wallet provider to configure the client for
|
|
58
|
+
* @returns Configured x402Client
|
|
59
|
+
*/
|
|
60
|
+
private createX402Client;
|
|
61
|
+
/**
|
|
62
|
+
* Parses response data based on content type.
|
|
63
|
+
*
|
|
64
|
+
* @param response - The fetch Response object
|
|
65
|
+
* @returns Parsed response data
|
|
66
|
+
*/
|
|
67
|
+
private parseResponseData;
|
|
54
68
|
}
|
|
55
69
|
export declare const x402ActionProvider: () => X402ActionProvider;
|