@aomi-labs/client 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -22,7 +22,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
22
  // package.json
23
23
  var package_default = {
24
24
  name: "@aomi-labs/client",
25
- version: "0.1.18",
25
+ version: "0.1.19",
26
26
  description: "Platform-agnostic TypeScript client for the Aomi backend API",
27
27
  type: "module",
28
28
  main: "./dist/index.cjs",
@@ -53,9 +53,10 @@ var package_default = {
53
53
  "clean:dist": "rm -rf dist"
54
54
  },
55
55
  dependencies: {
56
- "@getpara/aa-alchemy": "2.18.0",
57
- "@getpara/aa-pimlico": "2.18.0",
58
- viem: "^2.40.3"
56
+ "@alchemy/wallet-apis": "5.0.0-beta.22",
57
+ "@getpara/aa-alchemy": "2.21.0",
58
+ "@getpara/aa-pimlico": "2.21.0",
59
+ viem: "^2.47.11"
59
60
  }
60
61
  };
61
62
 
@@ -1161,10 +1162,11 @@ var AomiClient = class {
1161
1162
  // Batch Simulation
1162
1163
  // ===========================================================================
1163
1164
  /**
1164
- * Simulate pending transactions as an atomic batch.
1165
+ * Simulate transactions as an atomic batch.
1165
1166
  * Each tx sees state changes from previous txs (e.g., approve → swap).
1167
+ * Sends full tx payloads — the backend does not look up by ID.
1166
1168
  */
1167
- async simulateBatch(sessionId, txIds) {
1169
+ async simulateBatch(sessionId, transactions, options) {
1168
1170
  const url = joinApiPath(this.baseUrl, "/api/simulate");
1169
1171
  const headers = new Headers(
1170
1172
  withSessionHeader(sessionId, { "Content-Type": "application/json" })
@@ -1172,13 +1174,20 @@ var AomiClient = class {
1172
1174
  if (this.apiKey) {
1173
1175
  headers.set(API_KEY_HEADER, this.apiKey);
1174
1176
  }
1177
+ const payload = {
1178
+ transactions,
1179
+ from: options == null ? void 0 : options.from,
1180
+ chain_id: options == null ? void 0 : options.chainId
1181
+ };
1175
1182
  const response = await fetch(url, {
1176
1183
  method: "POST",
1177
1184
  headers,
1178
- body: JSON.stringify({ tx_ids: txIds })
1185
+ body: JSON.stringify(payload)
1179
1186
  });
1180
1187
  if (!response.ok) {
1181
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
1188
+ const body = await response.text().catch(() => "");
1189
+ throw new Error(`HTTP ${response.status}: ${response.statusText}${body ? `
1190
+ ${body}` : ""}`);
1182
1191
  }
1183
1192
  return await response.json();
1184
1193
  }
@@ -2978,7 +2987,7 @@ Run \`aomi tx\` to see available IDs.`
2978
2987
  return pendingTx;
2979
2988
  }
2980
2989
  async function simulateCommand(runtime) {
2981
- var _a3;
2990
+ var _a3, _b, _c;
2982
2991
  const state = readState();
2983
2992
  if (!state) {
2984
2993
  fatal("No active session. Run `aomi chat` first.");
@@ -2987,9 +2996,7 @@ async function simulateCommand(runtime) {
2987
2996
  if (txIds.length === 0) {
2988
2997
  fatal("Usage: aomi simulate <tx-id> [<tx-id> ...]\nRun `aomi tx` to see available IDs.");
2989
2998
  }
2990
- for (const txId of txIds) {
2991
- requirePendingTx(state, txId);
2992
- }
2999
+ const pendingTxs = txIds.map((txId) => requirePendingTx(state, txId));
2993
3000
  console.log(
2994
3001
  `${DIM}Simulating ${txIds.length} transaction(s) as atomic batch...${RESET}`
2995
3002
  );
@@ -2997,7 +3004,23 @@ async function simulateCommand(runtime) {
2997
3004
  baseUrl: state.baseUrl,
2998
3005
  apiKey: state.apiKey
2999
3006
  });
3000
- const response = await client.simulateBatch(state.sessionId, txIds);
3007
+ const transactions = pendingTxs.map((tx) => {
3008
+ var _a4;
3009
+ return {
3010
+ to: tx.to,
3011
+ value: tx.value,
3012
+ data: tx.data,
3013
+ label: (_a4 = tx.description) != null ? _a4 : tx.id
3014
+ };
3015
+ });
3016
+ const response = await client.simulateBatch(
3017
+ state.sessionId,
3018
+ transactions,
3019
+ {
3020
+ from: (_a3 = state.publicKey) != null ? _a3 : void 0,
3021
+ chainId: (_b = state.chainId) != null ? _b : void 0
3022
+ }
3023
+ );
3001
3024
  const { result } = response;
3002
3025
  const modeLabel = result.stateful ? "stateful (Anvil snapshot)" : "stateless (independent eth_call)";
3003
3026
  console.log(`
@@ -3032,7 +3055,7 @@ ${DIM}Total gas: ${result.total_gas.toLocaleString()}${RESET}`);
3032
3055
  } else {
3033
3056
  const failed = result.steps.find((s) => !s.success);
3034
3057
  console.log(
3035
- `\x1B[31mBatch failed at step ${(_a3 = failed == null ? void 0 : failed.step) != null ? _a3 : "?"}.${RESET} Fix the issue and re-queue, or run \`aomi sign\` on the successful prefix.`
3058
+ `\x1B[31mBatch failed at step ${(_c = failed == null ? void 0 : failed.step) != null ? _c : "?"}.${RESET} Fix the issue and re-queue, or run \`aomi sign\` on the successful prefix.`
3036
3059
  );
3037
3060
  }
3038
3061
  }
@@ -3374,6 +3397,25 @@ async function createAlchemyAAState(options) {
3374
3397
  if (ownerParams.kind === "unsupported_adapter") {
3375
3398
  return getUnsupportedAdapterState(plan, ownerParams.adapter);
3376
3399
  }
3400
+ if (owner.kind === "direct") {
3401
+ try {
3402
+ return await createAlchemyWalletApisState({
3403
+ plan,
3404
+ chain,
3405
+ privateKey: owner.privateKey,
3406
+ apiKey,
3407
+ gasPolicyId,
3408
+ mode: plan.mode
3409
+ });
3410
+ } catch (error) {
3411
+ return {
3412
+ plan,
3413
+ AA: null,
3414
+ isPending: false,
3415
+ error: error instanceof Error ? error : new Error(String(error))
3416
+ };
3417
+ }
3418
+ }
3377
3419
  try {
3378
3420
  const smartAccount = await createAlchemySmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
3379
3421
  apiKey,
@@ -3405,6 +3447,46 @@ async function createAlchemyAAState(options) {
3405
3447
  };
3406
3448
  }
3407
3449
  }
3450
+ async function createAlchemyWalletApisState(params) {
3451
+ const { createSmartWalletClient, alchemyWalletTransport } = await import("@alchemy/wallet-apis");
3452
+ const signer = privateKeyToAccount(params.privateKey);
3453
+ const walletClient = createSmartWalletClient(__spreadValues({
3454
+ transport: alchemyWalletTransport({ apiKey: params.apiKey }),
3455
+ chain: params.chain,
3456
+ signer
3457
+ }, params.gasPolicyId ? { paymaster: { policyId: params.gasPolicyId } } : {}));
3458
+ let accountAddress = signer.address;
3459
+ if (params.mode === "4337") {
3460
+ const account = await walletClient.requestAccount();
3461
+ accountAddress = account.address;
3462
+ }
3463
+ const sendCalls = async (calls) => {
3464
+ var _a3, _b;
3465
+ const result = await walletClient.sendCalls(__spreadProps(__spreadValues({}, params.mode === "4337" ? { account: accountAddress } : {}), {
3466
+ calls
3467
+ }));
3468
+ const status = await walletClient.waitForCallsStatus({ id: result.id });
3469
+ const transactionHash = (_b = (_a3 = status.receipts) == null ? void 0 : _a3[0]) == null ? void 0 : _b.transactionHash;
3470
+ if (!transactionHash) {
3471
+ throw new Error("Alchemy Wallets API did not return a transaction hash.");
3472
+ }
3473
+ return { transactionHash };
3474
+ };
3475
+ const AA = {
3476
+ provider: "alchemy",
3477
+ mode: params.mode,
3478
+ AAAddress: accountAddress,
3479
+ delegationAddress: params.mode === "7702" ? signer.address : void 0,
3480
+ sendTransaction: async (call) => sendCalls([call]),
3481
+ sendBatchTransaction: async (calls) => sendCalls(calls)
3482
+ };
3483
+ return {
3484
+ plan: params.plan,
3485
+ AA,
3486
+ isPending: false,
3487
+ error: null
3488
+ };
3489
+ }
3408
3490
  async function createPimlicoAAState(options) {
3409
3491
  var _a3;
3410
3492
  const {
@@ -3839,7 +3921,19 @@ async function signCommand(runtime) {
3839
3921
  try {
3840
3922
  const simResponse = await session.client.simulateBatch(
3841
3923
  state.sessionId,
3842
- pendingTxs.map((tx) => tx.id)
3924
+ pendingTxs.map((tx) => {
3925
+ var _a4;
3926
+ return {
3927
+ to: tx.to,
3928
+ value: tx.value,
3929
+ data: tx.data,
3930
+ label: (_a4 = tx.description) != null ? _a4 : tx.id
3931
+ };
3932
+ }),
3933
+ {
3934
+ from: account.address,
3935
+ chainId: primaryChainId
3936
+ }
3843
3937
  );
3844
3938
  const { result: sim } = simResponse;
3845
3939
  if (!sim.batch_success) {
package/dist/index.cjs CHANGED
@@ -619,10 +619,11 @@ var AomiClient = class {
619
619
  // Batch Simulation
620
620
  // ===========================================================================
621
621
  /**
622
- * Simulate pending transactions as an atomic batch.
622
+ * Simulate transactions as an atomic batch.
623
623
  * Each tx sees state changes from previous txs (e.g., approve → swap).
624
+ * Sends full tx payloads — the backend does not look up by ID.
624
625
  */
625
- async simulateBatch(sessionId, txIds) {
626
+ async simulateBatch(sessionId, transactions, options) {
626
627
  const url = joinApiPath(this.baseUrl, "/api/simulate");
627
628
  const headers = new Headers(
628
629
  withSessionHeader(sessionId, { "Content-Type": "application/json" })
@@ -630,13 +631,20 @@ var AomiClient = class {
630
631
  if (this.apiKey) {
631
632
  headers.set(API_KEY_HEADER, this.apiKey);
632
633
  }
634
+ const payload = {
635
+ transactions,
636
+ from: options == null ? void 0 : options.from,
637
+ chain_id: options == null ? void 0 : options.chainId
638
+ };
633
639
  const response = await fetch(url, {
634
640
  method: "POST",
635
641
  headers,
636
- body: JSON.stringify({ tx_ids: txIds })
642
+ body: JSON.stringify(payload)
637
643
  });
638
644
  if (!response.ok) {
639
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
645
+ const body = await response.text().catch(() => "");
646
+ throw new Error(`HTTP ${response.status}: ${response.statusText}${body ? `
647
+ ${body}` : ""}`);
640
648
  }
641
649
  return await response.json();
642
650
  }
@@ -1981,6 +1989,25 @@ async function createAlchemyAAState(options) {
1981
1989
  if (ownerParams.kind === "unsupported_adapter") {
1982
1990
  return getUnsupportedAdapterState(plan, ownerParams.adapter);
1983
1991
  }
1992
+ if (owner.kind === "direct") {
1993
+ try {
1994
+ return await createAlchemyWalletApisState({
1995
+ plan,
1996
+ chain,
1997
+ privateKey: owner.privateKey,
1998
+ apiKey,
1999
+ gasPolicyId,
2000
+ mode: plan.mode
2001
+ });
2002
+ } catch (error) {
2003
+ return {
2004
+ plan,
2005
+ AA: null,
2006
+ isPending: false,
2007
+ error: error instanceof Error ? error : new Error(String(error))
2008
+ };
2009
+ }
2010
+ }
1984
2011
  try {
1985
2012
  const smartAccount = await (0, import_aa_alchemy.createAlchemySmartAccount)(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
1986
2013
  apiKey,
@@ -2012,6 +2039,46 @@ async function createAlchemyAAState(options) {
2012
2039
  };
2013
2040
  }
2014
2041
  }
2042
+ async function createAlchemyWalletApisState(params) {
2043
+ const { createSmartWalletClient, alchemyWalletTransport } = await import("@alchemy/wallet-apis");
2044
+ const signer = (0, import_accounts.privateKeyToAccount)(params.privateKey);
2045
+ const walletClient = createSmartWalletClient(__spreadValues({
2046
+ transport: alchemyWalletTransport({ apiKey: params.apiKey }),
2047
+ chain: params.chain,
2048
+ signer
2049
+ }, params.gasPolicyId ? { paymaster: { policyId: params.gasPolicyId } } : {}));
2050
+ let accountAddress = signer.address;
2051
+ if (params.mode === "4337") {
2052
+ const account = await walletClient.requestAccount();
2053
+ accountAddress = account.address;
2054
+ }
2055
+ const sendCalls = async (calls) => {
2056
+ var _a, _b;
2057
+ const result = await walletClient.sendCalls(__spreadProps(__spreadValues({}, params.mode === "4337" ? { account: accountAddress } : {}), {
2058
+ calls
2059
+ }));
2060
+ const status = await walletClient.waitForCallsStatus({ id: result.id });
2061
+ const transactionHash = (_b = (_a = status.receipts) == null ? void 0 : _a[0]) == null ? void 0 : _b.transactionHash;
2062
+ if (!transactionHash) {
2063
+ throw new Error("Alchemy Wallets API did not return a transaction hash.");
2064
+ }
2065
+ return { transactionHash };
2066
+ };
2067
+ const AA = {
2068
+ provider: "alchemy",
2069
+ mode: params.mode,
2070
+ AAAddress: accountAddress,
2071
+ delegationAddress: params.mode === "7702" ? signer.address : void 0,
2072
+ sendTransaction: async (call) => sendCalls([call]),
2073
+ sendBatchTransaction: async (calls) => sendCalls(calls)
2074
+ };
2075
+ return {
2076
+ plan: params.plan,
2077
+ AA,
2078
+ isPending: false,
2079
+ error: null
2080
+ };
2081
+ }
2015
2082
  async function createPimlicoAAState(options) {
2016
2083
  var _a;
2017
2084
  const {