@embarkai/ui-kit 0.4.18 → 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/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 as createUserOperationWithDynamicFees2,
1704
- estimateUserOperationGas as estimateUserOperationGas2,
1705
- sendUserOperationWithRetry as sendUserOperationWithRetry2
1517
+ createUserOperationWithDynamicFees,
1518
+ estimateUserOperationGas,
1519
+ sendUserOperationWithRetry
1706
1520
  } from "@embarkai/core/bundler";
1707
- import { createPublicClientForChain as createPublicClientForChain3, getChainConfig as getChainConfig5 } from "@embarkai/core/read";
1708
- import { encodeFunctionData as encodeFunctionData2, hashTypedData } from "viem";
1709
- import { entryPoint07Abi as entryPoint07Abi2 } from "viem/account-abstraction";
1710
- import { privateKeyToAccount as privateKeyToAccount3 } from "viem/accounts";
1711
- function normalizeSignature2(signature) {
1712
- const sig = signature.slice(2);
1713
- const r = sig.slice(0, 64);
1714
- const s = sig.slice(64, 128);
1715
- const v = sig.slice(128, 130);
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
- const canonicalSHex = canonicalS.toString(16).padStart(64, "0");
1726
- const canonicalVHex = canonicalV.toString(16).padStart(2, "0");
1727
- return `0x${r}${canonicalSHex}${canonicalVHex}`;
1531
+ return {
1532
+ bundlerUrl: chainConfig.bundlerUrl,
1533
+ chainConfig,
1534
+ chainId,
1535
+ chainPublicClient: createPublicClientForChain2(chainId),
1536
+ entryPointAddress: chainConfig.entryPointV07Address
1537
+ };
1728
1538
  }
