@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.11 → 1.0.0-beta.12
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.
|
|
3
|
+
"version": "1.0.0-beta.12",
|
|
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",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@tetherto/wdk-failover-provider": "1.0.0-beta.2",
|
|
33
|
-
"@tetherto/wdk-wallet": "1.0.0-beta.
|
|
33
|
+
"@tetherto/wdk-wallet": "1.0.0-beta.14",
|
|
34
34
|
"@tetherto/wdk-wallet-evm": "1.0.0-beta.15",
|
|
35
35
|
"abstractionkit": "0.4.0",
|
|
36
36
|
"bare-node-runtime": "^1.4.0",
|
|
@@ -74,7 +74,7 @@ const withTimeout = (promise, ms) => {
|
|
|
74
74
|
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer))
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/** @implements {IWalletAccount} */
|
|
77
|
+
/** @implements {IWalletAccount<UserOperationV7>} */
|
|
78
78
|
export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc4337 {
|
|
79
79
|
/**
|
|
80
80
|
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account.
|
|
@@ -246,7 +246,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
246
246
|
* In a batched call (`tx` passed as `[tx1, tx2, ...]`), only the gas overrides on `tx1` are
|
|
247
247
|
* honored — a UserOperation has a single set of gas fields regardless of how many calls it batches.
|
|
248
248
|
*
|
|
249
|
-
*
|
|
249
|
+
* An already-signed UserOperation (as returned by `signTransaction`) may also be passed; in that case
|
|
250
|
+
* its fee is read from its own gas fields (in token-paymaster mode this reflects the native gas ceiling,
|
|
251
|
+
* not the token amount).
|
|
252
|
+
*
|
|
253
|
+
* @param {EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7} tx - The transaction, an array of multiple transactions to send in batch, or an already-signed UserOperation.
|
|
250
254
|
* @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
|
|
251
255
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
252
256
|
*/
|
|
@@ -257,6 +261,10 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
257
261
|
this._validateConfig(mergedConfig)
|
|
258
262
|
}
|
|
259
263
|
|
|
264
|
+
if (WalletAccountEvmErc4337._isSignedUserOperation(tx)) {
|
|
265
|
+
return { fee: mergedConfig.isSponsored ? 0n : WalletAccountEvmErc4337._getSignedUserOperationFee(tx) }
|
|
266
|
+
}
|
|
267
|
+
|
|
260
268
|
const txKey = WalletAccountEvmErc4337._getTxKey(tx)
|
|
261
269
|
|
|
262
270
|
if (mergedConfig.isSponsored) {
|
|
@@ -287,7 +295,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
287
295
|
*
|
|
288
296
|
* If the transaction is not sponsored, it also estimates the transaction's costs and checks them against the transaction max. fee option.
|
|
289
297
|
*
|
|
290
|
-
*
|
|
298
|
+
* An already-signed UserOperation (as returned by `signTransaction`) may also be passed; in that case it is
|
|
299
|
+
* broadcast directly to the bundler, reusing the nonce baked in at sign time. The max-fee check is skipped
|
|
300
|
+
* (it was already enforced during `signTransaction`).
|
|
301
|
+
*
|
|
302
|
+
* @param {EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7} tx - The transaction, an array of multiple transactions to send in batch, or an already-signed UserOperation.
|
|
291
303
|
* @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
|
|
292
304
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
293
305
|
* @throws {Error} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
|
|
@@ -299,6 +311,14 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
299
311
|
this._validateConfig(mergedConfig)
|
|
300
312
|
}
|
|
301
313
|
|
|
314
|
+
if (WalletAccountEvmErc4337._isSignedUserOperation(tx)) {
|
|
315
|
+
const fee = mergedConfig.isSponsored ? 0n : WalletAccountEvmErc4337._getSignedUserOperationFee(tx)
|
|
316
|
+
|
|
317
|
+
const hash = await this._broadcastSignedUserOperation(tx)
|
|
318
|
+
|
|
319
|
+
return { hash, fee }
|
|
320
|
+
}
|
|
321
|
+
|
|
302
322
|
const txs = [tx].flat()
|
|
303
323
|
const prepared = await this._prepareForSend(tx, txs, mergedConfig)
|
|
304
324
|
|
|
@@ -536,4 +556,50 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
536
556
|
throw err
|
|
537
557
|
}
|
|
538
558
|
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Broadcasts an already-signed UserOperation directly to the bundler.
|
|
562
|
+
*
|
|
563
|
+
* @private
|
|
564
|
+
* @param {UserOperationV7} userOp - The signed UserOperation.
|
|
565
|
+
* @returns {Promise<string>} The user operation hash.
|
|
566
|
+
*/
|
|
567
|
+
async _broadcastSignedUserOperation (userOp) {
|
|
568
|
+
try {
|
|
569
|
+
return await this._getBundler().sendUserOperation(userOp, ENTRYPOINT_V7)
|
|
570
|
+
} catch (err) {
|
|
571
|
+
if (err instanceof AbstractionKitError && err.message.includes('AA50')) {
|
|
572
|
+
throw new Error('Not enough funds on the safe account to repay the paymaster.')
|
|
573
|
+
}
|
|
574
|
+
throw err
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Determines whether a value is an already-signed UserOperation (as returned by `signTransaction`)
|
|
580
|
+
* rather than an unsigned {@link EvmErc4337Transaction} (or array of them).
|
|
581
|
+
*
|
|
582
|
+
* @private
|
|
583
|
+
* @param {EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7} tx - The value to inspect.
|
|
584
|
+
* @returns {boolean} True if the value is a signed UserOperation.
|
|
585
|
+
*/
|
|
586
|
+
static _isSignedUserOperation (tx) {
|
|
587
|
+
return !!tx.signature
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Computes the fee (with tolerance buffer) for an already-signed UserOperation, reusing the
|
|
592
|
+
* same native gas-cost formula as the unsigned native path.
|
|
593
|
+
*
|
|
594
|
+
* In token-paymaster mode this reflects the native gas ceiling rather than the token amount:
|
|
595
|
+
* the token cost is set by the paymaster at sign time and cannot be reproduced from the signed
|
|
596
|
+
* UserOperation.
|
|
597
|
+
*
|
|
598
|
+
* @private
|
|
599
|
+
* @param {UserOperationV7} userOp - The signed UserOperation.
|
|
600
|
+
* @returns {bigint} The fee, in the smart account's native coin (wei).
|
|
601
|
+
*/
|
|
602
|
+
static _getSignedUserOperationFee (userOp) {
|
|
603
|
+
return BigInt(calculateUserOperationMaxGasCost(userOp)) * FEE_TOLERANCE_COEFFICIENT / 100n
|
|
604
|
+
}
|
|
539
605
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @implements {IWalletAccount} */
|
|
2
|
-
export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc4337 implements IWalletAccount {
|
|
2
|
+
export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc4337 implements IWalletAccount<UserOperationV7> {
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account.
|
|
5
5
|
*
|
|
@@ -93,7 +93,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
93
93
|
* @param {Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>} [config] - If set, overrides the given configuration options.
|
|
94
94
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
95
95
|
*/
|
|
96
|
-
quoteSendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[], config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<Omit<TransactionResult, "hash">>;
|
|
96
|
+
quoteSendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<Omit<TransactionResult, "hash">>;
|
|
97
97
|
/**
|
|
98
98
|
* Sends a transaction.
|
|
99
99
|
*
|
|
@@ -107,7 +107,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
107
107
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
108
108
|
* @throws {Error} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
|
|
109
109
|
*/
|
|
110
|
-
sendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[], config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransactionResult>;
|
|
110
|
+
sendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransactionResult>;
|
|
111
111
|
/**
|
|
112
112
|
* Transfers a token to another address.
|
|
113
113
|
*
|
|
@@ -152,9 +152,12 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
152
152
|
private _signUserOperation;
|
|
153
153
|
/** @private */
|
|
154
154
|
private _sendUserOperation;
|
|
155
|
+
private _broadcastSignedUserOperation;
|
|
156
|
+
private static _isSignedUserOperation;
|
|
157
|
+
private static _getSignedUserOperationFee;
|
|
155
158
|
}
|
|
156
159
|
export type Eip1193Provider = import("ethers").Eip1193Provider;
|
|
157
|
-
export type IWalletAccount = import("@tetherto/wdk-wallet").IWalletAccount
|
|
160
|
+
export type IWalletAccount<TSignedTransaction> = import("@tetherto/wdk-wallet").IWalletAccount<TSignedTransaction>;
|
|
158
161
|
export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
|
|
159
162
|
export type EvmErc4337Transaction = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
|
|
160
163
|
export type EvmErc4337GasOverrides = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337GasOverrides;
|