@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.20 → 1.0.0-beta.21

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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  **Note**: This package is currently in beta. Please test thoroughly in development environments before using in production.
9
9
 
10
- A simple and secure package to manage ERC-4337 compliant wallets for EVM-compatible blockchains. This package provides a clean API for creating, managing, and interacting with account abstraction wallets using BIP-39 seed phrases and EVM-specific derivation paths.
10
+ An ERC-4337 wallet module for EVM-compatible blockchains in WDK (Wallet Development Kit) by Tether. This package provides a clean API for creating, managing, and interacting with account abstraction wallets using BIP-39 seed phrases and EVM-specific derivation paths.
11
11
 
12
12
  ## About WDK
13
13
 
package/index.js CHANGED
@@ -28,6 +28,8 @@
28
28
  /** @typedef {import('@tetherto/wdk-wallet-evm').KeyPair} KeyPair */
29
29
  /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337Transaction} EvmErc4337Transaction */
30
30
  /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337GasOverrides} EvmErc4337GasOverrides */
31
+ /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337TransferOptions} EvmErc4337TransferOptions */
32
+ /** @typedef {import('./src/wallet-account-evm-erc-4337.js').EvmErc4337ApproveOptions} EvmErc4337ApproveOptions */
31
33
  /** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').Nonce} Nonce */
32
34
  /** @typedef {import('@tetherto/wdk-wallet-evm').TransactionResult} TransactionResult */
33
35
  /** @typedef {import('@tetherto/wdk-wallet-evm').TransferOptions} TransferOptions */
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-evm-erc-4337",
3
- "version": "1.0.0-beta.20",
4
- "description": "A simple package to manage BIP-32 wallets for evm blockchains, which implement the erc-4337 standard and its account abstraction features",
3
+ "version": "1.0.0-beta.21",
4
+ "description": "ERC-4337 wallet module for EVM-compatible blockchains in WDK (Wallet Development Kit) by Tether.",
5
+ "homepage": "https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/",
5
6
  "keywords": [
6
7
  "wdk",
7
8
  "wallet",
@@ -32,7 +33,7 @@
32
33
  "dependencies": {
33
34
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
34
35
  "@tetherto/wdk-wallet": "1.0.0-beta.17",
35
- "@tetherto/wdk-wallet-evm": "1.0.0-beta.18",
36
+ "@tetherto/wdk-wallet-evm": "1.0.0-beta.19",
36
37
  "abstractionkit": "0.4.0",
37
38
  "bare-node-runtime": "^1.4.0",
38
39
  "ethers": "6.17.0"
@@ -42,17 +42,24 @@ import WalletAccountReadOnlyEvmErc4337, { FEE_TOLERANCE_COEFFICIENT } from './wa
42
42
  /** @typedef {import('@tetherto/wdk-wallet-evm').KeyPair} KeyPair */
43
43
 
44
44
  /** @typedef {import('@tetherto/wdk-wallet-evm').TransactionResult} TransactionResult */
45
- /** @typedef {import('@tetherto/wdk-wallet-evm').TransferOptions} TransferOptions */
46
45
  /** @typedef {import('@tetherto/wdk-wallet-evm').TransferResult} TransferResult */
47
46
  /** @typedef {import('@tetherto/wdk-wallet-evm').ApproveOptions} ApproveOptions */
48
47
 
49
48
  /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337Transaction} EvmErc4337Transaction */
49
+ /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337GasOverrides} EvmErc4337GasOverrides */
50
+ /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337TransferOptions} EvmErc4337TransferOptions */
50
51
  /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337WalletConfig} EvmErc4337WalletConfig */
51
52
  /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337WalletPaymasterTokenConfig} EvmErc4337WalletPaymasterTokenConfig */
52
53
  /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337WalletSponsorshipPolicyConfig} EvmErc4337WalletSponsorshipPolicyConfig */
53
54
  /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').TypedData} TypedData */
54
55
  /** @typedef {import('./wallet-account-read-only-evm-erc-4337.js').EvmErc4337WalletNativeCoinsConfig} EvmErc4337WalletNativeCoinsConfig */
55
56
 
57
+ /**
58
+ * The options of a token approval, extended with the optional UserOperationV7 gas overrides.
59
+ *
60
+ * @typedef {ApproveOptions & EvmErc4337GasOverrides} EvmErc4337ApproveOptions
61
+ */
62
+
56
63
  const QUOTE_MAX_AGE_MS = 2 * 60 * 1_000
57
64
 
58
65
  const NONCE_KEY_SHIFT = 64n
@@ -66,12 +73,15 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
66
73
  /**
67
74
  * Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account.
68
75
  *
69
- * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
76
+ * @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
70
77
  * @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
71
78
  * @param {EvmErc4337WalletConfig} config - The configuration object.
72
79
  */
