@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.8 → 1.0.0-beta.9

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.8",
3
+ "version": "1.0.0-beta.9",
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,8 +32,8 @@
32
32
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
33
33
  "@tetherto/wdk-wallet": "1.0.0-beta.9",
34
34
  "@tetherto/wdk-wallet-evm": "1.0.0-beta.13",
35
- "abstractionkit": "0.3.8",
36
- "bare-node-runtime": "^1.1.4",
35
+ "abstractionkit": "0.4.0",
36
+ "bare-node-runtime": "^1.4.0",
37
37
  "ethers": "6.16.0"
38
38
  },
39
39
  "devDependencies": {
@@ -50,14 +50,14 @@
50
50
  "wait-on": "8.0.4"
51
51
  },
52
52
  "overrides": {
53
- "axios": "1.16.1",
54
- "cookie": "1.0.2",
53
+ "axios": "1.17.0",
54
+ "cookie": "1.1.1",
55
55
  "fast-uri": "3.1.2",
56
56
  "@protobufjs/utf8": "1.1.1",
57
- "protobufjs": "7.5.6",
57
+ "protobufjs": "7.6.3",
58
58
  "serialize-javascript": "7.0.5",
59
- "tar": "7.5.7",
60
- "tmp": "0.2.5",
59
+ "tar": "7.5.16",
60
+ "tmp": "0.2.7",
61
61
  "undici": "7.26.0"
62
62
  },
63
63
  "exports": {
@@ -154,11 +154,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
154
154
  this._validateConfig(mergedConfig)
155
155
  }
156
156
 
157
- let cached = this._consumeCachedQuote(tx)
158
- if (!cached) {
159
- await this.quoteSendTransaction(tx, config)
160
- cached = this._consumeCachedQuote(tx)
161
- }
157
+ const cached = await this._resolveQuote(tx, config)
162
158
 
163
159
  const { userOp } = await this._signUserOperation([tx], { config: mergedConfig, cachedBuild: cached })
164
160
 
@@ -171,10 +167,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
171
167
  * Approves a specific amount of tokens to a spender.
172
168
  *
173
169
  * @param {ApproveOptions} options - The approve options.
170
+ * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
174
171
  * @returns {Promise<TransactionResult>} - The transaction's result.
175
172
  * @throws {Error} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
176
173
  */
