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