73
80
  constructor (seed, path, config) {
74
- const ownerAccount = new WalletAccountEvm(seed, path, config)
81
+ // Owner EOA only needs keys/address for 4337; strip `provider` so
82
+ // wdk-wallet-evm does not open a second JsonRpcProvider.
83
+ const { provider: _provider, ...ownerConfig } = config
84
+ const ownerAccount = new WalletAccountEvm(seed, path, ownerConfig)
75
85
 
76
86
  super(ownerAccount._address, config)
77
87
 
@@ -198,14 +208,13 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
198
208
  /**
199
209
  * Approves a specific amount of tokens to a spender.
200
210
  *
201
- * @param {ApproveOptions} options - The approve options.
202
- * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
211
+ * @param {EvmErc4337ApproveOptions} options - The approve options, including any UserOperationV7 gas/fee overrides to apply to the underlying transaction.
203
212
  * @returns {Promise<TransactionResult>} - The transaction's result.
204
213
  * @throws {ProviderRequiredError} - If the wallet is not connected to a provider.
205
214
  * @throws {ValueError} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
206
215
  */
207
- async approve (options, txOverrides) {
208
- if (!this._ownerAccount._provider) {
216
+ async approve (options) {
217
+ if (!this._provider) {
209
218
  throw new ProviderRequiredError('The wallet must be connected to a provider to approve funds.')
210
219
  }
211
220
 
@@ -222,13 +231,15 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
222
231
  }
223
232
 
224
233
  const abi = ['function approve(address spender, uint256 amount) returns (bool)']
225
- const contract = new Contract(token, abi, this._ownerAccount._provider)
234
+
235
+ // No runner needed - only encoding calldata for the UserOperation.
236
+ const contract = new Contract(token, abi)
226
237
 
227
238
  const tx = {
228
239
  to: token,
229
240
  value: 0,
230
241
  data: contract.interface.encodeFunctionData('approve', [spender, amount]),
231
- ...txOverrides
242
+ ...WalletAccountReadOnlyEvmErc4337._extractGasOverrides(options)
232
243
  }
233
244
 
234
245
  return await this.sendTransaction(tx)
@@ -341,9 +352,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
341
352
  *
342
353
  * If the transaction is not sponsored, it also estimates the transfer's costs and checks them against the transfer max. fee option.
343
354
  *
344
- * @param {TransferOptions} options - The transfer's options.
355
+ * @param {EvmErc4337TransferOptions} options - The transfer's options, including any UserOperationV7 gas/fee overrides to apply to the underlying transaction.
345
356
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
346
- * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
347
357
  * @returns {Promise<TransferResult>} The transfer's result.
348
358
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
349
359
  * @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.
@@ -351,7 +361,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
351
361
  * @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
352
362
  * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
353
363
  */
354
- async transfer (options, config, txOverrides) {
364
+ async transfer (options, config) {
355
365
  const mergedConfig = { ...this._config, ...config }
356
366
 
357
367
  if (config) {
@@ -360,8 +370,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
360
370
 
361
371
  const { isSponsored, transferMaxFee } = mergedConfig
362
372
 
363
- const baseTx = await WalletAccountEvm._getTransferTransaction(options)
364
- const tx = { ...baseTx, ...txOverrides }
373
+ const tx = await WalletAccountReadOnlyEvmErc4337._getTransferTransaction(options)
365
374
 
366
375
  const txs = [tx]
367
376
  const prepared = await this._prepareForSend(tx, txs, mergedConfig)
@@ -401,7 +410,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
401
410
  if (nonce === undefined) {
402
411
  const cached = this._consumeCachedQuote(tx)
403
412
  if (cached?.userOp) {
404
- const onChainNonce = await fetchAccountNonce(this._provider, cached.smartAccount.entrypointAddress, cached.smartAccount.accountAddress)
413
+ const onChainNonce = await fetchAccountNonce(this._eip1193Provider, cached.smartAccount.entrypointAddress, cached.smartAccount.accountAddress)
405
414
  if (cached.userOp.nonce === onChainNonce) {
406
415
  return cached
407
416
  }
@@ -451,7 +460,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
451
460
  throw new ValueError('nonceKey must be within the uint192 range (0 to 2^192 - 1).')
452
461
  }
453
462
  }
454
- return await fetchAccountNonce(this._provider, ENTRYPOINT_V7, this._address, key)
463
+ return await fetchAccountNonce(this._eip1193Provider, ENTRYPOINT_V7, this._address, key)
455
464
  }
456
465
 
457
466
  if (config.parallel) {
@@ -14,7 +14,7 @@
14
14
 
15
15
  'use strict'
16
16
 
17
- import { getAddress, isAddress, isHexString, JsonRpcProvider } from 'ethers'
17
+ import { getAddress, isAddress, isHexString } from 'ethers'
18
18
 
19
19
  import { WalletAccountReadOnly, NoSuchElementError, TransactionError, TransactionErrorReason, UnsupportedOperationError, ValueError } from '@tetherto/wdk-wallet'
20
20
 
@@ -35,8 +35,6 @@ import {
35
35
  /** @typedef {import('abstractionkit').MetaTransaction} MetaTransaction */
36
36
  /** @typedef {import('abstractionkit').SafeAccountV0_3_0} SafeAccountV0_3_0 */
37
37
 
38
- import FailoverProvider from '@tetherto/wdk-failover-provider'
39
-
40
38
  import { ConfigurationError } from './errors.js'
41
39
 
42
40
  const PaymasterMode = {
@@ -47,6 +45,7 @@ const PaymasterMode = {
47
45
 
48
46
  export const FEE_TOLERANCE_COEFFICIENT = 120n
49
47
 
48
+ /** @typedef {import('ethers').Provider} Provider */
50
49
  /** @typedef {import('ethers').Eip1193Provider} Eip1193Provider */
51
50
 
52
51
  /** @typedef {import('@tetherto/wdk-wallet-evm').TransactionResult} TransactionResult */
@@ -110,6 +109,12 @@ export const FEE_TOLERANCE_COEFFICIENT = 120n
110
109
  * @property {number | bigint} [maxPriorityFeePerGas] - Override for the UserOperation's max priority fee per gas.
111
110
  */
112
111
 
112
+ /**
113
+ * The options of a token transfer, extended with the optional UserOperationV7 gas overrides.
114
+ *
115
+ * @typedef {TransferOptions & EvmErc4337GasOverrides} EvmErc4337TransferOptions
116
+ */
117
+
113
118
  /**
114
119
  * A single explicit UserOperationV7 `nonce`, combined with `EvmErc4337GasOverrides` for the build
115
120
  * step to place the operation in a specific two-dimensional nonce lane. The `nonce` is derived
@@ -131,7 +136,7 @@ export const FEE_TOLERANCE_COEFFICIENT = 120n
131
136
  /**
132
137
  * @typedef {Object} EvmErc4337WalletCommonConfig
133
138
  * @property {number} chainId - The blockchain's id (e.g., 1 for ethereum).
134
- * @property {string | Eip1193Provider | Array<string | Eip1193Provider>} provider - The url of the rpc provider, or an instance of a class that implements eip-1193. It's also possible to provide an array of urls or EIP 1193 providers instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
139
+ * @property {string | Provider | Eip1193Provider | Array<string | Provider | Eip1193Provider>} provider - The url of the rpc provider, an already-built ethers `Provider` (reused as-is), or an instance of a class that implements eip-1193. It's also possible to provide an array of these instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
135
140
  * @property {number} [retries] - If set and if 'provider' is a list of urls or EIP 1193 providers, the number of additional retry attempts after the initial call fails. Total attempts = `1 + retries`. For example, `retries: 3` with 4 providers will try each provider once before throwing. If `retries` exceeds the number of providers, the failover will loop back and retry already-failed providers in round-robin order. Default: 3.
136
141
  * @property {string} bundlerUrl - The url of the bundler service.
137
142
  * @property {Record<string, string>} [bundlerHeaders] - Optional HTTP headers sent on every request to the bundler (e.g. `{ Authorization: 'Bearer <key>' }`). Use for bundlers that require authentication.
@@ -252,17 +257,23 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
252
257
  this._ownerAccountAddress = ownerAccountAddress
253
258
 
254
259
  /**
255
- * An EIP-1193–compatible provider used to interact with the blockchain.
260
+ * The shared ethers provider used to interact with the blockchain. A single instance is
261
+ * built here (or reused from the manager) and passed to every nested `WalletAccountReadOnlyEvm`
262
+ * so accounts do not open their own connection.
256
263
  *
257
- * Note: the provider type is restricted to EIP-1193 to ensure compatibility
258
- * with Safe4337Pack and to enable the failover mechanism. While RPC URLs
259
- * can still be provided in the configuration, they are internally wrapped
260
- * into an EIP-1193 provider.
264
+ * @protected
265
+ * @type {Provider}
266
+ */
267
+ this._provider = this._buildProvider(this._config)
268
+
269
+ /**
270
+ * The EIP-1193 view of {@link _provider} that abstractionkit (Safe4337Pack) requires. Built
271
+ * once and backed by the same underlying connection as {@link _provider}.
261
272
  *
262
273
  * @protected
263
274
  * @type {Eip1193Provider}
264
275
  */
265
- this._provider = this._createFailoverProvider(this._config)
276
+ this._eip1193Provider = WalletAccountReadOnlyEvmErc4337._buildEip1193Provider(this._provider, this._config)
266
277
 
267
278
  /** @private */
268
279
  this._deployedSmartAccount = undefined
@@ -404,22 +415,18 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
404
415
  * The result is cached internally for up to 2 minutes. If `transfer` is called with the
405
416
  * same transaction within that window, the cached fee is reused without an additional RPC round-trip.
406
417
  *
407
- * @param {TransferOptions} options - The transfer's options.
418
+ * @param {EvmErc4337TransferOptions} options - The transfer's options, including any UserOperationV7 gas/fee overrides to apply to the underlying transaction.
408
419
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
409
- * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
410
420
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
411
421
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
412
422
  * @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.
413
423
  * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
414
424
  * @throws {ConfigurationError} If the account was created from a safe address that is not deployed.
415
425
  */
416
- async quoteTransfer (options, config, txOverrides) {
417
- const baseTx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
418
- const tx = { ...baseTx, ...txOverrides }
419
-
420
- const result = await this.quoteSendTransaction(tx, config)
426
+ async quoteTransfer (options, config) {
427
+ const tx = await WalletAccountReadOnlyEvmErc4337._getTransferTransaction(options)
421
428
 
422
- return result
429
+ return await this.quoteSendTransaction(tx, config)
423
430
  }
424
431
 
425
432
  /**
@@ -544,7 +551,10 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
544
551
  throw new UnsupportedOperationError('verify(message, signature)')
545
552
  }
546
553
 
547
- const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(this._ownerAccountAddress, this._config)
554
+ const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(this._ownerAccountAddress, {
555
+ ...this._config,
556
+ provider: this._provider
557
+ })
548
558
  return await evmReadOnlyAccount.verify(message, signature)
549
559
  }
550
560
 
@@ -561,7 +571,10 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
561
571
  throw new UnsupportedOperationError('verifyTypedData(typedData, signature)')
562
572
  }
563
573
 
564
- const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(this._ownerAccountAddress, this._config)
574
+ const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(this._ownerAccountAddress, {
575
+ ...this._config,
576
+ provider: this._provider
577
+ })
565
578
 
566
579
  return await evmReadOnlyAccount.verifyTypedData(typedData, signature)
567
580
  }
@@ -621,7 +634,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
621
634
  const overrides = WalletAccountReadOnlyEvmErc4337._getInitCodeOverrides(config)
622
635
  const safeAddress = await this.getAddress()
623
636
 
624
- if (await SafeAccount030.isDeployed(safeAddress, this._provider)) {
637
+ if (await SafeAccount030.isDeployed(safeAddress, this._eip1193Provider)) {
625
638
  this._deployedSmartAccount = new SafeAccount030(safeAddress, overrides)
626
639
  return this._deployedSmartAccount
627
640
  }
@@ -688,7 +701,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
688
701
  */
689
702
  async _getChainId () {
690
703
  if (!this._chainId) {
691
- const chainId = BigInt(await this._provider.request({ method: 'eth_chainId' }))
704
+ const chainId = BigInt(await this._eip1193Provider.request({ method: 'eth_chainId' }))
692
705
 
693
706
  if (this._config.chainId !== undefined && chainId !== BigInt(this._config.chainId)) {
694
707
  throw new ConfigurationError(
@@ -703,57 +716,72 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
703
716
  }
704
717
 
705
718
  /**
706
- * Wraps a string RPC URL or provider into an EIP-1193 compatible provider.
719
+ * Adapts an ethers provider (or failover aggregate) to the EIP-1193 interface required by
720
+ * abstractionkit (Safe4337Pack), without constructing a new provider. Already-EIP-1193 objects
721
+ * (e.g. a browser wallet or a `BrowserProvider`) are returned as-is; ethers providers are wrapped
722
+ * so `request` forwards to `send`, reusing the same underlying connection.
707
723
  *
708
724
  * @protected
709
- * @param {string | Eip1193Provider} provider - The url of the rpc provider, or an instance of a class that implements eip-1193.
710
- * @returns { Eip1193Provider } A wrapped Eip1193Provider instance.
725
+ * @param {Provider | Eip1193Provider} provider - The ethers provider (or EIP-1193 provider) to adapt.
726
+ * @returns {Eip1193Provider} An EIP-1193-compatible provider that reuses the given client.
711
727
  */
712
- _wrapEip1193Provider (provider) {
713
- return typeof provider === 'string'
714
- ? {
715
- provider: new JsonRpcProvider(provider),
716
- request ({ method, params }) {
717
- return this.provider.send(method, params ?? [])
718
- }
719
- }
720
- : provider
728
+ static _asEip1193 (provider) {
729
+ if (typeof provider.request === 'function') {
730
+ return provider
731
+ }
732
+
733
+ return {
734
+ request ({ method, params }) {
735
+ return provider.send(method, params ?? [])
736
+ }
737
+ }
721
738
  }
722
739
 
723
740
  /**
724
- * Creates a FailoverProvider from the configured providers. If only one provider is supplied, it is wrapped and returned.
741
+ * Builds the EIP-1193 view that abstractionkit needs. A caller-supplied EIP-1193 provider is
742
+ * reused directly (so abstractionkit talks to it without an extra `BrowserProvider` round-trip);
743
+ * otherwise the shared ethers provider is adapted so `request` forwards to `send`. Both share the
744
+ * same underlying connection as {@link _provider}.
725
745
  *
726
746
  * @protected
727
- * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} [config] - The configuration object.
728
- * @returns {Eip1193Provider} A wrapped Eip1193Provider instance.
729
- * @throws {ValueError} If the `provider` option is set to an empty array.
747
+ * @param {Provider} provider - The shared ethers provider built from `config`.
748
+ * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} config - The configuration object.
749
+ * @returns {Eip1193Provider} The EIP-1193 provider that reuses the given connection.
730
750
  */
731
- _createFailoverProvider (config = this._config) {
732
- const { provider, retries = 3 } = config
733
-
734
- if (Array.isArray(provider)) {
735
- if (!provider.length) {
736
- throw new ValueError("The 'provider' option cannot be set to an empty list.")
737
- }
751
+ static _buildEip1193Provider (provider, config) {
752
+ const { provider: configured } = config
753
+ const source = configured && typeof configured.request === 'function' ? configured : provider
738
754
 
739
- const failoverProvider = new FailoverProvider({ retries })
740
-
741
- for (const entry of provider) {
742
- const option = this._wrapEip1193Provider(entry)
743
- failoverProvider.addProvider(option)
744
- }
755
+ return WalletAccountReadOnlyEvmErc4337._asEip1193(source)
756
+ }
745
757
 
746
- return failoverProvider.initialize()
758
+ /**
759
+ * Builds the single shared ethers provider from the configuration. Construction (url ->
760
+ * `JsonRpcProvider`, EIP-1193 -> `BrowserProvider`, array -> failover) and the reuse of an
761
+ * already-built provider are delegated to wdk-wallet-evm, so a manager can build one instance
762
+ * and share it with every account.
763
+ *
764
+ * @protected
765
+ * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} [config] - The configuration object.
766
+ * @returns {Provider} The shared provider.
767
+ * @throws {ValueError} If the `provider` option is set to an empty array.
768
+ */
769
+ _buildProvider (config = this._config) {
770
+ if (Array.isArray(config.provider) && config.provider.length === 0) {
771
+ throw new ValueError("The 'provider' option cannot be set to an empty list.")
747
772
  }
748
773
 
749
- return this._wrapEip1193Provider(provider)
774
+ return WalletAccountReadOnlyEvm._buildProvider(config)
750
775
  }
751
776
 
752
777
  /** @private */
753
778
  async _getEvmReadOnlyAccount () {
754
779
  if (!this._evmReadOnlyAccount) {
755
780
  const address = await this.getAddress()
756
- this._evmReadOnlyAccount = new WalletAccountReadOnlyEvm(address, this._config)
781
+ this._evmReadOnlyAccount = new WalletAccountReadOnlyEvm(address, {
782
+ ...this._config,
783
+ provider: this._provider
784
+ })
757
785
  }
758
786
 
759
787
  return this._evmReadOnlyAccount
@@ -829,8 +857,8 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
829
857
 
830
858
  const bundlerRpc = WalletAccountReadOnlyEvmErc4337._rpcTarget(config.bundlerUrl, config.bundlerHeaders)
831
859
  const baseUserOp = (mode === PaymasterMode.NATIVE || provider === 'candide')
832
- ? await smartAccount.createUserOperation(calls, this._provider, bundlerRpc, overrides)
833
- : await smartAccount.createUserOperation(calls, this._provider, undefined, { skipGasEstimation: true, ...overrides })
860
+ ? await smartAccount.createUserOperation(calls, this._eip1193Provider, bundlerRpc, overrides)
861
+ : await smartAccount.createUserOperation(calls, this._eip1193Provider, undefined, { skipGasEstimation: true, ...overrides })
834
862
 
835
863
  if (mode === PaymasterMode.NATIVE) {
836
864
  return { userOp: baseUserOp, smartAccount, mode, chainId }
@@ -843,22 +871,36 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
843
871
  }
844
872
 
845
873
  /**
846
- * Extracts the optional UserOperationV7 gas overrides from a single transaction.
874
+ * Returns an evm transaction to execute the given token transfer, carrying any UserOperationV7
875
+ * gas overrides set on the options.
876
+ *
877
+ * @protected
878
+ * @param {EvmErc4337TransferOptions} options - The transfer's options, including any gas/fee overrides to carry onto the transaction.
879
+ * @returns {Promise<EvmErc4337Transaction>} The ERC-20 transfer call as an evm transaction, with the options' gas overrides applied.
880
+ */
881
+ static async _getTransferTransaction (options) {
882
+ const tx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
883
+
884
+ return { ...tx, ...WalletAccountReadOnlyEvmErc4337._extractGasOverrides(options) }
885
+ }
886
+
887
+ /**
888
+ * Extracts the optional UserOperationV7 gas overrides from a transaction or an options object.
847
889
  *
848
890
  * Only the fields actually consumed by AbstractionKit's `CreateUserOperationOverrides`
849
891
  * are picked. Numeric values are coerced to bigint.
850
892
  *
851
893
  * @protected
852
- * @param {EvmErc4337Transaction} [tx] - The transaction to read overrides from.
853
- * @returns {EvmErc4337GasOverrides} The overrides object (empty if `tx` is falsy or has no override fields).
894
+ * @param {EvmErc4337GasOverrides} [source] - The transaction or options object to read overrides from.
895
+ * @returns {EvmErc4337GasOverrides} The overrides object (empty if `source` is falsy or has no override fields).
854
896
  */
855
- static _extractGasOverrides (tx) {
897
+ static _extractGasOverrides (source) {
856
898
  const overrides = {}
857
- if (!tx) return overrides
899
+ if (!source) return overrides
858
900
 
859
901
  const fields = ['callGasLimit', 'verificationGasLimit', 'preVerificationGas', 'maxFeePerGas', 'maxPriorityFeePerGas']
860
902
  for (const field of fields) {
861
- if (tx[field] !== undefined) overrides[field] = BigInt(tx[field])
903
+ if (source[field] !== undefined) overrides[field] = BigInt(source[field])
862
904
  }
863
905
 
864
906
  return overrides
@@ -16,11 +16,7 @@
16
16
 
17
17
  import WalletManager, { ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
18
18
 
19
- import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
20
-
21
- import { BrowserProvider, JsonRpcProvider } from 'ethers'
22
-
23
- import FailoverProvider from '@tetherto/wdk-failover-provider'
19
+ import WalletManagerEvm, { WalletAccountReadOnlyEvm } from '@tetherto/wdk-wallet-evm'
24
20
 
25
21
  import WalletAccountEvmErc4337 from './wallet-account-evm-erc-4337.js'
26
22
 
@@ -35,14 +31,14 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
35
31
  * An ethers provider to interact with a node of the blockchain.
36
32
  *
37
33
  * @protected
38
- * @type {Provider}
34
+ * @type {Provider | undefined}
39
35
  */
40
36
  _provider
41
37
 
42
38
  /**
43
39
  * Creates a new wallet manager for evm blockchains that implements the [erc-4337](https://www.erc4337.io/docs) standard and its account abstraction features.
44
40
  *
45
- * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
41
+ * @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
46
42
  * @param {EvmErc4337WalletConfig} config - The configuration object.
47
43
  * @throws {ValueError} If the `provider` option is set to an empty list.
48
44
  */
@@ -57,28 +53,11 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
57
53
  */
58
54
  this._config = config
59
55
 
60
- const { provider, retries = 3 } = config
61
-
62
- if (Array.isArray(provider)) {
63
- if (!provider.length) {
64
- throw new ValueError("The 'provider' option cannot be set to an empty list.")
65
- }
66
-
67
- const failoverProvider = new FailoverProvider({ retries })
68
-
69
- for (const entry of provider) {
70
- const option = typeof entry === 'string'
71
- ? new JsonRpcProvider(entry)
72
- : new BrowserProvider(entry)
73
- failoverProvider.addProvider(option)
74
- }
75
-
76
- this._provider = failoverProvider.initialize()
77
- } else {
78
- this._provider = typeof provider === 'string'
79
- ? new JsonRpcProvider(provider)
80
- : new BrowserProvider(provider)
56
+ if (Array.isArray(config.provider) && config.provider.length === 0) {
57
+ throw new ValueError("The 'provider' option cannot be set to an empty list.")
81
58
  }
59
+
60
+ this._provider = WalletAccountReadOnlyEvm._buildProvider(config)
82
61
  }
83
62
 
84
63
  /**
@@ -105,7 +84,7 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
105
84
  */
106
85
  async getAccountByPath (path) {
107
86
  if (!this._accounts[path]) {
108
- const account = new WalletAccountEvmErc4337(this.seed, path, this._config)
87
+ const account = new WalletAccountEvmErc4337(this.seed, path, this._accountConfig())
109
88
 
110
89
  this._accounts[path] = account
111
90
  }
@@ -113,6 +92,17 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
113
92
  return this._accounts[path]
114
93
  }
115
94
 
95
+ /**
96
+ * Builds the account config, injecting the manager's shared provider so accounts reuse the
97
+ * single ethers provider instance instead of opening their own.
98
+ *
99
+ * @private
100
+ * @returns {EvmErc4337WalletConfig} The account configuration.
101
+ */
102
+ _accountConfig () {
103
+ return { ...this._config, provider: this._provider }
104
+ }
105
+
116
106
  /**
117
107
  * Returns the current fee rates.
118
108
  *
package/types/index.d.ts CHANGED
@@ -13,6 +13,8 @@ export type FeeRates = import("@tetherto/wdk-wallet-evm").FeeRates;
13
13
  export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
14
14
  export type EvmErc4337Transaction = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
15
15
  export type EvmErc4337GasOverrides = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337GasOverrides;
16
+ export type EvmErc4337TransferOptions = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337TransferOptions;
17
+ export type EvmErc4337ApproveOptions = import("./src/wallet-account-evm-erc-4337.js").EvmErc4337ApproveOptions;
16
18
  export type Nonce = import("./src/wallet-account-read-only-evm-erc-4337.js").Nonce;
17
19
  export type TransactionResult = import("@tetherto/wdk-wallet-evm").TransactionResult;
18
20
  export type TransferOptions = import("@tetherto/wdk-wallet-evm").TransferOptions;
@@ -3,7 +3,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
3
3
  /**
4
4
  * Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account.
5
5
  *
6
- * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
6
+ * @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
7
7
  * @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
8
8
  * @param {EvmErc4337WalletConfig} config - The configuration object.
9
9
  */
@@ -82,13 +82,12 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
82
82
  /**
83
83
  * Approves a specific amount of tokens to a spender.
84
84
  *
85
- * @param {ApproveOptions} options - The approve options.
86
- * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
85
+ * @param {EvmErc4337ApproveOptions} options - The approve options, including any UserOperationV7 gas/fee overrides to apply to the underlying transaction.
87
86
  * @returns {Promise<TransactionResult>} - The transaction's result.
88
87
  * @throws {ProviderRequiredError} - If the wallet is not connected to a provider.
89
88
  * @throws {ValueError} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
90
89
  */
91
- approve(options: ApproveOptions, txOverrides?: EvmErc4337GasOverrides): Promise<TransactionResult>;
90
+ approve(options: EvmErc4337ApproveOptions): Promise<TransactionResult>;
92
91
  /**
93
92
  * Quotes the costs of a send transaction operation.
94
93
  *
@@ -130,9 +129,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
130
129
  *
131
130
  * If the transaction is not sponsored, it also estimates the transfer's costs and checks them against the transfer max. fee option.
132
131
  *
133
- * @param {TransferOptions} options - The transfer's options.
132
+ * @param {EvmErc4337TransferOptions} options - The transfer's options, including any UserOperationV7 gas/fee overrides to apply to the underlying transaction.
134
133
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
135
- * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
136
134
  * @returns {Promise<TransferResult>} The transfer's result.
137
135
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
138
136
  * @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.
@@ -140,7 +138,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
140
138
  * @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
141
139
  * @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
142
140
  */
143
- transfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>, txOverrides?: EvmErc4337GasOverrides): Promise<TransferResult>;
141
+ transfer(options: EvmErc4337TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransferResult>;
144
142
  /**
145
143
  * Returns a read-only copy of the account.
146
144
  *
@@ -174,8 +172,8 @@ export type IWalletAccount<TSignedTransaction> = import("@tetherto/wdk-wallet").
174
172
  export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
175
173
  export type EvmErc4337Transaction = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
176
174
  export type EvmErc4337GasOverrides = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337GasOverrides;
175
+ export type EvmErc4337TransferOptions = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337TransferOptions;
177
176
  export type TransactionResult = import("@tetherto/wdk-wallet-evm").TransactionResult;
178
- export type TransferOptions = import("@tetherto/wdk-wallet-evm").TransferOptions;
179
177
  export type TransferResult = import("@tetherto/wdk-wallet-evm").TransferResult;
180
178
  export type ApproveOptions = import("@tetherto/wdk-wallet-evm").ApproveOptions;
181
179
  export type EvmErc4337WalletConfig = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337WalletConfig;
@@ -183,6 +181,10 @@ export type EvmErc4337WalletPaymasterTokenConfig = import("./wallet-account-read
183
181
  export type EvmErc4337WalletSponsorshipPolicyConfig = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337WalletSponsorshipPolicyConfig;
184
182
  export type TypedData = import("./wallet-account-read-only-evm-erc-4337.js").TypedData;
185
183
  export type EvmErc4337WalletNativeCoinsConfig = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337WalletNativeCoinsConfig;
184
+ /**
185
+ * The options of a token approval, extended with the optional UserOperationV7 gas overrides.
186
+ */
187
+ export type EvmErc4337ApproveOptions = ApproveOptions & EvmErc4337GasOverrides;
186
188
  export type UserOperationV7 = import("abstractionkit").UserOperationV7;
187
189
  export type SafeAccountV0_3_0 = import("abstractionkit").SafeAccountV0_3_0;
188
190
  import WalletAccountReadOnlyEvmErc4337 from './wallet-account-read-only-evm-erc-4337.js';
@@ -54,17 +54,22 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
54
54
  */
55
55
  protected _config: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">;
56
56
  /**
57
- * An EIP-1193–compatible provider used to interact with the blockchain.
57
+ * The shared ethers provider used to interact with the blockchain. A single instance is
58
+ * built here (or reused from the manager) and passed to every nested `WalletAccountReadOnlyEvm`
59
+ * so accounts do not open their own connection.
58
60
  *
59
- * Note: the provider type is restricted to EIP-1193 to ensure compatibility
60
- * with Safe4337Pack and to enable the failover mechanism. While RPC URLs
61
- * can still be provided in the configuration, they are internally wrapped
62
- * into an EIP-1193 provider.
61
+ * @protected
62
+ * @type {Provider}
63
+ */
64
+ protected _provider: Provider;
65
+ /**
66
+ * An EIP-1193 adapter over {@link _provider}, built once and used only where abstractionkit
67
+ * (Safe4337Pack) requires the EIP-1193 interface. Reuses the same underlying connection.
63
68
  *
64
69
  * @protected
65
70
  * @type {Eip1193Provider}
66
71
  */
67
- protected _provider: Eip1193Provider;
72
+ protected _eip1193Provider: Eip1193Provider;
68
73
  /**
69
74
  * Cached AbstractionKit bundler.
70
75
  *
@@ -137,16 +142,15 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
137
142
  * The result is cached internally for up to 2 minutes. If `transfer` is called with the
138
143
  * same transaction within that window, the cached fee is reused without an additional RPC round-trip.
139
144
  *
140
- * @param {TransferOptions} options - The transfer's options.
145
+ * @param {EvmErc4337TransferOptions} options - The transfer's options, including any UserOperationV7 gas/fee overrides to apply to the underlying transaction.
141
146
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
142
- * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
143
147
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
144
148
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
145
149
  * @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.
146
150
  * @throws {TransactionError} If the token paymaster reports AA50 (account does not hold the paymaster token).
147
151
  * @throws {ConfigurationError} If the account was created from a safe address that is not deployed.
148
152
  */
149
- quoteTransfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>, txOverrides?: EvmErc4337GasOverrides): Promise<Omit<TransferResult, "hash">>;
153
+ quoteTransfer(options: EvmErc4337TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<Omit<TransferResult, "hash">>;
150
154
  /**
151
155
  * Returns a transaction's receipt.
152
156
  *
@@ -257,22 +261,34 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
257
261
  */
258
262
  protected _getChainId(): Promise<bigint>;
259
263
  /**
260
- * Wraps a string RPC URL or provider into an EIP-1193 compatible provider.
264
+ * Adapts an ethers provider (or failover aggregate) to the EIP-1193 interface required by
265
+ * abstractionkit (Safe4337Pack). Already-EIP-1193 objects are returned as-is.
266
+ *
267
+ * @protected
268
+ * @param {Provider | Eip1193Provider} provider - The ethers provider (or EIP-1193 provider) to adapt.
269
+ * @returns {Eip1193Provider} An EIP-1193-compatible provider that reuses the given client.
270
+ */
271
+ protected static _asEip1193 (provider: Provider | Eip1193Provider): Eip1193Provider
272
+ /**
273
+ * Builds the EIP-1193 view that abstractionkit needs. A caller-supplied EIP-1193 provider is
274
+ * reused directly; otherwise the shared ethers provider is adapted so `request` forwards to `send`.
261
275
  *
262
276
  * @protected
263
- * @param {string | Eip1193Provider} provider - The url of the rpc provider, or an instance of a class that implements eip-1193.
264
- * @returns { Eip1193Provider } A wrapped Eip1193Provider instance.
277
+ * @param {Provider} provider - The shared ethers provider built from `config`.
278
+ * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee'>} config - The configuration object.
279
+ * @returns {Eip1193Provider} The EIP-1193 provider that reuses the given connection.
265
280
  */
266
- protected _wrapEip1193Provider (provider: string | Eip1193Provider): Eip1193Provider
281
+ protected static _buildEip1193Provider (provider: Provider, config: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Eip1193Provider
267
282
  /**
268
- * Creates a FailoverProvider from the configured providers. If only one provider is supplied, it is wrapped and returned.
283
+ * Builds the single shared ethers provider from the configuration, reusing an already-built
284
+ * provider as-is and delegating construction to wdk-wallet-evm.
269
285
  *
270
286
  * @protected
271
287
  * @param {Omit<EvmErc4337WalletConfig, 'transferMaxFee'>} [config] - The configuration object.
272
- * @returns {Eip1193Provider} A wrapped Eip1193Provider instance.
288
+ * @returns {Provider} The shared provider.
273
289
  * @throws {ValueError} If the `provider` option is set to an empty array.
274
290
  */
275
- protected _createFailoverProvider (config?: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Eip1193Provider
291
+ protected _buildProvider (config?: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Provider
276
292
  /** @private */
277
293
  private _getEvmReadOnlyAccount;
278
294
  /**
@@ -287,16 +303,25 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
287
303
  */
288
304
  protected _buildUserOperation(calls: import('abstractionkit').MetaTransaction[], config: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">, txOverrides?: EvmErc4337GasOverrides & Nonce): Promise<BuiltUserOperation>;
289
305
  /**
290
- * Extracts the optional UserOperationV7 gas overrides from a single transaction.
306
+ * Returns an evm transaction to execute the given token transfer, carrying any UserOperationV7
307
+ * gas overrides set on the options.
308
+ *
309
+ * @protected
310
+ * @param {EvmErc4337TransferOptions} options - The transfer's options, including any gas/fee overrides to carry onto the transaction.
311
+ * @returns {Promise<EvmErc4337Transaction>} The ERC-20 transfer call as an evm transaction, with the options' gas overrides applied.
312
+ */
313
+ protected static _getTransferTransaction(options: EvmErc4337TransferOptions): Promise<EvmErc4337Transaction>;
314
+ /**
315
+ * Extracts the optional UserOperationV7 gas overrides from a transaction or an options object.
291
316
  *
292
317
  * Only the fields actually consumed by AbstractionKit's `CreateUserOperationOverrides`
293
318
  * are picked. Numeric values are coerced to bigint.
294
319
  *
295
320
  * @protected
296
- * @param {EvmErc4337Transaction} [tx] - The transaction to read overrides from.
297
- * @returns {EvmErc4337GasOverrides} The overrides object (empty if `tx` is falsy or has no override fields).
321
+ * @param {EvmErc4337GasOverrides} [source] - The transaction or options object to read overrides from.
322
+ * @returns {EvmErc4337GasOverrides} The overrides object (empty if `source` is falsy or has no override fields).
298
323
  */
299
- protected static _extractGasOverrides(tx?: EvmErc4337Transaction): EvmErc4337GasOverrides;
324
+ protected static _extractGasOverrides(source?: EvmErc4337GasOverrides): EvmErc4337GasOverrides;
300
325
  /**
301
326
  * Builds a UserOperation and returns its estimated gas cost.
302
327
  *
@@ -314,6 +339,7 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
314
339
  */
315
340
  protected _getUserOperationGasCost(txs: EvmErc4337Transaction[], config: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Promise<BuiltUserOperation & Omit<TransactionResult, "hash">>;
316
341
  }
342
+ export type Provider = import("ethers").Provider;
317
343
  export type Eip1193Provider = import("ethers").Eip1193Provider;
318
344
  export type TransactionResult = import("@tetherto/wdk-wallet-evm").TransactionResult;
319
345
  export type TransferOptions = import("@tetherto/wdk-wallet-evm").TransferOptions;
@@ -402,6 +428,10 @@ export type EvmErc4337GasOverrides = {
402
428
  */
403
429
  maxPriorityFeePerGas?: number | bigint;
404
430
  };
431
+ /**
432
+ * The options of a token transfer, extended with the optional UserOperationV7 gas overrides.
433
+ */
434
+ export type EvmErc4337TransferOptions = TransferOptions & EvmErc4337GasOverrides;
405
435
  /**
406
436
  * A single explicit UserOperationV7 `nonce`, combined with `EvmErc4337GasOverrides` for the build
407
437
  * step to place the operation in a specific two-dimensional nonce lane. The `nonce` is derived
@@ -460,9 +490,9 @@ export type EvmErc4337WalletCommonConfig = {
460
490
  */
461
491
  chainId: number;
462
492
  /**
463
- * - The url of the rpc provider, or an instance of a class that implements eip-1193. It's also possible to provide an array of urls or EIP 1193 providers instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
493
+ * - The url of the rpc provider, an already-built ethers `Provider` (reused as-is), or an instance of a class that implements eip-1193. It's also possible to provide an array of these instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
464
494
  */
465
- provider: string | Eip1193Provider | Array<string | Eip1193Provider>;
495
+ provider: string | Provider | Eip1193Provider | Array<string | Provider | Eip1193Provider>;
466
496
  /**
467
497
  * - If set and if 'provider' is a list of urls or EIP 1193 providers, the number of additional retry attempts after the initial call fails. Total attempts = `1 + retries`. For example, `retries: 3` with 4 providers will try each provider once before throwing. If `retries` exceeds the number of providers, the failover will loop back and retry already-failed providers in round-robin order. Default: 3.
468
498
  */
@@ -2,7 +2,7 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
2
2
  /**
3
3
  * Creates a new wallet manager for evm blockchains that implements the [erc-4337](https://www.erc4337.io/docs) standard and its account abstraction features.
4
4
  *
5
- * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
5
+ * @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
6
6
  * @param {EvmErc4337WalletConfig} config - The configuration object.
7
7
  * @throws {ValueError} If the `provider` option is set to an empty list.
8
8
  */
@@ -11,9 +11,9 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
11
11
  * An ethers provider to interact with a node of the blockchain.
12
12
  *
13
13
  * @protected
14
- * @type {Provider}
14
+ * @type {Provider | undefined}
15
15
  */
16
- protected _provider: Provider;
16
+ protected _provider: Provider | undefined;
17
17
  /**
18
18
  * Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
19
19
  *
@@ -34,6 +34,14 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
34
34
  * @returns {Promise<WalletAccountEvmErc4337>} The account.
35
35
  */
36
36
  getAccountByPath(path: string): Promise<WalletAccountEvmErc4337>;
37
+ /**
38
+ * Builds the account config, injecting the manager's shared provider so accounts reuse the
39
+ * single ethers provider instance instead of opening their own.
40
+ *
41
+ * @private
42
+ * @returns {EvmErc4337WalletConfig} The account configuration.
43
+ */
44
+ private _accountConfig;
37
45
  /**
38
46
  * Returns the current fee rates.
39
47
  *