@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.14 → 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.14",
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"
@@ -42,7 +42,7 @@
42
42
  "@pimlico/mock-paymaster": "0.0.4",
43
43
  "concurrently": "9.2.0",
44
44
  "cross-env": "7.0.3",
45
- "hardhat": "3.9.1",
45
+ "hardhat": "3.12.0",
46
46
  "jest": "29.7.0",
47
47
  "prool": "0.0.23",
48
48
  "standard": "17.1.2",
@@ -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.
@@ -316,6 +328,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
316
328
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
317
329
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
318
330
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
331
+ * @throws {ConfigurationError} If, in token mode, the configured `paymasterAddress` does not match the paymaster address returned by the paymaster RPC. This guards against the auto-generated ERC-20 approval targeting an unexpected paymaster contract.
319
332
  * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
320
333
  */
321
334
  async quoteSendTransaction (tx, config) {
@@ -349,6 +362,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
349
362
  * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
350
363
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
351
364
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
365
+ * @throws {ConfigurationError} If, in token mode, the configured `paymasterAddress` does not match the paymaster address returned by the paymaster RPC. This guards against the auto-generated ERC-20 approval targeting an unexpected paymaster contract.
352
366
  * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
353
367
  */
354
368
  async quoteTransfer (options, config, txOverrides) {
@@ -363,6 +377,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
363
377
  /**
364
378
  * Returns a transaction's receipt.
365
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.
366
381
  * @param {string} hash - The user operation hash.
367
382
  * @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
368
383
  */
@@ -376,6 +391,73 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
376
391
  return await evmReadOnlyAccount.getTransactionReceipt(result.transactionHash)
377
392
  }
378
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
+
379
461
  /**
380
462
  * Returns a user operation's receipt.
381
463
  *
@@ -775,6 +857,16 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
775
857
  paymasterOverrides
776
858
  )
777
859
 
778
- return { userOp: result.userOperation, tokenQuote: result.tokenQuote }
860
+ const sponsoredOp = result.userOperation
861
+
862
+ if (mode === PaymasterMode.TOKEN && sponsoredOp.paymaster &&
863
+ sponsoredOp.paymaster.toLowerCase() !== config.paymasterAddress.toLowerCase()) {
864
+ throw new ConfigurationError(
865
+ `paymasterAddress mismatch: configured ${config.paymasterAddress} but RPC ${config.paymasterUrl} returned ${sponsoredOp.paymaster}. ` +
866
+ 'The generated ERC-20 approval would target an unexpected paymaster.'
867
+ )
868
+ }
869
+
870
+ return { userOp: sponsoredOp, tokenQuote: result.tokenQuote }
779
871
  }
780
872
  }
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.