@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.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,742 @@ 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
|
+
} = options;
|
|
1409
|
+
if (!calls || localPrivateKey) {
|
|
1410
|
+
return null;
|
|
1411
|
+
}
|
|
1412
|
+
const config = __spreadProps(__spreadValues({}, accountAbstractionConfig), {
|
|
1413
|
+
provider: "alchemy"
|
|
1414
|
+
});
|
|
1415
|
+
const chainConfig = getAAChainConfig(config, calls, chainsById);
|
|
1416
|
+
if (!chainConfig) {
|
|
1417
|
+
if (throwOnMissingConfig) {
|
|
1418
|
+
const chainIds = Array.from(new Set(calls.map((c) => c.chainId)));
|
|
1419
|
+
throw new Error(
|
|
1420
|
+
`AA is not configured for chain ${chainIds[0]}, or batching is disabled for that chain.`
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
return null;
|
|
1424
|
+
}
|
|
1425
|
+
const apiKey = readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
|
|
1426
|
+
if (!apiKey) {
|
|
1427
|
+
if (throwOnMissingConfig) {
|
|
1428
|
+
throw new Error("Alchemy AA requires ALCHEMY_API_KEY.");
|
|
1429
|
+
}
|
|
1430
|
+
return null;
|
|
1431
|
+
}
|
|
1432
|
+
const chain = chainsById[chainConfig.chainId];
|
|
1433
|
+
if (!chain) {
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
const gasPolicyId = readGasPolicyEnv(
|
|
1437
|
+
chainConfig.chainId,
|
|
1438
|
+
chainSlugById,
|
|
1439
|
+
ALCHEMY_GAS_POLICY_ENVS,
|
|
1440
|
+
{ publicOnly }
|
|
1441
|
+
);
|
|
1442
|
+
if (chainConfig.sponsorship === "required" && !gasPolicyId) {
|
|
1443
|
+
if (throwOnMissingConfig) {
|
|
1444
|
+
throw new Error(
|
|
1445
|
+
`Alchemy gas policy required for chain ${chainConfig.chainId} but not configured.`
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
if (modeOverride && !chainConfig.supportedModes.includes(modeOverride)) {
|
|
1451
|
+
if (throwOnMissingConfig) {
|
|
1452
|
+
throw new Error(
|
|
1453
|
+
`AA mode "${modeOverride}" is not supported on chain ${chainConfig.chainId}.`
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
return null;
|
|
1457
|
+
}
|
|
1458
|
+
const resolvedChainConfig = modeOverride ? __spreadProps(__spreadValues({}, chainConfig), { defaultMode: modeOverride }) : chainConfig;
|
|
1459
|
+
const plan = buildAAExecutionPlan(config, resolvedChainConfig);
|
|
1460
|
+
return {
|
|
1461
|
+
chainConfig: resolvedChainConfig,
|
|
1462
|
+
plan,
|
|
1463
|
+
apiKey,
|
|
1464
|
+
chain,
|
|
1465
|
+
rpcUrl: getPreferredRpcUrl(chain),
|
|
1466
|
+
gasPolicyId,
|
|
1467
|
+
mode: resolvedChainConfig.defaultMode
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function resolvePimlicoConfig(options) {
|
|
1471
|
+
const {
|
|
1472
|
+
calls,
|
|
1473
|
+
localPrivateKey,
|
|
1474
|
+
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1475
|
+
chainsById,
|
|
1476
|
+
rpcUrl,
|
|
1477
|
+
modeOverride,
|
|
1478
|
+
publicOnly = false,
|
|
1479
|
+
throwOnMissingConfig = false
|
|
1480
|
+
} = options;
|
|
1481
|
+
if (!calls || localPrivateKey) {
|
|
1482
|
+
return null;
|
|
1483
|
+
}
|
|
1484
|
+
const config = __spreadProps(__spreadValues({}, accountAbstractionConfig), {
|
|
1485
|
+
provider: "pimlico"
|
|
1486
|
+
});
|
|
1487
|
+
const chainConfig = getAAChainConfig(config, calls, chainsById);
|
|
1488
|
+
if (!chainConfig) {
|
|
1489
|
+
if (throwOnMissingConfig) {
|
|
1490
|
+
const chainIds = Array.from(new Set(calls.map((c) => c.chainId)));
|
|
1491
|
+
throw new Error(
|
|
1492
|
+
`AA is not configured for chain ${chainIds[0]}, or batching is disabled for that chain.`
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
const apiKey = readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
|
|
1498
|
+
if (!apiKey) {
|
|
1499
|
+
if (throwOnMissingConfig) {
|
|
1500
|
+
throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
|
|
1501
|
+
}
|
|
1502
|
+
return null;
|
|
1503
|
+
}
|
|
1504
|
+
const chain = chainsById[chainConfig.chainId];
|
|
1505
|
+
if (!chain) {
|
|
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,
|
|
1524
|
+
mode: resolvedChainConfig.defaultMode
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
// src/aa/alchemy.ts
|
|
1529
|
+
function createAlchemyAAProvider({
|
|
1530
|
+
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1531
|
+
useAlchemyAA,
|
|
1532
|
+
chainsById,
|
|
1533
|
+
chainSlugById,
|
|
1534
|
+
getPreferredRpcUrl
|
|
1535
|
+
}) {
|
|
1536
|
+
return function useAlchemyAAProvider(calls, localPrivateKey) {
|
|
1537
|
+
var _a, _b;
|
|
1538
|
+
const resolved = resolveAlchemyConfig({
|
|
1539
|
+
calls,
|
|
1540
|
+
localPrivateKey,
|
|
1541
|
+
accountAbstractionConfig,
|
|
1542
|
+
chainsById,
|
|
1543
|
+
chainSlugById,
|
|
1544
|
+
getPreferredRpcUrl,
|
|
1545
|
+
publicOnly: true
|
|
1546
|
+
});
|
|
1547
|
+
const params = resolved ? {
|
|
1548
|
+
enabled: true,
|
|
1549
|
+
apiKey: resolved.apiKey,
|
|
1550
|
+
chain: resolved.chain,
|
|
1551
|
+
rpcUrl: resolved.rpcUrl,
|
|
1552
|
+
gasPolicyId: resolved.gasPolicyId,
|
|
1553
|
+
mode: resolved.mode
|
|
1554
|
+
} : void 0;
|
|
1555
|
+
const query = useAlchemyAA(params);
|
|
1556
|
+
return {
|
|
1557
|
+
plan: (_a = resolved == null ? void 0 : resolved.plan) != null ? _a : null,
|
|
1558
|
+
query,
|
|
1559
|
+
AA: query.AA,
|
|
1560
|
+
isPending: Boolean(resolved && query.isPending),
|
|
1561
|
+
error: (_b = query.error) != null ? _b : null
|
|
1562
|
+
};
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// src/aa/pimlico.ts
|
|
1567
|
+
function createPimlicoAAProvider({
|
|
1568
|
+
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1569
|
+
usePimlicoAA,
|
|
1570
|
+
chainsById,
|
|
1571
|
+
rpcUrl
|
|
1572
|
+
}) {
|
|
1573
|
+
return function usePimlicoAAProvider(calls, localPrivateKey) {
|
|
1574
|
+
var _a, _b;
|
|
1575
|
+
const resolved = resolvePimlicoConfig({
|
|
1576
|
+
calls,
|
|
1577
|
+
localPrivateKey,
|
|
1578
|
+
accountAbstractionConfig,
|
|
1579
|
+
chainsById,
|
|
1580
|
+
rpcUrl,
|
|
1581
|
+
publicOnly: true
|
|
1582
|
+
});
|
|
1583
|
+
const params = resolved ? {
|
|
1584
|
+
enabled: true,
|
|
1585
|
+
apiKey: resolved.apiKey,
|
|
1586
|
+
chain: resolved.chain,
|
|
1587
|
+
mode: resolved.mode,
|
|
1588
|
+
rpcUrl: resolved.rpcUrl
|
|
1589
|
+
} : void 0;
|
|
1590
|
+
const query = usePimlicoAA(params);
|
|
1591
|
+
return {
|
|
1592
|
+
plan: (_a = resolved == null ? void 0 : resolved.plan) != null ? _a : null,
|
|
1593
|
+
query,
|
|
1594
|
+
AA: query.AA,
|
|
1595
|
+
isPending: Boolean(resolved && query.isPending),
|
|
1596
|
+
error: (_b = query.error) != null ? _b : null
|
|
1597
|
+
};
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
// src/aa/adapt.ts
|
|
1602
|
+
function adaptSmartAccount(account) {
|
|
1603
|
+
return {
|
|
1604
|
+
provider: account.provider,
|
|
1605
|
+
mode: account.mode,
|
|
1606
|
+
AAAddress: account.smartAccountAddress,
|
|
1607
|
+
delegationAddress: account.delegationAddress,
|
|
1608
|
+
sendTransaction: async (call) => {
|
|
1609
|
+
const receipt = await account.sendTransaction(call);
|
|
1610
|
+
return { transactionHash: receipt.transactionHash };
|
|
1611
|
+
},
|
|
1612
|
+
sendBatchTransaction: async (calls) => {
|
|
1613
|
+
const receipt = await account.sendBatchTransaction(calls);
|
|
1614
|
+
return { transactionHash: receipt.transactionHash };
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
function isAlchemySponsorshipLimitError(error) {
|
|
1619
|
+
const message = error instanceof Error ? error.message : String(error != null ? error : "");
|
|
1620
|
+
const normalized = message.toLowerCase();
|
|
1621
|
+
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");
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
// src/aa/create.ts
|
|
1625
|
+
import { createAlchemySmartAccount } from "@getpara/aa-alchemy";
|
|
1626
|
+
import { createPimlicoSmartAccount } from "@getpara/aa-pimlico";
|
|
1627
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
1628
|
+
async function createAAProviderState(options) {
|
|
1629
|
+
if (options.provider === "alchemy") {
|
|
1630
|
+
return createAlchemyAAState(options);
|
|
1631
|
+
}
|
|
1632
|
+
return createPimlicoAAState(options);
|
|
1633
|
+
}
|
|
1634
|
+
async function createAlchemyAAState(options) {
|
|
1635
|
+
var _a, _b;
|
|
1636
|
+
const {
|
|
1637
|
+
chain,
|
|
1638
|
+
privateKey,
|
|
1639
|
+
rpcUrl,
|
|
1640
|
+
callList,
|
|
1641
|
+
mode,
|
|
1642
|
+
sponsored = true
|
|
1643
|
+
} = options;
|
|
1644
|
+
const resolved = resolveAlchemyConfig({
|
|
1645
|
+
calls: callList,
|
|
1646
|
+
chainsById: { [chain.id]: chain },
|
|
1647
|
+
modeOverride: mode,
|
|
1648
|
+
throwOnMissingConfig: true,
|
|
1649
|
+
getPreferredRpcUrl: () => rpcUrl
|
|
1650
|
+
});
|
|
1651
|
+
if (!resolved) {
|
|
1652
|
+
throw new Error("Alchemy AA config resolution failed.");
|
|
1653
|
+
}
|
|
1654
|
+
const apiKey = (_a = options.apiKey) != null ? _a : resolved.apiKey;
|
|
1655
|
+
const gasPolicyId = sponsored ? (_b = options.gasPolicyId) != null ? _b : readEnv(ALCHEMY_GAS_POLICY_ENVS) : void 0;
|
|
1656
|
+
const plan = __spreadProps(__spreadValues({}, resolved.plan), {
|
|
1657
|
+
sponsorship: gasPolicyId ? resolved.plan.sponsorship : "disabled",
|
|
1658
|
+
fallbackToEoa: false
|
|
1659
|
+
});
|
|
1660
|
+
const signer = privateKeyToAccount(privateKey);
|
|
1661
|
+
try {
|
|
1662
|
+
const smartAccount = await createAlchemySmartAccount({
|
|
1663
|
+
para: void 0,
|
|
1664
|
+
signer,
|
|
1665
|
+
apiKey,
|
|
1666
|
+
gasPolicyId,
|
|
1667
|
+
chain,
|
|
1668
|
+
rpcUrl,
|
|
1669
|
+
mode: plan.mode
|
|
1670
|
+
});
|
|
1671
|
+
if (!smartAccount) {
|
|
1672
|
+
return {
|
|
1673
|
+
plan,
|
|
1674
|
+
AA: null,
|
|
1675
|
+
isPending: false,
|
|
1676
|
+
error: new Error("Alchemy AA account could not be initialized.")
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
return {
|
|
1680
|
+
plan,
|
|
1681
|
+
AA: adaptSmartAccount(smartAccount),
|
|
1682
|
+
isPending: false,
|
|
1683
|
+
error: null
|
|
1684
|
+
};
|
|
1685
|
+
} catch (error) {
|
|
1686
|
+
return {
|
|
1687
|
+
plan,
|
|
1688
|
+
AA: null,
|
|
1689
|
+
isPending: false,
|
|
1690
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
async function createPimlicoAAState(options) {
|
|
1695
|
+
var _a;
|
|
1696
|
+
const {
|
|
1697
|
+
chain,
|
|
1698
|
+
privateKey,
|
|
1699
|
+
rpcUrl,
|
|
1700
|
+
callList,
|
|
1701
|
+
mode
|
|
1702
|
+
} = options;
|
|
1703
|
+
const resolved = resolvePimlicoConfig({
|
|
1704
|
+
calls: callList,
|
|
1705
|
+
chainsById: { [chain.id]: chain },
|
|
1706
|
+
rpcUrl,
|
|
1707
|
+
modeOverride: mode,
|
|
1708
|
+
throwOnMissingConfig: true
|
|
1709
|
+
});
|
|
1710
|
+
if (!resolved) {
|
|
1711
|
+
throw new Error("Pimlico AA config resolution failed.");
|
|
1712
|
+
}
|
|
1713
|
+
const apiKey = (_a = options.apiKey) != null ? _a : resolved.apiKey;
|
|
1714
|
+
const plan = __spreadProps(__spreadValues({}, resolved.plan), {
|
|
1715
|
+
fallbackToEoa: false
|
|
1716
|
+
});
|
|
1717
|
+
const signer = privateKeyToAccount(privateKey);
|
|
1718
|
+
try {
|
|
1719
|
+
const smartAccount = await createPimlicoSmartAccount({
|
|
1720
|
+
para: void 0,
|
|
1721
|
+
signer,
|
|
1722
|
+
apiKey,
|
|
1723
|
+
chain,
|
|
1724
|
+
rpcUrl,
|
|
1725
|
+
mode: plan.mode
|
|
1726
|
+
});
|
|
1727
|
+
if (!smartAccount) {
|
|
1728
|
+
return {
|
|
1729
|
+
plan,
|
|
1730
|
+
AA: null,
|
|
1731
|
+
isPending: false,
|
|
1732
|
+
error: new Error("Pimlico AA account could not be initialized.")
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
return {
|
|
1736
|
+
plan,
|
|
1737
|
+
AA: adaptSmartAccount(smartAccount),
|
|
1738
|
+
isPending: false,
|
|
1739
|
+
error: null
|
|
1740
|
+
};
|
|
1741
|
+
} catch (error) {
|
|
1742
|
+
return {
|
|
1743
|
+
plan,
|
|
1744
|
+
AA: null,
|
|
1745
|
+
isPending: false,
|
|
1746
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1020
1750
|
export {
|
|
1021
1751
|
AomiClient,
|
|
1752
|
+
DEFAULT_AA_CONFIG,
|
|
1022
1753
|
ClientSession as Session,
|
|
1023
1754
|
TypedEventEmitter,
|
|
1755
|
+
adaptSmartAccount,
|
|
1756
|
+
buildAAExecutionPlan,
|
|
1757
|
+
createAAProviderState,
|
|
1758
|
+
createAlchemyAAProvider,
|
|
1759
|
+
createPimlicoAAProvider,
|
|
1760
|
+
executeWalletCalls,
|
|
1761
|
+
getAAChainConfig,
|
|
1762
|
+
getWalletExecutorReady,
|
|
1763
|
+
isAlchemySponsorshipLimitError,
|
|
1024
1764
|
isAsyncCallback,
|
|
1025
1765
|
isInlineCall,
|
|
1766
|
+
isProviderConfigured,
|
|
1026
1767
|
isSystemError,
|
|
1027
1768
|
isSystemNotice,
|
|
1028
1769
|
normalizeEip712Payload,
|
|
1029
1770
|
normalizeTxPayload,
|
|
1771
|
+
parseAAConfig,
|
|
1772
|
+
readEnv,
|
|
1773
|
+
resolveAlchemyConfig,
|
|
1774
|
+
resolveDefaultProvider,
|
|
1775
|
+
resolvePimlicoConfig,
|
|
1030
1776
|
unwrapSystemEvent
|
|
1031
1777
|
};
|
|
1032
1778
|
//# sourceMappingURL=index.js.map
|