@aomi-labs/client 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
1
21
  // src/sse.ts
2
22
  function extractSseData(rawEvent) {
3
23
  const dataLines = rawEvent.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart());
@@ -1017,16 +1037,799 @@ var ClientSession = class extends TypedEventEmitter {
1017
1037
  }
1018
1038
  }
1019
1039
  };
1040
+
1041
+ // src/aa/types.ts
1042
+ var MODES = /* @__PURE__ */ new Set(["4337", "7702"]);
1043
+ var SPONSORSHIP_MODES = /* @__PURE__ */ new Set([
1044
+ "disabled",
1045
+ "optional",
1046
+ "required"
1047
+ ]);
1048
+ function isObject(value) {
1049
+ return typeof value === "object" && value !== null;
1050
+ }
1051
+ function assertChainConfig(value, index) {
1052
+ if (!isObject(value)) {
1053
+ throw new Error(`Invalid AA config chain at index ${index}: expected object`);
1054
+ }
1055
+ if (typeof value.chainId !== "number") {
1056
+ throw new Error(`Invalid AA config chain at index ${index}: chainId must be a number`);
1057
+ }
1058
+ if (typeof value.enabled !== "boolean") {
1059
+ throw new Error(`Invalid AA config chain ${value.chainId}: enabled must be a boolean`);
1060
+ }
1061
+ if (!MODES.has(value.defaultMode)) {
1062
+ throw new Error(`Invalid AA config chain ${value.chainId}: unsupported defaultMode`);
1063
+ }
1064
+ if (!Array.isArray(value.supportedModes) || value.supportedModes.length === 0) {
1065
+ throw new Error(`Invalid AA config chain ${value.chainId}: supportedModes must be a non-empty array`);
1066
+ }
1067
+ if (!value.supportedModes.every((mode) => MODES.has(mode))) {
1068
+ throw new Error(`Invalid AA config chain ${value.chainId}: supportedModes contains an unsupported mode`);
1069
+ }
1070
+ if (!value.supportedModes.includes(value.defaultMode)) {
1071
+ throw new Error(`Invalid AA config chain ${value.chainId}: defaultMode must be in supportedModes`);
1072
+ }
1073
+ if (typeof value.allowBatching !== "boolean") {
1074
+ throw new Error(`Invalid AA config chain ${value.chainId}: allowBatching must be a boolean`);
1075
+ }
1076
+ if (!SPONSORSHIP_MODES.has(value.sponsorship)) {
1077
+ throw new Error(`Invalid AA config chain ${value.chainId}: unsupported sponsorship mode`);
1078
+ }
1079
+ }
1080
+ function parseAAConfig(value) {
1081
+ if (!isObject(value)) {
1082
+ throw new Error("Invalid AA config: expected object");
1083
+ }
1084
+ if (typeof value.enabled !== "boolean") {
1085
+ throw new Error("Invalid AA config: enabled must be a boolean");
1086
+ }
1087
+ if (typeof value.provider !== "string" || !value.provider) {
1088
+ throw new Error("Invalid AA config: provider must be a non-empty string");
1089
+ }
1090
+ if (typeof value.fallbackToEoa !== "boolean") {
1091
+ throw new Error("Invalid AA config: fallbackToEoa must be a boolean");
1092
+ }
1093
+ if (!Array.isArray(value.chains)) {
1094
+ throw new Error("Invalid AA config: chains must be an array");
1095
+ }
1096
+ value.chains.forEach((chain, index) => assertChainConfig(chain, index));
1097
+ return {
1098
+ enabled: value.enabled,
1099
+ provider: value.provider,
1100
+ fallbackToEoa: value.fallbackToEoa,
1101
+ chains: value.chains
1102
+ };
1103
+ }
1104
+ function getAAChainConfig(config, calls, chainsById) {
1105
+ if (!config.enabled || calls.length === 0) {
1106
+ return null;
1107
+ }
1108
+ const chainIds = Array.from(new Set(calls.map((call) => call.chainId)));
1109
+ if (chainIds.length !== 1) {
1110
+ return null;
1111
+ }
1112
+ const chainId = chainIds[0];
1113
+ if (!chainsById[chainId]) {
1114
+ return null;
1115
+ }
1116
+ const chainConfig = config.chains.find((item) => item.chainId === chainId);
1117
+ if (!(chainConfig == null ? void 0 : chainConfig.enabled)) {
1118
+ return null;
1119
+ }
1120
+ if (calls.length > 1 && !chainConfig.allowBatching) {
1121
+ return null;
1122
+ }
1123
+ return chainConfig;
1124
+ }
1125
+ function buildAAExecutionPlan(config, chainConfig) {
1126
+ const mode = chainConfig.supportedModes.includes(chainConfig.defaultMode) ? chainConfig.defaultMode : chainConfig.supportedModes[0];
1127
+ if (!mode) {
1128
+ throw new Error(`No smart account mode configured for chain ${chainConfig.chainId}`);
1129
+ }
1130
+ return {
1131
+ provider: config.provider,
1132
+ chainId: chainConfig.chainId,
1133
+ mode,
1134
+ batchingEnabled: chainConfig.allowBatching,
1135
+ sponsorship: chainConfig.sponsorship,
1136
+ fallbackToEoa: config.fallbackToEoa
1137
+ };
1138
+ }
1139
+ function getWalletExecutorReady(providerState) {
1140
+ return !providerState.plan || !providerState.isPending && (Boolean(providerState.AA) || Boolean(providerState.error) || providerState.plan.fallbackToEoa);
1141
+ }
1142
+ function mapCall(call) {
1143
+ return {
1144
+ to: call.to,
1145
+ value: BigInt(call.value),
1146
+ data: call.data ? call.data : void 0
1147
+ };
1148
+ }
1149
+ var DEFAULT_AA_CONFIG = {
1150
+ enabled: true,
1151
+ provider: "alchemy",
1152
+ fallbackToEoa: true,
1153
+ chains: [
1154
+ {
1155
+ chainId: 1,
1156
+ enabled: true,
1157
+ defaultMode: "7702",
1158
+ supportedModes: ["4337", "7702"],
1159
+ allowBatching: true,
1160
+ sponsorship: "optional"
1161
+ },
1162
+ {
1163
+ chainId: 137,
1164
+ enabled: true,
1165
+ defaultMode: "4337",
1166
+ supportedModes: ["4337", "7702"],
1167
+ allowBatching: true,
1168
+ sponsorship: "optional"
1169
+ },
1170
+ {
1171
+ chainId: 42161,
1172
+ enabled: true,
1173
+ defaultMode: "4337",
1174
+ supportedModes: ["4337", "7702"],
1175
+ allowBatching: true,
1176
+ sponsorship: "optional"
1177
+ },
1178
+ {
1179
+ chainId: 10,
1180
+ enabled: true,
1181
+ defaultMode: "4337",
1182
+ supportedModes: ["4337", "7702"],
1183
+ allowBatching: true,
1184
+ sponsorship: "optional"
1185
+ },
1186
+ {
1187
+ chainId: 8453,
1188
+ enabled: true,
1189
+ defaultMode: "4337",
1190
+ supportedModes: ["4337", "7702"],
1191
+ allowBatching: true,
1192
+ sponsorship: "optional"
1193
+ }
1194
+ ]
1195
+ };
1196
+ async function executeWalletCalls(params) {
1197
+ const {
1198
+ callList,
1199
+ currentChainId,
1200
+ capabilities,
1201
+ localPrivateKey,
1202
+ providerState,
1203
+ sendCallsSyncAsync,
1204
+ sendTransactionAsync,
1205
+ switchChainAsync,
1206
+ chainsById,
1207
+ getPreferredRpcUrl
1208
+ } = params;
1209
+ if (providerState.plan && providerState.AA) {
1210
+ return executeViaAA(callList, providerState);
1211
+ }
1212
+ if (providerState.plan && providerState.error && !providerState.plan.fallbackToEoa) {
1213
+ throw providerState.error;
1214
+ }
1215
+ return executeViaEoa({
1216
+ callList,
1217
+ currentChainId,
1218
+ capabilities,
1219
+ localPrivateKey,
1220
+ sendCallsSyncAsync,
1221
+ sendTransactionAsync,
1222
+ switchChainAsync,
1223
+ chainsById,
1224
+ getPreferredRpcUrl
1225
+ });
1226
+ }
1227
+ async function executeViaAA(callList, providerState) {
1228
+ var _a;
1229
+ const AA = providerState.AA;
1230
+ const plan = providerState.plan;
1231
+ if (!AA || !plan) {
1232
+ throw (_a = providerState.error) != null ? _a : new Error("smart_account_unavailable");
1233
+ }
1234
+ const callsPayload = callList.map(mapCall);
1235
+ const receipt = callList.length > 1 ? await AA.sendBatchTransaction(callsPayload) : await AA.sendTransaction(callsPayload[0]);
1236
+ const txHash = receipt.transactionHash;
1237
+ const providerPrefix = AA.provider.toLowerCase();
1238
+ return {
1239
+ txHash,
1240
+ txHashes: [txHash],
1241
+ executionKind: `${providerPrefix}_${AA.mode}`,
1242
+ batched: callList.length > 1,
1243
+ sponsored: plan.sponsorship !== "disabled",
1244
+ AAAddress: AA.AAAddress,
1245
+ delegationAddress: AA.mode === "7702" ? AA.delegationAddress : void 0
1246
+ };
1247
+ }
1248
+ async function executeViaEoa({
1249
+ callList,
1250
+ currentChainId,
1251
+ capabilities,
1252
+ localPrivateKey,
1253
+ sendCallsSyncAsync,
1254
+ sendTransactionAsync,
1255
+ switchChainAsync,
1256
+ chainsById,
1257
+ getPreferredRpcUrl
1258
+ }) {
1259
+ var _a, _b;
1260
+ const { createPublicClient, createWalletClient, http } = await import("viem");
1261
+ const { privateKeyToAccount: privateKeyToAccount2 } = await import("viem/accounts");
1262
+ const hashes = [];
1263
+ if (localPrivateKey) {
1264
+ for (const call of callList) {
1265
+ const chain = chainsById[call.chainId];
1266
+ if (!chain) {
1267
+ throw new Error(`Unsupported chain ${call.chainId}`);
1268
+ }
1269
+ const rpcUrl = getPreferredRpcUrl(chain);
1270
+ if (!rpcUrl) {
1271
+ throw new Error(`No RPC for chain ${call.chainId}`);
1272
+ }
1273
+ const account = privateKeyToAccount2(localPrivateKey);
1274
+ const walletClient = createWalletClient({
1275
+ account,
1276
+ chain,
1277
+ transport: http(rpcUrl)
1278
+ });
1279
+ const hash = await walletClient.sendTransaction({
1280
+ account,
1281
+ to: call.to,
1282
+ value: BigInt(call.value),
1283
+ data: call.data ? call.data : void 0
1284
+ });
1285
+ const publicClient = createPublicClient({
1286
+ chain,
1287
+ transport: http(rpcUrl)
1288
+ });
1289
+ await publicClient.waitForTransactionReceipt({ hash });
1290
+ hashes.push(hash);
1291
+ }
1292
+ return {
1293
+ txHash: hashes[hashes.length - 1],
1294
+ txHashes: hashes,
1295
+ executionKind: "eoa",
1296
+ batched: hashes.length > 1,
1297
+ sponsored: false
1298
+ };
1299
+ }
1300
+ const chainIds = Array.from(new Set(callList.map((call) => call.chainId)));
1301
+ if (chainIds.length > 1) {
1302
+ throw new Error("mixed_chain_bundle_not_supported");
1303
+ }
1304
+ const chainId = chainIds[0];
1305
+ if (currentChainId !== chainId) {
1306
+ await switchChainAsync({ chainId });
1307
+ }
1308
+ const chainCaps = capabilities == null ? void 0 : capabilities[`eip155:${chainId}`];
1309
+ const atomicStatus = (_a = chainCaps == null ? void 0 : chainCaps.atomic) == null ? void 0 : _a.status;
1310
+ const canUseSendCalls = atomicStatus === "supported" || atomicStatus === "ready";
1311
+ if (canUseSendCalls) {
1312
+ const batchResult = await sendCallsSyncAsync({
1313
+ calls: callList.map(mapCall),
1314
+ capabilities: {
1315
+ atomic: {
1316
+ required: true
1317
+ }
1318
+ }
1319
+ });
1320
+ const receipts = (_b = batchResult.receipts) != null ? _b : [];
1321
+ for (const receipt of receipts) {
1322
+ if (receipt.transactionHash) {
1323
+ hashes.push(receipt.transactionHash);
1324
+ }
1325
+ }
1326
+ } else {
1327
+ for (const call of callList) {
1328
+ const hash = await sendTransactionAsync({
1329
+ chainId: call.chainId,
1330
+ to: call.to,
1331
+ value: BigInt(call.value),
1332
+ data: call.data ? call.data : void 0
1333
+ });
1334
+ hashes.push(hash);
1335
+ }
1336
+ }
1337
+ return {
1338
+ txHash: hashes[hashes.length - 1],
1339
+ txHashes: hashes,
1340
+ executionKind: "eoa",
1341
+ batched: hashes.length > 1,
1342
+ sponsored: false
1343
+ };
1344
+ }
1345
+
1346
+ // src/aa/env.ts
1347
+ var ALCHEMY_API_KEY_ENVS = [
1348
+ "ALCHEMY_API_KEY",
1349
+ "NEXT_PUBLIC_ALCHEMY_API_KEY"
1350
+ ];
1351
+ var ALCHEMY_GAS_POLICY_ENVS = [
1352
+ "ALCHEMY_GAS_POLICY_ID",
1353
+ "NEXT_PUBLIC_ALCHEMY_GAS_POLICY_ID"
1354
+ ];
1355
+ var PIMLICO_API_KEY_ENVS = [
1356
+ "PIMLICO_API_KEY",
1357
+ "NEXT_PUBLIC_PIMLICO_API_KEY"
1358
+ ];
1359
+ function readEnv(candidates, options = {}) {
1360
+ var _a;
1361
+ const { publicOnly = false } = options;
1362
+ for (const name of candidates) {
1363
+ if (publicOnly && !name.startsWith("NEXT_PUBLIC_")) {
1364
+ continue;
1365
+ }
1366
+ const value = (_a = process.env[name]) == null ? void 0 : _a.trim();
1367
+ if (value) return value;
1368
+ }
1369
+ return void 0;
1370
+ }
1371
+ function readGasPolicyEnv(chainId, chainSlugById, baseCandidates, options = {}) {
1372
+ const slug = chainSlugById[chainId];
1373
+ if (slug) {
1374
+ const chainSpecific = baseCandidates.map(
1375
+ (base) => `${base}_${slug.toUpperCase()}`
1376
+ );
1377
+ const found = readEnv(chainSpecific, options);
1378
+ if (found) return found;
1379
+ }
1380
+ return readEnv(baseCandidates, options);
1381
+ }
1382
+ function isProviderConfigured(provider, options = {}) {
1383
+ return provider === "alchemy" ? Boolean(readEnv(ALCHEMY_API_KEY_ENVS, options)) : Boolean(readEnv(PIMLICO_API_KEY_ENVS, options));
1384
+ }
1385
+ function resolveDefaultProvider(options = {}) {
1386
+ if (isProviderConfigured("alchemy", options)) return "alchemy";
1387
+ if (isProviderConfigured("pimlico", options)) return "pimlico";
1388
+ throw new Error(
1389
+ "AA requires provider credentials. Set ALCHEMY_API_KEY or PIMLICO_API_KEY, or use --eoa."
1390
+ );
1391
+ }
1392
+
1393
+ // src/aa/resolve.ts
1394
+ function resolveAlchemyConfig(options) {
1395
+ const {
1396
+ calls,
1397
+ localPrivateKey,
1398
+ accountAbstractionConfig = DEFAULT_AA_CONFIG,
1399
+ chainsById,
1400
+ chainSlugById = {},
1401
+ getPreferredRpcUrl = (chain2) => {
1402
+ var _a;
1403
+ return (_a = chain2.rpcUrls.default.http[0]) != null ? _a : "";
1404
+ },
1405
+ modeOverride,
1406
+ publicOnly = false,
1407
+ throwOnMissingConfig = false,
1408
+ apiKey: preResolvedApiKey,
1409
+ gasPolicyId: preResolvedGasPolicyId
1410
+ } = options;
1411
+ if (!calls || localPrivateKey) {
1412
+ return null;
1413
+ }
1414
+ const config = __spreadProps(__spreadValues({}, accountAbstractionConfig), {
1415
+ provider: "alchemy"
1416
+ });
1417
+ const chainConfig = getAAChainConfig(config, calls, chainsById);
1418
+ if (!chainConfig) {
1419
+ if (throwOnMissingConfig) {
1420
+ const chainIds = Array.from(new Set(calls.map((c) => c.chainId)));
1421
+ throw new Error(
1422
+ `AA is not configured for chain ${chainIds[0]}, or batching is disabled for that chain.`
1423
+ );
1424
+ }
1425
+ return null;
1426
+ }
1427
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
1428
+ if (!apiKey) {
1429
+ if (throwOnMissingConfig) {
1430
+ throw new Error("Alchemy AA requires ALCHEMY_API_KEY.");
1431
+ }
1432
+ return null;
1433
+ }
1434
+ const chain = chainsById[chainConfig.chainId];
1435
+ if (!chain) {
1436
+ return null;
1437
+ }
1438
+ const gasPolicyId = preResolvedGasPolicyId != null ? preResolvedGasPolicyId : readGasPolicyEnv(
1439
+ chainConfig.chainId,
1440
+ chainSlugById,
1441
+ ALCHEMY_GAS_POLICY_ENVS,
1442
+ { publicOnly }
1443
+ );
1444
+ if (chainConfig.sponsorship === "required" && !gasPolicyId) {
1445
+ if (throwOnMissingConfig) {
1446
+ throw new Error(
1447
+ `Alchemy gas policy required for chain ${chainConfig.chainId} but not configured.`
1448
+ );
1449
+ }
1450
+ return null;
1451
+ }
1452
+ if (modeOverride && !chainConfig.supportedModes.includes(modeOverride)) {
1453
+ if (throwOnMissingConfig) {
1454
+ throw new Error(
1455
+ `AA mode "${modeOverride}" is not supported on chain ${chainConfig.chainId}.`
1456
+ );
1457
+ }
1458
+ return null;
1459
+ }
1460
+ const resolvedChainConfig = modeOverride ? __spreadProps(__spreadValues({}, chainConfig), { defaultMode: modeOverride }) : chainConfig;
1461
+ const plan = buildAAExecutionPlan(config, resolvedChainConfig);
1462
+ return {
1463
+ chainConfig: resolvedChainConfig,
1464
+ plan,
1465
+ apiKey,
1466
+ chain,
1467
+ rpcUrl: getPreferredRpcUrl(chain),
1468
+ gasPolicyId,
1469
+ mode: resolvedChainConfig.defaultMode
1470
+ };
1471
+ }
1472
+ function resolvePimlicoConfig(options) {
1473
+ const {
1474
+ calls,
1475
+ localPrivateKey,
1476
+ accountAbstractionConfig = DEFAULT_AA_CONFIG,
1477
+ chainsById,
1478
+ rpcUrl,
1479
+ modeOverride,
1480
+ publicOnly = false,
1481
+ throwOnMissingConfig = false,
1482
+ apiKey: preResolvedApiKey
1483
+ } = options;
1484
+ if (!calls || localPrivateKey) {
1485
+ return null;
1486
+ }
1487
+ const config = __spreadProps(__spreadValues({}, accountAbstractionConfig), {
1488
+ provider: "pimlico"
1489
+ });
1490
+ const chainConfig = getAAChainConfig(config, calls, chainsById);
1491
+ if (!chainConfig) {
1492
+ if (throwOnMissingConfig) {
1493
+ const chainIds = Array.from(new Set(calls.map((c) => c.chainId)));
1494
+ throw new Error(
1495
+ `AA is not configured for chain ${chainIds[0]}, or batching is disabled for that chain.`
1496
+ );
1497
+ }
1498
+ return null;
1499
+ }
1500
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
1501
+ if (!apiKey) {
1502
+ if (throwOnMissingConfig) {
1503
+ throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
1504
+ }
1505
+ return null;
1506
+ }
1507
+ const chain = chainsById[chainConfig.chainId];
1508
+ if (!chain) {
1509
+ return null;
1510
+ }
1511
+ if (modeOverride && !chainConfig.supportedModes.includes(modeOverride)) {
1512
+ if (throwOnMissingConfig) {
1513
+ throw new Error(
1514
+ `AA mode "${modeOverride}" is not supported on chain ${chainConfig.chainId}.`
1515
+ );
1516
+ }
1517
+ return null;
1518
+ }
1519
+ const resolvedChainConfig = modeOverride ? __spreadProps(__spreadValues({}, chainConfig), { defaultMode: modeOverride }) : chainConfig;
1520
+ const plan = buildAAExecutionPlan(config, resolvedChainConfig);
1521
+ return {
1522
+ chainConfig: resolvedChainConfig,
1523
+ plan,
1524
+ apiKey,
1525
+ chain,
1526
+ rpcUrl,
1527
+ mode: resolvedChainConfig.defaultMode
1528
+ };
1529
+ }
1530
+
1531
+ // src/aa/alchemy.ts
1532
+ function createAlchemyAAProvider({
1533
+ accountAbstractionConfig = DEFAULT_AA_CONFIG,
1534
+ useAlchemyAA,
1535
+ chainsById,
1536
+ chainSlugById,
1537
+ getPreferredRpcUrl
1538
+ }) {
1539
+ return function useAlchemyAAProvider(calls, localPrivateKey) {
1540
+ var _a, _b;
1541
+ const resolved = resolveAlchemyConfig({
1542
+ calls,
1543
+ localPrivateKey,
1544
+ accountAbstractionConfig,
1545
+ chainsById,
1546
+ chainSlugById,
1547
+ getPreferredRpcUrl,
1548
+ publicOnly: true
1549
+ });
1550
+ const params = resolved ? {
1551
+ enabled: true,
1552
+ apiKey: resolved.apiKey,
1553
+ chain: resolved.chain,
1554
+ rpcUrl: resolved.rpcUrl,
1555
+ gasPolicyId: resolved.gasPolicyId,
1556
+ mode: resolved.mode
1557
+ } : void 0;
1558
+ const query = useAlchemyAA(params);
1559
+ return {
1560
+ plan: (_a = resolved == null ? void 0 : resolved.plan) != null ? _a : null,
1561
+ query,
1562
+ AA: query.AA,
1563
+ isPending: Boolean(resolved && query.isPending),
1564
+ error: (_b = query.error) != null ? _b : null
1565
+ };
1566
+ };
1567
+ }
1568
+
1569
+ // src/aa/pimlico.ts
1570
+ function createPimlicoAAProvider({
1571
+ accountAbstractionConfig = DEFAULT_AA_CONFIG,
1572
+ usePimlicoAA,
1573
+ chainsById,
1574
+ rpcUrl
1575
+ }) {
1576
+ return function usePimlicoAAProvider(calls, localPrivateKey) {
1577
+ var _a, _b;
1578
+ const resolved = resolvePimlicoConfig({
1579
+ calls,
1580
+ localPrivateKey,
1581
+ accountAbstractionConfig,
1582
+ chainsById,
1583
+ rpcUrl,
1584
+ publicOnly: true
1585
+ });
1586
+ const params = resolved ? {
1587
+ enabled: true,
1588
+ apiKey: resolved.apiKey,
1589
+ chain: resolved.chain,
1590
+ mode: resolved.mode,
1591
+ rpcUrl: resolved.rpcUrl
1592
+ } : void 0;
1593
+ const query = usePimlicoAA(params);
1594
+ return {
1595
+ plan: (_a = resolved == null ? void 0 : resolved.plan) != null ? _a : null,
1596
+ query,
1597
+ AA: query.AA,
1598
+ isPending: Boolean(resolved && query.isPending),
1599
+ error: (_b = query.error) != null ? _b : null
1600
+ };
1601
+ };
1602
+ }
1603
+
1604
+ // src/aa/adapt.ts
1605
+ function adaptSmartAccount(account) {
1606
+ return {
1607
+ provider: account.provider,
1608
+ mode: account.mode,
1609
+ AAAddress: account.smartAccountAddress,
1610
+ delegationAddress: account.delegationAddress,
1611
+ sendTransaction: async (call) => {
1612
+ const receipt = await account.sendTransaction(call);
1613
+ return { transactionHash: receipt.transactionHash };
1614
+ },
1615
+ sendBatchTransaction: async (calls) => {
1616
+ const receipt = await account.sendBatchTransaction(calls);
1617
+ return { transactionHash: receipt.transactionHash };
1618
+ }
1619
+ };
1620
+ }
1621
+ function isAlchemySponsorshipLimitError(error) {
1622
+ const message = error instanceof Error ? error.message : String(error != null ? error : "");
1623
+ const normalized = message.toLowerCase();
1624
+ return normalized.includes("gas sponsorship limit") || normalized.includes("put your team over your gas sponsorship limit") || normalized.includes("buy gas credits in your gas manager dashboard");
1625
+ }
1626
+
1627
+ // src/aa/create.ts
1628
+ import { createAlchemySmartAccount } from "@getpara/aa-alchemy";
1629
+ import { createPimlicoSmartAccount } from "@getpara/aa-pimlico";
1630
+ import { privateKeyToAccount } from "viem/accounts";
1631
+ async function createAAProviderState(options) {
1632
+ if (options.provider === "alchemy") {
1633
+ return createAlchemyAAState({
1634
+ chain: options.chain,
1635
+ owner: options.owner,
1636
+ rpcUrl: options.rpcUrl,
1637
+ callList: options.callList,
1638
+ mode: options.mode,
1639
+ apiKey: options.apiKey,
1640
+ gasPolicyId: options.gasPolicyId,
1641
+ sponsored: options.sponsored
1642
+ });
1643
+ }
1644
+ return createPimlicoAAState({
1645
+ chain: options.chain,
1646
+ owner: options.owner,
1647
+ rpcUrl: options.rpcUrl,
1648
+ callList: options.callList,
1649
+ mode: options.mode,
1650
+ apiKey: options.apiKey
1651
+ });
1652
+ }
1653
+ function getOwnerParams(owner) {
1654
+ if (!owner) {
1655
+ return null;
1656
+ }
1657
+ if ("privateKey" in owner) {
1658
+ return {
1659
+ para: void 0,
1660
+ signer: privateKeyToAccount(owner.privateKey)
1661
+ };
1662
+ }
1663
+ if ("signer" in owner) {
1664
+ return __spreadValues({
1665
+ para: owner.para,
1666
+ signer: owner.signer
1667
+ }, owner.address ? { address: owner.address } : {});
1668
+ }
1669
+ if ("para" in owner) {
1670
+ return __spreadValues({
1671
+ para: owner.para
1672
+ }, owner.address ? { address: owner.address } : {});
1673
+ }
1674
+ return null;
1675
+ }
1676
+ function getMissingOwnerState(plan, provider) {
1677
+ return {
1678
+ plan,
1679
+ AA: null,
1680
+ isPending: false,
1681
+ error: new Error(
1682
+ `${provider} AA account creation requires a signer or Para session.`
1683
+ )
1684
+ };
1685
+ }
1686
+ async function createAlchemyAAState(options) {
1687
+ var _a, _b;
1688
+ const {
1689
+ chain,
1690
+ owner,
1691
+ rpcUrl,
1692
+ callList,
1693
+ mode,
1694
+ sponsored = true
1695
+ } = options;
1696
+ const resolved = resolveAlchemyConfig({
1697
+ calls: callList,
1698
+ chainsById: { [chain.id]: chain },
1699
+ modeOverride: mode,
1700
+ throwOnMissingConfig: true,
1701
+ getPreferredRpcUrl: () => rpcUrl,
1702
+ apiKey: options.apiKey,
1703
+ gasPolicyId: options.gasPolicyId
1704
+ });
1705
+ if (!resolved) {
1706
+ throw new Error("Alchemy AA config resolution failed.");
1707
+ }
1708
+ const apiKey = (_a = options.apiKey) != null ? _a : resolved.apiKey;
1709
+ const gasPolicyId = sponsored ? (_b = options.gasPolicyId) != null ? _b : readEnv(ALCHEMY_GAS_POLICY_ENVS) : void 0;
1710
+ const plan = __spreadProps(__spreadValues({}, resolved.plan), {
1711
+ sponsorship: gasPolicyId ? resolved.plan.sponsorship : "disabled",
1712
+ fallbackToEoa: false
1713
+ });
1714
+ const ownerParams = getOwnerParams(owner);
1715
+ if (!ownerParams) {
1716
+ return getMissingOwnerState(plan, "alchemy");
1717
+ }
1718
+ try {
1719
+ const smartAccount = await createAlchemySmartAccount(__spreadProps(__spreadValues({}, ownerParams), {
1720
+ apiKey,
1721
+ gasPolicyId,
1722
+ chain,
1723
+ rpcUrl,
1724
+ mode: plan.mode
1725
+ }));
1726
+ if (!smartAccount) {
1727
+ return {
1728
+ plan,
1729
+ AA: null,
1730
+ isPending: false,
1731
+ error: new Error("Alchemy AA account could not be initialized.")
1732
+ };
1733
+ }
1734
+ return {
1735
+ plan,
1736
+ AA: adaptSmartAccount(smartAccount),
1737
+ isPending: false,
1738
+ error: null
1739
+ };
1740
+ } catch (error) {
1741
+ return {
1742
+ plan,
1743
+ AA: null,
1744
+ isPending: false,
1745
+ error: error instanceof Error ? error : new Error(String(error))
1746
+ };
1747
+ }
1748
+ }
1749
+ async function createPimlicoAAState(options) {
1750
+ var _a;
1751
+ const {
1752
+ chain,
1753
+ owner,
1754
+ rpcUrl,
1755
+ callList,
1756
+ mode
1757
+ } = options;
1758
+ const resolved = resolvePimlicoConfig({
1759
+ calls: callList,
1760
+ chainsById: { [chain.id]: chain },
1761
+ rpcUrl,
1762
+ modeOverride: mode,
1763
+ throwOnMissingConfig: true,
1764
+ apiKey: options.apiKey
1765
+ });
1766
+ if (!resolved) {
1767
+ throw new Error("Pimlico AA config resolution failed.");
1768
+ }
1769
+ const apiKey = (_a = options.apiKey) != null ? _a : resolved.apiKey;
1770
+ const plan = __spreadProps(__spreadValues({}, resolved.plan), {
1771
+ fallbackToEoa: false
1772
+ });
1773
+ const ownerParams = getOwnerParams(owner);
1774
+ if (!ownerParams) {
1775
+ return getMissingOwnerState(plan, "pimlico");
1776
+ }
1777
+ try {
1778
+ const smartAccount = await createPimlicoSmartAccount(__spreadProps(__spreadValues({}, ownerParams), {
1779
+ apiKey,
1780
+ chain,
1781
+ rpcUrl,
1782
+ mode: plan.mode
1783
+ }));
1784
+ if (!smartAccount) {
1785
+ return {
1786
+ plan,
1787
+ AA: null,
1788
+ isPending: false,
1789
+ error: new Error("Pimlico AA account could not be initialized.")
1790
+ };
1791
+ }
1792
+ return {
1793
+ plan,
1794
+ AA: adaptSmartAccount(smartAccount),
1795
+ isPending: false,
1796
+ error: null
1797
+ };
1798
+ } catch (error) {
1799
+ return {
1800
+ plan,
1801
+ AA: null,
1802
+ isPending: false,
1803
+ error: error instanceof Error ? error : new Error(String(error))
1804
+ };
1805
+ }
1806
+ }
1020
1807
  export {
1021
1808
  AomiClient,
1809
+ DEFAULT_AA_CONFIG,
1022
1810
  ClientSession as Session,
1023
1811
  TypedEventEmitter,
1812
+ adaptSmartAccount,
1813
+ buildAAExecutionPlan,
1814
+ createAAProviderState,
1815
+ createAlchemyAAProvider,
1816
+ createPimlicoAAProvider,
1817
+ executeWalletCalls,
1818
+ getAAChainConfig,
1819
+ getWalletExecutorReady,
1820
+ isAlchemySponsorshipLimitError,
1024
1821
  isAsyncCallback,
1025
1822
  isInlineCall,
1823
+ isProviderConfigured,
1026
1824
  isSystemError,
1027
1825
  isSystemNotice,
1028
1826
  normalizeEip712Payload,
1029
1827
  normalizeTxPayload,
1828
+ parseAAConfig,
1829
+ readEnv,
1830
+ resolveAlchemyConfig,
1831
+ resolveDefaultProvider,
1832
+ resolvePimlicoConfig,
1030
1833
  unwrapSystemEvent
1031
1834
  };
1032
1835
  //# sourceMappingURL=index.js.map