1729
- async function prepareUserOperation(session, params) {
1730
- const chainId = params.chainId ?? requireActiveChainId();
1731
- const chainConfig = getChainConfig5(chainId);
1732
- const chainPublicClient = createPublicClientForChain3(chainId);
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
- callData = "0x";
1741
- } else {
1742
- callData = encodeFunctionData2({
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, innerData]
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
- let isDeployed = false;
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: session.smartAccountAddress });
1751
- if (code && code !== "0x" && code.length > 2) {
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
- const nonce = await fetchEntryPointNonce(session.smartAccountAddress, entryPointAddress, {
1757
- client: chainPublicClient
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 (!isDeployed && nonceValue !== 0n) {
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 (shouldIncludeFactory) {
1766
- const factoryData = encodeFunctionData2({
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 createUserOperationWithDynamicFees2(
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 createUserOperationWithDynamicFees2(
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 = PAYMASTER_VERIFICATION_GAS_LIMIT2;
1802
- userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT2;
1625
+ userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT;
1626
+ userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT;
1803
1627
  }
1804
1628
  try {
1805
- const gasEst = await estimateUserOperationGas2(userOp, { chainId, retryWithoutFactory: true });
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 (e) {
1815
- console.log("[Account] Gas estimation failed:", e);
1816
- throw new Error(`Gas estimation failed: ${e}`);
1641
+ } catch (error) {
1642
+ console.log("[Account] Gas estimation failed:", error);
1643
+ throw new Error(`Gas estimation failed: ${error}`);
1817
1644
  }
1818
- userOp.nonce = nonce;
1819
- const hasFactoryData = !!(userOp.factory && userOp.factoryData);
1820
- const initCode = hasFactoryData ? (() => {
1821
- const factoryAddr = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
1822
- const factoryDataClean = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
1823
- return `0x${factoryAddr}${factoryDataClean}`;
1824
- })() : "0x";
1825
- const accountGasLimits = pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit));
1826
- const gasFees = pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas));
1827
- let paymasterAndData = "0x";
1828
- if (userOp.paymaster && userOp.paymaster !== "0x0000000000000000000000000000000000000000") {
1829
- const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
1830
- const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
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 opHash = await chainPublicClient.readContract({
1849
- address: entryPointAddress,
1850
- abi: entryPoint07Abi2,
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
- signature = await signDigestWithMpc(session.mpcUserId, opHash, {
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 = privateKeyToAccount3(session.ownerPrivateKey);
1871
- const rawSig = await account.sign({ hash: opHash });
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: opHash };
1713
+ return { userOp, userOpHash };
1881
1714
  }
1882
- async function sendUserOperation2(session, params) {
1883
- const chainId = params.chainId ?? requireActiveChainId();
1884
- const chainConfig = getChainConfig5(chainId);
1885
- const chainPublicClient = createPublicClientForChain3(chainId);
1886
- const bundlerUrl = chainConfig.bundlerUrl;
1887
- const { to: callTarget, value: amountWei, data: innerData = "0x", feeType = "standard" } = params;
1888
- const entryPointAddress = chainConfig.entryPointV07Address;
1889
- const amountWeiBigInt = BigInt(amountWei);
1890
- const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && amountWei === "0" && innerData === "0x";
1891
- let callData;
1892
- if (isMinimalTest) {
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
- userOp = await signUserOp(nonce);
2042
- const hash = await sendUserOperationWithRetry2(userOp, signUserOp, { maxRetries: 1, chainId });
2043
- return hash;
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 = normalizeSignature2(rawSig);
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 PAYMASTER_VERIFICATION_GAS_LIMIT2, PAYMASTER_POSTOP_GAS_LIMIT2;
2098
- var init_account = __esm({
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
- init_resolve_paymaster();
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/session.ts
2114
- import { privateKeyToAccount as privateKeyToAccount4 } from "viem/accounts";
2115
- import { getChainConfig as getChainConfig6, createPublicClientForChain as createPublicClientForChain4 } from "@embarkai/core/read";
2116
- async function createAccountSession(params) {
2117
- const { privateKey, mpcUserId, usePaymaster = false, chainId } = params;
2118
- if (!privateKey && !mpcUserId) throw new Error("Either privateKey or mpcUserId must be provided");
2119
- if (!privateKey && mpcUserId && !mpcUserId.trim()) throw new Error("mpcUserId cannot be empty when using MPC mode");
2120
- const chainConfig = getChainConfig6(chainId);
2121
- if (!chainConfig) {
2122
- throw new Error(`Chain ${chainId} is not supported`);
2123
- }
2124
- const factoryAddress = chainConfig.factoryAddress;
2125
- if (!factoryAddress) {
2126
- throw new Error(`Factory address not configured for chain ${chainId}`);
2127
- }
2128
- const publicClient = createPublicClientForChain4(chainId);
2129
- let ownerAddress;
2130
- let ownerPrivateKey;
2131
- if (privateKey) {
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
- ownerAddress,
2150
- smartAccountAddress,
2151
- factoryAddress,
2152
- ownerPrivateKey,
2153
- mpcUserId: privateKey ? void 0 : mpcUserId,
2154
- usePaymaster,
2155
- kind: "lumia",
2156
- address: smartAccountAddress
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 init_session = __esm({
2160
- "src/internal/clients/account/session.ts"() {
2161
- init_iframe_mpc_client();
2162
- init_constants2();
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 createPublicClientForChain5, getChainConfig as getChainConfig7 } from "@embarkai/core/read";
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 = getChainConfig7(chainId);
2173
- const publicClient = createPublicClientForChain5(chainId);
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
- sendUserOperation: () => sendUserOperation2,
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
- init_account();
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 getChainConfig8 } from "@embarkai/core/read";
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 = getChainConfig8(chainId);
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 ? getChainConfig8(activeChainId) : null;
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 encodeFunctionData3, isAddress, parseEther as parseEther3, parseUnits } from "viem";
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 = parseEther3(params.value).toString();
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 = encodeFunctionData3({
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 = encodeFunctionData3({
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 = encodeFunctionData3({
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 sendUserOperation2(session, {
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
- init_account();
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.18",
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",
@@ -19320,7 +19079,6 @@ var init_package = __esm({
19320
19079
  "build:iframe-html": "node scripts/copy-iframe-html.js",
19321
19080
  "build:copy-css": "node scripts/copy-styles-css.js",
19322
19081
  build: "pnpm build:css && tsup && pnpm build:iframe-html && pnpm build:copy-css",
19323
- prepack: "pnpm build",
19324
19082
  dev: "pnpm build:css && tsup --watch",
19325
19083
  "dev:iframe": "vite --config iframe/vite.config.ts",
19326
19084
  csv: "npx tsx src/i18n/utils/prepareCsvProofread.ts --origin en --target zh",
@@ -20432,9 +20190,9 @@ var init_DirectWalletHandler = __esm({
20432
20190
  // src/context/SessionContext.tsx
20433
20191
  import {
20434
20192
  createBundlerClientForChain,
20435
- createPublicClientForChain as createPublicClientForChain6,
20193
+ createPublicClientForChain as createPublicClientForChain5,
20436
20194
  DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID2,
20437
- getChainConfig as getChainConfig9,
20195
+ getChainConfig as getChainConfig8,
20438
20196
  getViemChain as getViemChain2
20439
20197
  } from "@embarkai/core/read";
20440
20198
  import { Fragment as Fragment42 } from "react";
@@ -20445,7 +20203,7 @@ function getChainParams(chainCfg) {
20445
20203
  return {
20446
20204
  activeChainId: chainCfg.id,
20447
20205
  chainConfig: chainCfg,
20448
- publicClient: createPublicClientForChain6(chainCfg.id),
20206
+ publicClient: createPublicClientForChain5(chainCfg.id),
20449
20207
  bundlerClient: createBundlerClientForChain(chainCfg.id),
20450
20208
  viemChain: getViemChain2(chainCfg.id)
20451
20209
  };
@@ -20543,7 +20301,7 @@ var init_SessionContext = __esm({
20543
20301
  // Set default chainId after hydration if not persisted
20544
20302
  onRehydrateStorage: () => (state) => {
20545
20303
  if (!state) return;
20546
- const hydartedChain = getChainParams(getChainConfig9(state.activeChainId || DEFAULT_CHAIN_ID2));
20304
+ const hydartedChain = getChainParams(getChainConfig8(state.activeChainId || DEFAULT_CHAIN_ID2));
20547
20305
  state.activeChainId = hydartedChain.activeChainId;
20548
20306
  state.publicClient = hydartedChain.publicClient;
20549
20307
  state.bundlerClient = hydartedChain.bundlerClient;
@@ -20590,8 +20348,8 @@ var init_env = __esm({
20590
20348
  });
20591
20349
 
20592
20350
  // src/internal/clients/base.ts
20593
- import { getChainConfig as getChainConfig10, getViemChain as getViemChain3, lumiaMainnetChain, lumiaTestnetChain } from "@embarkai/core/read";
20594
- import { http as http3 } from "viem";
20351
+ import { getChainConfig as getChainConfig9, getViemChain as getViemChain3, lumiaMainnetChain, lumiaTestnetChain } from "@embarkai/core/read";
20352
+ import { http as http2 } from "viem";
20595
20353
  import { createBundlerClient } from "viem/account-abstraction";
20596
20354
  function getTssUrl2() {
20597
20355
  const serviceUrls = getServiceUrls();
@@ -20621,17 +20379,17 @@ function getExplorerUrl() {
20621
20379
  const paramUrl = typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("explorerUrl") || void 0 : void 0;
20622
20380
  const net = getSelectedNetwork();
20623
20381
  const chainId = requireActiveChainId();
20624
- const chainConfig = getChainConfig10(chainId);
20382
+ const chainConfig = getChainConfig9(chainId);
20625
20383
  console.log("[getExplorerUrl] ", paramUrl, chainConfig.blockExplorerUrl);
20626
20384
  return paramUrl || chainConfig.blockExplorerUrl;
20627
20385
  }
20628
20386
  function getBundlerClient() {
20629
20387
  const chainId = requireActiveChainId();
20630
- const chainConfig = getChainConfig10(chainId);
20388
+ const chainConfig = getChainConfig9(chainId);
20631
20389
  const viemChain = getViemChain3(chainId);
20632
20390
  return createBundlerClient({
20633
20391
  chain: viemChain,
20634
- transport: http3(chainConfig.bundlerUrl, { timeout: 1e4, retryCount: 0, fetchOptions: { mode: "cors" } })
20392
+ transport: http2(chainConfig.bundlerUrl, { timeout: 1e4, retryCount: 0, fetchOptions: { mode: "cors" } })
20635
20393
  });
20636
20394
  }
20637
20395
  var BUILD_NETWORK, lumiaBeamTestnet, lumiaPrisma, FUNDER_PK;
@@ -23221,10 +22979,10 @@ var init_utils10 = __esm({
23221
22979
  // src/config/wagmi.ts
23222
22980
  import { lumiaMainnetChain as lumiaMainnetChain3, lumiaTestnetChain as lumiaTestnetChain3 } from "@embarkai/core/read";
23223
22981
  import { fallback } from "viem";
23224
- import { createConfig, createStorage as createStorage2, http as http4 } from "wagmi";
22982
+ import { createConfig, createStorage as createStorage2, http as http3 } from "wagmi";
23225
22983
  function buildTransport(urls) {
23226
22984
  const transports = urls.map(
23227
- (url) => http4(url, {
22985
+ (url) => http3(url, {
23228
22986
  timeout: 1e4,
23229
22987
  retryCount: 0,
23230
22988
  batch: false,
@@ -23748,10 +23506,10 @@ var init_LangToggle = __esm({
23748
23506
 
23749
23507
  // src/clients/bundler/getUserOperationByHash.ts
23750
23508
  import { bundlerRpc } from "@embarkai/core";
23751
- import { getChainConfig as getChainConfig11 } from "@embarkai/core/read";
23509
+ import { getChainConfig as getChainConfig10 } from "@embarkai/core/read";
23752
23510
  async function getUserOperationByHash(userOpHash, chainId) {
23753
23511
  const targetChainId = chainId ?? requireActiveChainId();
23754
- const chainConfig = getChainConfig11(targetChainId);
23512
+ const chainConfig = getChainConfig10(targetChainId);
23755
23513
  if (!chainConfig) {
23756
23514
  throw new Error(`Chain ${targetChainId} is not supported`);
23757
23515
  }
@@ -23787,10 +23545,10 @@ var init_getUserOperationByHash = __esm({
23787
23545
 
23788
23546
  // src/clients/bundler/getUserOperationReceipt.ts
23789
23547
  import { bundlerRpc as bundlerRpc2 } from "@embarkai/core";
23790
- import { getChainConfig as getChainConfig12 } from "@embarkai/core/read";
23548
+ import { getChainConfig as getChainConfig11 } from "@embarkai/core/read";
23791
23549
  async function getUserOperationReceipt(userOpHash, chainId) {
23792
23550
  const targetChainId = chainId ?? requireActiveChainId();
23793
- const chainConfig = getChainConfig12(targetChainId);
23551
+ const chainConfig = getChainConfig11(targetChainId);
23794
23552
  if (!chainConfig) {
23795
23553
  throw new Error(`Chain ${targetChainId} is not supported`);
23796
23554
  }
@@ -24608,7 +24366,7 @@ var init_useDirectWallet = __esm({
24608
24366
 
24609
24367
  // src/hooks/useSendDirectTransaction.ts
24610
24368
  import { useCallback as useCallback34, useState as useState35 } from "react";
24611
- import { isAddress as isAddress3, parseEther as parseEther4 } from "viem";
24369
+ import { isAddress as isAddress3, parseEther as parseEther3 } from "viem";
24612
24370
  import { useSendTransaction as useWagmiSendTransaction, useSwitchChain } from "wagmi";
24613
24371
  function useSendDirectTransaction() {
24614
24372
  const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
@@ -24637,7 +24395,7 @@ function useSendDirectTransaction() {
24637
24395
  }
24638
24396
  const hash = await sendTransactionAsync({
24639
24397
  to: params.to,
24640
- value: parseEther4(params.value),
24398
+ value: parseEther3(params.value),
24641
24399
  data: params.data
24642
24400
  });
24643
24401
  setTxHash(hash);
@@ -24667,7 +24425,7 @@ var init_useSendDirectTransaction = __esm({
24667
24425
 
24668
24426
  // src/hooks/useTransferToLinkedWallet.ts
24669
24427
  import { useCallback as useCallback35, useMemo as useMemo12, useState as useState36 } from "react";
24670
- import { encodeFunctionData as encodeFunctionData4, isAddress as isAddress4, parseEther as parseEther5, parseUnits as parseUnits3 } from "viem";
24428
+ import { encodeFunctionData as encodeFunctionData3, isAddress as isAddress4, parseEther as parseEther4, parseUnits as parseUnits3 } from "viem";
24671
24429
  function useTransferToLinkedWallet() {
24672
24430
  const session = useSession((st) => st.session);
24673
24431
  const { profiles } = useLinkedProfiles();
@@ -24698,19 +24456,19 @@ function useTransferToLinkedWallet() {
24698
24456
  let data;
24699
24457
  if (params.token === "native") {
24700
24458
  to = toAddress;
24701
- value = parseEther5(params.amount).toString();
24459
+ value = parseEther4(params.amount).toString();
24702
24460
  data = "0x";
24703
24461
  } else {
24704
24462
  const decimals = params.decimals ?? 18;
24705
24463
  to = params.token;
24706
24464
  value = "0";
24707
- data = encodeFunctionData4({
24465
+ data = encodeFunctionData3({
24708
24466
  abi: ERC20_TRANSFER_ABI2,
24709
24467
  functionName: "transfer",
24710
24468
  args: [toAddress, parseUnits3(params.amount, decimals)]
24711
24469
  });
24712
24470
  }
24713
- const hash = await sendUserOperation2(session, {
24471
+ const hash = await sendUserOperation(session, {
24714
24472
  to,
24715
24473
  value,
24716
24474
  data,
@@ -24740,7 +24498,7 @@ var ERC20_TRANSFER_ABI2;
24740
24498
  var init_useTransferToLinkedWallet = __esm({
24741
24499
  "src/hooks/useTransferToLinkedWallet.ts"() {
24742
24500
  init_SessionContext();
24743
- init_account();
24501
+ init_account2();
24744
24502
  init_linkedProfiles();
24745
24503
  ERC20_TRANSFER_ABI2 = [
24746
24504
  {
@@ -24870,7 +24628,7 @@ var init_clients2 = __esm({
24870
24628
 
24871
24629
  // src/modules/transactions.ts
24872
24630
  import { getViemChain as getViemChain4 } from "@embarkai/core/read";
24873
- import { parseEther as parseEther6 } from "viem";
24631
+ import { parseEther as parseEther5 } from "viem";
24874
24632
  import { useAccount as useAccount3, usePublicClient, useWalletClient } from "wagmi";
24875
24633
  function useTransactions() {
24876
24634
  const chainId = requireActiveChainId();
@@ -24884,7 +24642,7 @@ function useTransactions() {
24884
24642
  }
24885
24643
  const txParams = {
24886
24644
  to: params.to,
24887
- value: parseEther6(params.value),
24645
+ value: parseEther5(params.value),
24888
24646
  data: params.data,
24889
24647
  chain: viemChain
24890
24648
  };
@@ -25218,7 +24976,7 @@ var init_index = __esm({
25218
24976
  init_useNativeWalletSignature();
25219
24977
  init_useLogout();
25220
24978
  init_useNicknameResolve();
25221
- init_account();
24979
+ init_account2();
25222
24980
  init_clients2();
25223
24981
  init_auth();
25224
24982
  init_profile();
@@ -25277,9 +25035,11 @@ export {
25277
25035
  jwtTokenManager2 as jwtTokenManager,
25278
25036
  logout,
25279
25037
  looksLikeNickname,
25038
+ prepareBatchUserOperation,
25280
25039
  prepareUserOperation,
25281
25040
  requireActiveChainId,
25282
- sendUserOperation2 as sendUserOperation,
25041
+ sendBatchUserOperation,
25042
+ sendUserOperation,
25283
25043
  signTypedData,
25284
25044
  updateUserProfile,
25285
25045
  useAccountSession,