177
- async approve (options) {
174
+ async approve (options, txOverrides) {
178
175
  if (!this._ownerAccount._provider) {
179
176
  throw new Error('The wallet must be connected to a provider to approve funds.')
180
177
  }
@@ -197,7 +194,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
197
194
  const tx = {
198
195
  to: token,
199
196
  value: 0,
200
- data: contract.interface.encodeFunctionData('approve', [spender, amount])
197
+ data: contract.interface.encodeFunctionData('approve', [spender, amount]),
198
+ ...txOverrides
201
199
  }
202
200
 
203
201
  return await this.sendTransaction(tx)
@@ -206,8 +204,9 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
206
204
  /**
207
205
  * Quotes the costs of a send transaction operation.
208
206
  *
209
- * The result is cached internally for up to 2 minutes. If `sendTransaction` is called with the
210
- * same transaction within that window, the cached fee is reused without an additional RPC round-trip.
207
+ * The result is cached internally for up to 2 minutes. A subsequent `sendTransaction` with the
208
+ * same transaction reuses the cached operation — skipping the gas-estimation and paymaster
209
+ * round-trips — after a lightweight on-chain nonce check, re-quoting only if the nonce has moved.
211
210
  *
212
211
  * In a batched call (`tx` passed as `[tx1, tx2, ...]`), only the gas overrides on `tx1` are
213
212
  * honored — a UserOperation has a single set of gas fields regardless of how many calls it batches.
@@ -262,18 +261,12 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
262
261
  this._validateConfig(mergedConfig)
263
262
  }
264
263
 
265
- let cached = this._consumeCachedQuote(tx)
266
- if (!cached) {
267
- await this.quoteSendTransaction(tx, config)
268
- cached = this._consumeCachedQuote(tx)
269
- }
264
+ const cached = await this._resolveQuote(tx, config)
270
265
 
271
266
  const fee = cached.fee
272
267
 
273
268
  const hash = await this._sendUserOperation([tx].flat(), { config: mergedConfig, cachedBuild: cached })
274
269
 
275
- await this._bumpCachedNonces()
276
-
277
270
  return { hash, fee }
278
271
  }
279
272
 
@@ -282,9 +275,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
282
275
  *
283
276
  * @param {TransferOptions} options - The transfer's options.
284
277
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
278
+ * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
285
279
  * @returns {Promise<TransferResult>} The transfer's result.
286
280
  */
287
- async transfer (options, config) {
281
+ async transfer (options, config, txOverrides) {
288
282
  const mergedConfig = { ...this._config, ...config }
289
283
 
290
284
  if (config) {
@@ -293,13 +287,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
293
287
 
294
288
  const { isSponsored, transferMaxFee } = mergedConfig
295
289
 
296
- const tx = await WalletAccountEvm._getTransferTransaction(options)
290
+ const baseTx = await WalletAccountEvm._getTransferTransaction(options)
291
+ const tx = { ...baseTx, ...txOverrides }
297
292
 
298
- let cached = this._consumeCachedQuote(tx)
299
- if (!cached) {
300
- await this.quoteSendTransaction(tx, config)
301
- cached = this._consumeCachedQuote(tx)
302
- }
293
+ const cached = await this._resolveQuote(tx, config)
303
294
 
304
295
  const fee = cached.fee
305
296
 
@@ -309,8 +300,6 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
309
300
 
310
301
  const hash = await this._sendUserOperation([tx], { config: mergedConfig, cachedBuild: cached })
311
302
 
312
- await this._bumpCachedNonces()
313
-
314
303
  return { hash, fee }
315
304
  }
316
305
 
@@ -335,34 +324,20 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
335
324
  }
336
325
 
337
326
  /** @private */
338
- async _bumpCachedNonces () {
339
- const entriesWithUserOp = [...this._quoteCache.entries()].filter(([, { userOp }]) => userOp)
340
-
341
- if (entriesWithUserOp.length === 0) return
342
-
343
- const [, firstQuote] = entriesWithUserOp[0]
344
- const onChainNonce = await fetchAccountNonce(this._provider, firstQuote.smartAccount.entrypointAddress, firstQuote.smartAccount.accountAddress)
345
-
346
- const mode = WalletAccountReadOnlyEvmErc4337._resolvePaymasterMode(this._config)
347
-
348
- await Promise.all(entriesWithUserOp.map(async ([txKey, quote]) => {
349
- quote.userOp.nonce = onChainNonce + 1n
350
-
351
- if (mode !== 'native') {
352
- try {
353
- const { userOp } = await this._applyPaymasterToUserOp({
354
- mode,
355
- smartAccount: quote.smartAccount,
356
- userOp: quote.userOp,
357
- config: this._config,
358
- chainId: quote.chainId
359
- })
360
- quote.userOp = userOp
361
- } catch {
362
- this._quoteCache.delete(txKey)
363
- }
364
- }
365
- }))
327
+ async _resolveQuote (tx, config) {
328
+ let cached = this._consumeCachedQuote(tx)
329
+
330
+ if (cached?.userOp) {
331
+ const onChainNonce = await fetchAccountNonce(this._provider, cached.smartAccount.entrypointAddress, cached.smartAccount.accountAddress)
332
+ if (cached.userOp.nonce !== onChainNonce) cached = undefined
333
+ }
334
+
335
+ if (!cached) {
336
+ await this.quoteSendTransaction(tx, config)
337
+ cached = this._consumeCachedQuote(tx)
338
+ }
339
+
340
+ return cached
366
341
  }
367
342
 
368
343
  /** @private */
@@ -333,12 +333,14 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
333
333
  *
334
334
  * @param {TransferOptions} options - The transfer's options.
335
335
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
336
+ * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
336
337
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
337
338
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
338
339
  * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
339
340
  */
340
- async quoteTransfer (options, config) {
341
- const tx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
341
+ async quoteTransfer (options, config, txOverrides) {
342
+ const baseTx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
343
+ const tx = { ...baseTx, ...txOverrides }
342
344
 
343
345
  const result = await this.quoteSendTransaction(tx, config)
344
346
 
@@ -67,15 +67,17 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
67
67
  * Approves a specific amount of tokens to a spender.
68
68
  *
69
69
  * @param {ApproveOptions} options - The approve options.
70
+ * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
70
71
  * @returns {Promise<TransactionResult>} - The transaction's result.
71
72
  * @throws {Error} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
72
73
  */
73
- approve(options: ApproveOptions): Promise<TransactionResult>;
74
+ approve(options: ApproveOptions, txOverrides?: EvmErc4337GasOverrides): Promise<TransactionResult>;
74
75
  /**
75
76
  * Quotes the costs of a send transaction operation.
76
77
  *
77
- * The result is cached internally for up to 2 minutes. If `sendTransaction` is called with the
78
- * same transaction within that window, the cached fee is reused without an additional RPC round-trip.
78
+ * The result is cached internally for up to 2 minutes. A subsequent `sendTransaction` with the
79
+ * same transaction reuses the cached operation — skipping the gas-estimation and paymaster
80
+ * round-trips — after a lightweight on-chain nonce check, re-quoting only if the nonce has moved.
79
81
  *
80
82
  * In a batched call (`tx` passed as `[tx1, tx2, ...]`), only the gas overrides on `tx1` are
81
83
  * honored — a UserOperation has a single set of gas fields regardless of how many calls it batches.
@@ -101,9 +103,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
101
103
  *
102
104
  * @param {TransferOptions} options - The transfer's options.
103
105
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
106
+ * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
104
107
  * @returns {Promise<TransferResult>} The transfer's result.
105
108
  */
106
- transfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransferResult>;
109
+ transfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>, txOverrides?: EvmErc4337GasOverrides): Promise<TransferResult>;
107
110
  /**
108
111
  * Returns a read-only copy of the account.
109
112
  *
@@ -115,7 +118,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
115
118
  */
116
119
  dispose(): void;
117
120
  /** @private */
118
- private _bumpCachedNonces;
121
+ private _resolveQuote;
119
122
  /** @private */
120
123
  private static _getTxKey;
121
124
  /** @private */
@@ -129,6 +132,7 @@ export type Eip1193Provider = import("ethers").Eip1193Provider;
129
132
  export type IWalletAccount = import("@tetherto/wdk-wallet").IWalletAccount;
130
133
  export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
131
134
  export type EvmErc4337Transaction = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
135
+ export type EvmErc4337GasOverrides = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337GasOverrides;
132
136
  export type TransactionResult = import("@tetherto/wdk-wallet-evm").TransactionResult;
133
137
  export type TransferOptions = import("@tetherto/wdk-wallet-evm").TransferOptions;
134
138
  export type TransferResult = import("@tetherto/wdk-wallet-evm").TransferResult;
@@ -111,11 +111,12 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
111
111
  *
112
112
  * @param {TransferOptions} options - The transfer's options.
113
113
  * @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
114
+ * @param {EvmErc4337GasOverrides} [txOverrides] - If set, applies these UserOperationV7 gas/fee overrides to the underlying transaction.
114
115
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
115
116
  * @throws {ConfigurationError} If the override `config` is invalid or has missing required fields.
116
117
  * @throws {Error} If the token paymaster reports AA50 (account does not hold the paymaster token).
117
118
  */
118
- quoteTransfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<Omit<TransferResult, "hash">>;
119
+ quoteTransfer(options: TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>, txOverrides?: EvmErc4337GasOverrides): Promise<Omit<TransferResult, "hash">>;
119
120
  /**
120
121
  * Returns a transaction's receipt.
121
122
  *