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