@layr-labs/ecloud-sdk 0.2.0 → 0.2.1-dev

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.
@@ -0,0 +1,2990 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/browser.ts
31
+ var browser_exports = {};
32
+ __export(browser_exports, {
33
+ UserApiClient: () => UserApiClient,
34
+ assertValidImageReference: () => assertValidImageReference,
35
+ assertValidPrivateKey: () => assertValidPrivateKey,
36
+ encodeStartAppData: () => encodeStartAppData,
37
+ encodeStopAppData: () => encodeStopAppData,
38
+ encodeTerminateAppData: () => encodeTerminateAppData,
39
+ estimateBatchGas: () => estimateBatchGas,
40
+ estimateTransactionGas: () => estimateTransactionGas,
41
+ extractAppNameFromImage: () => extractAppNameFromImage,
42
+ formatETH: () => formatETH,
43
+ generateNewPrivateKey: () => generateNewPrivateKey,
44
+ getActiveAppCount: () => getActiveAppCount,
45
+ getAllAppsByDeveloper: () => getAllAppsByDeveloper,
46
+ getAppsByCreator: () => getAppsByCreator,
47
+ getAppsByDeveloper: () => getAppsByDeveloper,
48
+ getAvailableEnvironments: () => getAvailableEnvironments,
49
+ getBuildType: () => getBuildType,
50
+ getEnvironmentConfig: () => getEnvironmentConfig,
51
+ getMaxActiveAppsPerUser: () => getMaxActiveAppsPerUser,
52
+ isEnvironmentAvailable: () => isEnvironmentAvailable,
53
+ isMainnet: () => isMainnet,
54
+ isSubscriptionActive: () => isSubscriptionActive,
55
+ sanitizeString: () => sanitizeString,
56
+ sanitizeURL: () => sanitizeURL,
57
+ sanitizeXURL: () => sanitizeXURL,
58
+ validateAppID: () => validateAppID,
59
+ validateAppName: () => validateAppName,
60
+ validateCreateAppParams: () => validateCreateAppParams,
61
+ validateDescription: () => validateDescription,
62
+ validateImageReference: () => validateImageReference,
63
+ validateInstanceTypeSKU: () => validateInstanceTypeSKU,
64
+ validateLogVisibility: () => validateLogVisibility,
65
+ validateLogsParams: () => validateLogsParams,
66
+ validatePrivateKeyFormat: () => validatePrivateKeyFormat,
67
+ validateURL: () => validateURL,
68
+ validateXURL: () => validateXURL
69
+ });
70
+ module.exports = __toCommonJS(browser_exports);
71
+
72
+ // src/client/common/config/environment.ts
73
+ var SEPOLIA_CHAIN_ID = 11155111;
74
+ var MAINNET_CHAIN_ID = 1;
75
+ var CommonAddresses = {
76
+ ERC7702Delegator: "0x63c0c19a282a1b52b07dd5a65b58948a07dae32b"
77
+ };
78
+ var ChainAddresses = {
79
+ [MAINNET_CHAIN_ID]: {
80
+ PermissionController: "0x25E5F8B1E7aDf44518d35D5B2271f114e081f0E5"
81
+ },
82
+ [SEPOLIA_CHAIN_ID]: {
83
+ PermissionController: "0x44632dfBdCb6D3E21EF613B0ca8A6A0c618F5a37"
84
+ }
85
+ };
86
+ var ENVIRONMENTS = {
87
+ "sepolia-dev": {
88
+ name: "sepolia",
89
+ build: "dev",
90
+ appControllerAddress: "0xa86DC1C47cb2518327fB4f9A1627F51966c83B92",
91
+ permissionControllerAddress: ChainAddresses[SEPOLIA_CHAIN_ID].PermissionController,
92
+ erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
93
+ kmsServerURL: "http://10.128.0.57:8080",
94
+ userApiServerURL: "https://userapi-compute-sepolia-dev.eigencloud.xyz",
95
+ defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com"
96
+ },
97
+ sepolia: {
98
+ name: "sepolia",
99
+ build: "prod",
100
+ appControllerAddress: "0x0dd810a6ffba6a9820a10d97b659f07d8d23d4E2",
101
+ permissionControllerAddress: ChainAddresses[SEPOLIA_CHAIN_ID].PermissionController,
102
+ erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
103
+ kmsServerURL: "http://10.128.15.203:8080",
104
+ userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
105
+ defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com"
106
+ },
107
+ "mainnet-alpha": {
108
+ name: "mainnet-alpha",
109
+ build: "prod",
110
+ appControllerAddress: "0xc38d35Fc995e75342A21CBd6D770305b142Fbe67",
111
+ permissionControllerAddress: ChainAddresses[MAINNET_CHAIN_ID].PermissionController,
112
+ erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
113
+ kmsServerURL: "http://10.128.0.2:8080",
114
+ userApiServerURL: "https://userapi-compute.eigencloud.xyz",
115
+ defaultRPCURL: "https://ethereum-rpc.publicnode.com"
116
+ }
117
+ };
118
+ var CHAIN_ID_TO_ENVIRONMENT = {
119
+ [SEPOLIA_CHAIN_ID.toString()]: "sepolia",
120
+ [MAINNET_CHAIN_ID.toString()]: "mainnet-alpha"
121
+ };
122
+ function getEnvironmentConfig(environment, chainID) {
123
+ const env = ENVIRONMENTS[environment];
124
+ if (!env) {
125
+ throw new Error(`Unknown environment: ${environment}`);
126
+ }
127
+ if (!isEnvironmentAvailable(environment)) {
128
+ throw new Error(
129
+ `Environment ${environment} is not available in this build type. Available environments: ${getAvailableEnvironments().join(", ")}`
130
+ );
131
+ }
132
+ if (chainID) {
133
+ const expectedEnv = CHAIN_ID_TO_ENVIRONMENT[chainID.toString()];
134
+ if (expectedEnv && expectedEnv !== environment) {
135
+ throw new Error(`Environment ${environment} does not match chain ID ${chainID}`);
136
+ }
137
+ }
138
+ const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
139
+ return {
140
+ ...env,
141
+ chainID: BigInt(resolvedChainID)
142
+ };
143
+ }
144
+ function getBuildType() {
145
+ const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
146
+ const runtimeType = process.env.BUILD_TYPE?.toLowerCase();
147
+ const buildType = buildTimeType || runtimeType;
148
+ if (buildType === "dev") {
149
+ return "dev";
150
+ }
151
+ return "prod";
152
+ }
153
+ function getAvailableEnvironments() {
154
+ const buildType = getBuildType();
155
+ if (buildType === "dev") {
156
+ return ["sepolia-dev"];
157
+ }
158
+ return ["sepolia", "mainnet-alpha"];
159
+ }
160
+ function isEnvironmentAvailable(environment) {
161
+ return getAvailableEnvironments().includes(environment);
162
+ }
163
+ function isMainnet(environmentConfig) {
164
+ return environmentConfig.chainID === BigInt(MAINNET_CHAIN_ID);
165
+ }
166
+
167
+ // src/client/common/utils/validation.ts
168
+ var import_viem2 = require("viem");
169
+
170
+ // src/client/common/utils/helpers.ts
171
+ var import_viem = require("viem");
172
+ var import_chains2 = require("viem/chains");
173
+ var import_accounts = require("viem/accounts");
174
+
175
+ // src/client/common/constants.ts
176
+ var import_chains = require("viem/chains");
177
+
178
+ // src/client/common/utils/helpers.ts
179
+ function addHexPrefix(value) {
180
+ return value.startsWith("0x") ? value : `0x${value}`;
181
+ }
182
+ function stripHexPrefix(value) {
183
+ return value.startsWith("0x") ? value.slice(2) : value;
184
+ }
185
+
186
+ // src/client/common/utils/validation.ts
187
+ function validateAppName(name) {
188
+ if (!name) {
189
+ throw new Error("App name cannot be empty");
190
+ }
191
+ if (name.includes(" ")) {
192
+ throw new Error("App name cannot contain spaces");
193
+ }
194
+ if (name.length > 50) {
195
+ throw new Error("App name cannot be longer than 50 characters");
196
+ }
197
+ }
198
+ function validateImageReference(value) {
199
+ if (!value) {
200
+ return "Image reference cannot be empty";
201
+ }
202
+ if (!value.includes("/")) {
203
+ return "Image reference must contain at least one /";
204
+ }
205
+ return true;
206
+ }
207
+ function assertValidImageReference(value) {
208
+ const result = validateImageReference(value);
209
+ if (result !== true) {
210
+ throw new Error(result);
211
+ }
212
+ }
213
+ function extractAppNameFromImage(imageRef) {
214
+ const parts = imageRef.split("/");
215
+ let imageName = parts.length > 1 ? parts[parts.length - 1] : imageRef;
216
+ if (imageName.includes(":")) {
217
+ imageName = imageName.split(":")[0];
218
+ }
219
+ return imageName;
220
+ }
221
+ function validateInstanceTypeSKU(sku, availableTypes) {
222
+ if (!sku) {
223
+ throw new Error("Instance type SKU cannot be empty");
224
+ }
225
+ for (const it of availableTypes) {
226
+ if (it.sku === sku) {
227
+ return sku;
228
+ }
229
+ }
230
+ const validSKUs = availableTypes.map((it) => it.sku).join(", ");
231
+ throw new Error(`Invalid instance-type value: ${sku} (must be one of: ${validSKUs})`);
232
+ }
233
+ function validatePrivateKeyFormat(key) {
234
+ const keyWithoutPrefix = stripHexPrefix(key);
235
+ if (!/^[0-9a-fA-F]{64}$/.test(keyWithoutPrefix)) {
236
+ return false;
237
+ }
238
+ return true;
239
+ }
240
+ function assertValidPrivateKey(key) {
241
+ if (!key) {
242
+ throw new Error("Private key is required");
243
+ }
244
+ if (!validatePrivateKeyFormat(key)) {
245
+ throw new Error(
246
+ "Invalid private key format (must be 64 hex characters, optionally prefixed with 0x)"
247
+ );
248
+ }
249
+ }
250
+ function validateURL(rawURL) {
251
+ if (!rawURL.trim()) {
252
+ return "URL cannot be empty";
253
+ }
254
+ try {
255
+ const url = new URL(rawURL);
256
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
257
+ return "URL scheme must be http or https";
258
+ }
259
+ } catch {
260
+ return "Invalid URL format";
261
+ }
262
+ return void 0;
263
+ }
264
+ var VALID_X_HOSTS = ["twitter.com", "www.twitter.com", "x.com", "www.x.com"];
265
+ function validateXURL(rawURL) {
266
+ const urlErr = validateURL(rawURL);
267
+ if (urlErr) {
268
+ return urlErr;
269
+ }
270
+ try {
271
+ const url = new URL(rawURL);
272
+ const host = url.hostname.toLowerCase();
273
+ if (!VALID_X_HOSTS.includes(host)) {
274
+ return "URL must be a valid X/Twitter URL (x.com or twitter.com)";
275
+ }
276
+ if (!url.pathname || url.pathname === "/") {
277
+ return "X URL must include a username or profile path";
278
+ }
279
+ } catch {
280
+ return "Invalid X URL format";
281
+ }
282
+ return void 0;
283
+ }
284
+ var MAX_DESCRIPTION_LENGTH = 1e3;
285
+ function validateDescription(description) {
286
+ if (!description.trim()) {
287
+ return "Description cannot be empty";
288
+ }
289
+ if (description.length > MAX_DESCRIPTION_LENGTH) {
290
+ return `Description cannot exceed ${MAX_DESCRIPTION_LENGTH} characters`;
291
+ }
292
+ return void 0;
293
+ }
294
+ var MAX_IMAGE_SIZE = 4 * 1024 * 1024;
295
+ function validateAppID(appID) {
296
+ if (!appID) {
297
+ throw new Error("App ID is required");
298
+ }
299
+ const normalized = typeof appID === "string" ? addHexPrefix(appID) : appID;
300
+ if ((0, import_viem2.isAddress)(normalized)) {
301
+ return normalized;
302
+ }
303
+ throw new Error(`Invalid app ID: '${appID}' is not a valid address`);
304
+ }
305
+ function validateLogVisibility(logVisibility) {
306
+ switch (logVisibility) {
307
+ case "public":
308
+ return { logRedirect: "always", publicLogs: true };
309
+ case "private":
310
+ return { logRedirect: "always", publicLogs: false };
311
+ case "off":
312
+ return { logRedirect: "", publicLogs: false };
313
+ default:
314
+ throw new Error(
315
+ `Invalid log-visibility value: ${logVisibility} (must be public, private, or off)`
316
+ );
317
+ }
318
+ }
319
+ function hasScheme(rawURL) {
320
+ return rawURL.startsWith("http://") || rawURL.startsWith("https://");
321
+ }
322
+ function sanitizeString(s) {
323
+ return s.trim().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
324
+ }
325
+ function sanitizeURL(rawURL) {
326
+ rawURL = rawURL.trim();
327
+ if (!hasScheme(rawURL)) {
328
+ rawURL = "https://" + rawURL;
329
+ }
330
+ const err = validateURL(rawURL);
331
+ if (err) {
332
+ throw new Error(err);
333
+ }
334
+ return rawURL;
335
+ }
336
+ function sanitizeXURL(rawURL) {
337
+ rawURL = rawURL.trim();
338
+ if (!rawURL.includes("://") && !rawURL.includes(".")) {
339
+ const username = rawURL.startsWith("@") ? rawURL.slice(1) : rawURL;
340
+ rawURL = `https://x.com/${username}`;
341
+ } else if (!hasScheme(rawURL)) {
342
+ rawURL = "https://" + rawURL;
343
+ }
344
+ rawURL = rawURL.replace(/twitter\.com/g, "x.com");
345
+ rawURL = rawURL.replace(/www\.x\.com/g, "x.com");
346
+ const err = validateXURL(rawURL);
347
+ if (err) {
348
+ throw new Error(err);
349
+ }
350
+ return rawURL;
351
+ }
352
+ function validateCreateAppParams(params) {
353
+ if (!params.name) {
354
+ throw new Error("Project name is required");
355
+ }
356
+ if (params.name.includes(" ")) {
357
+ throw new Error("Project name cannot contain spaces");
358
+ }
359
+ if (!params.language) {
360
+ throw new Error("Language is required");
361
+ }
362
+ }
363
+ function validateLogsParams(params) {
364
+ if (!params.appID) {
365
+ throw new Error("App ID is required for viewing logs");
366
+ }
367
+ validateAppID(params.appID);
368
+ }
369
+
370
+ // src/client/common/utils/billing.ts
371
+ function isSubscriptionActive(status) {
372
+ return status === "active" || status === "trialing";
373
+ }
374
+
375
+ // src/client/common/auth/generate.ts
376
+ var import_accounts2 = require("viem/accounts");
377
+ function generateNewPrivateKey() {
378
+ const privateKey = (0, import_accounts2.generatePrivateKey)();
379
+ const address = (0, import_accounts2.privateKeyToAddress)(privateKey);
380
+ return {
381
+ privateKey,
382
+ address
383
+ };
384
+ }
385
+
386
+ // src/client/common/utils/userapi.ts
387
+ var import_axios = __toESM(require("axios"), 1);
388
+
389
+ // src/client/common/utils/auth.ts
390
+ var import_viem3 = require("viem");
391
+ var APP_CONTROLLER_ABI = (0, import_viem3.parseAbi)([
392
+ "function calculateApiPermissionDigestHash(bytes4 permission, uint256 expiry) view returns (bytes32)"
393
+ ]);
394
+ async function calculatePermissionSignature(options) {
395
+ const { permission, expiry, appControllerAddress, publicClient, walletClient } = options;
396
+ const digest = await publicClient.readContract({
397
+ address: appControllerAddress,
398
+ abi: APP_CONTROLLER_ABI,
399
+ functionName: "calculateApiPermissionDigestHash",
400
+ args: [permission, expiry]
401
+ });
402
+ const account = walletClient.account;
403
+ if (!account) {
404
+ throw new Error("WalletClient must have an account attached");
405
+ }
406
+ const signature = await walletClient.signMessage({
407
+ account,
408
+ message: { raw: digest }
409
+ });
410
+ return { signature, digest };
411
+ }
412
+
413
+ // src/client/common/utils/userapi.ts
414
+ function isJsonObject(value) {
415
+ return typeof value === "object" && value !== null && !Array.isArray(value);
416
+ }
417
+ function readString(obj, key) {
418
+ const v = obj[key];
419
+ return typeof v === "string" ? v : void 0;
420
+ }
421
+ function readNumber(obj, key) {
422
+ const v = obj[key];
423
+ return typeof v === "number" && Number.isFinite(v) ? v : void 0;
424
+ }
425
+ var MAX_ADDRESS_COUNT = 5;
426
+ var CanViewAppLogsPermission = "0x2fd3f2fe";
427
+ var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
428
+ var CanUpdateAppProfilePermission = "0x036fef61";
429
+ function getDefaultClientId() {
430
+ const version = true ? "0.2.1-dev" : "0.0.0";
431
+ return `ecloud-sdk/v${version}`;
432
+ }
433
+ var UserApiClient = class {
434
+ constructor(config, walletClient, publicClient, clientId) {
435
+ this.config = config;
436
+ this.walletClient = walletClient;
437
+ this.publicClient = publicClient;
438
+ this.clientId = clientId || getDefaultClientId();
439
+ }
440
+ /**
441
+ * Get the address of the connected wallet
442
+ */
443
+ get address() {
444
+ const account = this.walletClient.account;
445
+ if (!account) {
446
+ throw new Error("WalletClient must have an account attached");
447
+ }
448
+ return account.address;
449
+ }
450
+ async getInfos(appIDs, addressCount = 1) {
451
+ const count = Math.min(addressCount, MAX_ADDRESS_COUNT);
452
+ const endpoint = `${this.config.userApiServerURL}/info`;
453
+ const url = `${endpoint}?${new URLSearchParams({ apps: appIDs.join(",") })}`;
454
+ const res = await this.makeAuthenticatedRequest(url, CanViewSensitiveAppInfoPermission);
455
+ const result = await res.json();
456
+ return result.apps.map((app, i) => {
457
+ const evmAddresses = app.addresses?.data?.evmAddresses?.slice(0, count) || [];
458
+ const solanaAddresses = app.addresses?.data?.solanaAddresses?.slice(0, count) || [];
459
+ return {
460
+ address: appIDs[i],
461
+ status: app.app_status,
462
+ ip: app.ip,
463
+ machineType: app.machine_type,
464
+ profile: app.profile,
465
+ metrics: app.metrics,
466
+ evmAddresses,
467
+ solanaAddresses
468
+ };
469
+ });
470
+ }
471
+ /**
472
+ * Get app details from UserAPI (includes releases and build/provenance info when available).
473
+ *
474
+ * Endpoint: GET /apps/:appAddress
475
+ */
476
+ async getApp(appAddress) {
477
+ const endpoint = `${this.config.userApiServerURL}/apps/${appAddress}`;
478
+ const res = await this.makeAuthenticatedRequest(endpoint);
479
+ const raw = await res.json();
480
+ if (!isJsonObject(raw)) {
481
+ throw new Error("Unexpected /apps/:id response: expected object");
482
+ }
483
+ const id = readString(raw, "id");
484
+ if (!id) {
485
+ throw new Error("Unexpected /apps/:id response: missing 'id'");
486
+ }
487
+ const releasesRaw = raw.releases;
488
+ const releases = Array.isArray(releasesRaw) ? releasesRaw.map((r) => transformAppRelease(r)).filter((r) => !!r) : [];
489
+ return {
490
+ id,
491
+ creator: readString(raw, "creator"),
492
+ contractStatus: readString(raw, "contract_status") ?? readString(raw, "contractStatus"),
493
+ releases
494
+ };
495
+ }
496
+ /**
497
+ * Get available SKUs (instance types) from UserAPI
498
+ */
499
+ async getSKUs() {
500
+ const endpoint = `${this.config.userApiServerURL}/skus`;
501
+ const response = await this.makeAuthenticatedRequest(endpoint);
502
+ const result = await response.json();
503
+ return {
504
+ skus: result.skus || result.SKUs || []
505
+ };
506
+ }
507
+ /**
508
+ * Get logs for an app
509
+ */
510
+ async getLogs(appID) {
511
+ const endpoint = `${this.config.userApiServerURL}/logs/${appID}`;
512
+ const response = await this.makeAuthenticatedRequest(endpoint, CanViewAppLogsPermission);
513
+ return await response.text();
514
+ }
515
+ /**
516
+ * Get statuses for apps
517
+ */
518
+ async getStatuses(appIDs) {
519
+ const endpoint = `${this.config.userApiServerURL}/status`;
520
+ const url = `${endpoint}?${new URLSearchParams({ apps: appIDs.join(",") })}`;
521
+ const response = await this.makeAuthenticatedRequest(url);
522
+ const result = await response.json();
523
+ const apps = result.apps || result.Apps || [];
524
+ return apps.map((app, i) => ({
525
+ address: app.address || appIDs[i],
526
+ status: app.status || app.Status || ""
527
+ }));
528
+ }
529
+ /**
530
+ * Upload app profile information with optional image
531
+ *
532
+ * @param appAddress - The app's contract address
533
+ * @param name - Display name for the app
534
+ * @param options - Optional fields including website, description, xURL, and image
535
+ * @param options.image - Image file as Blob or File (browser: from input element, Node.js: new Blob([buffer]))
536
+ * @param options.imageName - Filename for the image (required if image is provided)
537
+ */
538
+ async uploadAppProfile(appAddress, name, options) {
539
+ const endpoint = `${this.config.userApiServerURL}/apps/${appAddress}/profile`;
540
+ const formData = new FormData();
541
+ formData.append("name", name);
542
+ if (options?.website) {
543
+ formData.append("website", options.website);
544
+ }
545
+ if (options?.description) {
546
+ formData.append("description", options.description);
547
+ }
548
+ if (options?.xURL) {
549
+ formData.append("xURL", options.xURL);
550
+ }
551
+ if (options?.image) {
552
+ const fileName = options.image instanceof File ? options.image.name : options.imageName || "image";
553
+ formData.append("image", options.image, fileName);
554
+ }
555
+ const headers = {
556
+ "x-client-id": this.clientId
557
+ };
558
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
559
+ const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
560
+ Object.assign(headers, authHeaders);
561
+ try {
562
+ const response = await import_axios.default.post(endpoint, formData, {
563
+ headers,
564
+ maxRedirects: 0,
565
+ validateStatus: () => true,
566
+ // Don't throw on any status
567
+ maxContentLength: Infinity,
568
+ // Allow large file uploads
569
+ maxBodyLength: Infinity
570
+ // Allow large file uploads
571
+ });
572
+ const status = response.status;
573
+ if (status !== 200 && status !== 201) {
574
+ const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
575
+ if (status === 403 && body.includes("Cloudflare") && body.includes("challenge-platform")) {
576
+ throw new Error(
577
+ `Cloudflare protection is blocking the request. This is likely due to bot detection.
578
+ Status: ${status}`
579
+ );
580
+ }
581
+ throw new Error(
582
+ `UserAPI request failed: ${status} ${status >= 200 && status < 300 ? "OK" : "Error"} - ${body.substring(0, 500)}${body.length > 500 ? "..." : ""}`
583
+ );
584
+ }
585
+ return response.data;
586
+ } catch (error) {
587
+ if (error.message?.includes("fetch failed") || error.message?.includes("ECONNREFUSED") || error.message?.includes("ENOTFOUND") || error.cause) {
588
+ const cause = error.cause?.message || error.cause || error.message;
589
+ throw new Error(
590
+ `Failed to connect to UserAPI at ${endpoint}: ${cause}
591
+ Please check:
592
+ 1. Your internet connection
593
+ 2. The API server is accessible: ${this.config.userApiServerURL}
594
+ 3. Firewall/proxy settings`
595
+ );
596
+ }
597
+ throw error;
598
+ }
599
+ }
600
+ async makeAuthenticatedRequest(url, permission) {
601
+ const headers = {
602
+ "x-client-id": this.clientId
603
+ };
604
+ if (permission) {
605
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
606
+ const authHeaders = await this.generateAuthHeaders(permission, expiry);
607
+ Object.assign(headers, authHeaders);
608
+ }
609
+ try {
610
+ const response = await import_axios.default.get(url, {
611
+ headers,
612
+ maxRedirects: 0,
613
+ validateStatus: () => true
614
+ // Don't throw on any status
615
+ });
616
+ const status = response.status;
617
+ const statusText = status >= 200 && status < 300 ? "OK" : "Error";
618
+ if (status < 200 || status >= 300) {
619
+ const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
620
+ throw new Error(`UserAPI request failed: ${status} ${statusText} - ${body}`);
621
+ }
622
+ return {
623
+ json: async () => response.data,
624
+ text: async () => typeof response.data === "string" ? response.data : JSON.stringify(response.data)
625
+ };
626
+ } catch (error) {
627
+ if (error.message?.includes("fetch failed") || error.message?.includes("ECONNREFUSED") || error.message?.includes("ENOTFOUND") || error.cause) {
628
+ const cause = error.cause?.message || error.cause || error.message;
629
+ throw new Error(
630
+ `Failed to connect to UserAPI at ${url}: ${cause}
631
+ Please check:
632
+ 1. Your internet connection
633
+ 2. The API server is accessible: ${this.config.userApiServerURL}
634
+ 3. Firewall/proxy settings`
635
+ );
636
+ }
637
+ throw error;
638
+ }
639
+ }
640
+ /**
641
+ * Generate authentication headers for UserAPI requests
642
+ */
643
+ async generateAuthHeaders(permission, expiry) {
644
+ const { signature } = await calculatePermissionSignature({
645
+ permission,
646
+ expiry,
647
+ appControllerAddress: this.config.appControllerAddress,
648
+ publicClient: this.publicClient,
649
+ walletClient: this.walletClient
650
+ });
651
+ return {
652
+ Authorization: `Bearer ${stripHexPrefix(signature)}`,
653
+ "X-eigenx-expiry": expiry.toString()
654
+ };
655
+ }
656
+ };
657
+ function transformAppReleaseBuild(raw) {
658
+ if (!isJsonObject(raw)) return void 0;
659
+ const depsRaw = raw.dependencies;
660
+ const deps = isJsonObject(depsRaw) ? Object.fromEntries(
661
+ Object.entries(depsRaw).flatMap(([digest, depRaw]) => {
662
+ const parsed = transformAppReleaseBuild(depRaw);
663
+ return parsed ? [[digest, parsed]] : [];
664
+ })
665
+ ) : void 0;
666
+ return {
667
+ buildId: readString(raw, "build_id") ?? readString(raw, "buildId"),
668
+ billingAddress: readString(raw, "billing_address") ?? readString(raw, "billingAddress"),
669
+ repoUrl: readString(raw, "repo_url") ?? readString(raw, "repoUrl"),
670
+ gitRef: readString(raw, "git_ref") ?? readString(raw, "gitRef"),
671
+ status: readString(raw, "status"),
672
+ buildType: readString(raw, "build_type") ?? readString(raw, "buildType"),
673
+ imageName: readString(raw, "image_name") ?? readString(raw, "imageName"),
674
+ imageDigest: readString(raw, "image_digest") ?? readString(raw, "imageDigest"),
675
+ imageUrl: readString(raw, "image_url") ?? readString(raw, "imageUrl"),
676
+ provenanceJson: raw.provenance_json ?? raw.provenanceJson,
677
+ provenanceSignature: readString(raw, "provenance_signature") ?? readString(raw, "provenanceSignature"),
678
+ createdAt: readString(raw, "created_at") ?? readString(raw, "createdAt"),
679
+ updatedAt: readString(raw, "updated_at") ?? readString(raw, "updatedAt"),
680
+ errorMessage: readString(raw, "error_message") ?? readString(raw, "errorMessage"),
681
+ dependencies: deps
682
+ };
683
+ }
684
+ function transformAppRelease(raw) {
685
+ if (!isJsonObject(raw)) return void 0;
686
+ return {
687
+ appId: readString(raw, "appId") ?? readString(raw, "app_id"),
688
+ rmsReleaseId: readString(raw, "rmsReleaseId") ?? readString(raw, "rms_release_id"),
689
+ imageDigest: readString(raw, "imageDigest") ?? readString(raw, "image_digest"),
690
+ registryUrl: readString(raw, "registryUrl") ?? readString(raw, "registry_url"),
691
+ publicEnv: readString(raw, "publicEnv") ?? readString(raw, "public_env"),
692
+ encryptedEnv: readString(raw, "encryptedEnv") ?? readString(raw, "encrypted_env"),
693
+ upgradeByTime: readNumber(raw, "upgradeByTime") ?? readNumber(raw, "upgrade_by_time"),
694
+ createdAt: readString(raw, "createdAt") ?? readString(raw, "created_at"),
695
+ createdAtBlock: readString(raw, "createdAtBlock") ?? readString(raw, "created_at_block"),
696
+ build: raw.build ? transformAppReleaseBuild(raw.build) : void 0
697
+ };
698
+ }
699
+
700
+ // src/client/common/contract/eip7702.ts
701
+ var import_viem4 = require("viem");
702
+
703
+ // src/client/common/abis/ERC7702Delegator.json
704
+ var ERC7702Delegator_default = [
705
+ {
706
+ type: "constructor",
707
+ inputs: [
708
+ {
709
+ name: "_delegationManager",
710
+ type: "address",
711
+ internalType: "contractIDelegationManager"
712
+ },
713
+ {
714
+ name: "_entryPoint",
715
+ type: "address",
716
+ internalType: "contractIEntryPoint"
717
+ }
718
+ ],
719
+ stateMutability: "nonpayable"
720
+ },
721
+ {
722
+ type: "receive",
723
+ stateMutability: "payable"
724
+ },
725
+ {
726
+ type: "function",
727
+ name: "DOMAIN_VERSION",
728
+ inputs: [],
729
+ outputs: [
730
+ {
731
+ name: "",
732
+ type: "string",
733
+ internalType: "string"
734
+ }
735
+ ],
736
+ stateMutability: "view"
737
+ },
738
+ {
739
+ type: "function",
740
+ name: "NAME",
741
+ inputs: [],
742
+ outputs: [
743
+ {
744
+ name: "",
745
+ type: "string",
746
+ internalType: "string"
747
+ }
748
+ ],
749
+ stateMutability: "view"
750
+ },
751
+ {
752
+ type: "function",
753
+ name: "PACKED_USER_OP_TYPEHASH",
754
+ inputs: [],
755
+ outputs: [
756
+ {
757
+ name: "",
758
+ type: "bytes32",
759
+ internalType: "bytes32"
760
+ }
761
+ ],
762
+ stateMutability: "view"
763
+ },
764
+ {
765
+ type: "function",
766
+ name: "VERSION",
767
+ inputs: [],
768
+ outputs: [
769
+ {
770
+ name: "",
771
+ type: "string",
772
+ internalType: "string"
773
+ }
774
+ ],
775
+ stateMutability: "view"
776
+ },
777
+ {
778
+ type: "function",
779
+ name: "addDeposit",
780
+ inputs: [],
781
+ outputs: [],
782
+ stateMutability: "payable"
783
+ },
784
+ {
785
+ type: "function",
786
+ name: "delegationManager",
787
+ inputs: [],
788
+ outputs: [
789
+ {
790
+ name: "",
791
+ type: "address",
792
+ internalType: "contractIDelegationManager"
793
+ }
794
+ ],
795
+ stateMutability: "view"
796
+ },
797
+ {
798
+ type: "function",
799
+ name: "disableDelegation",
800
+ inputs: [
801
+ {
802
+ name: "_delegation",
803
+ type: "tuple",
804
+ internalType: "structDelegation",
805
+ components: [
806
+ {
807
+ name: "delegate",
808
+ type: "address",
809
+ internalType: "address"
810
+ },
811
+ {
812
+ name: "delegator",
813
+ type: "address",
814
+ internalType: "address"
815
+ },
816
+ {
817
+ name: "authority",
818
+ type: "bytes32",
819
+ internalType: "bytes32"
820
+ },
821
+ {
822
+ name: "caveats",
823
+ type: "tuple[]",
824
+ internalType: "structCaveat[]",
825
+ components: [
826
+ {
827
+ name: "enforcer",
828
+ type: "address",
829
+ internalType: "address"
830
+ },
831
+ {
832
+ name: "terms",
833
+ type: "bytes",
834
+ internalType: "bytes"
835
+ },
836
+ {
837
+ name: "args",
838
+ type: "bytes",
839
+ internalType: "bytes"
840
+ }
841
+ ]
842
+ },
843
+ {
844
+ name: "salt",
845
+ type: "uint256",
846
+ internalType: "uint256"
847
+ },
848
+ {
849
+ name: "signature",
850
+ type: "bytes",
851
+ internalType: "bytes"
852
+ }
853
+ ]
854
+ }
855
+ ],
856
+ outputs: [],
857
+ stateMutability: "nonpayable"
858
+ },
859
+ {
860
+ type: "function",
861
+ name: "eip712Domain",
862
+ inputs: [],
863
+ outputs: [
864
+ {
865
+ name: "fields",
866
+ type: "bytes1",
867
+ internalType: "bytes1"
868
+ },
869
+ {
870
+ name: "name",
871
+ type: "string",
872
+ internalType: "string"
873
+ },
874
+ {
875
+ name: "version",
876
+ type: "string",
877
+ internalType: "string"
878
+ },
879
+ {
880
+ name: "chainId",
881
+ type: "uint256",
882
+ internalType: "uint256"
883
+ },
884
+ {
885
+ name: "verifyingContract",
886
+ type: "address",
887
+ internalType: "address"
888
+ },
889
+ {
890
+ name: "salt",
891
+ type: "bytes32",
892
+ internalType: "bytes32"
893
+ },
894
+ {
895
+ name: "extensions",
896
+ type: "uint256[]",
897
+ internalType: "uint256[]"
898
+ }
899
+ ],
900
+ stateMutability: "view"
901
+ },
902
+ {
903
+ type: "function",
904
+ name: "enableDelegation",
905
+ inputs: [
906
+ {
907
+ name: "_delegation",
908
+ type: "tuple",
909
+ internalType: "structDelegation",
910
+ components: [
911
+ {
912
+ name: "delegate",
913
+ type: "address",
914
+ internalType: "address"
915
+ },
916
+ {
917
+ name: "delegator",
918
+ type: "address",
919
+ internalType: "address"
920
+ },
921
+ {
922
+ name: "authority",
923
+ type: "bytes32",
924
+ internalType: "bytes32"
925
+ },
926
+ {
927
+ name: "caveats",
928
+ type: "tuple[]",
929
+ internalType: "structCaveat[]",
930
+ components: [
931
+ {
932
+ name: "enforcer",
933
+ type: "address",
934
+ internalType: "address"
935
+ },
936
+ {
937
+ name: "terms",
938
+ type: "bytes",
939
+ internalType: "bytes"
940
+ },
941
+ {
942
+ name: "args",
943
+ type: "bytes",
944
+ internalType: "bytes"
945
+ }
946
+ ]
947
+ },
948
+ {
949
+ name: "salt",
950
+ type: "uint256",
951
+ internalType: "uint256"
952
+ },
953
+ {
954
+ name: "signature",
955
+ type: "bytes",
956
+ internalType: "bytes"
957
+ }
958
+ ]
959
+ }
960
+ ],
961
+ outputs: [],
962
+ stateMutability: "nonpayable"
963
+ },
964
+ {
965
+ type: "function",
966
+ name: "entryPoint",
967
+ inputs: [],
968
+ outputs: [
969
+ {
970
+ name: "",
971
+ type: "address",
972
+ internalType: "contractIEntryPoint"
973
+ }
974
+ ],
975
+ stateMutability: "view"
976
+ },
977
+ {
978
+ type: "function",
979
+ name: "execute",
980
+ inputs: [
981
+ {
982
+ name: "_execution",
983
+ type: "tuple",
984
+ internalType: "structExecution",
985
+ components: [
986
+ {
987
+ name: "target",
988
+ type: "address",
989
+ internalType: "address"
990
+ },
991
+ {
992
+ name: "value",
993
+ type: "uint256",
994
+ internalType: "uint256"
995
+ },
996
+ {
997
+ name: "callData",
998
+ type: "bytes",
999
+ internalType: "bytes"
1000
+ }
1001
+ ]
1002
+ }
1003
+ ],
1004
+ outputs: [],
1005
+ stateMutability: "payable"
1006
+ },
1007
+ {
1008
+ type: "function",
1009
+ name: "execute",
1010
+ inputs: [
1011
+ {
1012
+ name: "_mode",
1013
+ type: "bytes32",
1014
+ internalType: "ModeCode"
1015
+ },
1016
+ {
1017
+ name: "_executionCalldata",
1018
+ type: "bytes",
1019
+ internalType: "bytes"
1020
+ }
1021
+ ],
1022
+ outputs: [],
1023
+ stateMutability: "payable"
1024
+ },
1025
+ {
1026
+ type: "function",
1027
+ name: "executeFromExecutor",
1028
+ inputs: [
1029
+ {
1030
+ name: "_mode",
1031
+ type: "bytes32",
1032
+ internalType: "ModeCode"
1033
+ },
1034
+ {
1035
+ name: "_executionCalldata",
1036
+ type: "bytes",
1037
+ internalType: "bytes"
1038
+ }
1039
+ ],
1040
+ outputs: [
1041
+ {
1042
+ name: "returnData_",
1043
+ type: "bytes[]",
1044
+ internalType: "bytes[]"
1045
+ }
1046
+ ],
1047
+ stateMutability: "payable"
1048
+ },
1049
+ {
1050
+ type: "function",
1051
+ name: "getDeposit",
1052
+ inputs: [],
1053
+ outputs: [
1054
+ {
1055
+ name: "",
1056
+ type: "uint256",
1057
+ internalType: "uint256"
1058
+ }
1059
+ ],
1060
+ stateMutability: "view"
1061
+ },
1062
+ {
1063
+ type: "function",
1064
+ name: "getDomainHash",
1065
+ inputs: [],
1066
+ outputs: [
1067
+ {
1068
+ name: "",
1069
+ type: "bytes32",
1070
+ internalType: "bytes32"
1071
+ }
1072
+ ],
1073
+ stateMutability: "view"
1074
+ },
1075
+ {
1076
+ type: "function",
1077
+ name: "getNonce",
1078
+ inputs: [
1079
+ {
1080
+ name: "_key",
1081
+ type: "uint192",
1082
+ internalType: "uint192"
1083
+ }
1084
+ ],
1085
+ outputs: [
1086
+ {
1087
+ name: "",
1088
+ type: "uint256",
1089
+ internalType: "uint256"
1090
+ }
1091
+ ],
1092
+ stateMutability: "view"
1093
+ },
1094
+ {
1095
+ type: "function",
1096
+ name: "getNonce",
1097
+ inputs: [],
1098
+ outputs: [
1099
+ {
1100
+ name: "",
1101
+ type: "uint256",
1102
+ internalType: "uint256"
1103
+ }
1104
+ ],
1105
+ stateMutability: "view"
1106
+ },
1107
+ {
1108
+ type: "function",
1109
+ name: "getPackedUserOperationHash",
1110
+ inputs: [
1111
+ {
1112
+ name: "_userOp",
1113
+ type: "tuple",
1114
+ internalType: "structPackedUserOperation",
1115
+ components: [
1116
+ {
1117
+ name: "sender",
1118
+ type: "address",
1119
+ internalType: "address"
1120
+ },
1121
+ {
1122
+ name: "nonce",
1123
+ type: "uint256",
1124
+ internalType: "uint256"
1125
+ },
1126
+ {
1127
+ name: "initCode",
1128
+ type: "bytes",
1129
+ internalType: "bytes"
1130
+ },
1131
+ {
1132
+ name: "callData",
1133
+ type: "bytes",
1134
+ internalType: "bytes"
1135
+ },
1136
+ {
1137
+ name: "accountGasLimits",
1138
+ type: "bytes32",
1139
+ internalType: "bytes32"
1140
+ },
1141
+ {
1142
+ name: "preVerificationGas",
1143
+ type: "uint256",
1144
+ internalType: "uint256"
1145
+ },
1146
+ {
1147
+ name: "gasFees",
1148
+ type: "bytes32",
1149
+ internalType: "bytes32"
1150
+ },
1151
+ {
1152
+ name: "paymasterAndData",
1153
+ type: "bytes",
1154
+ internalType: "bytes"
1155
+ },
1156
+ {
1157
+ name: "signature",
1158
+ type: "bytes",
1159
+ internalType: "bytes"
1160
+ }
1161
+ ]
1162
+ }
1163
+ ],
1164
+ outputs: [
1165
+ {
1166
+ name: "",
1167
+ type: "bytes32",
1168
+ internalType: "bytes32"
1169
+ }
1170
+ ],
1171
+ stateMutability: "view"
1172
+ },
1173
+ {
1174
+ type: "function",
1175
+ name: "getPackedUserOperationTypedDataHash",
1176
+ inputs: [
1177
+ {
1178
+ name: "_userOp",
1179
+ type: "tuple",
1180
+ internalType: "structPackedUserOperation",
1181
+ components: [
1182
+ {
1183
+ name: "sender",
1184
+ type: "address",
1185
+ internalType: "address"
1186
+ },
1187
+ {
1188
+ name: "nonce",
1189
+ type: "uint256",
1190
+ internalType: "uint256"
1191
+ },
1192
+ {
1193
+ name: "initCode",
1194
+ type: "bytes",
1195
+ internalType: "bytes"
1196
+ },
1197
+ {
1198
+ name: "callData",
1199
+ type: "bytes",
1200
+ internalType: "bytes"
1201
+ },
1202
+ {
1203
+ name: "accountGasLimits",
1204
+ type: "bytes32",
1205
+ internalType: "bytes32"
1206
+ },
1207
+ {
1208
+ name: "preVerificationGas",
1209
+ type: "uint256",
1210
+ internalType: "uint256"
1211
+ },
1212
+ {
1213
+ name: "gasFees",
1214
+ type: "bytes32",
1215
+ internalType: "bytes32"
1216
+ },
1217
+ {
1218
+ name: "paymasterAndData",
1219
+ type: "bytes",
1220
+ internalType: "bytes"
1221
+ },
1222
+ {
1223
+ name: "signature",
1224
+ type: "bytes",
1225
+ internalType: "bytes"
1226
+ }
1227
+ ]
1228
+ }
1229
+ ],
1230
+ outputs: [
1231
+ {
1232
+ name: "",
1233
+ type: "bytes32",
1234
+ internalType: "bytes32"
1235
+ }
1236
+ ],
1237
+ stateMutability: "view"
1238
+ },
1239
+ {
1240
+ type: "function",
1241
+ name: "isDelegationDisabled",
1242
+ inputs: [
1243
+ {
1244
+ name: "_delegationHash",
1245
+ type: "bytes32",
1246
+ internalType: "bytes32"
1247
+ }
1248
+ ],
1249
+ outputs: [
1250
+ {
1251
+ name: "",
1252
+ type: "bool",
1253
+ internalType: "bool"
1254
+ }
1255
+ ],
1256
+ stateMutability: "view"
1257
+ },
1258
+ {
1259
+ type: "function",
1260
+ name: "isValidSignature",
1261
+ inputs: [
1262
+ {
1263
+ name: "_hash",
1264
+ type: "bytes32",
1265
+ internalType: "bytes32"
1266
+ },
1267
+ {
1268
+ name: "_signature",
1269
+ type: "bytes",
1270
+ internalType: "bytes"
1271
+ }
1272
+ ],
1273
+ outputs: [
1274
+ {
1275
+ name: "magicValue_",
1276
+ type: "bytes4",
1277
+ internalType: "bytes4"
1278
+ }
1279
+ ],
1280
+ stateMutability: "view"
1281
+ },
1282
+ {
1283
+ type: "function",
1284
+ name: "onERC1155BatchReceived",
1285
+ inputs: [
1286
+ {
1287
+ name: "",
1288
+ type: "address",
1289
+ internalType: "address"
1290
+ },
1291
+ {
1292
+ name: "",
1293
+ type: "address",
1294
+ internalType: "address"
1295
+ },
1296
+ {
1297
+ name: "",
1298
+ type: "uint256[]",
1299
+ internalType: "uint256[]"
1300
+ },
1301
+ {
1302
+ name: "",
1303
+ type: "uint256[]",
1304
+ internalType: "uint256[]"
1305
+ },
1306
+ {
1307
+ name: "",
1308
+ type: "bytes",
1309
+ internalType: "bytes"
1310
+ }
1311
+ ],
1312
+ outputs: [
1313
+ {
1314
+ name: "",
1315
+ type: "bytes4",
1316
+ internalType: "bytes4"
1317
+ }
1318
+ ],
1319
+ stateMutability: "view"
1320
+ },
1321
+ {
1322
+ type: "function",
1323
+ name: "onERC1155Received",
1324
+ inputs: [
1325
+ {
1326
+ name: "",
1327
+ type: "address",
1328
+ internalType: "address"
1329
+ },
1330
+ {
1331
+ name: "",
1332
+ type: "address",
1333
+ internalType: "address"
1334
+ },
1335
+ {
1336
+ name: "",
1337
+ type: "uint256",
1338
+ internalType: "uint256"
1339
+ },
1340
+ {
1341
+ name: "",
1342
+ type: "uint256",
1343
+ internalType: "uint256"
1344
+ },
1345
+ {
1346
+ name: "",
1347
+ type: "bytes",
1348
+ internalType: "bytes"
1349
+ }
1350
+ ],
1351
+ outputs: [
1352
+ {
1353
+ name: "",
1354
+ type: "bytes4",
1355
+ internalType: "bytes4"
1356
+ }
1357
+ ],
1358
+ stateMutability: "view"
1359
+ },
1360
+ {
1361
+ type: "function",
1362
+ name: "onERC721Received",
1363
+ inputs: [
1364
+ {
1365
+ name: "",
1366
+ type: "address",
1367
+ internalType: "address"
1368
+ },
1369
+ {
1370
+ name: "",
1371
+ type: "address",
1372
+ internalType: "address"
1373
+ },
1374
+ {
1375
+ name: "",
1376
+ type: "uint256",
1377
+ internalType: "uint256"
1378
+ },
1379
+ {
1380
+ name: "",
1381
+ type: "bytes",
1382
+ internalType: "bytes"
1383
+ }
1384
+ ],
1385
+ outputs: [
1386
+ {
1387
+ name: "",
1388
+ type: "bytes4",
1389
+ internalType: "bytes4"
1390
+ }
1391
+ ],
1392
+ stateMutability: "view"
1393
+ },
1394
+ {
1395
+ type: "function",
1396
+ name: "redeemDelegations",
1397
+ inputs: [
1398
+ {
1399
+ name: "_permissionContexts",
1400
+ type: "bytes[]",
1401
+ internalType: "bytes[]"
1402
+ },
1403
+ {
1404
+ name: "_modes",
1405
+ type: "bytes32[]",
1406
+ internalType: "ModeCode[]"
1407
+ },
1408
+ {
1409
+ name: "_executionCallDatas",
1410
+ type: "bytes[]",
1411
+ internalType: "bytes[]"
1412
+ }
1413
+ ],
1414
+ outputs: [],
1415
+ stateMutability: "nonpayable"
1416
+ },
1417
+ {
1418
+ type: "function",
1419
+ name: "supportsExecutionMode",
1420
+ inputs: [
1421
+ {
1422
+ name: "_mode",
1423
+ type: "bytes32",
1424
+ internalType: "ModeCode"
1425
+ }
1426
+ ],
1427
+ outputs: [
1428
+ {
1429
+ name: "",
1430
+ type: "bool",
1431
+ internalType: "bool"
1432
+ }
1433
+ ],
1434
+ stateMutability: "view"
1435
+ },
1436
+ {
1437
+ type: "function",
1438
+ name: "supportsInterface",
1439
+ inputs: [
1440
+ {
1441
+ name: "_interfaceId",
1442
+ type: "bytes4",
1443
+ internalType: "bytes4"
1444
+ }
1445
+ ],
1446
+ outputs: [
1447
+ {
1448
+ name: "",
1449
+ type: "bool",
1450
+ internalType: "bool"
1451
+ }
1452
+ ],
1453
+ stateMutability: "view"
1454
+ },
1455
+ {
1456
+ type: "function",
1457
+ name: "validateUserOp",
1458
+ inputs: [
1459
+ {
1460
+ name: "_userOp",
1461
+ type: "tuple",
1462
+ internalType: "structPackedUserOperation",
1463
+ components: [
1464
+ {
1465
+ name: "sender",
1466
+ type: "address",
1467
+ internalType: "address"
1468
+ },
1469
+ {
1470
+ name: "nonce",
1471
+ type: "uint256",
1472
+ internalType: "uint256"
1473
+ },
1474
+ {
1475
+ name: "initCode",
1476
+ type: "bytes",
1477
+ internalType: "bytes"
1478
+ },
1479
+ {
1480
+ name: "callData",
1481
+ type: "bytes",
1482
+ internalType: "bytes"
1483
+ },
1484
+ {
1485
+ name: "accountGasLimits",
1486
+ type: "bytes32",
1487
+ internalType: "bytes32"
1488
+ },
1489
+ {
1490
+ name: "preVerificationGas",
1491
+ type: "uint256",
1492
+ internalType: "uint256"
1493
+ },
1494
+ {
1495
+ name: "gasFees",
1496
+ type: "bytes32",
1497
+ internalType: "bytes32"
1498
+ },
1499
+ {
1500
+ name: "paymasterAndData",
1501
+ type: "bytes",
1502
+ internalType: "bytes"
1503
+ },
1504
+ {
1505
+ name: "signature",
1506
+ type: "bytes",
1507
+ internalType: "bytes"
1508
+ }
1509
+ ]
1510
+ },
1511
+ {
1512
+ name: "",
1513
+ type: "bytes32",
1514
+ internalType: "bytes32"
1515
+ },
1516
+ {
1517
+ name: "_missingAccountFunds",
1518
+ type: "uint256",
1519
+ internalType: "uint256"
1520
+ }
1521
+ ],
1522
+ outputs: [
1523
+ {
1524
+ name: "validationData_",
1525
+ type: "uint256",
1526
+ internalType: "uint256"
1527
+ }
1528
+ ],
1529
+ stateMutability: "nonpayable"
1530
+ },
1531
+ {
1532
+ type: "function",
1533
+ name: "withdrawDeposit",
1534
+ inputs: [
1535
+ {
1536
+ name: "_withdrawAddress",
1537
+ type: "address",
1538
+ internalType: "addresspayable"
1539
+ },
1540
+ {
1541
+ name: "_withdrawAmount",
1542
+ type: "uint256",
1543
+ internalType: "uint256"
1544
+ }
1545
+ ],
1546
+ outputs: [],
1547
+ stateMutability: "nonpayable"
1548
+ },
1549
+ {
1550
+ type: "event",
1551
+ name: "EIP712DomainChanged",
1552
+ inputs: [],
1553
+ anonymous: false
1554
+ },
1555
+ {
1556
+ type: "event",
1557
+ name: "SentPrefund",
1558
+ inputs: [
1559
+ {
1560
+ name: "sender",
1561
+ type: "address",
1562
+ indexed: true,
1563
+ internalType: "address"
1564
+ },
1565
+ {
1566
+ name: "amount",
1567
+ type: "uint256",
1568
+ indexed: false,
1569
+ internalType: "uint256"
1570
+ },
1571
+ {
1572
+ name: "success",
1573
+ type: "bool",
1574
+ indexed: false,
1575
+ internalType: "bool"
1576
+ }
1577
+ ],
1578
+ anonymous: false
1579
+ },
1580
+ {
1581
+ type: "event",
1582
+ name: "SetDelegationManager",
1583
+ inputs: [
1584
+ {
1585
+ name: "newDelegationManager",
1586
+ type: "address",
1587
+ indexed: true,
1588
+ internalType: "contractIDelegationManager"
1589
+ }
1590
+ ],
1591
+ anonymous: false
1592
+ },
1593
+ {
1594
+ type: "event",
1595
+ name: "SetEntryPoint",
1596
+ inputs: [
1597
+ {
1598
+ name: "entryPoint",
1599
+ type: "address",
1600
+ indexed: true,
1601
+ internalType: "contractIEntryPoint"
1602
+ }
1603
+ ],
1604
+ anonymous: false
1605
+ },
1606
+ {
1607
+ type: "event",
1608
+ name: "TryExecuteUnsuccessful",
1609
+ inputs: [
1610
+ {
1611
+ name: "batchExecutionindex",
1612
+ type: "uint256",
1613
+ indexed: false,
1614
+ internalType: "uint256"
1615
+ },
1616
+ {
1617
+ name: "result",
1618
+ type: "bytes",
1619
+ indexed: false,
1620
+ internalType: "bytes"
1621
+ }
1622
+ ],
1623
+ anonymous: false
1624
+ },
1625
+ {
1626
+ type: "error",
1627
+ name: "ECDSAInvalidSignature",
1628
+ inputs: []
1629
+ },
1630
+ {
1631
+ type: "error",
1632
+ name: "ECDSAInvalidSignatureLength",
1633
+ inputs: [
1634
+ {
1635
+ name: "length",
1636
+ type: "uint256",
1637
+ internalType: "uint256"
1638
+ }
1639
+ ]
1640
+ },
1641
+ {
1642
+ type: "error",
1643
+ name: "ECDSAInvalidSignatureS",
1644
+ inputs: [
1645
+ {
1646
+ name: "s",
1647
+ type: "bytes32",
1648
+ internalType: "bytes32"
1649
+ }
1650
+ ]
1651
+ },
1652
+ {
1653
+ type: "error",
1654
+ name: "ExecutionFailed",
1655
+ inputs: []
1656
+ },
1657
+ {
1658
+ type: "error",
1659
+ name: "InvalidEIP712NameLength",
1660
+ inputs: []
1661
+ },
1662
+ {
1663
+ type: "error",
1664
+ name: "InvalidEIP712VersionLength",
1665
+ inputs: []
1666
+ },
1667
+ {
1668
+ type: "error",
1669
+ name: "InvalidShortString",
1670
+ inputs: []
1671
+ },
1672
+ {
1673
+ type: "error",
1674
+ name: "NotDelegationManager",
1675
+ inputs: []
1676
+ },
1677
+ {
1678
+ type: "error",
1679
+ name: "NotEntryPoint",
1680
+ inputs: []
1681
+ },
1682
+ {
1683
+ type: "error",
1684
+ name: "NotEntryPointOrSelf",
1685
+ inputs: []
1686
+ },
1687
+ {
1688
+ type: "error",
1689
+ name: "NotSelf",
1690
+ inputs: []
1691
+ },
1692
+ {
1693
+ type: "error",
1694
+ name: "StringTooLong",
1695
+ inputs: [
1696
+ {
1697
+ name: "str",
1698
+ type: "string",
1699
+ internalType: "string"
1700
+ }
1701
+ ]
1702
+ },
1703
+ {
1704
+ type: "error",
1705
+ name: "UnauthorizedCallContext",
1706
+ inputs: []
1707
+ },
1708
+ {
1709
+ type: "error",
1710
+ name: "UnsupportedCallType",
1711
+ inputs: [
1712
+ {
1713
+ name: "callType",
1714
+ type: "bytes1",
1715
+ internalType: "CallType"
1716
+ }
1717
+ ]
1718
+ },
1719
+ {
1720
+ type: "error",
1721
+ name: "UnsupportedExecType",
1722
+ inputs: [
1723
+ {
1724
+ name: "execType",
1725
+ type: "bytes1",
1726
+ internalType: "ExecType"
1727
+ }
1728
+ ]
1729
+ }
1730
+ ];
1731
+
1732
+ // src/client/common/contract/eip7702.ts
1733
+ var EXECUTE_BATCH_MODE = "0x0100000000000000000000000000000000000000000000000000000000000000";
1734
+ var GAS_LIMIT_BUFFER_PERCENTAGE = 20n;
1735
+ var GAS_PRICE_BUFFER_PERCENTAGE = 100n;
1736
+ function encodeExecuteBatchData(executions) {
1737
+ const encodedExecutions = (0, import_viem4.encodeAbiParameters)(
1738
+ [
1739
+ {
1740
+ type: "tuple[]",
1741
+ components: [
1742
+ { name: "target", type: "address" },
1743
+ { name: "value", type: "uint256" },
1744
+ { name: "callData", type: "bytes" }
1745
+ ]
1746
+ }
1747
+ ],
1748
+ [executions]
1749
+ );
1750
+ return (0, import_viem4.encodeFunctionData)({
1751
+ abi: ERC7702Delegator_default,
1752
+ functionName: "execute",
1753
+ args: [EXECUTE_BATCH_MODE, encodedExecutions]
1754
+ });
1755
+ }
1756
+ async function estimateBatchGas(options) {
1757
+ const { publicClient, account, executions } = options;
1758
+ const executeBatchData = encodeExecuteBatchData(executions);
1759
+ const [gasTipCap, block, estimatedGas] = await Promise.all([
1760
+ publicClient.estimateMaxPriorityFeePerGas(),
1761
+ publicClient.getBlock(),
1762
+ publicClient.estimateGas({
1763
+ account,
1764
+ to: account,
1765
+ data: executeBatchData
1766
+ })
1767
+ ]);
1768
+ const baseFee = block.baseFeePerGas ?? 0n;
1769
+ const maxFeePerGas = (baseFee + gasTipCap) * (100n + GAS_PRICE_BUFFER_PERCENTAGE) / 100n;
1770
+ const gasLimit = estimatedGas * (100n + GAS_LIMIT_BUFFER_PERCENTAGE) / 100n;
1771
+ const maxCostWei = gasLimit * maxFeePerGas;
1772
+ return {
1773
+ gasLimit,
1774
+ maxFeePerGas,
1775
+ maxPriorityFeePerGas: gasTipCap,
1776
+ maxCostWei,
1777
+ maxCostEth: formatETH(maxCostWei)
1778
+ };
1779
+ }
1780
+
1781
+ // src/client/common/contract/caller.ts
1782
+ var import_viem5 = require("viem");
1783
+
1784
+ // src/client/common/abis/AppController.json
1785
+ var AppController_default = [
1786
+ {
1787
+ type: "constructor",
1788
+ inputs: [
1789
+ {
1790
+ name: "_version",
1791
+ type: "string",
1792
+ internalType: "string"
1793
+ },
1794
+ {
1795
+ name: "_permissionController",
1796
+ type: "address",
1797
+ internalType: "contractIPermissionController"
1798
+ },
1799
+ {
1800
+ name: "_releaseManager",
1801
+ type: "address",
1802
+ internalType: "contractIReleaseManager"
1803
+ },
1804
+ {
1805
+ name: "_computeAVSRegistrar",
1806
+ type: "address",
1807
+ internalType: "contractIComputeAVSRegistrar"
1808
+ },
1809
+ {
1810
+ name: "_computeOperator",
1811
+ type: "address",
1812
+ internalType: "contractIComputeOperator"
1813
+ },
1814
+ {
1815
+ name: "_appBeacon",
1816
+ type: "address",
1817
+ internalType: "contractIBeacon"
1818
+ }
1819
+ ],
1820
+ stateMutability: "nonpayable"
1821
+ },
1822
+ {
1823
+ type: "function",
1824
+ name: "API_PERMISSION_TYPEHASH",
1825
+ inputs: [],
1826
+ outputs: [
1827
+ {
1828
+ name: "",
1829
+ type: "bytes32",
1830
+ internalType: "bytes32"
1831
+ }
1832
+ ],
1833
+ stateMutability: "view"
1834
+ },
1835
+ {
1836
+ type: "function",
1837
+ name: "appBeacon",
1838
+ inputs: [],
1839
+ outputs: [
1840
+ {
1841
+ name: "",
1842
+ type: "address",
1843
+ internalType: "contractIBeacon"
1844
+ }
1845
+ ],
1846
+ stateMutability: "view"
1847
+ },
1848
+ {
1849
+ type: "function",
1850
+ name: "calculateApiPermissionDigestHash",
1851
+ inputs: [
1852
+ {
1853
+ name: "permission",
1854
+ type: "bytes4",
1855
+ internalType: "bytes4"
1856
+ },
1857
+ {
1858
+ name: "expiry",
1859
+ type: "uint256",
1860
+ internalType: "uint256"
1861
+ }
1862
+ ],
1863
+ outputs: [
1864
+ {
1865
+ name: "",
1866
+ type: "bytes32",
1867
+ internalType: "bytes32"
1868
+ }
1869
+ ],
1870
+ stateMutability: "view"
1871
+ },
1872
+ {
1873
+ type: "function",
1874
+ name: "calculateAppId",
1875
+ inputs: [
1876
+ {
1877
+ name: "deployer",
1878
+ type: "address",
1879
+ internalType: "address"
1880
+ },
1881
+ {
1882
+ name: "salt",
1883
+ type: "bytes32",
1884
+ internalType: "bytes32"
1885
+ }
1886
+ ],
1887
+ outputs: [
1888
+ {
1889
+ name: "",
1890
+ type: "address",
1891
+ internalType: "contractIApp"
1892
+ }
1893
+ ],
1894
+ stateMutability: "view"
1895
+ },
1896
+ {
1897
+ type: "function",
1898
+ name: "computeAVSRegistrar",
1899
+ inputs: [],
1900
+ outputs: [
1901
+ {
1902
+ name: "",
1903
+ type: "address",
1904
+ internalType: "contractIComputeAVSRegistrar"
1905
+ }
1906
+ ],
1907
+ stateMutability: "view"
1908
+ },
1909
+ {
1910
+ type: "function",
1911
+ name: "computeOperator",
1912
+ inputs: [],
1913
+ outputs: [
1914
+ {
1915
+ name: "",
1916
+ type: "address",
1917
+ internalType: "contractIComputeOperator"
1918
+ }
1919
+ ],
1920
+ stateMutability: "view"
1921
+ },
1922
+ {
1923
+ type: "function",
1924
+ name: "createApp",
1925
+ inputs: [
1926
+ {
1927
+ name: "salt",
1928
+ type: "bytes32",
1929
+ internalType: "bytes32"
1930
+ },
1931
+ {
1932
+ name: "release",
1933
+ type: "tuple",
1934
+ internalType: "structIAppController.Release",
1935
+ components: [
1936
+ {
1937
+ name: "rmsRelease",
1938
+ type: "tuple",
1939
+ internalType: "structIReleaseManagerTypes.Release",
1940
+ components: [
1941
+ {
1942
+ name: "artifacts",
1943
+ type: "tuple[]",
1944
+ internalType: "structIReleaseManagerTypes.Artifact[]",
1945
+ components: [
1946
+ {
1947
+ name: "digest",
1948
+ type: "bytes32",
1949
+ internalType: "bytes32"
1950
+ },
1951
+ {
1952
+ name: "registry",
1953
+ type: "string",
1954
+ internalType: "string"
1955
+ }
1956
+ ]
1957
+ },
1958
+ {
1959
+ name: "upgradeByTime",
1960
+ type: "uint32",
1961
+ internalType: "uint32"
1962
+ }
1963
+ ]
1964
+ },
1965
+ {
1966
+ name: "publicEnv",
1967
+ type: "bytes",
1968
+ internalType: "bytes"
1969
+ },
1970
+ {
1971
+ name: "encryptedEnv",
1972
+ type: "bytes",
1973
+ internalType: "bytes"
1974
+ }
1975
+ ]
1976
+ }
1977
+ ],
1978
+ outputs: [
1979
+ {
1980
+ name: "app",
1981
+ type: "address",
1982
+ internalType: "contractIApp"
1983
+ }
1984
+ ],
1985
+ stateMutability: "nonpayable"
1986
+ },
1987
+ {
1988
+ type: "function",
1989
+ name: "domainSeparator",
1990
+ inputs: [],
1991
+ outputs: [
1992
+ {
1993
+ name: "",
1994
+ type: "bytes32",
1995
+ internalType: "bytes32"
1996
+ }
1997
+ ],
1998
+ stateMutability: "view"
1999
+ },
2000
+ {
2001
+ type: "function",
2002
+ name: "getActiveAppCount",
2003
+ inputs: [
2004
+ {
2005
+ name: "user",
2006
+ type: "address",
2007
+ internalType: "address"
2008
+ }
2009
+ ],
2010
+ outputs: [
2011
+ {
2012
+ name: "",
2013
+ type: "uint32",
2014
+ internalType: "uint32"
2015
+ }
2016
+ ],
2017
+ stateMutability: "view"
2018
+ },
2019
+ {
2020
+ type: "function",
2021
+ name: "getAppCreator",
2022
+ inputs: [
2023
+ {
2024
+ name: "app",
2025
+ type: "address",
2026
+ internalType: "contractIApp"
2027
+ }
2028
+ ],
2029
+ outputs: [
2030
+ {
2031
+ name: "",
2032
+ type: "address",
2033
+ internalType: "address"
2034
+ }
2035
+ ],
2036
+ stateMutability: "view"
2037
+ },
2038
+ {
2039
+ type: "function",
2040
+ name: "getAppLatestReleaseBlockNumber",
2041
+ inputs: [
2042
+ {
2043
+ name: "app",
2044
+ type: "address",
2045
+ internalType: "contractIApp"
2046
+ }
2047
+ ],
2048
+ outputs: [
2049
+ {
2050
+ name: "",
2051
+ type: "uint32",
2052
+ internalType: "uint32"
2053
+ }
2054
+ ],
2055
+ stateMutability: "view"
2056
+ },
2057
+ {
2058
+ type: "function",
2059
+ name: "getAppOperatorSetId",
2060
+ inputs: [
2061
+ {
2062
+ name: "app",
2063
+ type: "address",
2064
+ internalType: "contractIApp"
2065
+ }
2066
+ ],
2067
+ outputs: [
2068
+ {
2069
+ name: "",
2070
+ type: "uint32",
2071
+ internalType: "uint32"
2072
+ }
2073
+ ],
2074
+ stateMutability: "view"
2075
+ },
2076
+ {
2077
+ type: "function",
2078
+ name: "getAppStatus",
2079
+ inputs: [
2080
+ {
2081
+ name: "app",
2082
+ type: "address",
2083
+ internalType: "contractIApp"
2084
+ }
2085
+ ],
2086
+ outputs: [
2087
+ {
2088
+ name: "",
2089
+ type: "uint8",
2090
+ internalType: "enumIAppController.AppStatus"
2091
+ }
2092
+ ],
2093
+ stateMutability: "view"
2094
+ },
2095
+ {
2096
+ type: "function",
2097
+ name: "getApps",
2098
+ inputs: [
2099
+ {
2100
+ name: "offset",
2101
+ type: "uint256",
2102
+ internalType: "uint256"
2103
+ },
2104
+ {
2105
+ name: "limit",
2106
+ type: "uint256",
2107
+ internalType: "uint256"
2108
+ }
2109
+ ],
2110
+ outputs: [
2111
+ {
2112
+ name: "apps",
2113
+ type: "address[]",
2114
+ internalType: "contractIApp[]"
2115
+ },
2116
+ {
2117
+ name: "appConfigsMem",
2118
+ type: "tuple[]",
2119
+ internalType: "structIAppController.AppConfig[]",
2120
+ components: [
2121
+ {
2122
+ name: "creator",
2123
+ type: "address",
2124
+ internalType: "address"
2125
+ },
2126
+ {
2127
+ name: "operatorSetId",
2128
+ type: "uint32",
2129
+ internalType: "uint32"
2130
+ },
2131
+ {
2132
+ name: "latestReleaseBlockNumber",
2133
+ type: "uint32",
2134
+ internalType: "uint32"
2135
+ },
2136
+ {
2137
+ name: "status",
2138
+ type: "uint8",
2139
+ internalType: "enumIAppController.AppStatus"
2140
+ }
2141
+ ]
2142
+ }
2143
+ ],
2144
+ stateMutability: "view"
2145
+ },
2146
+ {
2147
+ type: "function",
2148
+ name: "getAppsByCreator",
2149
+ inputs: [
2150
+ {
2151
+ name: "creator",
2152
+ type: "address",
2153
+ internalType: "address"
2154
+ },
2155
+ {
2156
+ name: "offset",
2157
+ type: "uint256",
2158
+ internalType: "uint256"
2159
+ },
2160
+ {
2161
+ name: "limit",
2162
+ type: "uint256",
2163
+ internalType: "uint256"
2164
+ }
2165
+ ],
2166
+ outputs: [
2167
+ {
2168
+ name: "apps",
2169
+ type: "address[]",
2170
+ internalType: "contractIApp[]"
2171
+ },
2172
+ {
2173
+ name: "appConfigsMem",
2174
+ type: "tuple[]",
2175
+ internalType: "structIAppController.AppConfig[]",
2176
+ components: [
2177
+ {
2178
+ name: "creator",
2179
+ type: "address",
2180
+ internalType: "address"
2181
+ },
2182
+ {
2183
+ name: "operatorSetId",
2184
+ type: "uint32",
2185
+ internalType: "uint32"
2186
+ },
2187
+ {
2188
+ name: "latestReleaseBlockNumber",
2189
+ type: "uint32",
2190
+ internalType: "uint32"
2191
+ },
2192
+ {
2193
+ name: "status",
2194
+ type: "uint8",
2195
+ internalType: "enumIAppController.AppStatus"
2196
+ }
2197
+ ]
2198
+ }
2199
+ ],
2200
+ stateMutability: "view"
2201
+ },
2202
+ {
2203
+ type: "function",
2204
+ name: "getAppsByDeveloper",
2205
+ inputs: [
2206
+ {
2207
+ name: "developer",
2208
+ type: "address",
2209
+ internalType: "address"
2210
+ },
2211
+ {
2212
+ name: "offset",
2213
+ type: "uint256",
2214
+ internalType: "uint256"
2215
+ },
2216
+ {
2217
+ name: "limit",
2218
+ type: "uint256",
2219
+ internalType: "uint256"
2220
+ }
2221
+ ],
2222
+ outputs: [
2223
+ {
2224
+ name: "apps",
2225
+ type: "address[]",
2226
+ internalType: "contractIApp[]"
2227
+ },
2228
+ {
2229
+ name: "appConfigsMem",
2230
+ type: "tuple[]",
2231
+ internalType: "structIAppController.AppConfig[]",
2232
+ components: [
2233
+ {
2234
+ name: "creator",
2235
+ type: "address",
2236
+ internalType: "address"
2237
+ },
2238
+ {
2239
+ name: "operatorSetId",
2240
+ type: "uint32",
2241
+ internalType: "uint32"
2242
+ },
2243
+ {
2244
+ name: "latestReleaseBlockNumber",
2245
+ type: "uint32",
2246
+ internalType: "uint32"
2247
+ },
2248
+ {
2249
+ name: "status",
2250
+ type: "uint8",
2251
+ internalType: "enumIAppController.AppStatus"
2252
+ }
2253
+ ]
2254
+ }
2255
+ ],
2256
+ stateMutability: "view"
2257
+ },
2258
+ {
2259
+ type: "function",
2260
+ name: "getMaxActiveAppsPerUser",
2261
+ inputs: [
2262
+ {
2263
+ name: "user",
2264
+ type: "address",
2265
+ internalType: "address"
2266
+ }
2267
+ ],
2268
+ outputs: [
2269
+ {
2270
+ name: "",
2271
+ type: "uint32",
2272
+ internalType: "uint32"
2273
+ }
2274
+ ],
2275
+ stateMutability: "view"
2276
+ },
2277
+ {
2278
+ type: "function",
2279
+ name: "globalActiveAppCount",
2280
+ inputs: [],
2281
+ outputs: [
2282
+ {
2283
+ name: "",
2284
+ type: "uint32",
2285
+ internalType: "uint32"
2286
+ }
2287
+ ],
2288
+ stateMutability: "view"
2289
+ },
2290
+ {
2291
+ type: "function",
2292
+ name: "initialize",
2293
+ inputs: [
2294
+ {
2295
+ name: "admin",
2296
+ type: "address",
2297
+ internalType: "address"
2298
+ }
2299
+ ],
2300
+ outputs: [],
2301
+ stateMutability: "nonpayable"
2302
+ },
2303
+ {
2304
+ type: "function",
2305
+ name: "maxGlobalActiveApps",
2306
+ inputs: [],
2307
+ outputs: [
2308
+ {
2309
+ name: "",
2310
+ type: "uint32",
2311
+ internalType: "uint32"
2312
+ }
2313
+ ],
2314
+ stateMutability: "view"
2315
+ },
2316
+ {
2317
+ type: "function",
2318
+ name: "permissionController",
2319
+ inputs: [],
2320
+ outputs: [
2321
+ {
2322
+ name: "",
2323
+ type: "address",
2324
+ internalType: "contractIPermissionController"
2325
+ }
2326
+ ],
2327
+ stateMutability: "view"
2328
+ },
2329
+ {
2330
+ type: "function",
2331
+ name: "releaseManager",
2332
+ inputs: [],
2333
+ outputs: [
2334
+ {
2335
+ name: "",
2336
+ type: "address",
2337
+ internalType: "contractIReleaseManager"
2338
+ }
2339
+ ],
2340
+ stateMutability: "view"
2341
+ },
2342
+ {
2343
+ type: "function",
2344
+ name: "setMaxActiveAppsPerUser",
2345
+ inputs: [
2346
+ {
2347
+ name: "user",
2348
+ type: "address",
2349
+ internalType: "address"
2350
+ },
2351
+ {
2352
+ name: "limit",
2353
+ type: "uint32",
2354
+ internalType: "uint32"
2355
+ }
2356
+ ],
2357
+ outputs: [],
2358
+ stateMutability: "nonpayable"
2359
+ },
2360
+ {
2361
+ type: "function",
2362
+ name: "setMaxGlobalActiveApps",
2363
+ inputs: [
2364
+ {
2365
+ name: "limit",
2366
+ type: "uint32",
2367
+ internalType: "uint32"
2368
+ }
2369
+ ],
2370
+ outputs: [],
2371
+ stateMutability: "nonpayable"
2372
+ },
2373
+ {
2374
+ type: "function",
2375
+ name: "startApp",
2376
+ inputs: [
2377
+ {
2378
+ name: "app",
2379
+ type: "address",
2380
+ internalType: "contractIApp"
2381
+ }
2382
+ ],
2383
+ outputs: [],
2384
+ stateMutability: "nonpayable"
2385
+ },
2386
+ {
2387
+ type: "function",
2388
+ name: "stopApp",
2389
+ inputs: [
2390
+ {
2391
+ name: "app",
2392
+ type: "address",
2393
+ internalType: "contractIApp"
2394
+ }
2395
+ ],
2396
+ outputs: [],
2397
+ stateMutability: "nonpayable"
2398
+ },
2399
+ {
2400
+ type: "function",
2401
+ name: "suspend",
2402
+ inputs: [
2403
+ {
2404
+ name: "account",
2405
+ type: "address",
2406
+ internalType: "address"
2407
+ },
2408
+ {
2409
+ name: "apps",
2410
+ type: "address[]",
2411
+ internalType: "contractIApp[]"
2412
+ }
2413
+ ],
2414
+ outputs: [],
2415
+ stateMutability: "nonpayable"
2416
+ },
2417
+ {
2418
+ type: "function",
2419
+ name: "terminateApp",
2420
+ inputs: [
2421
+ {
2422
+ name: "app",
2423
+ type: "address",
2424
+ internalType: "contractIApp"
2425
+ }
2426
+ ],
2427
+ outputs: [],
2428
+ stateMutability: "nonpayable"
2429
+ },
2430
+ {
2431
+ type: "function",
2432
+ name: "terminateAppByAdmin",
2433
+ inputs: [
2434
+ {
2435
+ name: "app",
2436
+ type: "address",
2437
+ internalType: "contractIApp"
2438
+ }
2439
+ ],
2440
+ outputs: [],
2441
+ stateMutability: "nonpayable"
2442
+ },
2443
+ {
2444
+ type: "function",
2445
+ name: "updateAppMetadataURI",
2446
+ inputs: [
2447
+ {
2448
+ name: "app",
2449
+ type: "address",
2450
+ internalType: "contractIApp"
2451
+ },
2452
+ {
2453
+ name: "metadataURI",
2454
+ type: "string",
2455
+ internalType: "string"
2456
+ }
2457
+ ],
2458
+ outputs: [],
2459
+ stateMutability: "nonpayable"
2460
+ },
2461
+ {
2462
+ type: "function",
2463
+ name: "upgradeApp",
2464
+ inputs: [
2465
+ {
2466
+ name: "app",
2467
+ type: "address",
2468
+ internalType: "contractIApp"
2469
+ },
2470
+ {
2471
+ name: "release",
2472
+ type: "tuple",
2473
+ internalType: "structIAppController.Release",
2474
+ components: [
2475
+ {
2476
+ name: "rmsRelease",
2477
+ type: "tuple",
2478
+ internalType: "structIReleaseManagerTypes.Release",
2479
+ components: [
2480
+ {
2481
+ name: "artifacts",
2482
+ type: "tuple[]",
2483
+ internalType: "structIReleaseManagerTypes.Artifact[]",
2484
+ components: [
2485
+ {
2486
+ name: "digest",
2487
+ type: "bytes32",
2488
+ internalType: "bytes32"
2489
+ },
2490
+ {
2491
+ name: "registry",
2492
+ type: "string",
2493
+ internalType: "string"
2494
+ }
2495
+ ]
2496
+ },
2497
+ {
2498
+ name: "upgradeByTime",
2499
+ type: "uint32",
2500
+ internalType: "uint32"
2501
+ }
2502
+ ]
2503
+ },
2504
+ {
2505
+ name: "publicEnv",
2506
+ type: "bytes",
2507
+ internalType: "bytes"
2508
+ },
2509
+ {
2510
+ name: "encryptedEnv",
2511
+ type: "bytes",
2512
+ internalType: "bytes"
2513
+ }
2514
+ ]
2515
+ }
2516
+ ],
2517
+ outputs: [
2518
+ {
2519
+ name: "",
2520
+ type: "uint256",
2521
+ internalType: "uint256"
2522
+ }
2523
+ ],
2524
+ stateMutability: "nonpayable"
2525
+ },
2526
+ {
2527
+ type: "function",
2528
+ name: "version",
2529
+ inputs: [],
2530
+ outputs: [
2531
+ {
2532
+ name: "",
2533
+ type: "string",
2534
+ internalType: "string"
2535
+ }
2536
+ ],
2537
+ stateMutability: "view"
2538
+ },
2539
+ {
2540
+ type: "event",
2541
+ name: "AppCreated",
2542
+ inputs: [
2543
+ {
2544
+ name: "creator",
2545
+ type: "address",
2546
+ indexed: true,
2547
+ internalType: "address"
2548
+ },
2549
+ {
2550
+ name: "app",
2551
+ type: "address",
2552
+ indexed: true,
2553
+ internalType: "contractIApp"
2554
+ },
2555
+ {
2556
+ name: "operatorSetId",
2557
+ type: "uint32",
2558
+ indexed: false,
2559
+ internalType: "uint32"
2560
+ }
2561
+ ],
2562
+ anonymous: false
2563
+ },
2564
+ {
2565
+ type: "event",
2566
+ name: "AppMetadataURIUpdated",
2567
+ inputs: [
2568
+ {
2569
+ name: "app",
2570
+ type: "address",
2571
+ indexed: true,
2572
+ internalType: "contractIApp"
2573
+ },
2574
+ {
2575
+ name: "metadataURI",
2576
+ type: "string",
2577
+ indexed: false,
2578
+ internalType: "string"
2579
+ }
2580
+ ],
2581
+ anonymous: false
2582
+ },
2583
+ {
2584
+ type: "event",
2585
+ name: "AppStarted",
2586
+ inputs: [
2587
+ {
2588
+ name: "app",
2589
+ type: "address",
2590
+ indexed: true,
2591
+ internalType: "contractIApp"
2592
+ }
2593
+ ],
2594
+ anonymous: false
2595
+ },
2596
+ {
2597
+ type: "event",
2598
+ name: "AppStopped",
2599
+ inputs: [
2600
+ {
2601
+ name: "app",
2602
+ type: "address",
2603
+ indexed: true,
2604
+ internalType: "contractIApp"
2605
+ }
2606
+ ],
2607
+ anonymous: false
2608
+ },
2609
+ {
2610
+ type: "event",
2611
+ name: "AppSuspended",
2612
+ inputs: [
2613
+ {
2614
+ name: "app",
2615
+ type: "address",
2616
+ indexed: true,
2617
+ internalType: "contractIApp"
2618
+ }
2619
+ ],
2620
+ anonymous: false
2621
+ },
2622
+ {
2623
+ type: "event",
2624
+ name: "AppTerminated",
2625
+ inputs: [
2626
+ {
2627
+ name: "app",
2628
+ type: "address",
2629
+ indexed: true,
2630
+ internalType: "contractIApp"
2631
+ }
2632
+ ],
2633
+ anonymous: false
2634
+ },
2635
+ {
2636
+ type: "event",
2637
+ name: "AppTerminatedByAdmin",
2638
+ inputs: [
2639
+ {
2640
+ name: "app",
2641
+ type: "address",
2642
+ indexed: true,
2643
+ internalType: "contractIApp"
2644
+ }
2645
+ ],
2646
+ anonymous: false
2647
+ },
2648
+ {
2649
+ type: "event",
2650
+ name: "AppUpgraded",
2651
+ inputs: [
2652
+ {
2653
+ name: "app",
2654
+ type: "address",
2655
+ indexed: true,
2656
+ internalType: "contractIApp"
2657
+ },
2658
+ {
2659
+ name: "rmsReleaseId",
2660
+ type: "uint256",
2661
+ indexed: false,
2662
+ internalType: "uint256"
2663
+ },
2664
+ {
2665
+ name: "release",
2666
+ type: "tuple",
2667
+ indexed: false,
2668
+ internalType: "structIAppController.Release",
2669
+ components: [
2670
+ {
2671
+ name: "rmsRelease",
2672
+ type: "tuple",
2673
+ internalType: "structIReleaseManagerTypes.Release",
2674
+ components: [
2675
+ {
2676
+ name: "artifacts",
2677
+ type: "tuple[]",
2678
+ internalType: "structIReleaseManagerTypes.Artifact[]",
2679
+ components: [
2680
+ {
2681
+ name: "digest",
2682
+ type: "bytes32",
2683
+ internalType: "bytes32"
2684
+ },
2685
+ {
2686
+ name: "registry",
2687
+ type: "string",
2688
+ internalType: "string"
2689
+ }
2690
+ ]
2691
+ },
2692
+ {
2693
+ name: "upgradeByTime",
2694
+ type: "uint32",
2695
+ internalType: "uint32"
2696
+ }
2697
+ ]
2698
+ },
2699
+ {
2700
+ name: "publicEnv",
2701
+ type: "bytes",
2702
+ internalType: "bytes"
2703
+ },
2704
+ {
2705
+ name: "encryptedEnv",
2706
+ type: "bytes",
2707
+ internalType: "bytes"
2708
+ }
2709
+ ]
2710
+ }
2711
+ ],
2712
+ anonymous: false
2713
+ },
2714
+ {
2715
+ type: "event",
2716
+ name: "GlobalMaxActiveAppsSet",
2717
+ inputs: [
2718
+ {
2719
+ name: "limit",
2720
+ type: "uint32",
2721
+ indexed: false,
2722
+ internalType: "uint32"
2723
+ }
2724
+ ],
2725
+ anonymous: false
2726
+ },
2727
+ {
2728
+ type: "event",
2729
+ name: "Initialized",
2730
+ inputs: [
2731
+ {
2732
+ name: "version",
2733
+ type: "uint8",
2734
+ indexed: false,
2735
+ internalType: "uint8"
2736
+ }
2737
+ ],
2738
+ anonymous: false
2739
+ },
2740
+ {
2741
+ type: "event",
2742
+ name: "MaxActiveAppsSet",
2743
+ inputs: [
2744
+ {
2745
+ name: "user",
2746
+ type: "address",
2747
+ indexed: true,
2748
+ internalType: "address"
2749
+ },
2750
+ {
2751
+ name: "limit",
2752
+ type: "uint32",
2753
+ indexed: false,
2754
+ internalType: "uint32"
2755
+ }
2756
+ ],
2757
+ anonymous: false
2758
+ },
2759
+ {
2760
+ type: "error",
2761
+ name: "AccountHasActiveApps",
2762
+ inputs: []
2763
+ },
2764
+ {
2765
+ type: "error",
2766
+ name: "AppAlreadyExists",
2767
+ inputs: []
2768
+ },
2769
+ {
2770
+ type: "error",
2771
+ name: "AppDoesNotExist",
2772
+ inputs: []
2773
+ },
2774
+ {
2775
+ type: "error",
2776
+ name: "GlobalMaxActiveAppsExceeded",
2777
+ inputs: []
2778
+ },
2779
+ {
2780
+ type: "error",
2781
+ name: "InvalidAppStatus",
2782
+ inputs: []
2783
+ },
2784
+ {
2785
+ type: "error",
2786
+ name: "InvalidPermissions",
2787
+ inputs: []
2788
+ },
2789
+ {
2790
+ type: "error",
2791
+ name: "InvalidReleaseMetadataURI",
2792
+ inputs: []
2793
+ },
2794
+ {
2795
+ type: "error",
2796
+ name: "InvalidShortString",
2797
+ inputs: []
2798
+ },
2799
+ {
2800
+ type: "error",
2801
+ name: "InvalidSignature",
2802
+ inputs: []
2803
+ },
2804
+ {
2805
+ type: "error",
2806
+ name: "MaxActiveAppsExceeded",
2807
+ inputs: []
2808
+ },
2809
+ {
2810
+ type: "error",
2811
+ name: "MoreThanOneArtifact",
2812
+ inputs: []
2813
+ },
2814
+ {
2815
+ type: "error",
2816
+ name: "SignatureExpired",
2817
+ inputs: []
2818
+ },
2819
+ {
2820
+ type: "error",
2821
+ name: "StringTooLong",
2822
+ inputs: [
2823
+ {
2824
+ name: "str",
2825
+ type: "string",
2826
+ internalType: "string"
2827
+ }
2828
+ ]
2829
+ }
2830
+ ];
2831
+
2832
+ // src/client/common/contract/caller.ts
2833
+ function formatETH(wei) {
2834
+ const eth = Number(wei) / 1e18;
2835
+ const costStr = eth.toFixed(6);
2836
+ const trimmed = costStr.replace(/\.?0+$/, "");
2837
+ if (trimmed === "0" && wei > 0n) {
2838
+ return "<0.000001";
2839
+ }
2840
+ return trimmed;
2841
+ }
2842
+ async function estimateTransactionGas(options) {
2843
+ const { publicClient, from, to, data, value = 0n } = options;
2844
+ const fees = await publicClient.estimateFeesPerGas();
2845
+ const gasLimit = await publicClient.estimateGas({
2846
+ account: from,
2847
+ to,
2848
+ data,
2849
+ value
2850
+ });
2851
+ const maxFeePerGas = fees.maxFeePerGas;
2852
+ const maxPriorityFeePerGas = fees.maxPriorityFeePerGas;
2853
+ const maxCostWei = gasLimit * maxFeePerGas;
2854
+ const maxCostEth = formatETH(maxCostWei);
2855
+ return {
2856
+ gasLimit,
2857
+ maxFeePerGas,
2858
+ maxPriorityFeePerGas,
2859
+ maxCostWei,
2860
+ maxCostEth
2861
+ };
2862
+ }
2863
+ async function getActiveAppCount(publicClient, environmentConfig, user) {
2864
+ const count = await publicClient.readContract({
2865
+ address: environmentConfig.appControllerAddress,
2866
+ abi: AppController_default,
2867
+ functionName: "getActiveAppCount",
2868
+ args: [user]
2869
+ });
2870
+ return Number(count);
2871
+ }
2872
+ async function getMaxActiveAppsPerUser(publicClient, environmentConfig, user) {
2873
+ const quota = await publicClient.readContract({
2874
+ address: environmentConfig.appControllerAddress,
2875
+ abi: AppController_default,
2876
+ functionName: "getMaxActiveAppsPerUser",
2877
+ args: [user]
2878
+ });
2879
+ return Number(quota);
2880
+ }
2881
+ async function getAppsByCreator(publicClient, environmentConfig, creator, offset, limit) {
2882
+ const result = await publicClient.readContract({
2883
+ address: environmentConfig.appControllerAddress,
2884
+ abi: AppController_default,
2885
+ functionName: "getAppsByCreator",
2886
+ args: [creator, offset, limit]
2887
+ });
2888
+ return {
2889
+ apps: result[0],
2890
+ appConfigs: result[1]
2891
+ };
2892
+ }
2893
+ async function getAppsByDeveloper(publicClient, environmentConfig, developer, offset, limit) {
2894
+ const result = await publicClient.readContract({
2895
+ address: environmentConfig.appControllerAddress,
2896
+ abi: AppController_default,
2897
+ functionName: "getAppsByDeveloper",
2898
+ args: [developer, offset, limit]
2899
+ });
2900
+ return {
2901
+ apps: result[0],
2902
+ appConfigs: result[1]
2903
+ };
2904
+ }
2905
+ async function getAllAppsByDeveloper(publicClient, env, developer, pageSize = 100n) {
2906
+ let offset = 0n;
2907
+ const allApps = [];
2908
+ const allConfigs = [];
2909
+ while (true) {
2910
+ const { apps, appConfigs } = await getAppsByDeveloper(publicClient, env, developer, offset, pageSize);
2911
+ if (apps.length === 0) break;
2912
+ allApps.push(...apps);
2913
+ allConfigs.push(...appConfigs);
2914
+ if (apps.length < Number(pageSize)) break;
2915
+ offset += pageSize;
2916
+ }
2917
+ return {
2918
+ apps: allApps,
2919
+ appConfigs: allConfigs
2920
+ };
2921
+ }
2922
+
2923
+ // src/client/common/contract/encoders.ts
2924
+ var import_viem6 = require("viem");
2925
+ var CONTROLLER_ABI = (0, import_viem6.parseAbi)([
2926
+ "function startApp(address appId)",
2927
+ "function stopApp(address appId)",
2928
+ "function terminateApp(address appId)"
2929
+ ]);
2930
+ function encodeStartAppData(appId) {
2931
+ return (0, import_viem6.encodeFunctionData)({
2932
+ abi: CONTROLLER_ABI,
2933
+ functionName: "startApp",
2934
+ args: [appId]
2935
+ });
2936
+ }
2937
+ function encodeStopAppData(appId) {
2938
+ return (0, import_viem6.encodeFunctionData)({
2939
+ abi: CONTROLLER_ABI,
2940
+ functionName: "stopApp",
2941
+ args: [appId]
2942
+ });
2943
+ }
2944
+ function encodeTerminateAppData(appId) {
2945
+ return (0, import_viem6.encodeFunctionData)({
2946
+ abi: CONTROLLER_ABI,
2947
+ functionName: "terminateApp",
2948
+ args: [appId]
2949
+ });
2950
+ }
2951
+ // Annotate the CommonJS export names for ESM import in node:
2952
+ 0 && (module.exports = {
2953
+ UserApiClient,
2954
+ assertValidImageReference,
2955
+ assertValidPrivateKey,
2956
+ encodeStartAppData,
2957
+ encodeStopAppData,
2958
+ encodeTerminateAppData,
2959
+ estimateBatchGas,
2960
+ estimateTransactionGas,
2961
+ extractAppNameFromImage,
2962
+ formatETH,
2963
+ generateNewPrivateKey,
2964
+ getActiveAppCount,
2965
+ getAllAppsByDeveloper,
2966
+ getAppsByCreator,
2967
+ getAppsByDeveloper,
2968
+ getAvailableEnvironments,
2969
+ getBuildType,
2970
+ getEnvironmentConfig,
2971
+ getMaxActiveAppsPerUser,
2972
+ isEnvironmentAvailable,
2973
+ isMainnet,
2974
+ isSubscriptionActive,
2975
+ sanitizeString,
2976
+ sanitizeURL,
2977
+ sanitizeXURL,
2978
+ validateAppID,
2979
+ validateAppName,
2980
+ validateCreateAppParams,
2981
+ validateDescription,
2982
+ validateImageReference,
2983
+ validateInstanceTypeSKU,
2984
+ validateLogVisibility,
2985
+ validateLogsParams,
2986
+ validatePrivateKeyFormat,
2987
+ validateURL,
2988
+ validateXURL
2989
+ });
2990
+ //# sourceMappingURL=browser.cjs.map