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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-evm-erc-4337",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
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",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
34
34
  "@tetherto/wdk-wallet": "1.0.0-beta.17",
35
- "@tetherto/wdk-wallet-evm": "1.0.0-beta.17",
35
+ "@tetherto/wdk-wallet-evm": "1.0.0-beta.18",
36
36
  "abstractionkit": "0.4.0",
37
37
  "bare-node-runtime": "^1.4.0",
38
38
  "ethers": "6.17.0"
package/src/errors.js CHANGED
@@ -14,7 +14,14 @@
14
14
 
15
15
  'use strict'
16
16
 
17
- export class ConfigurationError extends Error {
17
+ import { ValueError } from '@tetherto/wdk-wallet'
18
+
19
+ /**
20
+ * Thrown when the wallet configuration is invalid or has missing required fields.
21
+ *
22
+ * It extends {@link ValueError}, so it is also part of the `WdkError` taxonomy.
23
+ */
24
+ export class ConfigurationError extends ValueError {
18
25
  /**
19
26
  * Create a new configuration error.
20
27
  *
@@ -16,6 +16,8 @@
16
16
 
17
17
  import { Contract, hexlify, keccak256, randomBytes, toUtf8Bytes } from 'ethers'
18
18
 
19
+ import { MaximumFeeExceededError, ProviderRequiredError, TransactionError, TransactionErrorReason, ValueError } from '@tetherto/wdk-wallet'
20
+
19
21
  import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
20
22
 
21
23
  import { AbstractionKitError, ENTRYPOINT_V7, calculateUserOperationMaxGasCost, fetchAccountNonce } from 'abstractionkit'
@@ -152,7 +154,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
152
154
  * @param {EvmErc4337Transaction} tx - The transaction to include in the user operation.
153
155
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
154
156
  * @returns {Promise<UserOperationV7>} The signed user operation.
155
- * @throws {Error} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
157
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
158
+ * @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.
159
+ * @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
160
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
156
161
  */
157
162
  async signTransaction (tx, config) {
158
163
  const mergedConfig = { ...this._config, ...config }
@@ -167,7 +172,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
167
172
 
168
173
  const { isSponsored, transactionMaxFee } = mergedConfig
169
174
  if (!isSponsored && transactionMaxFee !== undefined && fee > transactionMaxFee) {
170
- throw new Error('Exceeded maximum fee cost for transaction operation.')
175
+ throw new MaximumFeeExceededError('Exceeded maximum fee cost for transaction operation.')
171
176
  }
172
177
 
173
178
  const { userOp } = await this._signUserOperation([tx], { config: mergedConfig, cachedBuild: prepared })
@@ -183,11 +188,12 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
183
188
  * @param {ApproveOptions} options - The approve options.
184
189
  * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
185
190
  * @returns {Promise<TransactionResult>} - The transaction's result.
186
- * @throws {Error} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
191
+ * @throws {ProviderRequiredError} - If the wallet is not connected to a provider.
192
+ * @throws {ValueError} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
187
193
  */
188
194
  async approve (options, txOverrides) {
189
195
  if (!this._ownerAccount._provider) {
190
- throw new Error('The wallet must be connected to a provider to approve funds.')
196
+ throw new ProviderRequiredError('The wallet must be connected to a provider to approve funds.')
191
197
  }
192
198
 
193
199
  const { token, spender, amount } = options
@@ -196,7 +202,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
196
202
  if (chainId === 1n && token.toLowerCase() === USDT_MAINNET_ADDRESS.toLowerCase()) {
197
203
  const currentAllowance = await this.getAllowance(token, spender)
198
204
  if (currentAllowance > 0n && BigInt(amount) > 0n) {
199
- throw new Error(
205
+ throw new ValueError(
200
206
  'USDT requires the current allowance to be reset to 0 before setting a new non-zero value. Please send an "approve" transaction with an amount of 0 first.'
201
207
  )
202
208
  }
@@ -232,6 +238,9 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
232
238
  * @param {EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7} tx - The transaction, an array of multiple transactions to send in batch, or an already-signed UserOperation.
233
239
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
234
240
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
241
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
242
+ * @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.
243
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
235
244
  */
236
245
  async quoteSendTransaction (tx, config) {
237
246
  const mergedConfig = { ...this._config, ...config }
@@ -281,8 +290,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
281
290
  * @param {EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7} tx - The transaction, an array of multiple transactions to send in batch, or an already-signed UserOperation.
282
291
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
283
292
  * @returns {Promise<TransactionResult>} The transaction's result.
284
- * @throws {Error} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
285
- * @throws {Error} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
293
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
294
+ * @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.
295
+ * @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
296
+ * @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
297
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
286
298
  */
287
299
  async sendTransaction (tx, config) {
288
300
  const mergedConfig = { ...this._config, ...config }
@@ -304,7 +316,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
304
316
 
305
317
  const { isSponsored, transactionMaxFee } = mergedConfig
306
318
  if (!isSponsored && transactionMaxFee !== undefined && prepared.fee > transactionMaxFee) {
307
- throw new Error('Exceeded maximum fee cost for transaction operation.')
319
+ throw new MaximumFeeExceededError('Exceeded maximum fee cost for transaction operation.')
308
320
  }
309
321
 
310
322
  const hash = await this._sendUserOperation(txs, { config: mergedConfig, cachedBuild: prepared })
@@ -320,8 +332,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
320
332
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
321
333
  * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
322
334
  * @returns {Promise<TransferResult>} The transfer's result.
323
- * @throws {Error} If the transaction is not sponsored, and the transfer's cost surpasses the transfer max. fee option.
324
- * @throws {Error} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
335
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
336
+ * @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.
337
+ * @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transfer's cost surpasses the transfer max. fee option.
338
+ * @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
339
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
325
340
  */
326
341
  async transfer (options, config, txOverrides) {
327
342
  const mergedConfig = { ...this._config, ...config }
@@ -338,8 +353,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
338
353
  const txs = [tx]
339
354
  const prepared = await this._prepareForSend(tx, txs, mergedConfig)
340
355
 
341
- if (!isSponsored && transferMaxFee !== undefined && prepared.fee >= transferMaxFee) {
342
- throw new Error('Exceeded maximum fee cost for transfer operation.')
356
+ if (!isSponsored && transferMaxFee !== undefined && prepared.fee > transferMaxFee) {
357
+ throw new MaximumFeeExceededError('Exceeded maximum fee cost for transfer operation.')
343
358
  }
344
359
 
345
360
  const hash = await this._sendUserOperation(txs, { config: mergedConfig, cachedBuild: prepared })
@@ -409,7 +424,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
409
424
  } else {
410
425
  key = BigInt(config.nonceKey)
411
426
  if (key < 0n || key > MAX_UINT192) {
412
- throw new Error('nonceKey must be within the uint192 range (0 to 2^192 - 1).')
427
+ throw new ValueError('nonceKey must be within the uint192 range (0 to 2^192 - 1).')
413
428
  }
414
429
  }
415
430
  return await fetchAccountNonce(this._provider, ENTRYPOINT_V7, this._address, key)
@@ -476,7 +491,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
476
491
  return await this._getBundler().sendUserOperation(userOp, smartAccount.entrypointAddress)
477
492
  } catch (err) {
478
493
  if (err instanceof AbstractionKitError && err.message.includes('AA50')) {
479
- throw new Error('Not enough funds on the safe account to repay the paymaster.')
494
+ throw new TransactionError('Not enough funds on the safe account to repay the paymaster.', {
495
+ reason: TransactionErrorReason.INSUFFICIENT_BALANCE,
496
+ cause: err
497
+ })
480
498
  }
481
499
  throw err
482
500
  }
@@ -488,13 +506,17 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
488
506
  * @private
489
507
  * @param {UserOperationV7} userOp - The signed UserOperation.
490
508
  * @returns {Promise<string>} The user operation hash.
509
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
491
510
  */
492
511
  async _broadcastSignedUserOperation (userOp) {
493
512
  try {
494
513
  return await this._getBundler().sendUserOperation(userOp, ENTRYPOINT_V7)
495
514
  } catch (err) {
496
515
  if (err instanceof AbstractionKitError && err.message.includes('AA50')) {
497
- throw new Error('Not enough funds on the safe account to repay the paymaster.')
516
+ throw new TransactionError('Not enough funds on the safe account to repay the paymaster.', {
517
+ reason: TransactionErrorReason.INSUFFICIENT_BALANCE,
518
+ cause: err
519
+ })
498
520
  }
499
521
  throw err
500
522
  }
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { isHexString, JsonRpcProvider } from 'ethers'
18
18
 
19
- import { WalletAccountReadOnly, NoSuchElementError, ValueError } from '@tetherto/wdk-wallet'
19
+ import { WalletAccountReadOnly, NoSuchElementError, TransactionError, TransactionErrorReason, ValueError } from '@tetherto/wdk-wallet'
20
20
 
21
21
  import { WalletAccountReadOnlyEvm } from '@tetherto/wdk-wallet-evm'
22
22
 
@@ -329,7 +329,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
329
329
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
330
330
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
331
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.
332
- * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
332
+ * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
333
333
  */
334
334
  async quoteSendTransaction (tx, config) {
335
335
  const mergedConfig = { ...this._config, ...config }
@@ -363,7 +363,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
363
363
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
364
364
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
365
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.
366
- * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
366
+ * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
367
367
  */
368
368
  async quoteTransfer (options, config, txOverrides) {
369
369
  const baseTx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
@@ -632,14 +632,14 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
632
632
  * @protected
633
633
  * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} [config] - The configuration object.
634
634
  * @returns {Eip1193Provider} A wrapped Eip1193Provider instance.
635
- * @throws {Error} If the `provider` option is set to an empty array.
635
+ * @throws {ValueError} If the `provider` option is set to an empty array.
636
636
  */
637
637
  _createFailoverProvider (config = this._config) {
638
638
  const { provider, retries = 3 } = config
639
639
 
640
640
  if (Array.isArray(provider)) {
641
641
  if (!provider.length) {
642
- throw new Error("The 'provider' option cannot be set to an empty list.")
642
+ throw new ValueError("The 'provider' option cannot be set to an empty list.")
643
643
  }
644
644
 
645
645
  const failoverProvider = new FailoverProvider({ retries })
@@ -781,7 +781,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
781
781
  * @param {EvmErc4337Transaction[]} txs - The EVM transactions to include in the UserOperation.
782
782
  * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} config - The wallet configuration to use for the build.
783
783
  * @returns {Promise<BuiltUserOperation & Omit<TransactionResult, 'hash'>>} The built operation plus its raw fee (no tolerance buffer applied).
784
- * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
784
+ * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
785
785
  */
786
786
  async _getUserOperationGasCost (txs, config) {
787
787
  const calls = WalletAccountReadOnlyEvmErc4337._toMetaTransactions(txs)
@@ -797,9 +797,10 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
797
797
  return { fee, ...buildResult }
798
798
  } catch (error) {
799
799
  if (error instanceof AbstractionKitError && error.message.includes('AA50')) {
800
- throw new Error(
800
+ throw new TransactionError(
801
801
  'Token paymaster requires the account to hold the paymaster token for fee estimation. ' +
802
- 'Fund the account with the paymaster token before quoting.'
802
+ 'Fund the account with the paymaster token before quoting.',
803
+ { reason: TransactionErrorReason.INSUFFICIENT_BALANCE, cause: error }
803
804
  )
804
805
  }
805
806
  throw error
@@ -14,7 +14,7 @@
14
14
 
15
15
  'use strict'
16
16
 
17
- import WalletManager from '@tetherto/wdk-wallet'
17
+ import WalletManager, { ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
18
18
 
19
19
  import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
20
20
 
@@ -44,6 +44,7 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
44
44
  *
45
45
  * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
46
46
  * @param {EvmErc4337WalletConfig} config - The configuration object.
47
+ * @throws {ValueError} If the `provider` option is set to an empty list.
47
48
  */
48
49
  constructor (seed, config) {
49
50
  super(seed, config)
@@ -60,7 +61,7 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
60
61
 
61
62
  if (Array.isArray(provider)) {
62
63
  if (!provider.length) {
63
- throw new Error("The 'provider' option cannot be set to an empty list.")
64
+ throw new ValueError("The 'provider' option cannot be set to an empty list.")
64
65
  }
65
66
 
66
67
  const failoverProvider = new FailoverProvider({ retries })
@@ -116,10 +117,11 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
116
117
  * Returns the current fee rates.
117
118
  *
118
119
  * @returns {Promise<FeeRates>} The fee rates (in weis).
120
+ * @throws {ProviderRequiredError} If the wallet is not connected to a provider.
119
121
  */
120
122
  async getFeeRates () {
121
123
  if (!this._provider) {
122
- throw new Error('The wallet must be connected to a provider to get fee rates.')
124
+ throw new ProviderRequiredError('The wallet must be connected to a provider to get fee rates.')
123
125
  }
124
126
 
125
127
  const data = await this._provider.getFeeData()
@@ -1,4 +1,9 @@
1
- export class ConfigurationError extends Error {
1
+ /**
2
+ * Thrown when the wallet configuration is invalid or has missing required fields.
3
+ *
4
+ * It extends {@link ValueError}, so it is also part of the `WdkError` taxonomy.
5
+ */
6
+ export class ConfigurationError extends ValueError {
2
7
  /**
3
8
  * Create a new configuration error.
4
9
  *
@@ -6,3 +11,4 @@ export class ConfigurationError extends Error {
6
11
  */
7
12
  constructor(message: string);
8
13
  }
14
+ import { ValueError } from '@tetherto/wdk-wallet';
@@ -63,7 +63,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
63
63
  * @param {EvmErc4337Transaction} tx - The transaction to include in the user operation.
64
64
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
65
65
  * @returns {Promise<UserOperationV7>} The signed user operation.
66
- * @throws {Error} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
66
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
67
+ * @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.
68
+ * @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
69
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
67
70
  */
68
71
  signTransaction(tx: EvmErc4337Transaction, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<UserOperationV7>;
69
72
  /**
@@ -72,7 +75,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
72
75
  * @param {ApproveOptions} options - The approve options.
73
76
  * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
74
77
  * @returns {Promise<TransactionResult>} - The transaction's result.
75
- * @throws {Error} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
78
+ * @throws {ProviderRequiredError} - If the wallet is not connected to a provider.
79
+ * @throws {ValueError} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
76
80
  */
77
81
  approve(options: ApproveOptions, txOverrides?: EvmErc4337GasOverrides): Promise<TransactionResult>;
78
82
  /**
@@ -88,6 +92,9 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
88
92
  * @param {EvmErc4337Transaction | EvmErc4337Transaction[]} tx - The transaction, or an array of multiple transactions to send in batch.
89
93
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
90
94
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
95
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
96
+ * @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.
97
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
91
98
  */
92
99
  quoteSendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<Omit<TransactionResult, "hash">>;
93
100
  /**
@@ -101,7 +108,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
101
108
  * @param {EvmErc4337Transaction | EvmErc4337Transaction[]} tx - The transaction, or an array of multiple transactions to send in batch.
102
109
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
103
110
  * @returns {Promise<TransactionResult>} The transaction's result.
104
- * @throws {Error} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
111
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
112
+ * @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.
113
+ * @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
114
+ * @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
115
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
105
116
  */
106
117
  sendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransactionResult>;
107
118
  /**
@@ -113,7 +124,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
113
124
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
114
125
  * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
115
126
  * @returns {Promise<TransferResult>} The transfer's result.
116
- * @throws {Error} If the transaction is not sponsored, and the transfer's cost surpasses the transfer max. fee option.
127
+ * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
128
+ * @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.
129
+ * @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transfer's cost surpasses the transfer max. fee option.
130
+ * @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
131
+ * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
117
132
  */
118
133
  transfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>, txOverrides?: EvmErc4337GasOverrides): Promise<TransferResult>;
119
134
  /**
@@ -100,7 +100,8 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
100
100
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
101
101
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
102
102
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
103
- * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
103
+ * @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.
104
+ * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
104
105
  */
105
106
  quoteSendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[], config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<Omit<TransactionResult, "hash">>;
106
107
  /**
@@ -114,7 +115,8 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
114
115
  * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
115
116
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
116
117
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
117
- * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
118
+ * @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.
119
+ * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
118
120
  */
119
121
  quoteTransfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>, txOverrides?: EvmErc4337GasOverrides): Promise<Omit<TransferResult, "hash">>;
120
122
  /**
@@ -225,7 +227,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
225
227
  * @protected
226
228
  * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee'>} [config] - The configuration object.
227
229
  * @returns {Eip1193Provider} A wrapped Eip1193Provider instance.
228
- * @throws {Error} If the `provider` option is set to an empty array.
230
+ * @throws {ValueError} If the `provider` option is set to an empty array.
229
231
  */
230
232
  protected _createFailoverProvider (config?: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Eip1193Provider
231
233
  /** @private */
@@ -264,7 +266,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
264
266
  * @param {EvmErc4337Transaction[]} txs - The EVM transactions to include in the UserOperation.
265
267
  * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee'>} config - The wallet configuration to use for the build.
266
268
  * @returns {Promise<BuiltUserOperation & Omit<TransactionResult, 'hash'>>} The built operation plus its raw fee (no tolerance buffer applied).
267
- * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
269
+ * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
268
270
  */
269
271
  protected _getUserOperationGasCost(txs: EvmErc4337Transaction[], config: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Promise<BuiltUserOperation & Omit<TransactionResult, "hash">>;
270
272
  }
@@ -4,6 +4,7 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
4
4
  *
5
5
  * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
6
6
  * @param {EvmErc4337WalletConfig} config - The configuration object.
7
+ * @throws {ValueError} If the `provider` option is set to an empty list.
7
8
  */
8
9
  constructor(seed: string | Uint8Array, config: EvmErc4337WalletConfig);
9
10
  /**
@@ -37,6 +38,7 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
37
38
  * Returns the current fee rates.
38
39
  *
39
40
  * @returns {Promise<FeeRates>} The fee rates (in weis).
41
+ * @throws {ProviderRequiredError} If the wallet is not connected to a provider.
40
42
  */
41
43
  getFeeRates(): Promise<FeeRates>;
42
44
  }