@embarkai/ui-kit 0.4.19 → 0.4.20
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/README.md +66 -0
- package/dist/iframe/index.html +1 -1
- package/dist/iframe/main.js +9 -5
- package/dist/index.cjs +497 -729
- package/dist/index.d.cts +207 -232
- package/dist/index.d.ts +207 -232
- package/dist/index.js +437 -676
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -700,10 +700,13 @@ async function signDigestWithMpc(userId, digest32, userOpDetails) {
|
|
|
700
700
|
if (!accessToken) {
|
|
701
701
|
throw new Error("No access token available for signing");
|
|
702
702
|
}
|
|
703
|
+
const batchOperations = userOpDetails?.operations || [];
|
|
704
|
+
const firstBatchOperation = batchOperations[0];
|
|
705
|
+
const batchValue = batchOperations.length > 0 ? batchOperations.reduce((total, operation) => total + BigInt(operation.value || "0"), 0n).toString() : void 0;
|
|
703
706
|
const transaction = {
|
|
704
|
-
to: userOpDetails?.callTarget || "0x0000000000000000000000000000000000000000",
|
|
705
|
-
value: userOpDetails?.value || "0",
|
|
706
|
-
data: userOpDetails?.callData || "0x",
|
|
707
|
+
to: userOpDetails?.callTarget || firstBatchOperation?.to || "0x0000000000000000000000000000000000000000",
|
|
708
|
+
value: userOpDetails?.value || batchValue || "0",
|
|
709
|
+
data: userOpDetails?.callData || firstBatchOperation?.data || "0x",
|
|
707
710
|
digest32,
|
|
708
711
|
// Pre-computed digest - DO NOT recompute!
|
|
709
712
|
// Additional UserOp fields for display in confirmation modal
|
|
@@ -1038,11 +1041,14 @@ var init_BalanceFeedProvider2 = __esm({
|
|
|
1038
1041
|
});
|
|
1039
1042
|
|
|
1040
1043
|
// src/internal/clients/account/constants.ts
|
|
1041
|
-
var PAYMASTER_VERIFICATION_GAS_LIMIT, PAYMASTER_POSTOP_GAS_LIMIT, SALT_ZERO, SALT_ZERO_UINT256, COMPAT_CREATE_ABI, executeAbi, entryPointDepositAbi;
|
|
1044
|
+
var PAYMASTER_VERIFICATION_GAS_LIMIT, PAYMASTER_POSTOP_GAS_LIMIT, MAX_BUNDLER_VERIFICATION_GAS, PAYMASTER_VERIFICATION_GAS, PAYMASTER_POSTOP_GAS, SALT_ZERO, SALT_ZERO_UINT256, COMPAT_CREATE_ABI, executeAbi, executeBatchAbi, entryPointDepositAbi;
|
|
1042
1045
|
var init_constants2 = __esm({
|
|
1043
1046
|
"src/internal/clients/account/constants.ts"() {
|
|
1044
1047
|
PAYMASTER_VERIFICATION_GAS_LIMIT = "0x249f0";
|
|
1045
1048
|
PAYMASTER_POSTOP_GAS_LIMIT = "0x186a0";
|
|
1049
|
+
MAX_BUNDLER_VERIFICATION_GAS = 5000000n;
|
|
1050
|
+
PAYMASTER_VERIFICATION_GAS = 150000n;
|
|
1051
|
+
PAYMASTER_POSTOP_GAS = 100000n;
|
|
1046
1052
|
SALT_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1047
1053
|
SALT_ZERO_UINT256 = 0n;
|
|
1048
1054
|
COMPAT_CREATE_ABI = [
|
|
@@ -1070,6 +1076,19 @@ var init_constants2 = __esm({
|
|
|
1070
1076
|
outputs: []
|
|
1071
1077
|
}
|
|
1072
1078
|
];
|
|
1079
|
+
executeBatchAbi = [
|
|
1080
|
+
{
|
|
1081
|
+
type: "function",
|
|
1082
|
+
name: "executeBatch",
|
|
1083
|
+
stateMutability: "payable",
|
|
1084
|
+
inputs: [
|
|
1085
|
+
{ name: "dest", type: "address[]" },
|
|
1086
|
+
{ name: "value", type: "uint256[]" },
|
|
1087
|
+
{ name: "func", type: "bytes[]" }
|
|
1088
|
+
],
|
|
1089
|
+
outputs: []
|
|
1090
|
+
}
|
|
1091
|
+
];
|
|
1073
1092
|
entryPointDepositAbi = [
|
|
1074
1093
|
{
|
|
1075
1094
|
type: "function",
|
|
@@ -1277,317 +1296,6 @@ var init_ChainSync2 = __esm({
|
|
|
1277
1296
|
}
|
|
1278
1297
|
});
|
|
1279
1298
|
|
|
1280
|
-
// src/internal/akHelpers.ts
|
|
1281
|
-
async function fetchEntryPointNonce(account, entryPoint, context) {
|
|
1282
|
-
const { client } = context;
|
|
1283
|
-
try {
|
|
1284
|
-
const nonce = await client.readContract({
|
|
1285
|
-
address: entryPoint,
|
|
1286
|
-
abi: ENTRY_POINT_NONCE_ABI,
|
|
1287
|
-
functionName: "getNonce",
|
|
1288
|
-
args: [account, 0n]
|
|
1289
|
-
});
|
|
1290
|
-
if (typeof nonce === "bigint") return `0x${nonce.toString(16)}`;
|
|
1291
|
-
} catch {
|
|
1292
|
-
}
|
|
1293
|
-
return "0x0";
|
|
1294
|
-
}
|
|
1295
|
-
var pack2x128;
|
|
1296
|
-
var init_akHelpers = __esm({
|
|
1297
|
-
"src/internal/akHelpers.ts"() {
|
|
1298
|
-
init_abis();
|
|
1299
|
-
pack2x128 = (hi, lo) => {
|
|
1300
|
-
return `0x${(hi << 128n | lo & (1n << 128n) - 1n).toString(16).padStart(64, "0")}`;
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
});
|
|
1304
|
-
|
|
1305
|
-
// src/internal/clients/account/resolve-paymaster.ts
|
|
1306
|
-
import { resolveProjectPaymaster } from "@embarkai/core";
|
|
1307
|
-
import { getChainConfig as getChainConfig2 } from "@embarkai/core/read";
|
|
1308
|
-
async function resolveUiKitPaymaster(chainId, shouldUsePaymaster) {
|
|
1309
|
-
if (!shouldUsePaymaster) {
|
|
1310
|
-
return {
|
|
1311
|
-
address: null,
|
|
1312
|
-
source: "none",
|
|
1313
|
-
chainId
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
const chainConfig = getChainConfig2(chainId);
|
|
1317
|
-
return resolveProjectPaymaster({
|
|
1318
|
-
chainId,
|
|
1319
|
-
projectId: getProjectId(),
|
|
1320
|
-
defaultPaymasterAddress: chainConfig?.paymasterAddress,
|
|
1321
|
-
dashboardApiUrl: getDashboardApiUrl()
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
var init_resolve_paymaster = __esm({
|
|
1325
|
-
"src/internal/clients/account/resolve-paymaster.ts"() {
|
|
1326
|
-
init_base();
|
|
1327
|
-
init_projectId();
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
|
|
1331
|
-
// src/internal/clients/account/deposit-for-smart-account.ts
|
|
1332
|
-
import { getChainConfig as getChainConfig3, getViemChain } from "@embarkai/core/read";
|
|
1333
|
-
import { createWalletClient, http, parseEther } from "viem";
|
|
1334
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
1335
|
-
async function depositForSmartAccount(address, amountEth = "0.01") {
|
|
1336
|
-
const chainId = requireActiveChainId();
|
|
1337
|
-
const chainConfig = getChainConfig3(chainId);
|
|
1338
|
-
if (!FUNDER_PK) throw new Error("VITE_FUNDER_PK is not set");
|
|
1339
|
-
const entryPointAddress = chainConfig.entryPointV07Address;
|
|
1340
|
-
const funder = privateKeyToAccount(FUNDER_PK);
|
|
1341
|
-
const viemChain = getViemChain(chainId);
|
|
1342
|
-
const wallet = createWalletClient({
|
|
1343
|
-
account: funder,
|
|
1344
|
-
chain: viemChain,
|
|
1345
|
-
transport: http(viemChain.rpcUrls.default.http[0])
|
|
1346
|
-
});
|
|
1347
|
-
const hash = await wallet.writeContract({
|
|
1348
|
-
address: entryPointAddress,
|
|
1349
|
-
abi: entryPointDepositAbi,
|
|
1350
|
-
functionName: "depositTo",
|
|
1351
|
-
args: [address],
|
|
1352
|
-
value: parseEther(amountEth),
|
|
1353
|
-
type: "legacy",
|
|
1354
|
-
gasPrice: 1000000000n
|
|
1355
|
-
});
|
|
1356
|
-
return hash;
|
|
1357
|
-
}
|
|
1358
|
-
var init_deposit_for_smart_account = __esm({
|
|
1359
|
-
"src/internal/clients/account/deposit-for-smart-account.ts"() {
|
|
1360
|
-
init_index();
|
|
1361
|
-
init_base();
|
|
1362
|
-
init_constants2();
|
|
1363
|
-
}
|
|
1364
|
-
});
|
|
1365
|
-
|
|
1366
|
-
// src/internal/clients/account/user-operations.ts
|
|
1367
|
-
import {
|
|
1368
|
-
createUserOperationWithDynamicFees,
|
|
1369
|
-
estimateUserOperationGas,
|
|
1370
|
-
sendUserOperationWithRetry
|
|
1371
|
-
} from "@embarkai/core/bundler";
|
|
1372
|
-
import { createPublicClientForChain, getChainConfig as getChainConfig4 } from "@embarkai/core/read";
|
|
1373
|
-
import { encodeFunctionData } from "viem";
|
|
1374
|
-
import { entryPoint07Abi } from "viem/account-abstraction";
|
|
1375
|
-
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
1376
|
-
async function sendUserOperation(session, params) {
|
|
1377
|
-
const chainId = params.chainId ?? requireActiveChainId();
|
|
1378
|
-
const chainConfig = getChainConfig4(chainId);
|
|
1379
|
-
if (!chainConfig) {
|
|
1380
|
-
throw new Error(`Chain ${chainId} is not supported`);
|
|
1381
|
-
}
|
|
1382
|
-
const chainPublicClient = createPublicClientForChain(chainId);
|
|
1383
|
-
const bundlerUrl = chainConfig.bundlerUrl;
|
|
1384
|
-
const { to: callTarget, value: amountWei, data: innerData = "0x", feeType = "standard" } = params;
|
|
1385
|
-
const entryPointAddress = chainConfig.entryPointV07Address;
|
|
1386
|
-
const amountWeiBigInt = BigInt(amountWei);
|
|
1387
|
-
const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && amountWei === "0" && innerData === "0x";
|
|
1388
|
-
let callData;
|
|
1389
|
-
if (isMinimalTest) {
|
|
1390
|
-
callData = "0x";
|
|
1391
|
-
} else {
|
|
1392
|
-
callData = encodeFunctionData({
|
|
1393
|
-
abi: executeAbi,
|
|
1394
|
-
functionName: "execute",
|
|
1395
|
-
args: [callTarget, amountWeiBigInt, innerData]
|
|
1396
|
-
});
|
|
1397
|
-
}
|
|
1398
|
-
let isDeployed = false;
|
|
1399
|
-
try {
|
|
1400
|
-
const code = await chainPublicClient.getCode({ address: session.smartAccountAddress });
|
|
1401
|
-
if (code && code !== "0x" && code.length > 2) {
|
|
1402
|
-
isDeployed = true;
|
|
1403
|
-
}
|
|
1404
|
-
} catch {
|
|
1405
|
-
}
|
|
1406
|
-
const nonce = await fetchEntryPointNonce(session.smartAccountAddress, entryPointAddress, {
|
|
1407
|
-
client: chainPublicClient
|
|
1408
|
-
});
|
|
1409
|
-
const nonceValue = BigInt(nonce);
|
|
1410
|
-
if (!isDeployed && nonceValue !== 0n) {
|
|
1411
|
-
throw new Error(`Undeployed account has non-zero nonce: ${nonce}. This will cause CodeHashChanged error.`);
|
|
1412
|
-
}
|
|
1413
|
-
const shouldIncludeFactory = !isDeployed;
|
|
1414
|
-
let userOp;
|
|
1415
|
-
if (shouldIncludeFactory) {
|
|
1416
|
-
const factoryData = encodeFunctionData({
|
|
1417
|
-
abi: COMPAT_CREATE_ABI,
|
|
1418
|
-
functionName: "createAccount",
|
|
1419
|
-
args: [session.ownerAddress, SALT_ZERO_UINT256]
|
|
1420
|
-
});
|
|
1421
|
-
userOp = await createUserOperationWithDynamicFees(
|
|
1422
|
-
{
|
|
1423
|
-
sender: session.smartAccountAddress,
|
|
1424
|
-
nonce,
|
|
1425
|
-
callData,
|
|
1426
|
-
includeFactory: true,
|
|
1427
|
-
factoryAddress: session.factoryAddress,
|
|
1428
|
-
factoryData,
|
|
1429
|
-
feeType
|
|
1430
|
-
},
|
|
1431
|
-
{ client: chainPublicClient, bundlerUrl, chainConfig }
|
|
1432
|
-
);
|
|
1433
|
-
} else {
|
|
1434
|
-
userOp = await createUserOperationWithDynamicFees(
|
|
1435
|
-
{
|
|
1436
|
-
sender: session.smartAccountAddress,
|
|
1437
|
-
nonce,
|
|
1438
|
-
callData,
|
|
1439
|
-
includeFactory: false,
|
|
1440
|
-
feeType
|
|
1441
|
-
},
|
|
1442
|
-
{ client: chainPublicClient, bundlerUrl, chainConfig }
|
|
1443
|
-
);
|
|
1444
|
-
}
|
|
1445
|
-
const storeUsePaymaster = useSession.getState().usePaymaster;
|
|
1446
|
-
const shouldUsePaymaster = storeUsePaymaster ?? session.usePaymaster ?? false;
|
|
1447
|
-
const resolvedPaymaster = await resolveUiKitPaymaster(chainId, shouldUsePaymaster);
|
|
1448
|
-
if (resolvedPaymaster.address) {
|
|
1449
|
-
userOp.paymaster = resolvedPaymaster.address;
|
|
1450
|
-
userOp.paymasterData = "0x";
|
|
1451
|
-
userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT;
|
|
1452
|
-
userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT;
|
|
1453
|
-
}
|
|
1454
|
-
try {
|
|
1455
|
-
const gasEst = await estimateUserOperationGas(
|
|
1456
|
-
{ ...userOp, signature: `0x${"00".repeat(65)}` },
|
|
1457
|
-
{ chainId: chainConfig.id, retryWithoutFactory: true }
|
|
1458
|
-
);
|
|
1459
|
-
console.log("[Account] Gas estimation from bundler:", {
|
|
1460
|
-
callGasLimit: gasEst.callGasLimit,
|
|
1461
|
-
verificationGasLimit: gasEst.verificationGasLimit,
|
|
1462
|
-
preVerificationGas: gasEst.preVerificationGas
|
|
1463
|
-
});
|
|
1464
|
-
userOp.callGasLimit = gasEst.callGasLimit;
|
|
1465
|
-
userOp.verificationGasLimit = gasEst.verificationGasLimit;
|
|
1466
|
-
userOp.preVerificationGas = gasEst.preVerificationGas;
|
|
1467
|
-
} catch (e) {
|
|
1468
|
-
console.log("[Account] Gas estimation failed:", e);
|
|
1469
|
-
throw new Error(`Gas estimation failed: ${e}`);
|
|
1470
|
-
}
|
|
1471
|
-
const signUserOp = async (nonce2) => {
|
|
1472
|
-
userOp.nonce = nonce2;
|
|
1473
|
-
const hasFactoryData = !!(userOp.factory && userOp.factoryData);
|
|
1474
|
-
const initCode = hasFactoryData ? (() => {
|
|
1475
|
-
const factoryAddr = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
|
|
1476
|
-
const factoryDataClean = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
|
|
1477
|
-
return `0x${factoryAddr}${factoryDataClean}`;
|
|
1478
|
-
})() : "0x";
|
|
1479
|
-
const accountGasLimits = pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit));
|
|
1480
|
-
const gasFees = pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas));
|
|
1481
|
-
let paymasterAndData = "0x";
|
|
1482
|
-
if (userOp.paymaster && userOp.paymaster !== "0x0000000000000000000000000000000000000000") {
|
|
1483
|
-
const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
|
|
1484
|
-
const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
|
|
1485
|
-
const paymasterDataField = userOp.paymasterData || "0x";
|
|
1486
|
-
const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
|
|
1487
|
-
const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
|
|
1488
|
-
const paymasterDataClean = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
|
|
1489
|
-
paymasterAndData = `0x${paymasterAddr}${packedPaymasterGasLimits.slice(2)}${paymasterDataClean}`;
|
|
1490
|
-
}
|
|
1491
|
-
const packedForHash = {
|
|
1492
|
-
sender: session.smartAccountAddress,
|
|
1493
|
-
nonce: BigInt(nonce2),
|
|
1494
|
-
initCode,
|
|
1495
|
-
callData,
|
|
1496
|
-
accountGasLimits,
|
|
1497
|
-
preVerificationGas: BigInt(userOp.preVerificationGas),
|
|
1498
|
-
gasFees,
|
|
1499
|
-
paymasterAndData,
|
|
1500
|
-
signature: "0x"
|
|
1501
|
-
};
|
|
1502
|
-
const opHash = await chainPublicClient.readContract({
|
|
1503
|
-
address: entryPointAddress,
|
|
1504
|
-
abi: entryPoint07Abi,
|
|
1505
|
-
functionName: "getUserOpHash",
|
|
1506
|
-
args: [packedForHash]
|
|
1507
|
-
});
|
|
1508
|
-
let signature;
|
|
1509
|
-
if (session.mpcUserId) {
|
|
1510
|
-
signature = await signDigestWithMpc(session.mpcUserId, opHash, {
|
|
1511
|
-
sender: userOp.sender,
|
|
1512
|
-
nonce: userOp.nonce,
|
|
1513
|
-
callData: userOp.callData,
|
|
1514
|
-
callGasLimit: userOp.callGasLimit,
|
|
1515
|
-
verificationGasLimit: userOp.verificationGasLimit,
|
|
1516
|
-
preVerificationGas: userOp.preVerificationGas,
|
|
1517
|
-
maxFeePerGas: userOp.maxFeePerGas,
|
|
1518
|
-
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
|
|
1519
|
-
paymaster: userOp.paymaster,
|
|
1520
|
-
factory: userOp.factory,
|
|
1521
|
-
factoryData: userOp.factoryData,
|
|
1522
|
-
callTarget,
|
|
1523
|
-
value: amountWei
|
|
1524
|
-
});
|
|
1525
|
-
} else if (session.ownerPrivateKey) {
|
|
1526
|
-
const account = privateKeyToAccount2(session.ownerPrivateKey);
|
|
1527
|
-
const rawSig = await account.sign({ hash: opHash });
|
|
1528
|
-
signature = normalizeSignature(rawSig);
|
|
1529
|
-
} else {
|
|
1530
|
-
throw new Error("No signing method available");
|
|
1531
|
-
}
|
|
1532
|
-
userOp.signature = signature;
|
|
1533
|
-
if (typeof userOp.sender !== "string") {
|
|
1534
|
-
userOp.sender = session.smartAccountAddress;
|
|
1535
|
-
}
|
|
1536
|
-
return userOp;
|
|
1537
|
-
};
|
|
1538
|
-
userOp = await signUserOp(nonce);
|
|
1539
|
-
const hash = await sendUserOperationWithRetry(userOp, signUserOp, { chainId, maxRetries: 1 });
|
|
1540
|
-
return hash;
|
|
1541
|
-
}
|
|
1542
|
-
var init_user_operations = __esm({
|
|
1543
|
-
"src/internal/clients/account/user-operations.ts"() {
|
|
1544
|
-
init_SessionContext();
|
|
1545
|
-
init_akHelpers();
|
|
1546
|
-
init_iframe_mpc_client();
|
|
1547
|
-
init_constants2();
|
|
1548
|
-
init_helpers();
|
|
1549
|
-
init_resolve_paymaster();
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1552
|
-
|
|
1553
|
-
// src/internal/clients/account/deploy-account.ts
|
|
1554
|
-
import { createPublicClientForChain as createPublicClientForChain2 } from "@embarkai/core/read";
|
|
1555
|
-
async function deployAccount(session, feeType = "economy", options) {
|
|
1556
|
-
const chainId = options?.chainId ?? requireActiveChainId();
|
|
1557
|
-
if (!options?.force) {
|
|
1558
|
-
const publicClient = createPublicClientForChain2(chainId);
|
|
1559
|
-
try {
|
|
1560
|
-
const code = await publicClient.getCode({
|
|
1561
|
-
address: session.smartAccountAddress
|
|
1562
|
-
});
|
|
1563
|
-
const isDeployed = code && code !== "0x" && code.length > 2;
|
|
1564
|
-
if (isDeployed) {
|
|
1565
|
-
console.log("[deployAccount] Account already deployed, skipping deployment");
|
|
1566
|
-
return null;
|
|
1567
|
-
}
|
|
1568
|
-
console.log("[deployAccount] Account not deployed, initiating deployment");
|
|
1569
|
-
} catch (error) {
|
|
1570
|
-
console.warn("[deployAccount] Failed to check deployment status, proceeding with deployment:", error);
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
return sendUserOperation(session, {
|
|
1574
|
-
to: "0x0000000000000000000000000000000000000000",
|
|
1575
|
-
// to: burn address
|
|
1576
|
-
value: "0",
|
|
1577
|
-
// value: 0 (no funds)
|
|
1578
|
-
data: "0x",
|
|
1579
|
-
// data: empty (no contract call)
|
|
1580
|
-
feeType,
|
|
1581
|
-
chainId
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
var init_deploy_account = __esm({
|
|
1585
|
-
"src/internal/clients/account/deploy-account.ts"() {
|
|
1586
|
-
init_SessionContext();
|
|
1587
|
-
init_user_operations();
|
|
1588
|
-
}
|
|
1589
|
-
});
|
|
1590
|
-
|
|
1591
1299
|
// src/internal/clients/account/register-smart-account-address.ts
|
|
1592
1300
|
async function registerSmartAccountAddress(chainId, smartAccountAddress, factoryAddress) {
|
|
1593
1301
|
const accessToken = jwtTokenManager2.getAccessToken();
|
|
@@ -1698,77 +1406,193 @@ var init_register_smart_account_address = __esm({
|
|
|
1698
1406
|
}
|
|
1699
1407
|
});
|
|
1700
1408
|
|
|
1701
|
-
// src/internal/clients/account.ts
|
|
1409
|
+
// src/internal/clients/account/session.ts
|
|
1410
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
1411
|
+
import { getChainConfig as getChainConfig2, createPublicClientForChain } from "@embarkai/core/read";
|
|
1412
|
+
async function createAccountSession(params) {
|
|
1413
|
+
const { privateKey, mpcUserId, usePaymaster = false, chainId } = params;
|
|
1414
|
+
if (!privateKey && !mpcUserId) throw new Error("Either privateKey or mpcUserId must be provided");
|
|
1415
|
+
if (!privateKey && mpcUserId && !mpcUserId.trim()) throw new Error("mpcUserId cannot be empty when using MPC mode");
|
|
1416
|
+
const chainConfig = getChainConfig2(chainId);
|
|
1417
|
+
if (!chainConfig) {
|
|
1418
|
+
throw new Error(`Chain ${chainId} is not supported`);
|
|
1419
|
+
}
|
|
1420
|
+
const factoryAddress = chainConfig.factoryAddress;
|
|
1421
|
+
if (!factoryAddress) {
|
|
1422
|
+
throw new Error(`Factory address not configured for chain ${chainId}`);
|
|
1423
|
+
}
|
|
1424
|
+
const publicClient = createPublicClientForChain(chainId);
|
|
1425
|
+
let ownerAddress;
|
|
1426
|
+
let ownerPrivateKey;
|
|
1427
|
+
if (privateKey) {
|
|
1428
|
+
const account = privateKeyToAccount(privateKey);
|
|
1429
|
+
ownerAddress = account.address;
|
|
1430
|
+
ownerPrivateKey = privateKey;
|
|
1431
|
+
} else if (mpcUserId) {
|
|
1432
|
+
const dkgResult = await ensureDkgAndGetOwner(mpcUserId);
|
|
1433
|
+
if (!dkgResult.ownerAddress) throw new Error("Failed to get owner address from DKG");
|
|
1434
|
+
ownerAddress = dkgResult.ownerAddress;
|
|
1435
|
+
} else {
|
|
1436
|
+
throw new Error("Either privateKey or mpcUserId must be provided");
|
|
1437
|
+
}
|
|
1438
|
+
const smartAccountAddress = await predictCompatAddress(ownerAddress, factoryAddress, SALT_ZERO, { client: publicClient });
|
|
1439
|
+
if (mpcUserId) {
|
|
1440
|
+
registerSmartAccountAddress(chainId, smartAccountAddress, factoryAddress).catch((error) => {
|
|
1441
|
+
console.warn("[Account] Background Smart Account registration failed:", error);
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
return {
|
|
1445
|
+
ownerAddress,
|
|
1446
|
+
smartAccountAddress,
|
|
1447
|
+
factoryAddress,
|
|
1448
|
+
ownerPrivateKey,
|
|
1449
|
+
mpcUserId: privateKey ? void 0 : mpcUserId,
|
|
1450
|
+
usePaymaster,
|
|
1451
|
+
kind: "lumia",
|
|
1452
|
+
address: smartAccountAddress
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
var init_session = __esm({
|
|
1456
|
+
"src/internal/clients/account/session.ts"() {
|
|
1457
|
+
init_iframe_mpc_client();
|
|
1458
|
+
init_constants2();
|
|
1459
|
+
init_helpers();
|
|
1460
|
+
init_register_smart_account_address();
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
|
|
1464
|
+
// src/internal/akHelpers.ts
|
|
1465
|
+
async function fetchEntryPointNonce(account, entryPoint, context) {
|
|
1466
|
+
const { client } = context;
|
|
1467
|
+
try {
|
|
1468
|
+
const nonce = await client.readContract({
|
|
1469
|
+
address: entryPoint,
|
|
1470
|
+
abi: ENTRY_POINT_NONCE_ABI,
|
|
1471
|
+
functionName: "getNonce",
|
|
1472
|
+
args: [account, 0n]
|
|
1473
|
+
});
|
|
1474
|
+
if (typeof nonce === "bigint") return `0x${nonce.toString(16)}`;
|
|
1475
|
+
} catch {
|
|
1476
|
+
}
|
|
1477
|
+
return "0x0";
|
|
1478
|
+
}
|
|
1479
|
+
var pack2x128;
|
|
1480
|
+
var init_akHelpers = __esm({
|
|
1481
|
+
"src/internal/akHelpers.ts"() {
|
|
1482
|
+
init_abis();
|
|
1483
|
+
pack2x128 = (hi, lo) => {
|
|
1484
|
+
return `0x${(hi << 128n | lo & (1n << 128n) - 1n).toString(16).padStart(64, "0")}`;
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
// src/internal/clients/account/resolve-paymaster.ts
|
|
1490
|
+
import { resolveProjectPaymaster } from "@embarkai/core";
|
|
1491
|
+
import { getChainConfig as getChainConfig3 } from "@embarkai/core/read";
|
|
1492
|
+
async function resolveUiKitPaymaster(chainId, shouldUsePaymaster) {
|
|
1493
|
+
if (!shouldUsePaymaster) {
|
|
1494
|
+
return {
|
|
1495
|
+
address: null,
|
|
1496
|
+
source: "none",
|
|
1497
|
+
chainId
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
const chainConfig = getChainConfig3(chainId);
|
|
1501
|
+
return resolveProjectPaymaster({
|
|
1502
|
+
chainId,
|
|
1503
|
+
projectId: getProjectId(),
|
|
1504
|
+
defaultPaymasterAddress: chainConfig?.paymasterAddress,
|
|
1505
|
+
dashboardApiUrl: getDashboardApiUrl()
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
var init_resolve_paymaster = __esm({
|
|
1509
|
+
"src/internal/clients/account/resolve-paymaster.ts"() {
|
|
1510
|
+
init_base();
|
|
1511
|
+
init_projectId();
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1515
|
+
// src/internal/clients/account/user-operations.ts
|
|
1702
1516
|
import {
|
|
1703
|
-
createUserOperationWithDynamicFees
|
|
1704
|
-
estimateUserOperationGas
|
|
1705
|
-
sendUserOperationWithRetry
|
|
1517
|
+
createUserOperationWithDynamicFees,
|
|
1518
|
+
estimateUserOperationGas,
|
|
1519
|
+
sendUserOperationWithRetry
|
|
1706
1520
|
} from "@embarkai/core/bundler";
|
|
1707
|
-
import { createPublicClientForChain as
|
|
1708
|
-
import { encodeFunctionData
|
|
1709
|
-
import { entryPoint07Abi
|
|
1710
|
-
import { privateKeyToAccount as
|
|
1711
|
-
function
|
|
1712
|
-
const
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
const sBigInt = BigInt(`0x${s}`);
|
|
1717
|
-
const secp256k1n = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
1718
|
-
const secp256k1nHalf = secp256k1n >> 1n;
|
|
1719
|
-
let canonicalS = sBigInt;
|
|
1720
|
-
let canonicalV = parseInt(v, 16);
|
|
1721
|
-
if (sBigInt > secp256k1nHalf) {
|
|
1722
|
-
canonicalS = secp256k1n - sBigInt;
|
|
1723
|
-
canonicalV = canonicalV === 27 ? 28 : canonicalV === 28 ? 27 : canonicalV === 0 ? 1 : 0;
|
|
1521
|
+
import { createPublicClientForChain as createPublicClientForChain2, getChainConfig as getChainConfig4 } from "@embarkai/core/read";
|
|
1522
|
+
import { encodeFunctionData } from "viem";
|
|
1523
|
+
import { entryPoint07Abi } from "viem/account-abstraction";
|
|
1524
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
1525
|
+
function resolveExecutionContext(chainIdOverride) {
|
|
1526
|
+
const chainId = chainIdOverride ?? requireActiveChainId();
|
|
1527
|
+
const chainConfig = getChainConfig4(chainId);
|
|
1528
|
+
if (!chainConfig) {
|
|
1529
|
+
throw new Error(`Chain ${chainId} is not supported`);
|
|
1724
1530
|
}
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1531
|
+
return {
|
|
1532
|
+
bundlerUrl: chainConfig.bundlerUrl,
|
|
1533
|
+
chainConfig,
|
|
1534
|
+
chainId,
|
|
1535
|
+
chainPublicClient: createPublicClientForChain2(chainId),
|
|
1536
|
+
entryPointAddress: chainConfig.entryPointV07Address
|
|
1537
|
+
};
|
|
1728
1538
|
}
|
|
1729
|
-
|
|
1730
|
-
const
|
|
1731
|
-
const
|
|
1732
|
-
const
|
|
1733
|
-
const bundlerUrl = chainConfig.bundlerUrl;
|
|
1734
|
-
const { to: callTarget, value: amountWei, data: innerData = "0x", feeType = "standard" } = params;
|
|
1735
|
-
const entryPointAddress = chainConfig.entryPointV07Address;
|
|
1736
|
-
const amountWeiBigInt = BigInt(amountWei);
|
|
1737
|
-
const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && amountWei === "0" && innerData === "0x";
|
|
1738
|
-
let callData;
|
|
1539
|
+
function encodeSingleExecution(params) {
|
|
1540
|
+
const { to: callTarget, value, data = "0x" } = params;
|
|
1541
|
+
const amountWeiBigInt = BigInt(value);
|
|
1542
|
+
const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && value === "0" && data === "0x";
|
|
1739
1543
|
if (isMinimalTest) {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1544
|
+
return {
|
|
1545
|
+
callData: "0x",
|
|
1546
|
+
signingMetadata: { callTarget, value }
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
return {
|
|
1550
|
+
callData: encodeFunctionData({
|
|
1743
1551
|
abi: executeAbi,
|
|
1744
1552
|
functionName: "execute",
|
|
1745
|
-
args: [callTarget, amountWeiBigInt,
|
|
1746
|
-
})
|
|
1553
|
+
args: [callTarget, amountWeiBigInt, data]
|
|
1554
|
+
}),
|
|
1555
|
+
signingMetadata: { callTarget, value }
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
function encodeBatchExecution(operations) {
|
|
1559
|
+
if (!operations.length) {
|
|
1560
|
+
throw new Error("At least one operation is required for batch UserOperation");
|
|
1747
1561
|
}
|
|
1748
|
-
|
|
1562
|
+
return {
|
|
1563
|
+
callData: encodeFunctionData({
|
|
1564
|
+
abi: executeBatchAbi,
|
|
1565
|
+
functionName: "executeBatch",
|
|
1566
|
+
args: [operations.map((operation) => operation.to), operations.map((operation) => BigInt(operation.value)), operations.map((operation) => operation.data)]
|
|
1567
|
+
}),
|
|
1568
|
+
signingMetadata: { operations }
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
async function isAccountDeployed(context, smartAccountAddress) {
|
|
1749
1572
|
try {
|
|
1750
|
-
const code = await chainPublicClient.getCode({ address:
|
|
1751
|
-
|
|
1752
|
-
isDeployed = true;
|
|
1753
|
-
}
|
|
1573
|
+
const code = await context.chainPublicClient.getCode({ address: smartAccountAddress });
|
|
1574
|
+
return !!code && code !== "0x" && code.length > 2;
|
|
1754
1575
|
} catch {
|
|
1576
|
+
return false;
|
|
1755
1577
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1578
|
+
}
|
|
1579
|
+
async function createUnsignedUserOperation(session, context, callData, feeType) {
|
|
1580
|
+
const deployed = await isAccountDeployed(context, session.smartAccountAddress);
|
|
1581
|
+
const nonce = await fetchEntryPointNonce(session.smartAccountAddress, context.entryPointAddress, {
|
|
1582
|
+
client: context.chainPublicClient
|
|
1758
1583
|
});
|
|
1759
1584
|
const nonceValue = BigInt(nonce);
|
|
1760
|
-
if (!
|
|
1585
|
+
if (!deployed && nonceValue !== 0n) {
|
|
1761
1586
|
throw new Error(`Undeployed account has non-zero nonce: ${nonce}. This will cause CodeHashChanged error.`);
|
|
1762
1587
|
}
|
|
1763
|
-
const shouldIncludeFactory = !isDeployed;
|
|
1764
1588
|
let userOp;
|
|
1765
|
-
if (
|
|
1766
|
-
const factoryData =
|
|
1589
|
+
if (!deployed) {
|
|
1590
|
+
const factoryData = encodeFunctionData({
|
|
1767
1591
|
abi: COMPAT_CREATE_ABI,
|
|
1768
1592
|
functionName: "createAccount",
|
|
1769
1593
|
args: [session.ownerAddress, SALT_ZERO_UINT256]
|
|
1770
1594
|
});
|
|
1771
|
-
userOp = await
|
|
1595
|
+
userOp = await createUserOperationWithDynamicFees(
|
|
1772
1596
|
{
|
|
1773
1597
|
sender: session.smartAccountAddress,
|
|
1774
1598
|
nonce,
|
|
@@ -1778,10 +1602,10 @@ async function prepareUserOperation(session, params) {
|
|
|
1778
1602
|
factoryData,
|
|
1779
1603
|
feeType
|
|
1780
1604
|
},
|
|
1781
|
-
{ client: chainPublicClient, bundlerUrl, chainConfig }
|
|
1605
|
+
{ client: context.chainPublicClient, bundlerUrl: context.bundlerUrl, chainConfig: context.chainConfig }
|
|
1782
1606
|
);
|
|
1783
1607
|
} else {
|
|
1784
|
-
userOp = await
|
|
1608
|
+
userOp = await createUserOperationWithDynamicFees(
|
|
1785
1609
|
{
|
|
1786
1610
|
sender: session.smartAccountAddress,
|
|
1787
1611
|
nonce,
|
|
@@ -1789,20 +1613,23 @@ async function prepareUserOperation(session, params) {
|
|
|
1789
1613
|
includeFactory: false,
|
|
1790
1614
|
feeType
|
|
1791
1615
|
},
|
|
1792
|
-
{ client: chainPublicClient, bundlerUrl, chainConfig }
|
|
1616
|
+
{ client: context.chainPublicClient, bundlerUrl: context.bundlerUrl, chainConfig: context.chainConfig }
|
|
1793
1617
|
);
|
|
1794
1618
|
}
|
|
1795
1619
|
const storeUsePaymaster = useSession.getState().usePaymaster;
|
|
1796
1620
|
const shouldUsePaymaster = storeUsePaymaster ?? session.usePaymaster ?? false;
|
|
1797
|
-
const resolvedPaymaster = await resolveUiKitPaymaster(chainId, shouldUsePaymaster);
|
|
1621
|
+
const resolvedPaymaster = await resolveUiKitPaymaster(context.chainId, shouldUsePaymaster);
|
|
1798
1622
|
if (resolvedPaymaster.address) {
|
|
1799
1623
|
userOp.paymaster = resolvedPaymaster.address;
|
|
1800
1624
|
userOp.paymasterData = "0x";
|
|
1801
|
-
userOp.paymasterVerificationGasLimit =
|
|
1802
|
-
userOp.paymasterPostOpGasLimit =
|
|
1625
|
+
userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT;
|
|
1626
|
+
userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT;
|
|
1803
1627
|
}
|
|
1804
1628
|
try {
|
|
1805
|
-
const gasEst = await
|
|
1629
|
+
const gasEst = await estimateUserOperationGas(
|
|
1630
|
+
{ ...userOp, signature: `0x${"00".repeat(65)}` },
|
|
1631
|
+
{ chainId: context.chainId, retryWithoutFactory: true }
|
|
1632
|
+
);
|
|
1806
1633
|
console.log("[Account] Gas estimation from bundler:", {
|
|
1807
1634
|
callGasLimit: gasEst.callGasLimit,
|
|
1808
1635
|
verificationGasLimit: gasEst.verificationGasLimit,
|
|
@@ -1811,49 +1638,54 @@ async function prepareUserOperation(session, params) {
|
|
|
1811
1638
|
userOp.callGasLimit = gasEst.callGasLimit;
|
|
1812
1639
|
userOp.verificationGasLimit = gasEst.verificationGasLimit;
|
|
1813
1640
|
userOp.preVerificationGas = gasEst.preVerificationGas;
|
|
1814
|
-
} catch (
|
|
1815
|
-
console.log("[Account] Gas estimation failed:",
|
|
1816
|
-
throw new Error(`Gas estimation failed: ${
|
|
1641
|
+
} catch (error) {
|
|
1642
|
+
console.log("[Account] Gas estimation failed:", error);
|
|
1643
|
+
throw new Error(`Gas estimation failed: ${error}`);
|
|
1817
1644
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
const
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
const paymasterDataField = userOp.paymasterData || "0x";
|
|
1832
|
-
const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
|
|
1833
|
-
const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
|
|
1834
|
-
const paymasterDataClean = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
|
|
1835
|
-
paymasterAndData = `0x${paymasterAddr}${packedPaymasterGasLimits.slice(2)}${paymasterDataClean}`;
|
|
1645
|
+
return { nonce, userOp };
|
|
1646
|
+
}
|
|
1647
|
+
function buildInitCode(userOp) {
|
|
1648
|
+
if (!(userOp.factory && userOp.factoryData)) {
|
|
1649
|
+
return "0x";
|
|
1650
|
+
}
|
|
1651
|
+
const factoryAddress = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
|
|
1652
|
+
const factoryData = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
|
|
1653
|
+
return `0x${factoryAddress}${factoryData}`;
|
|
1654
|
+
}
|
|
1655
|
+
function buildPaymasterAndData(userOp) {
|
|
1656
|
+
if (!userOp.paymaster || userOp.paymaster === "0x0000000000000000000000000000000000000000") {
|
|
1657
|
+
return "0x";
|
|
1836
1658
|
}
|
|
1659
|
+
const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
|
|
1660
|
+
const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
|
|
1661
|
+
const paymasterDataField = userOp.paymasterData || "0x";
|
|
1662
|
+
const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
|
|
1663
|
+
const paymasterAddress = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
|
|
1664
|
+
const paymasterData = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
|
|
1665
|
+
return `0x${paymasterAddress}${packedPaymasterGasLimits.slice(2)}${paymasterData}`;
|
|
1666
|
+
}
|
|
1667
|
+
async function signPreparedUserOperation(session, context, userOp, nonce, signingMetadata) {
|
|
1668
|
+
userOp.nonce = nonce;
|
|
1837
1669
|
const packedForHash = {
|
|
1838
1670
|
sender: session.smartAccountAddress,
|
|
1839
1671
|
nonce: BigInt(nonce),
|
|
1840
|
-
initCode,
|
|
1841
|
-
callData,
|
|
1842
|
-
accountGasLimits,
|
|
1672
|
+
initCode: buildInitCode(userOp),
|
|
1673
|
+
callData: userOp.callData,
|
|
1674
|
+
accountGasLimits: pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit)),
|
|
1843
1675
|
preVerificationGas: BigInt(userOp.preVerificationGas),
|
|
1844
|
-
gasFees,
|
|
1845
|
-
paymasterAndData,
|
|
1676
|
+
gasFees: pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas)),
|
|
1677
|
+
paymasterAndData: buildPaymasterAndData(userOp),
|
|
1846
1678
|
signature: "0x"
|
|
1847
1679
|
};
|
|
1848
|
-
const
|
|
1849
|
-
address: entryPointAddress,
|
|
1850
|
-
abi:
|
|
1680
|
+
const userOpHash = await context.chainPublicClient.readContract({
|
|
1681
|
+
address: context.entryPointAddress,
|
|
1682
|
+
abi: entryPoint07Abi,
|
|
1851
1683
|
functionName: "getUserOpHash",
|
|
1852
1684
|
args: [packedForHash]
|
|
1853
1685
|
});
|
|
1854
|
-
let signature;
|
|
1855
1686
|
if (session.mpcUserId) {
|
|
1856
|
-
|
|
1687
|
+
const primaryBatchOperation = signingMetadata.operations?.[0];
|
|
1688
|
+
userOp.signature = await signDigestWithMpc(session.mpcUserId, userOpHash, {
|
|
1857
1689
|
sender: userOp.sender,
|
|
1858
1690
|
nonce: userOp.nonce,
|
|
1859
1691
|
callData: userOp.callData,
|
|
@@ -1864,184 +1696,67 @@ async function prepareUserOperation(session, params) {
|
|
|
1864
1696
|
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
|
|
1865
1697
|
paymaster: userOp.paymaster,
|
|
1866
1698
|
factory: userOp.factory,
|
|
1867
|
-
factoryData: userOp.factoryData
|
|
1699
|
+
factoryData: userOp.factoryData,
|
|
1700
|
+
callTarget: signingMetadata.callTarget ?? primaryBatchOperation?.to,
|
|
1701
|
+
value: signingMetadata.value,
|
|
1702
|
+
operations: signingMetadata.operations
|
|
1868
1703
|
});
|
|
1869
1704
|
} else if (session.ownerPrivateKey) {
|
|
1870
|
-
const account =
|
|
1871
|
-
|
|
1872
|
-
signature = normalizeSignature2(rawSig);
|
|
1705
|
+
const account = privateKeyToAccount2(session.ownerPrivateKey);
|
|
1706
|
+
userOp.signature = normalizeSignature(await account.sign({ hash: userOpHash }));
|
|
1873
1707
|
} else {
|
|
1874
1708
|
throw new Error("No signing method available");
|
|
1875
1709
|
}
|
|
1876
|
-
userOp.signature = signature;
|
|
1877
1710
|
if (typeof userOp.sender !== "string") {
|
|
1878
1711
|
userOp.sender = session.smartAccountAddress;
|
|
1879
1712
|
}
|
|
1880
|
-
return { userOp, userOpHash
|
|
1713
|
+
return { userOp, userOpHash };
|
|
1881
1714
|
}
|
|
1882
|
-
async function
|
|
1883
|
-
const
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
const
|
|
1889
|
-
const
|
|
1890
|
-
const
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
callData = "0x";
|
|
1894
|
-
} else {
|
|
1895
|
-
callData = encodeFunctionData2({
|
|
1896
|
-
abi: executeAbi,
|
|
1897
|
-
functionName: "execute",
|
|
1898
|
-
args: [callTarget, amountWeiBigInt, innerData]
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
let isDeployed = false;
|
|
1902
|
-
try {
|
|
1903
|
-
const code = await chainPublicClient.getCode({ address: session.smartAccountAddress });
|
|
1904
|
-
if (code && code !== "0x" && code.length > 2) {
|
|
1905
|
-
isDeployed = true;
|
|
1906
|
-
}
|
|
1907
|
-
} catch {
|
|
1908
|
-
}
|
|
1909
|
-
const nonce = await fetchEntryPointNonce(session.smartAccountAddress, entryPointAddress, {
|
|
1910
|
-
client: chainPublicClient
|
|
1911
|
-
});
|
|
1912
|
-
const nonceValue = BigInt(nonce);
|
|
1913
|
-
if (!isDeployed && nonceValue !== 0n) {
|
|
1914
|
-
throw new Error(`Undeployed account has non-zero nonce: ${nonce}. This will cause CodeHashChanged error.`);
|
|
1915
|
-
}
|
|
1916
|
-
const shouldIncludeFactory = !isDeployed;
|
|
1917
|
-
let userOp;
|
|
1918
|
-
if (shouldIncludeFactory) {
|
|
1919
|
-
const factoryData = encodeFunctionData2({
|
|
1920
|
-
abi: COMPAT_CREATE_ABI,
|
|
1921
|
-
functionName: "createAccount",
|
|
1922
|
-
args: [session.ownerAddress, SALT_ZERO_UINT256]
|
|
1923
|
-
});
|
|
1924
|
-
userOp = await createUserOperationWithDynamicFees2(
|
|
1925
|
-
{
|
|
1926
|
-
sender: session.smartAccountAddress,
|
|
1927
|
-
nonce,
|
|
1928
|
-
callData,
|
|
1929
|
-
includeFactory: true,
|
|
1930
|
-
factoryAddress: session.factoryAddress,
|
|
1931
|
-
factoryData,
|
|
1932
|
-
feeType
|
|
1933
|
-
},
|
|
1934
|
-
{ client: chainPublicClient, bundlerUrl, chainConfig }
|
|
1935
|
-
);
|
|
1936
|
-
} else {
|
|
1937
|
-
userOp = await createUserOperationWithDynamicFees2(
|
|
1938
|
-
{
|
|
1939
|
-
sender: session.smartAccountAddress,
|
|
1940
|
-
nonce,
|
|
1941
|
-
callData,
|
|
1942
|
-
includeFactory: false,
|
|
1943
|
-
feeType
|
|
1944
|
-
},
|
|
1945
|
-
{ client: chainPublicClient, bundlerUrl, chainConfig }
|
|
1946
|
-
);
|
|
1947
|
-
}
|
|
1948
|
-
const storeUsePaymaster = useSession.getState().usePaymaster;
|
|
1949
|
-
const shouldUsePaymaster = storeUsePaymaster ?? session.usePaymaster ?? false;
|
|
1950
|
-
const resolvedPaymaster = await resolveUiKitPaymaster(chainId, shouldUsePaymaster);
|
|
1951
|
-
if (resolvedPaymaster.address) {
|
|
1952
|
-
userOp.paymaster = resolvedPaymaster.address;
|
|
1953
|
-
userOp.paymasterData = "0x";
|
|
1954
|
-
userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT2;
|
|
1955
|
-
userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT2;
|
|
1956
|
-
}
|
|
1957
|
-
try {
|
|
1958
|
-
const gasEst = await estimateUserOperationGas2(userOp, {
|
|
1959
|
-
chainId,
|
|
1960
|
-
retryWithoutFactory: true
|
|
1961
|
-
});
|
|
1962
|
-
console.log("[Account] Gas estimation from bundler:", {
|
|
1963
|
-
callGasLimit: gasEst.callGasLimit,
|
|
1964
|
-
verificationGasLimit: gasEst.verificationGasLimit,
|
|
1965
|
-
preVerificationGas: gasEst.preVerificationGas
|
|
1966
|
-
});
|
|
1967
|
-
userOp.callGasLimit = gasEst.callGasLimit;
|
|
1968
|
-
userOp.verificationGasLimit = gasEst.verificationGasLimit;
|
|
1969
|
-
userOp.preVerificationGas = gasEst.preVerificationGas;
|
|
1970
|
-
} catch (e) {
|
|
1971
|
-
console.log("[Account] Gas estimation failed:", e);
|
|
1972
|
-
throw new Error(`Gas estimation failed: ${e}`);
|
|
1973
|
-
}
|
|
1974
|
-
const signUserOp = async (nonce2) => {
|
|
1975
|
-
userOp.nonce = nonce2;
|
|
1976
|
-
const hasFactoryData = !!(userOp.factory && userOp.factoryData);
|
|
1977
|
-
const initCode = hasFactoryData ? (() => {
|
|
1978
|
-
const factoryAddr = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
|
|
1979
|
-
const factoryDataClean = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
|
|
1980
|
-
return `0x${factoryAddr}${factoryDataClean}`;
|
|
1981
|
-
})() : "0x";
|
|
1982
|
-
const accountGasLimits = pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit));
|
|
1983
|
-
const gasFees = pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas));
|
|
1984
|
-
let paymasterAndData = "0x";
|
|
1985
|
-
if (userOp.paymaster && userOp.paymaster !== "0x0000000000000000000000000000000000000000") {
|
|
1986
|
-
const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
|
|
1987
|
-
const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
|
|
1988
|
-
const paymasterDataField = userOp.paymasterData || "0x";
|
|
1989
|
-
const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
|
|
1990
|
-
const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
|
|
1991
|
-
const paymasterDataClean = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
|
|
1992
|
-
paymasterAndData = `0x${paymasterAddr}${packedPaymasterGasLimits.slice(2)}${paymasterDataClean}`;
|
|
1993
|
-
}
|
|
1994
|
-
const packedForHash = {
|
|
1995
|
-
sender: session.smartAccountAddress,
|
|
1996
|
-
nonce: BigInt(nonce2),
|
|
1997
|
-
initCode,
|
|
1998
|
-
callData,
|
|
1999
|
-
accountGasLimits,
|
|
2000
|
-
preVerificationGas: BigInt(userOp.preVerificationGas),
|
|
2001
|
-
gasFees,
|
|
2002
|
-
paymasterAndData,
|
|
2003
|
-
signature: "0x"
|
|
2004
|
-
};
|
|
2005
|
-
const opHash = await chainPublicClient.readContract({
|
|
2006
|
-
address: entryPointAddress,
|
|
2007
|
-
abi: entryPoint07Abi2,
|
|
2008
|
-
functionName: "getUserOpHash",
|
|
2009
|
-
args: [packedForHash]
|
|
2010
|
-
});
|
|
2011
|
-
let signature;
|
|
2012
|
-
if (session.mpcUserId) {
|
|
2013
|
-
signature = await signDigestWithMpc(session.mpcUserId, opHash, {
|
|
2014
|
-
sender: userOp.sender,
|
|
2015
|
-
nonce: userOp.nonce,
|
|
2016
|
-
callData: userOp.callData,
|
|
2017
|
-
callGasLimit: userOp.callGasLimit,
|
|
2018
|
-
verificationGasLimit: userOp.verificationGasLimit,
|
|
2019
|
-
preVerificationGas: userOp.preVerificationGas,
|
|
2020
|
-
maxFeePerGas: userOp.maxFeePerGas,
|
|
2021
|
-
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
|
|
2022
|
-
paymaster: userOp.paymaster,
|
|
2023
|
-
factory: userOp.factory,
|
|
2024
|
-
factoryData: userOp.factoryData,
|
|
2025
|
-
callTarget,
|
|
2026
|
-
value: amountWei
|
|
2027
|
-
});
|
|
2028
|
-
} else if (session.ownerPrivateKey) {
|
|
2029
|
-
const account = privateKeyToAccount3(session.ownerPrivateKey);
|
|
2030
|
-
const rawSig = await account.sign({ hash: opHash });
|
|
2031
|
-
signature = normalizeSignature2(rawSig);
|
|
2032
|
-
} else {
|
|
2033
|
-
throw new Error("No signing method available");
|
|
2034
|
-
}
|
|
2035
|
-
userOp.signature = signature;
|
|
2036
|
-
if (typeof userOp.sender !== "string") {
|
|
2037
|
-
userOp.sender = session.smartAccountAddress;
|
|
2038
|
-
}
|
|
2039
|
-
return userOp;
|
|
1715
|
+
async function prepareExecutionUserOperation(session, params, callData, signingMetadata) {
|
|
1716
|
+
const context = resolveExecutionContext(params.chainId);
|
|
1717
|
+
const { nonce, userOp } = await createUnsignedUserOperation(session, context, callData, params.feeType ?? "standard");
|
|
1718
|
+
return signPreparedUserOperation(session, context, userOp, nonce, signingMetadata);
|
|
1719
|
+
}
|
|
1720
|
+
async function sendExecutionUserOperation(session, params, callData, signingMetadata) {
|
|
1721
|
+
const context = resolveExecutionContext(params.chainId);
|
|
1722
|
+
const { nonce, userOp } = await createUnsignedUserOperation(session, context, callData, params.feeType ?? "standard");
|
|
1723
|
+
const signUserOp = async (nextNonce) => {
|
|
1724
|
+
const { userOp: signedUserOp2 } = await signPreparedUserOperation(session, context, userOp, nextNonce, signingMetadata);
|
|
1725
|
+
return signedUserOp2;
|
|
2040
1726
|
};
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
1727
|
+
const signedUserOp = await signUserOp(nonce);
|
|
1728
|
+
return sendUserOperationWithRetry(signedUserOp, signUserOp, { chainId: context.chainId, maxRetries: 1 });
|
|
1729
|
+
}
|
|
1730
|
+
async function prepareUserOperation(session, params) {
|
|
1731
|
+
const { callData, signingMetadata } = encodeSingleExecution(params);
|
|
1732
|
+
return prepareExecutionUserOperation(session, params, callData, signingMetadata);
|
|
1733
|
+
}
|
|
1734
|
+
async function prepareBatchUserOperation(session, params) {
|
|
1735
|
+
const { callData, signingMetadata } = encodeBatchExecution(params.operations);
|
|
1736
|
+
return prepareExecutionUserOperation(session, params, callData, signingMetadata);
|
|
1737
|
+
}
|
|
1738
|
+
async function sendUserOperation(session, params) {
|
|
1739
|
+
const { callData, signingMetadata } = encodeSingleExecution(params);
|
|
1740
|
+
return sendExecutionUserOperation(session, params, callData, signingMetadata);
|
|
2044
1741
|
}
|
|
1742
|
+
async function sendBatchUserOperation(session, params) {
|
|
1743
|
+
const { callData, signingMetadata } = encodeBatchExecution(params.operations);
|
|
1744
|
+
return sendExecutionUserOperation(session, params, callData, signingMetadata);
|
|
1745
|
+
}
|
|
1746
|
+
var init_user_operations = __esm({
|
|
1747
|
+
"src/internal/clients/account/user-operations.ts"() {
|
|
1748
|
+
init_SessionContext();
|
|
1749
|
+
init_akHelpers();
|
|
1750
|
+
init_iframe_mpc_client();
|
|
1751
|
+
init_constants2();
|
|
1752
|
+
init_helpers();
|
|
1753
|
+
init_resolve_paymaster();
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
// src/internal/clients/account/signing.ts
|
|
1758
|
+
import { hashTypedData } from "viem";
|
|
1759
|
+
import { privateKeyToAccount as privateKeyToAccount3 } from "viem/accounts";
|
|
2045
1760
|
async function signTypedData(session, params) {
|
|
2046
1761
|
const { domain, types, primaryType, message, chainId: paramsChainId } = params;
|
|
2047
1762
|
if (paramsChainId !== void 0 && domain.chainId !== void 0 && paramsChainId !== domain.chainId) {
|
|
@@ -2088,89 +1803,63 @@ async function signTypedData(session, params) {
|
|
|
2088
1803
|
} else if (session.ownerPrivateKey) {
|
|
2089
1804
|
const account = privateKeyToAccount3(session.ownerPrivateKey);
|
|
2090
1805
|
const rawSig = await account.sign({ hash: digest });
|
|
2091
|
-
signature =
|
|
1806
|
+
signature = normalizeSignature(rawSig);
|
|
2092
1807
|
} else {
|
|
2093
1808
|
throw new Error("No signing method available");
|
|
2094
1809
|
}
|
|
2095
1810
|
return signature;
|
|
2096
1811
|
}
|
|
2097
|
-
var
|
|
2098
|
-
|
|
2099
|
-
"src/internal/clients/account.ts"() {
|
|
2100
|
-
init_constants2();
|
|
2101
|
-
init_SessionContext();
|
|
2102
|
-
init_akHelpers();
|
|
1812
|
+
var init_signing = __esm({
|
|
1813
|
+
"src/internal/clients/account/signing.ts"() {
|
|
2103
1814
|
init_iframe_mpc_client();
|
|
2104
|
-
|
|
2105
|
-
init_deposit_for_smart_account();
|
|
2106
|
-
init_deploy_account();
|
|
2107
|
-
init_register_smart_account_address();
|
|
2108
|
-
PAYMASTER_VERIFICATION_GAS_LIMIT2 = "0x249f0";
|
|
2109
|
-
PAYMASTER_POSTOP_GAS_LIMIT2 = "0x186a0";
|
|
1815
|
+
init_helpers();
|
|
2110
1816
|
}
|
|
2111
1817
|
});
|
|
2112
1818
|
|
|
2113
|
-
// src/internal/clients/account/
|
|
2114
|
-
import {
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
const account = privateKeyToAccount4(privateKey);
|
|
2133
|
-
ownerAddress = account.address;
|
|
2134
|
-
ownerPrivateKey = privateKey;
|
|
2135
|
-
} else if (mpcUserId) {
|
|
2136
|
-
const dkgResult = await ensureDkgAndGetOwner(mpcUserId);
|
|
2137
|
-
if (!dkgResult.ownerAddress) throw new Error("Failed to get owner address from DKG");
|
|
2138
|
-
ownerAddress = dkgResult.ownerAddress;
|
|
2139
|
-
} else {
|
|
2140
|
-
throw new Error("Either privateKey or mpcUserId must be provided");
|
|
2141
|
-
}
|
|
2142
|
-
const smartAccountAddress = await predictCompatAddress(ownerAddress, factoryAddress, SALT_ZERO, { client: publicClient });
|
|
2143
|
-
if (mpcUserId) {
|
|
2144
|
-
registerSmartAccountAddress(chainId, smartAccountAddress, factoryAddress).catch((error) => {
|
|
2145
|
-
console.warn("[Account] Background Smart Account registration failed:", error);
|
|
2146
|
-
});
|
|
1819
|
+
// src/internal/clients/account/deploy-account.ts
|
|
1820
|
+
import { createPublicClientForChain as createPublicClientForChain3 } from "@embarkai/core/read";
|
|
1821
|
+
async function deployAccount(session, feeType = "economy", options) {
|
|
1822
|
+
const chainId = options?.chainId ?? requireActiveChainId();
|
|
1823
|
+
if (!options?.force) {
|
|
1824
|
+
const publicClient = createPublicClientForChain3(chainId);
|
|
1825
|
+
try {
|
|
1826
|
+
const code = await publicClient.getCode({
|
|
1827
|
+
address: session.smartAccountAddress
|
|
1828
|
+
});
|
|
1829
|
+
const isDeployed = code && code !== "0x" && code.length > 2;
|
|
1830
|
+
if (isDeployed) {
|
|
1831
|
+
console.log("[deployAccount] Account already deployed, skipping deployment");
|
|
1832
|
+
return null;
|
|
1833
|
+
}
|
|
1834
|
+
console.log("[deployAccount] Account not deployed, initiating deployment");
|
|
1835
|
+
} catch (error) {
|
|
1836
|
+
console.warn("[deployAccount] Failed to check deployment status, proceeding with deployment:", error);
|
|
1837
|
+
}
|
|
2147
1838
|
}
|
|
2148
|
-
return {
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
};
|
|
1839
|
+
return sendUserOperation(session, {
|
|
1840
|
+
to: "0x0000000000000000000000000000000000000000",
|
|
1841
|
+
// to: burn address
|
|
1842
|
+
value: "0",
|
|
1843
|
+
// value: 0 (no funds)
|
|
1844
|
+
data: "0x",
|
|
1845
|
+
// data: empty (no contract call)
|
|
1846
|
+
feeType,
|
|
1847
|
+
chainId
|
|
1848
|
+
});
|
|
2158
1849
|
}
|
|
2159
|
-
var
|
|
2160
|
-
"src/internal/clients/account/
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
init_helpers();
|
|
2164
|
-
init_register_smart_account_address();
|
|
1850
|
+
var init_deploy_account = __esm({
|
|
1851
|
+
"src/internal/clients/account/deploy-account.ts"() {
|
|
1852
|
+
init_SessionContext();
|
|
1853
|
+
init_user_operations();
|
|
2165
1854
|
}
|
|
2166
1855
|
});
|
|
2167
1856
|
|
|
2168
1857
|
// src/internal/clients/account/get-entry-point-deposit.ts
|
|
2169
|
-
import { createPublicClientForChain as
|
|
1858
|
+
import { createPublicClientForChain as createPublicClientForChain4, getChainConfig as getChainConfig5 } from "@embarkai/core/read";
|
|
2170
1859
|
async function getEntryPointDeposit(address) {
|
|
2171
1860
|
const chainId = requireActiveChainId();
|
|
2172
|
-
const chainConfig =
|
|
2173
|
-
const publicClient =
|
|
1861
|
+
const chainConfig = getChainConfig5(chainId);
|
|
1862
|
+
const publicClient = createPublicClientForChain4(chainId);
|
|
2174
1863
|
const entryPointAddress = chainConfig.entryPointV07Address;
|
|
2175
1864
|
const depositAbi = [{ type: "function", name: "balanceOf", stateMutability: "view", inputs: [{ name: "account", type: "address" }], outputs: [{ name: "", type: "uint256" }] }];
|
|
2176
1865
|
return await publicClient.readContract({
|
|
@@ -2186,6 +1875,62 @@ var init_get_entry_point_deposit = __esm({
|
|
|
2186
1875
|
}
|
|
2187
1876
|
});
|
|
2188
1877
|
|
|
1878
|
+
// src/internal/clients/account/deposit-for-smart-account.ts
|
|
1879
|
+
import { getChainConfig as getChainConfig6, getViemChain } from "@embarkai/core/read";
|
|
1880
|
+
import { createWalletClient, http, parseEther } from "viem";
|
|
1881
|
+
import { privateKeyToAccount as privateKeyToAccount4 } from "viem/accounts";
|
|
1882
|
+
async function depositForSmartAccount(address, amountEth = "0.01") {
|
|
1883
|
+
const chainId = requireActiveChainId();
|
|
1884
|
+
const chainConfig = getChainConfig6(chainId);
|
|
1885
|
+
if (!FUNDER_PK) throw new Error("VITE_FUNDER_PK is not set");
|
|
1886
|
+
const entryPointAddress = chainConfig.entryPointV07Address;
|
|
1887
|
+
const funder = privateKeyToAccount4(FUNDER_PK);
|
|
1888
|
+
const viemChain = getViemChain(chainId);
|
|
1889
|
+
const wallet = createWalletClient({
|
|
1890
|
+
account: funder,
|
|
1891
|
+
chain: viemChain,
|
|
1892
|
+
transport: http(viemChain.rpcUrls.default.http[0])
|
|
1893
|
+
});
|
|
1894
|
+
const hash = await wallet.writeContract({
|
|
1895
|
+
address: entryPointAddress,
|
|
1896
|
+
abi: entryPointDepositAbi,
|
|
1897
|
+
functionName: "depositTo",
|
|
1898
|
+
args: [address],
|
|
1899
|
+
value: parseEther(amountEth),
|
|
1900
|
+
type: "legacy",
|
|
1901
|
+
gasPrice: 1000000000n
|
|
1902
|
+
});
|
|
1903
|
+
return hash;
|
|
1904
|
+
}
|
|
1905
|
+
var init_deposit_for_smart_account = __esm({
|
|
1906
|
+
"src/internal/clients/account/deposit-for-smart-account.ts"() {
|
|
1907
|
+
init_index();
|
|
1908
|
+
init_base();
|
|
1909
|
+
init_constants2();
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
|
|
1913
|
+
// src/internal/clients/account/index.ts
|
|
1914
|
+
var init_account = __esm({
|
|
1915
|
+
"src/internal/clients/account/index.ts"() {
|
|
1916
|
+
init_constants2();
|
|
1917
|
+
init_session();
|
|
1918
|
+
init_user_operations();
|
|
1919
|
+
init_signing();
|
|
1920
|
+
init_deploy_account();
|
|
1921
|
+
init_get_entry_point_deposit();
|
|
1922
|
+
init_deposit_for_smart_account();
|
|
1923
|
+
init_register_smart_account_address();
|
|
1924
|
+
}
|
|
1925
|
+
});
|
|
1926
|
+
|
|
1927
|
+
// src/internal/clients/account.ts
|
|
1928
|
+
var init_account2 = __esm({
|
|
1929
|
+
"src/internal/clients/account.ts"() {
|
|
1930
|
+
init_account();
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
|
|
2189
1934
|
// src/internal/clients/utils.ts
|
|
2190
1935
|
var init_utils = __esm({
|
|
2191
1936
|
"src/internal/clients/utils.ts"() {
|
|
@@ -2409,12 +2154,23 @@ var init_nickname_types = __esm({
|
|
|
2409
2154
|
// src/internal/clients/index.ts
|
|
2410
2155
|
var clients_exports = {};
|
|
2411
2156
|
__export(clients_exports, {
|
|
2157
|
+
COMPAT_CREATE_ABI: () => COMPAT_CREATE_ABI,
|
|
2412
2158
|
FUNDER_PK: () => FUNDER_PK,
|
|
2159
|
+
MAX_BUNDLER_VERIFICATION_GAS: () => MAX_BUNDLER_VERIFICATION_GAS,
|
|
2160
|
+
PAYMASTER_POSTOP_GAS: () => PAYMASTER_POSTOP_GAS,
|
|
2161
|
+
PAYMASTER_POSTOP_GAS_LIMIT: () => PAYMASTER_POSTOP_GAS_LIMIT,
|
|
2162
|
+
PAYMASTER_VERIFICATION_GAS: () => PAYMASTER_VERIFICATION_GAS,
|
|
2163
|
+
PAYMASTER_VERIFICATION_GAS_LIMIT: () => PAYMASTER_VERIFICATION_GAS_LIMIT,
|
|
2164
|
+
SALT_ZERO: () => SALT_ZERO,
|
|
2165
|
+
SALT_ZERO_UINT256: () => SALT_ZERO_UINT256,
|
|
2413
2166
|
changeNickname: () => changeNickname,
|
|
2414
2167
|
checkNicknameAvailability: () => checkNicknameAvailability,
|
|
2415
2168
|
createAccountSession: () => createAccountSession,
|
|
2416
2169
|
deployAccount: () => deployAccount,
|
|
2417
2170
|
depositForSmartAccount: () => depositForSmartAccount,
|
|
2171
|
+
entryPointDepositAbi: () => entryPointDepositAbi,
|
|
2172
|
+
executeAbi: () => executeAbi,
|
|
2173
|
+
executeBatchAbi: () => executeBatchAbi,
|
|
2418
2174
|
getAllSmartAccounts: () => getAllSmartAccounts,
|
|
2419
2175
|
getBundlerClient: () => getBundlerClient,
|
|
2420
2176
|
getDashboardApiUrl: () => getDashboardApiUrl,
|
|
@@ -2426,15 +2182,18 @@ __export(clients_exports, {
|
|
|
2426
2182
|
getTssUrl: () => getTssUrl2,
|
|
2427
2183
|
lumiaBeamTestnet: () => lumiaBeamTestnet,
|
|
2428
2184
|
lumiaPrisma: () => lumiaPrisma,
|
|
2185
|
+
prepareBatchUserOperation: () => prepareBatchUserOperation,
|
|
2429
2186
|
prepareUserOperation: () => prepareUserOperation,
|
|
2187
|
+
registerSmartAccountAddress: () => registerSmartAccountAddress,
|
|
2430
2188
|
resolveNickname: () => resolveNickname,
|
|
2431
|
-
|
|
2189
|
+
sendBatchUserOperation: () => sendBatchUserOperation,
|
|
2190
|
+
sendUserOperation: () => sendUserOperation,
|
|
2432
2191
|
signTypedData: () => signTypedData
|
|
2433
2192
|
});
|
|
2434
2193
|
var init_clients = __esm({
|
|
2435
2194
|
"src/internal/clients/index.ts"() {
|
|
2436
2195
|
init_base();
|
|
2437
|
-
|
|
2196
|
+
init_account2();
|
|
2438
2197
|
init_utils();
|
|
2439
2198
|
init_nickname();
|
|
2440
2199
|
init_nickname_types();
|
|
@@ -9241,13 +9000,13 @@ var init_truncateMiddle = __esm({
|
|
|
9241
9000
|
|
|
9242
9001
|
// src/internal/components/ChainsMenu/ChainsMenu.tsx
|
|
9243
9002
|
import { PAYMASTER_CACHE_TTL_MS } from "@embarkai/core";
|
|
9244
|
-
import { getChainConfig as
|
|
9003
|
+
import { getChainConfig as getChainConfig7 } from "@embarkai/core/read";
|
|
9245
9004
|
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
9246
9005
|
import { ArrowLeft as ArrowLeft4, Copy, ExternalLink, Loader as Loader8 } from "lucide-react";
|
|
9247
9006
|
import { useEffect as useEffect18, useRef as useRef11, useState as useState9 } from "react";
|
|
9248
9007
|
import { jsx as jsx49, jsxs as jsxs42 } from "react/jsx-runtime";
|
|
9249
9008
|
function getPaymasterExplorerUrl(chainId, paymasterAddress) {
|
|
9250
|
-
const chainConfig =
|
|
9009
|
+
const chainConfig = getChainConfig7(chainId);
|
|
9251
9010
|
const explorerUrl = chainConfig?.blockExplorerUrl;
|
|
9252
9011
|
if (!explorerUrl) return paymasterAddress;
|
|
9253
9012
|
return `${explorerUrl.replace(/\/$/, "")}/address/${paymasterAddress}`;
|
|
@@ -9264,7 +9023,7 @@ function ChainsMenu() {
|
|
|
9264
9023
|
const maxScrollHeight = useLayoutStore((st) => st.maxScrollHeight);
|
|
9265
9024
|
const setPage = useLayoutDataStore((st) => st.setPage);
|
|
9266
9025
|
const visibleNetworks = NETWORK_OPTIONS.filter((option) => option.isActive);
|
|
9267
|
-
const activeChainConfig = activeChainId ?
|
|
9026
|
+
const activeChainConfig = activeChainId ? getChainConfig7(activeChainId) : null;
|
|
9268
9027
|
const activeDefaultPaymasterAddress = activeChainConfig?.paymasterAddress;
|
|
9269
9028
|
const activePaymasterQuery = useQuery5({
|
|
9270
9029
|
queryKey: ["chain-paymaster", config.current.projectId, activeChainId],
|
|
@@ -16624,7 +16383,7 @@ var init_useNicknameResolve = __esm({
|
|
|
16624
16383
|
|
|
16625
16384
|
// src/hooks/useSendTransaction.ts
|
|
16626
16385
|
import { useCallback as useCallback21, useState as useState25 } from "react";
|
|
16627
|
-
import { encodeFunctionData as
|
|
16386
|
+
import { encodeFunctionData as encodeFunctionData2, isAddress, parseEther as parseEther2, parseUnits } from "viem";
|
|
16628
16387
|
function useSendTransaction() {
|
|
16629
16388
|
const session = useSession((st) => st.session);
|
|
16630
16389
|
const address = useSession((st) => st.address);
|
|
@@ -16667,7 +16426,7 @@ function useSendTransaction() {
|
|
|
16667
16426
|
switch (assetType) {
|
|
16668
16427
|
case "native": {
|
|
16669
16428
|
callTarget = params.to;
|
|
16670
|
-
valueWei =
|
|
16429
|
+
valueWei = parseEther2(params.value).toString();
|
|
16671
16430
|
innerData = params.data || "0x";
|
|
16672
16431
|
break;
|
|
16673
16432
|
}
|
|
@@ -16677,7 +16436,7 @@ function useSendTransaction() {
|
|
|
16677
16436
|
const amount = parseUnits(params.value, decimals);
|
|
16678
16437
|
callTarget = params.tokenAddress;
|
|
16679
16438
|
valueWei = "0";
|
|
16680
|
-
innerData =
|
|
16439
|
+
innerData = encodeFunctionData2({
|
|
16681
16440
|
abi: ERC20_TRANSFER_ABI,
|
|
16682
16441
|
functionName: "transfer",
|
|
16683
16442
|
args: [params.to, amount]
|
|
@@ -16687,7 +16446,7 @@ function useSendTransaction() {
|
|
|
16687
16446
|
case "erc721": {
|
|
16688
16447
|
callTarget = params.tokenAddress;
|
|
16689
16448
|
valueWei = "0";
|
|
16690
|
-
innerData =
|
|
16449
|
+
innerData = encodeFunctionData2({
|
|
16691
16450
|
abi: ERC721_SAFE_TRANSFER_ABI,
|
|
16692
16451
|
functionName: "safeTransferFrom",
|
|
16693
16452
|
args: [address, params.to, BigInt(params.tokenId)]
|
|
@@ -16698,7 +16457,7 @@ function useSendTransaction() {
|
|
|
16698
16457
|
const amount = params.value ? BigInt(params.value) : 1n;
|
|
16699
16458
|
callTarget = params.tokenAddress;
|
|
16700
16459
|
valueWei = "0";
|
|
16701
|
-
innerData =
|
|
16460
|
+
innerData = encodeFunctionData2({
|
|
16702
16461
|
abi: ERC1155_SAFE_TRANSFER_ABI,
|
|
16703
16462
|
functionName: "safeTransferFrom",
|
|
16704
16463
|
args: [address, params.to, BigInt(params.tokenId), amount, "0x"]
|
|
@@ -16710,7 +16469,7 @@ function useSendTransaction() {
|
|
|
16710
16469
|
return null;
|
|
16711
16470
|
}
|
|
16712
16471
|
}
|
|
16713
|
-
const hash = await
|
|
16472
|
+
const hash = await sendUserOperation(session, {
|
|
16714
16473
|
to: callTarget,
|
|
16715
16474
|
value: valueWei,
|
|
16716
16475
|
data: innerData,
|
|
@@ -16745,7 +16504,7 @@ var ERC20_TRANSFER_ABI, ERC721_SAFE_TRANSFER_ABI, ERC1155_SAFE_TRANSFER_ABI;
|
|
|
16745
16504
|
var init_useSendTransaction = __esm({
|
|
16746
16505
|
"src/hooks/useSendTransaction.ts"() {
|
|
16747
16506
|
init_SessionContext();
|
|
16748
|
-
|
|
16507
|
+
init_account2();
|
|
16749
16508
|
ERC20_TRANSFER_ABI = [
|
|
16750
16509
|
{
|
|
16751
16510
|
type: "function",
|
|
@@ -19302,7 +19061,7 @@ var init_package = __esm({
|
|
|
19302
19061
|
"package.json"() {
|
|
19303
19062
|
package_default = {
|
|
19304
19063
|
name: "@embarkai/ui-kit",
|
|
19305
|
-
version: "0.4.
|
|
19064
|
+
version: "0.4.20",
|
|
19306
19065
|
description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
|
|
19307
19066
|
type: "module",
|
|
19308
19067
|
main: "./dist/index.cjs",
|
|
@@ -20431,9 +20190,9 @@ var init_DirectWalletHandler = __esm({
|
|
|
20431
20190
|
// src/context/SessionContext.tsx
|
|
20432
20191
|
import {
|
|
20433
20192
|
createBundlerClientForChain,
|
|
20434
|
-
createPublicClientForChain as
|
|
20193
|
+
createPublicClientForChain as createPublicClientForChain5,
|
|
20435
20194
|
DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID2,
|
|
20436
|
-
getChainConfig as
|
|
20195
|
+
getChainConfig as getChainConfig8,
|
|
20437
20196
|
getViemChain as getViemChain2
|
|
20438
20197
|
} from "@embarkai/core/read";
|
|
20439
20198
|
import { Fragment as Fragment42 } from "react";
|
|
@@ -20444,7 +20203,7 @@ function getChainParams(chainCfg) {
|
|
|
20444
20203
|
return {
|
|
20445
20204
|
activeChainId: chainCfg.id,
|
|
20446
20205
|
chainConfig: chainCfg,
|
|
20447
|
-
publicClient:
|
|
20206
|
+
publicClient: createPublicClientForChain5(chainCfg.id),
|
|
20448
20207
|
bundlerClient: createBundlerClientForChain(chainCfg.id),
|
|
20449
20208
|
viemChain: getViemChain2(chainCfg.id)
|
|
20450
20209
|
};
|
|
@@ -20542,7 +20301,7 @@ var init_SessionContext = __esm({
|
|
|
20542
20301
|
// Set default chainId after hydration if not persisted
|
|
20543
20302
|
onRehydrateStorage: () => (state) => {
|
|
20544
20303
|
if (!state) return;
|
|
20545
|
-
const hydartedChain = getChainParams(
|
|
20304
|
+
const hydartedChain = getChainParams(getChainConfig8(state.activeChainId || DEFAULT_CHAIN_ID2));
|
|
20546
20305
|
state.activeChainId = hydartedChain.activeChainId;
|
|
20547
20306
|
state.publicClient = hydartedChain.publicClient;
|
|
20548
20307
|
state.bundlerClient = hydartedChain.bundlerClient;
|
|
@@ -20589,8 +20348,8 @@ var init_env = __esm({
|
|
|
20589
20348
|
});
|
|
20590
20349
|
|
|
20591
20350
|
// src/internal/clients/base.ts
|
|
20592
|
-
import { getChainConfig as
|
|
20593
|
-
import { http as
|
|
20351
|
+
import { getChainConfig as getChainConfig9, getViemChain as getViemChain3, lumiaMainnetChain, lumiaTestnetChain } from "@embarkai/core/read";
|
|
20352
|
+
import { http as http2 } from "viem";
|
|
20594
20353
|
import { createBundlerClient } from "viem/account-abstraction";
|
|
20595
20354
|
function getTssUrl2() {
|
|
20596
20355
|
const serviceUrls = getServiceUrls();
|
|
@@ -20620,17 +20379,17 @@ function getExplorerUrl() {
|
|
|
20620
20379
|
const paramUrl = typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("explorerUrl") || void 0 : void 0;
|
|
20621
20380
|
const net = getSelectedNetwork();
|
|
20622
20381
|
const chainId = requireActiveChainId();
|
|
20623
|
-
const chainConfig =
|
|
20382
|
+
const chainConfig = getChainConfig9(chainId);
|
|
20624
20383
|
console.log("[getExplorerUrl] ", paramUrl, chainConfig.blockExplorerUrl);
|
|
20625
20384
|
return paramUrl || chainConfig.blockExplorerUrl;
|
|
20626
20385
|
}
|
|
20627
20386
|
function getBundlerClient() {
|
|
20628
20387
|
const chainId = requireActiveChainId();
|
|
20629
|
-
const chainConfig =
|
|
20388
|
+
const chainConfig = getChainConfig9(chainId);
|
|
20630
20389
|
const viemChain = getViemChain3(chainId);
|
|
20631
20390
|
return createBundlerClient({
|
|
20632
20391
|
chain: viemChain,
|
|
20633
|
-
transport:
|
|
20392
|
+
transport: http2(chainConfig.bundlerUrl, { timeout: 1e4, retryCount: 0, fetchOptions: { mode: "cors" } })
|
|
20634
20393
|
});
|
|
20635
20394
|
}
|
|
20636
20395
|
var BUILD_NETWORK, lumiaBeamTestnet, lumiaPrisma, FUNDER_PK;
|
|
@@ -23220,10 +22979,10 @@ var init_utils10 = __esm({
|
|
|
23220
22979
|
// src/config/wagmi.ts
|
|
23221
22980
|
import { lumiaMainnetChain as lumiaMainnetChain3, lumiaTestnetChain as lumiaTestnetChain3 } from "@embarkai/core/read";
|
|
23222
22981
|
import { fallback } from "viem";
|
|
23223
|
-
import { createConfig, createStorage as createStorage2, http as
|
|
22982
|
+
import { createConfig, createStorage as createStorage2, http as http3 } from "wagmi";
|
|
23224
22983
|
function buildTransport(urls) {
|
|
23225
22984
|
const transports = urls.map(
|
|
23226
|
-
(url) =>
|
|
22985
|
+
(url) => http3(url, {
|
|
23227
22986
|
timeout: 1e4,
|
|
23228
22987
|
retryCount: 0,
|
|
23229
22988
|
batch: false,
|
|
@@ -23747,10 +23506,10 @@ var init_LangToggle = __esm({
|
|
|
23747
23506
|
|
|
23748
23507
|
// src/clients/bundler/getUserOperationByHash.ts
|
|
23749
23508
|
import { bundlerRpc } from "@embarkai/core";
|
|
23750
|
-
import { getChainConfig as
|
|
23509
|
+
import { getChainConfig as getChainConfig10 } from "@embarkai/core/read";
|
|
23751
23510
|
async function getUserOperationByHash(userOpHash, chainId) {
|
|
23752
23511
|
const targetChainId = chainId ?? requireActiveChainId();
|
|
23753
|
-
const chainConfig =
|
|
23512
|
+
const chainConfig = getChainConfig10(targetChainId);
|
|
23754
23513
|
if (!chainConfig) {
|
|
23755
23514
|
throw new Error(`Chain ${targetChainId} is not supported`);
|
|
23756
23515
|
}
|
|
@@ -23786,10 +23545,10 @@ var init_getUserOperationByHash = __esm({
|
|
|
23786
23545
|
|
|
23787
23546
|
// src/clients/bundler/getUserOperationReceipt.ts
|
|
23788
23547
|
import { bundlerRpc as bundlerRpc2 } from "@embarkai/core";
|
|
23789
|
-
import { getChainConfig as
|
|
23548
|
+
import { getChainConfig as getChainConfig11 } from "@embarkai/core/read";
|
|
23790
23549
|
async function getUserOperationReceipt(userOpHash, chainId) {
|
|
23791
23550
|
const targetChainId = chainId ?? requireActiveChainId();
|
|
23792
|
-
const chainConfig =
|
|
23551
|
+
const chainConfig = getChainConfig11(targetChainId);
|
|
23793
23552
|
if (!chainConfig) {
|
|
23794
23553
|
throw new Error(`Chain ${targetChainId} is not supported`);
|
|
23795
23554
|
}
|
|
@@ -24607,7 +24366,7 @@ var init_useDirectWallet = __esm({
|
|
|
24607
24366
|
|
|
24608
24367
|
// src/hooks/useSendDirectTransaction.ts
|
|
24609
24368
|
import { useCallback as useCallback34, useState as useState35 } from "react";
|
|
24610
|
-
import { isAddress as isAddress3, parseEther as
|
|
24369
|
+
import { isAddress as isAddress3, parseEther as parseEther3 } from "viem";
|
|
24611
24370
|
import { useSendTransaction as useWagmiSendTransaction, useSwitchChain } from "wagmi";
|
|
24612
24371
|
function useSendDirectTransaction() {
|
|
24613
24372
|
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
@@ -24636,7 +24395,7 @@ function useSendDirectTransaction() {
|
|
|
24636
24395
|
}
|
|
24637
24396
|
const hash = await sendTransactionAsync({
|
|
24638
24397
|
to: params.to,
|
|
24639
|
-
value:
|
|
24398
|
+
value: parseEther3(params.value),
|
|
24640
24399
|
data: params.data
|
|
24641
24400
|
});
|
|
24642
24401
|
setTxHash(hash);
|
|
@@ -24666,7 +24425,7 @@ var init_useSendDirectTransaction = __esm({
|
|
|
24666
24425
|
|
|
24667
24426
|
// src/hooks/useTransferToLinkedWallet.ts
|
|
24668
24427
|
import { useCallback as useCallback35, useMemo as useMemo12, useState as useState36 } from "react";
|
|
24669
|
-
import { encodeFunctionData as
|
|
24428
|
+
import { encodeFunctionData as encodeFunctionData3, isAddress as isAddress4, parseEther as parseEther4, parseUnits as parseUnits3 } from "viem";
|
|
24670
24429
|
function useTransferToLinkedWallet() {
|
|
24671
24430
|
const session = useSession((st) => st.session);
|
|
24672
24431
|
const { profiles } = useLinkedProfiles();
|
|
@@ -24697,19 +24456,19 @@ function useTransferToLinkedWallet() {
|
|
|
24697
24456
|
let data;
|
|
24698
24457
|
if (params.token === "native") {
|
|
24699
24458
|
to = toAddress;
|
|
24700
|
-
value =
|
|
24459
|
+
value = parseEther4(params.amount).toString();
|
|
24701
24460
|
data = "0x";
|
|
24702
24461
|
} else {
|
|
24703
24462
|
const decimals = params.decimals ?? 18;
|
|
24704
24463
|
to = params.token;
|
|
24705
24464
|
value = "0";
|
|
24706
|
-
data =
|
|
24465
|
+
data = encodeFunctionData3({
|
|
24707
24466
|
abi: ERC20_TRANSFER_ABI2,
|
|
24708
24467
|
functionName: "transfer",
|
|
24709
24468
|
args: [toAddress, parseUnits3(params.amount, decimals)]
|
|
24710
24469
|
});
|
|
24711
24470
|
}
|
|
24712
|
-
const hash = await
|
|
24471
|
+
const hash = await sendUserOperation(session, {
|
|
24713
24472
|
to,
|
|
24714
24473
|
value,
|
|
24715
24474
|
data,
|
|
@@ -24739,7 +24498,7 @@ var ERC20_TRANSFER_ABI2;
|
|
|
24739
24498
|
var init_useTransferToLinkedWallet = __esm({
|
|
24740
24499
|
"src/hooks/useTransferToLinkedWallet.ts"() {
|
|
24741
24500
|
init_SessionContext();
|
|
24742
|
-
|
|
24501
|
+
init_account2();
|
|
24743
24502
|
init_linkedProfiles();
|
|
24744
24503
|
ERC20_TRANSFER_ABI2 = [
|
|
24745
24504
|
{
|
|
@@ -24869,7 +24628,7 @@ var init_clients2 = __esm({
|
|
|
24869
24628
|
|
|
24870
24629
|
// src/modules/transactions.ts
|
|
24871
24630
|
import { getViemChain as getViemChain4 } from "@embarkai/core/read";
|
|
24872
|
-
import { parseEther as
|
|
24631
|
+
import { parseEther as parseEther5 } from "viem";
|
|
24873
24632
|
import { useAccount as useAccount3, usePublicClient, useWalletClient } from "wagmi";
|
|
24874
24633
|
function useTransactions() {
|
|
24875
24634
|
const chainId = requireActiveChainId();
|
|
@@ -24883,7 +24642,7 @@ function useTransactions() {
|
|
|
24883
24642
|
}
|
|
24884
24643
|
const txParams = {
|
|
24885
24644
|
to: params.to,
|
|
24886
|
-
value:
|
|
24645
|
+
value: parseEther5(params.value),
|
|
24887
24646
|
data: params.data,
|
|
24888
24647
|
chain: viemChain
|
|
24889
24648
|
};
|
|
@@ -25217,7 +24976,7 @@ var init_index = __esm({
|
|
|
25217
24976
|
init_useNativeWalletSignature();
|
|
25218
24977
|
init_useLogout();
|
|
25219
24978
|
init_useNicknameResolve();
|
|
25220
|
-
|
|
24979
|
+
init_account2();
|
|
25221
24980
|
init_clients2();
|
|
25222
24981
|
init_auth();
|
|
25223
24982
|
init_profile();
|
|
@@ -25276,9 +25035,11 @@ export {
|
|
|
25276
25035
|
jwtTokenManager2 as jwtTokenManager,
|
|
25277
25036
|
logout,
|
|
25278
25037
|
looksLikeNickname,
|
|
25038
|
+
prepareBatchUserOperation,
|
|
25279
25039
|
prepareUserOperation,
|
|
25280
25040
|
requireActiveChainId,
|
|
25281
|
-
|
|
25041
|
+
sendBatchUserOperation,
|
|
25042
|
+
sendUserOperation,
|
|
25282
25043
|
signTypedData,
|
|
25283
25044
|
updateUserProfile,
|
|
25284
25045
|
useAccountSession,
|