@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.15 → 1.0.0-beta.16

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/index.js CHANGED
@@ -16,6 +16,12 @@
16
16
 
17
17
  /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').UserOperationReceipt} UserOperationReceipt */
18
18
  /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').BuiltUserOperation} BuiltUserOperation */
19
+ /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337TransactionDetails} EvmErc4337TransactionDetails */
20
+
21
+ /** @typedef {import('@tetherto/wdk-wallet').Finality} Finality */
22
+ /** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
23
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionTarget} WaitForTransactionTarget */
24
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
19
25
 
20
26
  /** @typedef {import('@tetherto/wdk-wallet-evm').FeeRates} FeeRates */
21
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-evm-erc-4337",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "A simple package to manage BIP-32 wallets for evm blockchains, which implement the erc-4337 standard and its account abstraction features",
5
5
  "keywords": [
6
6
  "wdk",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
34
- "@tetherto/wdk-wallet": "1.0.0-beta.14",
35
- "@tetherto/wdk-wallet-evm": "1.0.0-beta.15",
34
+ "@tetherto/wdk-wallet": "1.0.0-beta.17",
35
+ "@tetherto/wdk-wallet-evm": "1.0.0-beta.17",
36
36
  "abstractionkit": "0.4.0",
37
37
  "bare-node-runtime": "^1.4.0",
38
38
  "ethers": "6.17.0"
@@ -14,9 +14,9 @@
14
14
 
15
15
  'use strict'
16
16
 
17
- import { JsonRpcProvider } from 'ethers'
17
+ import { isHexString, JsonRpcProvider } from 'ethers'
18
18
 
19
- import { WalletAccountReadOnly } from '@tetherto/wdk-wallet'
19
+ import { WalletAccountReadOnly, NoSuchElementError, ValueError } from '@tetherto/wdk-wallet'
20
20
 
21
21
  import { WalletAccountReadOnlyEvm } from '@tetherto/wdk-wallet-evm'
22
22
 
@@ -60,6 +60,18 @@ export const FEE_TOLERANCE_COEFFICIENT = 120n
60
60
  /** @typedef {import('abstractionkit').UserOperationV7} UserOperationV7 */
61
61
  /** @typedef {import('abstractionkit').TokenQuote} TokenQuote */
62
62
 
63
+ /** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
64
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
65
+
66
+ /**
67
+ * The ERC-4337-specific fields added to a normalized transaction receipt.
68
+ *
69
+ * @typedef {Object} EvmErc4337TransactionDetails
70
+ * @property {number} confirmations - The number of confirmations (0 while pending or dropped).
71
+ * @property {EvmTransactionReceipt | null} receipt - The native ethers receipt, or null while the user operation is pending or dropped.
72
+ * @property {UserOperationReceipt | null} userOperationReceipt - The user operation receipt, or null while pending or unavailable.
73
+ */
74
+
63
75
  /**
64
76
  * @typedef {Object} BuiltUserOperation
65
77
  * @property {UserOperationV7} userOp - The fully-populated UserOperation ready to sign.
@@ -365,6 +377,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
365
377
  /**
366
378
  * Returns a transaction's receipt.
367
379
  *
380
+ * @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw ethers receipt and the user operation receipt remain available on its `receipt` and `userOperationReceipt` properties.
368
381
  * @param {string} hash - The user operation hash.
369
382
  * @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
370
383
  */
@@ -378,6 +391,73 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
378
391
  return await evmReadOnlyAccount.getTransactionReceipt(result.transactionHash)
379
392
  }
380
393
 
394
+ /**
395
+ * Returns a normalized, finality-based receipt for a user operation. Finality and confirmations come from the bundling transaction; `success` and `fee` come from the user operation.
396
+ *
397
+ * @param {string} hash - The user operation hash.
398
+ * @returns {Promise<TransactionReceipt & EvmErc4337TransactionDetails>} The normalized receipt.
399
+ * @throws {ValueError} If the hash is not a valid user operation hash.
400
+ * @throws {NoSuchElementError} If no user operation has been found for the given hash.
401
+ */
402
+ async getTransaction (hash) {
403
+ if (!isHexString(hash, 32)) {
404
+ throw new ValueError(`Invalid user operation hash: '${hash}'.`)
405
+ }
406
+
407
+ const bundler = this._getBundler()
408
+
409
+ const userOpByHash = await bundler.getUserOperationByHash(hash)
410
+ if (!userOpByHash) {
411
+ throw new NoSuchElementError(`No user operation found for '${hash}'.`)
412
+ }
413
+
414
+ if (!userOpByHash.transactionHash) {
415
+ return {
416
+ hash,
417
+ finality: 'pending',
418
+ confirmations: 0,
419
+ receipt: null,
420
+ userOperationReceipt: null
421
+ }
422
+ }
423
+
424
+ const [evmReadOnlyAccount, userOpReceipt] = await Promise.all([
425
+ this._getEvmReadOnlyAccount(),
426
+ bundler.getUserOperationReceipt(hash)
427
+ ])
428
+
429
+ const info = await evmReadOnlyAccount.getTransaction(userOpByHash.transactionHash)
430
+
431
+ return {
432
+ ...info,
433
+ hash,
434
+ success: userOpReceipt ? userOpReceipt.success : info.success,
435
+ fee: userOpReceipt ? userOpReceipt.actualGasCost : info.fee,
436
+ userOperationReceipt: userOpReceipt
437
+ }
438
+ }
439
+
440
+ /**
441
+ * Blocks until a user operation reaches a terminal state (the requested finality target or `dropped`), or times out.
442
+ *
443
+ * @param {string} hash - The user operation hash.
444
+ * @param {WaitForTransactionOptions} [options] - The wait options.
445
+ * @returns {Promise<TransactionReceipt & EvmErc4337TransactionDetails>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
446
+ * @throws {TimeoutError} If the target is not reached before the timeout.
447
+ */
448
+ async waitForTransaction (hash, options = {}) {
449
+ return await super.waitForTransaction(hash, options)
450
+ }
451
+
452
+ /**
453
+ * Overrides the base default to allow for slower ERC-4337 bundling, inclusion, and confirmation.
454
+ *
455
+ * @type {number}
456
+ */
457
+ get defaultWaitTimeout () {
458
+ return 180000
459
+ }
460
+
381
461
  /**
382
462
  * Returns a user operation's receipt.
383
463
  *
package/types/index.d.ts CHANGED
@@ -4,6 +4,11 @@ export { default as WalletAccountEvmErc4337 } from "./src/wallet-account-evm-erc
4
4
  export { ConfigurationError } from "./src/errors.js";
5
5
  export type UserOperationReceipt = import("./src/wallet-account-read-only-evm-erc-4337.js").UserOperationReceipt;
6
6
  export type BuiltUserOperation = import("./src/wallet-account-read-only-evm-erc-4337.js").BuiltUserOperation;
7
+ export type EvmErc4337TransactionDetails = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337TransactionDetails;
8
+ export type Finality = import("@tetherto/wdk-wallet").Finality;
9
+ export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
10
+ export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
11
+ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
7
12
  export type FeeRates = import("@tetherto/wdk-wallet-evm").FeeRates;
8
13
  export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
9
14
  export type EvmErc4337Transaction = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
@@ -120,10 +120,35 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
120
120
  /**
121
121
  * Returns a transaction's receipt.
122
122
  *
123
+ * @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw ethers receipt and the user operation receipt remain available on its `receipt` and `userOperationReceipt` properties.
123
124
  * @param {string} hash - The user operation hash.
124
125
  * @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
125
126
  */
126
127
  getTransactionReceipt(hash: string): Promise<EvmTransactionReceipt | null>;
128
+ /**
129
+ * Returns a normalized, finality-based receipt for a user operation. Finality and confirmations come from the bundling transaction; `success` and `fee` come from the user operation.
130
+ *
131
+ * @param {string} hash - The user operation hash.
132
+ * @returns {Promise<TransactionReceipt & EvmErc4337TransactionDetails>} The normalized receipt.
133
+ * @throws {ValueError} If the hash is not a valid user operation hash.
134
+ * @throws {NoSuchElementError} If no user operation has been found for the given hash.
135
+ */
136
+ getTransaction(hash: string): Promise<TransactionReceipt & EvmErc4337TransactionDetails>;
137
+ /**
138
+ * Blocks until a user operation reaches a terminal state (the requested finality target or `dropped`), or times out.
139
+ *
140
+ * @param {string} hash - The user operation hash.
141
+ * @param {WaitForTransactionOptions} [options] - The wait options.
142
+ * @returns {Promise<TransactionReceipt & EvmErc4337TransactionDetails>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
143
+ * @throws {TimeoutError} If the target is not reached before the timeout.
144
+ */
145
+ waitForTransaction(hash: string, options?: WaitForTransactionOptions): Promise<TransactionReceipt & EvmErc4337TransactionDetails>;
146
+ /**
147
+ * Overrides the base default to allow for slower ERC-4337 bundling, inclusion, and confirmation.
148
+ *
149
+ * @type {number}
150
+ */
151
+ get defaultWaitTimeout(): number;
127
152
  /**
128
153
  * Returns a user operation's receipt.
129
154
  *
@@ -250,6 +275,25 @@ export type TransferResult = import("@tetherto/wdk-wallet-evm").TransferResult;
250
275
  export type EvmTransactionReceipt = import("@tetherto/wdk-wallet-evm").EvmTransactionReceipt;
251
276
  export type TypedData = import("@tetherto/wdk-wallet-evm").TypedData;
252
277
  export type UserOperationReceipt = import('abstractionkit').UserOperationReceiptResult;
278
+ export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
279
+ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
280
+ /**
281
+ * The ERC-4337-specific fields added to a normalized transaction receipt.
282
+ */
283
+ export type EvmErc4337TransactionDetails = {
284
+ /**
285
+ * - The number of confirmations (0 while pending or dropped).
286
+ */
287
+ confirmations: number;
288
+ /**
289
+ * - The native ethers receipt, or null while the user operation is pending or dropped.
290
+ */
291
+ receipt: EvmTransactionReceipt | null;
292
+ /**
293
+ * - The user operation receipt, or null while pending or unavailable.
294
+ */
295
+ userOperationReceipt: UserOperationReceipt | null;
296
+ };
253
297
  export type EvmErc4337Transaction = {
254
298
  /**
255
299
  * - The call's recipient.