@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.2 → 1.0.0-beta.4
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/AGENTS.md +50 -0
- package/README.md +191 -84
- package/hardhat.config.cjs +26 -0
- package/index.js +4 -0
- package/package.json +25 -9
- package/src/errors.js +28 -0
- package/src/wallet-account-evm-erc-4337.js +77 -38
- package/src/wallet-account-read-only-evm-erc-4337.js +207 -55
- package/types/index.d.ts +2 -0
- package/types/src/errors.d.ts +8 -0
- package/types/src/wallet-account-evm-erc-4337.d.ts +17 -13
- package/types/src/wallet-account-read-only-evm-erc-4337.d.ts +111 -29
package/AGENTS.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Agent Guide
|
|
2
|
+
|
|
3
|
+
This repository is part of the Tether WDK (Wallet Development Kit) ecosystem. It follows strict coding conventions and tooling standards to ensure consistency, reliability, and cross-platform compatibility (Node.js and Bare runtime).
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
- **Architecture:** Modular architecture with clear separation between Core, Wallet managers, and Protocols.
|
|
7
|
+
- **Runtime:** Supports both Node.js and Bare runtime.
|
|
8
|
+
|
|
9
|
+
## Tech Stack & Tooling
|
|
10
|
+
- **Language:** JavaScript (ES2015+).
|
|
11
|
+
- **Module System:** ES Modules (`"type": "module"` in package.json).
|
|
12
|
+
- **Type Checking:** TypeScript is used purely for generating type declarations (`.d.ts`). The source code remains JavaScript.
|
|
13
|
+
- Command: `npm run build:types`
|
|
14
|
+
- **Linting:** `standard` (JavaScript Standard Style).
|
|
15
|
+
- Command: `npm run lint` / `npm run lint:fix`
|
|
16
|
+
- **Testing:** `jest` (configured with `experimental-vm-modules` for ESM support).
|
|
17
|
+
- Command: `npm test`
|
|
18
|
+
- **Dependencies:** `cross-env` is consistently used for environment variable management in scripts.
|
|
19
|
+
|
|
20
|
+
## Coding Conventions
|
|
21
|
+
- **File Naming:** Kebab-case (e.g., `wallet-manager.js`).
|
|
22
|
+
- **Class Naming:** PascalCase (e.g., `WdkManager`).
|
|
23
|
+
- **Private Members:** Prefixed with `_` (underscore) and explicitly documented with `@private`.
|
|
24
|
+
- **Imports:** Explicit file extensions are mandatory (e.g., `import ... from './file.js'`).
|
|
25
|
+
- **Copyright:** All source files must include the standard Tether copyright header.
|
|
26
|
+
|
|
27
|
+
## Documentation (JSDoc)
|
|
28
|
+
Source code must be strictly typed using JSDoc comments to support the `build:types` process.
|
|
29
|
+
- **Types:** Use `@typedef` to define or import types.
|
|
30
|
+
- **Methods:** Use `@param`, `@returns`, `@throws`.
|
|
31
|
+
- **Generics:** Use `@template`.
|
|
32
|
+
|
|
33
|
+
## Development Workflow
|
|
34
|
+
1. **Install:** `npm install`
|
|
35
|
+
2. **Lint:** `npm run lint`
|
|
36
|
+
3. **Test:** `npm test`
|
|
37
|
+
4. **Build Types:** `npm run build:types`
|
|
38
|
+
|
|
39
|
+
## Key Files
|
|
40
|
+
- `index.js`: Main entry point.
|
|
41
|
+
- `bare.js`: Entry point for Bare runtime optimization.
|
|
42
|
+
- `src/`: Core logic.
|
|
43
|
+
- `types/`: Generated type definitions (do not edit manually).
|
|
44
|
+
|
|
45
|
+
## Repository Specifics
|
|
46
|
+
- **Domain:** EVM Account Abstraction (ERC-4337).
|
|
47
|
+
- **Key Libraries:** `@tetherto/wdk-safe-relay-kit`, `ethers`.
|
|
48
|
+
- **Features:** UserOperations, Bundlers, Paymasters.
|
|
49
|
+
- **Architecture:** specialized wallet manager for Smart Accounts.
|
|
50
|
+
- **Testing:** Requires local Hardhat node (localhost:8545).
|
package/README.md
CHANGED
|
@@ -43,20 +43,32 @@ import WalletManagerEvmErc4337, {
|
|
|
43
43
|
// Use a BIP-39 seed phrase (replace with your own secure phrase)
|
|
44
44
|
const seedPhrase = 'test only example nut use this real life secret phrase must random'
|
|
45
45
|
|
|
46
|
-
// Create wallet manager with ERC-4337 config
|
|
46
|
+
// Create wallet manager with ERC-4337 config (paymaster token mode)
|
|
47
47
|
const wallet = new WalletManagerEvmErc4337(seedPhrase, {
|
|
48
|
-
//
|
|
48
|
+
// Common parameters (required for all modes)
|
|
49
49
|
chainId: 1, // Ethereum Mainnet
|
|
50
50
|
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', // RPC endpoint
|
|
51
51
|
bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key', // ERC-4337 bundler
|
|
52
52
|
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', // EntryPoint contract
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
paymasterUrl: 'https://api.paymaster.com',
|
|
53
|
+
safeModulesVersion: '0.3.0',
|
|
54
|
+
|
|
55
|
+
// Paymaster token mode parameters
|
|
56
|
+
paymasterUrl: 'https://api.paymaster.com',
|
|
57
|
+
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
58
|
+
paymasterToken: { address: '0xdAC17F958D2ee523a2206206994597C13D831ec7' }, // USDT
|
|
57
59
|
transferMaxFee: 100000000000000 // Optional: Maximum fee in wei
|
|
58
60
|
})
|
|
59
61
|
|
|
62
|
+
// Or use native coins mode (no paymaster needed)
|
|
63
|
+
const nativeWallet = new WalletManagerEvmErc4337(seedPhrase, {
|
|
64
|
+
chainId: 1,
|
|
65
|
+
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
66
|
+
bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
|
|
67
|
+
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
68
|
+
safeModulesVersion: '0.3.0',
|
|
69
|
+
useNativeCoins: true
|
|
70
|
+
})
|
|
71
|
+
|
|
60
72
|
// Get a full access account
|
|
61
73
|
const account = await wallet.getAccount(0)
|
|
62
74
|
|
|
@@ -121,11 +133,13 @@ For addresses where you don't have the seed phrase:
|
|
|
121
133
|
```javascript
|
|
122
134
|
import { WalletAccountReadOnlyEvmErc4337 } from '@tetherto/wdk-wallet-evm-erc-4337'
|
|
123
135
|
|
|
124
|
-
// Create a read-only account
|
|
136
|
+
// Create a read-only account (native coins mode — no paymaster needed for quoting)
|
|
125
137
|
const readOnlyAccount = new WalletAccountReadOnlyEvmErc4337('0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', { // Smart contract wallet address
|
|
126
138
|
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
127
139
|
bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
|
|
128
|
-
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'
|
|
140
|
+
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
141
|
+
safeModulesVersion: '0.3.0',
|
|
142
|
+
useNativeCoins: true
|
|
129
143
|
})
|
|
130
144
|
|
|
131
145
|
// Check native token balance
|
|
@@ -174,9 +188,9 @@ const transferResult = await account.transfer({
|
|
|
174
188
|
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT contract address
|
|
175
189
|
recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient's address
|
|
176
190
|
amount: 1000000n // Amount in token's base units (1 USDT = 1000000 for 6 decimals)
|
|
177
|
-
})
|
|
178
|
-
console.log('UserOperation hash:', transferResult.hash)
|
|
179
|
-
console.log('Transfer fee:', transferResult.fee, 'wei')
|
|
191
|
+
})
|
|
192
|
+
console.log('UserOperation hash:', transferResult.hash)
|
|
193
|
+
console.log('Transfer fee:', transferResult.fee, 'wei')
|
|
180
194
|
|
|
181
195
|
// Quote token transfer fee
|
|
182
196
|
const transferQuote = await account.quoteTransfer({
|
|
@@ -185,6 +199,14 @@ const transferQuote = await account.quoteTransfer({
|
|
|
185
199
|
amount: 1000000n // Amount in token's base units
|
|
186
200
|
})
|
|
187
201
|
console.log('Transfer fee estimate:', transferQuote.fee, 'wei')
|
|
202
|
+
|
|
203
|
+
// Transfer using native coins for gas (override constructor config)
|
|
204
|
+
const nativeTransfer = await account.transfer({
|
|
205
|
+
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
206
|
+
recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24',
|
|
207
|
+
amount: 1000000n
|
|
208
|
+
}, { useNativeCoins: true })
|
|
209
|
+
console.log('Native gas transfer hash:', nativeTransfer.hash)
|
|
188
210
|
```
|
|
189
211
|
|
|
190
212
|
### Message Signing and Verification
|
|
@@ -248,24 +270,44 @@ new WalletManagerEvmErc4337(seed, config)
|
|
|
248
270
|
|
|
249
271
|
**Parameters:**
|
|
250
272
|
- `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
|
|
251
|
-
- `config` (object): Configuration object
|
|
273
|
+
- `config` (object): Configuration object. The configuration is a union of common fields and one of three gas payment modes.
|
|
274
|
+
|
|
275
|
+
**Common fields (required for all modes):**
|
|
276
|
+
- `chainId` (number): Chain ID of the target network
|
|
252
277
|
- `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
|
|
253
278
|
- `bundlerUrl` (string): URL of the ERC-4337 bundler service
|
|
254
279
|
- `entryPointAddress` (string): Address of the EntryPoint contract
|
|
255
|
-
- `
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
- `
|
|
280
|
+
- `safeModulesVersion` (string): The safe modules version
|
|
281
|
+
|
|
282
|
+
**Paymaster token mode** (pay gas fees with an ERC-20 token via a paymaster):
|
|
283
|
+
- `paymasterUrl` (string): URL of the paymaster service
|
|
284
|
+
- `paymasterAddress` (string): Address of the paymaster smart contract
|
|
285
|
+
- `paymasterToken` (object): Paymaster token configuration
|
|
286
|
+
- `address` (string): Token contract address
|
|
287
|
+
- `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations
|
|
288
|
+
|
|
289
|
+
**Sponsorship mode** (gas fees are sponsored by a paymaster):
|
|
290
|
+
- `isSponsored` (true): Enables transaction sponsorship
|
|
291
|
+
- `paymasterUrl` (string): URL of the paymaster service
|
|
292
|
+
- `sponsorshipPolicyId` (string, optional): Sponsorship policy ID
|
|
293
|
+
|
|
294
|
+
**Native coins mode** (pay gas fees with native coins, e.g. ETH):
|
|
295
|
+
- `useNativeCoins` (true): Enables native coin gas payment
|
|
296
|
+
- `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations
|
|
259
297
|
|
|
260
298
|
**Example:**
|
|
261
299
|
```javascript
|
|
300
|
+
// Paymaster token mode
|
|
262
301
|
const wallet = new WalletManagerEvmErc4337(seedPhrase, {
|
|
302
|
+
chainId: 1,
|
|
263
303
|
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
264
304
|
bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
|
|
265
305
|
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
306
|
+
safeModulesVersion: '0.3.0',
|
|
307
|
+
paymasterUrl: 'https://api.paymaster.com',
|
|
308
|
+
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
309
|
+
paymasterToken: { address: '0xdAC17F958D2ee523a2206206994597C13D831ec7' },
|
|
310
|
+
transferMaxFee: 100000000000000n
|
|
269
311
|
})
|
|
270
312
|
```
|
|
271
313
|
|
|
@@ -354,14 +396,7 @@ new WalletAccountEvmErc4337(seed, path, config)
|
|
|
354
396
|
**Parameters:**
|
|
355
397
|
- `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
|
|
356
398
|
- `path` (string): BIP-44 derivation path (e.g., "0'/0/0")
|
|
357
|
-
- `config` (object): Configuration object
|
|
358
|
-
- `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
|
|
359
|
-
- `bundlerUrl` (string): URL of the ERC-4337 bundler service
|
|
360
|
-
- `entryPointAddress` (string): Address of the EntryPoint contract
|
|
361
|
-
- `factoryAddress` (string): Address of the account factory contract
|
|
362
|
-
- `chainId` (number): Chain ID of the target network
|
|
363
|
-
- `paymasterUrl` (string, optional): URL of the paymaster service
|
|
364
|
-
- `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations (in wei)
|
|
399
|
+
- `config` (object): Configuration object. Same configuration union as `WalletManagerEvmErc4337` — see [constructor parameters](#constructor) for the full description of common fields and the three gas payment modes (paymaster token, sponsorship, native coins).
|
|
365
400
|
|
|
366
401
|
#### Methods
|
|
367
402
|
|
|
@@ -370,10 +405,10 @@ new WalletAccountEvmErc4337(seed, path, config)
|
|
|
370
405
|
| `getAddress()` | Returns the smart contract wallet address | `Promise<string>` |
|
|
371
406
|
| `sign(message)` | Signs a message using the account's private key | `Promise<string>` |
|
|
372
407
|
| `verify(message, signature)` | Verifies a message signature | `Promise<boolean>` |
|
|
373
|
-
| `sendTransaction(tx)` | Sends a transaction via UserOperation | `Promise<{hash: string, fee: bigint}>` |
|
|
374
|
-
| `quoteSendTransaction(tx)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
|
|
375
|
-
| `transfer(options)` | Transfers ERC20 tokens via UserOperation | `Promise<{hash: string, fee: bigint}>` |
|
|
376
|
-
| `quoteTransfer(options)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
408
|
+
| `sendTransaction(tx, config)` | Sends a transaction via UserOperation | `Promise<{hash: string, fee: bigint}>` |
|
|
409
|
+
| `quoteSendTransaction(tx, config)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
|
|
410
|
+
| `transfer(options, config)` | Transfers ERC20 tokens via UserOperation | `Promise<{hash: string, fee: bigint}>` |
|
|
411
|
+
| `quoteTransfer(options, config)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
377
412
|
| `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
|
|
378
413
|
| `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
|
|
379
414
|
| `dispose()` | Disposes the wallet account, clearing private keys from memory | `void` |
|
|
@@ -418,17 +453,24 @@ const isValid = await account.verify('Hello ERC-4337!', signature)
|
|
|
418
453
|
console.log('Signature valid:', isValid)
|
|
419
454
|
```
|
|
420
455
|
|
|
421
|
-
##### `sendTransaction(tx)`
|
|
456
|
+
##### `sendTransaction(tx, config)`
|
|
422
457
|
Sends a transaction via UserOperation through the ERC-4337 bundler.
|
|
423
458
|
|
|
424
459
|
**Parameters:**
|
|
425
|
-
- `tx` (object): The transaction object
|
|
460
|
+
- `tx` (object | object[]): The transaction object, or an array of multiple transactions to send in batch.
|
|
426
461
|
- `to` (string): Recipient address
|
|
427
462
|
- `value` (number | bigint): Amount in wei
|
|
428
463
|
- `data` (string, optional): Transaction data in hex format
|
|
429
464
|
- `gasLimit` (number | bigint, optional): Maximum gas units for the UserOperation
|
|
430
465
|
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
431
466
|
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
467
|
+
- `config` (object, optional): If set, overrides the given configuration options. The provided fields are merged with the constructor configuration (i.e. only the specified properties are overridden). The merged configuration is validated to ensure all required fields for the resulting gas payment mode are present. Accepts any combination of fields from `EvmErc4337WalletPaymasterTokenConfig`, `EvmErc4337WalletSponsorshipPolicyConfig`, or `EvmErc4337WalletNativeCoinsConfig`.
|
|
468
|
+
- `isSponsored` (boolean, optional): Override sponsorship setting
|
|
469
|
+
- `useNativeCoins` (boolean, optional): Override to use native coins for gas
|
|
470
|
+
- `paymasterUrl` (string, optional): Override paymaster service URL
|
|
471
|
+
- `paymasterAddress` (string, optional): Override paymaster smart contract address
|
|
472
|
+
- `paymasterToken` (object, optional): Override paymaster token
|
|
473
|
+
- `sponsorshipPolicyId` (string, optional): Override sponsorship policy ID
|
|
432
474
|
|
|
433
475
|
**Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing UserOperation hash and total fee (in wei)
|
|
434
476
|
|
|
@@ -442,19 +484,33 @@ const result = await account.sendTransaction({
|
|
|
442
484
|
})
|
|
443
485
|
console.log('UserOperation hash:', result.hash)
|
|
444
486
|
console.log('Total fee paid:', result.fee, 'wei')
|
|
487
|
+
|
|
488
|
+
// Send sponsored transaction (overrides constructor config)
|
|
489
|
+
const sponsoredResult = await account.sendTransaction({
|
|
490
|
+
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
491
|
+
value: 1000000000000000000n
|
|
492
|
+
}, {
|
|
493
|
+
isSponsored: true,
|
|
494
|
+
sponsorshipPolicyId: 'POLICY_ID'
|
|
495
|
+
})
|
|
496
|
+
console.log('Sponsored hash:', sponsoredResult.hash)
|
|
497
|
+
|
|
498
|
+
// Send transaction using native coins for gas
|
|
499
|
+
const nativeResult = await account.sendTransaction({
|
|
500
|
+
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
501
|
+
value: 1000000000000000000n
|
|
502
|
+
}, {
|
|
503
|
+
useNativeCoins: true
|
|
504
|
+
})
|
|
505
|
+
console.log('Native gas hash:', nativeResult.hash)
|
|
445
506
|
```
|
|
446
507
|
|
|
447
|
-
##### `quoteSendTransaction(tx)`
|
|
508
|
+
##### `quoteSendTransaction(tx, config)`
|
|
448
509
|
Estimates the fee for a UserOperation without submitting it to the bundler.
|
|
449
510
|
|
|
450
511
|
**Parameters:**
|
|
451
|
-
- `tx` (object): Same as sendTransaction
|
|
452
|
-
|
|
453
|
-
- `value` (number | bigint): Amount in wei
|
|
454
|
-
- `data` (string, optional): Transaction data in hex format
|
|
455
|
-
- `gasLimit` (number | bigint, optional): Maximum gas units
|
|
456
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
457
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
512
|
+
- `tx` (object | object[]): Same as sendTransaction `tx` parameter.
|
|
513
|
+
- `config` (object, optional): Same as sendTransaction `config` parameter — overrides the given configuration options by merging with the constructor configuration.
|
|
458
514
|
|
|
459
515
|
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated total fee (in wei)
|
|
460
516
|
|
|
@@ -466,54 +522,74 @@ const quote = await account.quoteSendTransaction({
|
|
|
466
522
|
})
|
|
467
523
|
console.log('Estimated UserOperation fee:', quote.fee, 'wei')
|
|
468
524
|
console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
|
|
525
|
+
|
|
526
|
+
// Quote with native coins gas payment
|
|
527
|
+
const nativeQuote = await account.quoteSendTransaction({
|
|
528
|
+
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
529
|
+
value: 1000000000000000000n
|
|
530
|
+
}, { useNativeCoins: true })
|
|
531
|
+
console.log('Estimated native gas fee:', nativeQuote.fee, 'wei')
|
|
469
532
|
```
|
|
470
533
|
|
|
471
|
-
##### `transfer(options)`
|
|
534
|
+
##### `transfer(options, config)`
|
|
472
535
|
Transfers ERC20 tokens via UserOperation through the bundler.
|
|
473
536
|
|
|
474
537
|
**Parameters:**
|
|
475
538
|
- `options` (object): Transfer options
|
|
476
|
-
- `
|
|
477
|
-
- `
|
|
478
|
-
- `
|
|
479
|
-
|
|
480
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
481
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
539
|
+
- `token` (string): ERC20 token contract address
|
|
540
|
+
- `recipient` (string): Recipient address
|
|
541
|
+
- `amount` (number | bigint): Amount in token's smallest unit
|
|
542
|
+
- `config` (object, optional): Same as sendTransaction `config` parameter — overrides the given configuration options by merging with the constructor configuration.
|
|
482
543
|
|
|
483
544
|
**Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing UserOperation hash and fee (in wei)
|
|
484
545
|
|
|
485
546
|
**Example:**
|
|
486
547
|
```javascript
|
|
487
548
|
const result = await account.transfer({
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
maxFeePerGas: 20000000000n
|
|
549
|
+
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
550
|
+
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
551
|
+
amount: 1000000n // 1 USDT (6 decimals)
|
|
492
552
|
})
|
|
493
553
|
console.log('UserOperation hash:', result.hash)
|
|
494
554
|
console.log('Gas fee paid:', result.fee, 'wei')
|
|
555
|
+
|
|
556
|
+
// Send sponsored token transfer
|
|
557
|
+
const sponsoredTransfer = await account.transfer({
|
|
558
|
+
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
559
|
+
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
560
|
+
amount: 1000000n
|
|
561
|
+
}, {
|
|
562
|
+
isSponsored: true,
|
|
563
|
+
sponsorshipPolicyId: 'POLICY_ID'
|
|
564
|
+
})
|
|
565
|
+
console.log('Sponsored transfer hash:', sponsoredTransfer.hash)
|
|
566
|
+
|
|
567
|
+
// Transfer using native coins for gas
|
|
568
|
+
const nativeTransfer = await account.transfer({
|
|
569
|
+
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
570
|
+
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
571
|
+
amount: 1000000n
|
|
572
|
+
}, {
|
|
573
|
+
useNativeCoins: true
|
|
574
|
+
})
|
|
575
|
+
console.log('Native gas transfer hash:', nativeTransfer.hash)
|
|
495
576
|
```
|
|
496
577
|
|
|
497
|
-
##### `quoteTransfer(options)`
|
|
578
|
+
##### `quoteTransfer(options, config)`
|
|
498
579
|
Estimates the fee for an ERC20 token transfer UserOperation without submitting it.
|
|
499
580
|
|
|
500
581
|
**Parameters:**
|
|
501
|
-
- `options` (object): Same as transfer
|
|
502
|
-
|
|
503
|
-
- `tokenAddress` (string): ERC20 token contract address
|
|
504
|
-
- `value` (number | bigint): Amount in token's smallest unit
|
|
505
|
-
- `gasLimit` (number | bigint, optional): Maximum gas units
|
|
506
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
507
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
582
|
+
- `options` (object): Same as transfer `options` parameter.
|
|
583
|
+
- `config` (object, optional): Same as sendTransaction `config` parameter — overrides the given configuration options by merging with the constructor configuration.
|
|
508
584
|
|
|
509
585
|
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated fee (in wei)
|
|
510
586
|
|
|
511
587
|
**Example:**
|
|
512
588
|
```javascript
|
|
513
589
|
const quote = await account.quoteTransfer({
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
590
|
+
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
591
|
+
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
592
|
+
amount: 1000000n // 1 USDT (6 decimals)
|
|
517
593
|
})
|
|
518
594
|
console.log('Estimated transfer fee:', quote.fee, 'wei')
|
|
519
595
|
```
|
|
@@ -578,19 +654,39 @@ new WalletAccountReadOnlyEvmErc4337(address, config)
|
|
|
578
654
|
|
|
579
655
|
**Parameters:**
|
|
580
656
|
- `address` (string): The smart contract wallet address
|
|
581
|
-
- `config` (object): Configuration object
|
|
582
|
-
- `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
|
|
583
|
-
- `bundlerUrl` (string): URL of the ERC-4337 bundler service
|
|
584
|
-
- `entryPointAddress` (string): Address of the EntryPoint contract
|
|
657
|
+
- `config` (object): Configuration object. Same configuration union as `WalletManagerEvmErc4337` (excluding `transferMaxFee`) — see [constructor parameters](#constructor) for the full description of common fields and the three gas payment modes.
|
|
585
658
|
|
|
586
659
|
#### Methods
|
|
587
660
|
|
|
588
661
|
| Method | Description | Returns |
|
|
589
662
|
|--------|-------------|---------|
|
|
663
|
+
| `predictSafeAddress(owner, config)` | Static method to predict Safe address for an EOA | `string` |
|
|
590
664
|
| `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
|
|
591
665
|
| `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
|
|
592
|
-
| `
|
|
593
|
-
| `
|
|
666
|
+
| `getPaymasterTokenBalance()` | Returns the paymaster token balance | `Promise<bigint>` |
|
|
667
|
+
| `quoteSendTransaction(tx, config)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
|
|
668
|
+
| `quoteTransfer(options, config)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
669
|
+
| `verify(message, signature)` | Verifies a message signature | `Promise<boolean>` |
|
|
670
|
+
|
|
671
|
+
##### `predictSafeAddress(owner, config)` (static)
|
|
672
|
+
Predicts the Safe smart contract address for a given EOA owner without requiring network calls.
|
|
673
|
+
|
|
674
|
+
**Parameters:**
|
|
675
|
+
- `owner` (string): The EOA address that will own the Safe
|
|
676
|
+
- `config` (object): Configuration object
|
|
677
|
+
- `chainId` (number): Chain ID of the target network
|
|
678
|
+
- `safeModulesVersion` (string, optional): Safe modules version (e.g., "0.3.0")
|
|
679
|
+
|
|
680
|
+
**Returns:** `string` - The predicted Safe address
|
|
681
|
+
|
|
682
|
+
**Example:**
|
|
683
|
+
```javascript
|
|
684
|
+
const safeAddress = WalletAccountReadOnlyEvmErc4337.predictSafeAddress(
|
|
685
|
+
'0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
686
|
+
{ chainId: 1, safeModulesVersion: '0.3.0' }
|
|
687
|
+
)
|
|
688
|
+
console.log('Predicted Safe address:', safeAddress)
|
|
689
|
+
```
|
|
594
690
|
|
|
595
691
|
##### `getBalance()`
|
|
596
692
|
Returns the smart contract wallet's native token balance (e.g., ETH, MATIC, etc.) in wei.
|
|
@@ -619,17 +715,15 @@ const usdtBalance = await readOnlyAccount.getTokenBalance('0xdAC17F958D2ee523a22
|
|
|
619
715
|
console.log('Smart account USDT balance:', Number(usdtBalance) / 1e6)
|
|
620
716
|
```
|
|
621
717
|
|
|
622
|
-
##### `quoteSendTransaction(tx)`
|
|
718
|
+
##### `quoteSendTransaction(tx, config)`
|
|
623
719
|
Estimates the fee for a UserOperation without submitting it to the bundler.
|
|
624
720
|
|
|
625
721
|
**Parameters:**
|
|
626
|
-
- `tx` (object): The transaction object
|
|
722
|
+
- `tx` (object | object[]): The transaction object, or an array of multiple transactions to send in batch.
|
|
627
723
|
- `to` (string): Recipient address
|
|
628
724
|
- `value` (number | bigint): Amount in wei
|
|
629
725
|
- `data` (string, optional): Transaction data in hex format
|
|
630
|
-
|
|
631
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
632
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
726
|
+
- `config` (object, optional): If set, overrides the given configuration options by merging with the constructor configuration. See [`sendTransaction` config](#sendtransactiontx-config) for the full list of overridable fields.
|
|
633
727
|
|
|
634
728
|
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated total UserOperation fee (in wei)
|
|
635
729
|
|
|
@@ -643,31 +737,44 @@ console.log('Estimated UserOperation fee:', quote.fee, 'wei')
|
|
|
643
737
|
console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
|
|
644
738
|
```
|
|
645
739
|
|
|
646
|
-
##### `quoteTransfer(options)`
|
|
740
|
+
##### `quoteTransfer(options, config)`
|
|
647
741
|
Estimates the fee for an ERC20 token transfer UserOperation without submitting it to the bundler.
|
|
648
742
|
|
|
649
743
|
**Parameters:**
|
|
650
744
|
- `options` (object): Transfer options
|
|
651
|
-
- `
|
|
652
|
-
- `
|
|
653
|
-
- `
|
|
654
|
-
|
|
655
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
656
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
745
|
+
- `token` (string): ERC20 token contract address
|
|
746
|
+
- `recipient` (string): Recipient address
|
|
747
|
+
- `amount` (number | bigint): Amount in token's smallest unit
|
|
748
|
+
- `config` (object, optional): Same as `quoteSendTransaction` config parameter.
|
|
657
749
|
|
|
658
750
|
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated UserOperation fee (in wei)
|
|
659
751
|
|
|
660
752
|
**Example:**
|
|
661
753
|
```javascript
|
|
662
754
|
const quote = await readOnlyAccount.quoteTransfer({
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
755
|
+
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
756
|
+
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
757
|
+
amount: 1000000n // 1 USDT (6 decimals)
|
|
666
758
|
})
|
|
667
759
|
console.log('Estimated transfer UserOperation fee:', quote.fee, 'wei')
|
|
668
760
|
console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
|
|
669
761
|
```
|
|
670
762
|
|
|
763
|
+
##### `verify(message, signature)`
|
|
764
|
+
Verifies a message signature using the account's public key.
|
|
765
|
+
|
|
766
|
+
**Parameters:**
|
|
767
|
+
- `message` (string): Original message
|
|
768
|
+
- `signature` (string): Signature as hex string
|
|
769
|
+
|
|
770
|
+
**Returns:** `Promise<boolean>` - True if signature is valid
|
|
771
|
+
|
|
772
|
+
**Example:**
|
|
773
|
+
```javascript
|
|
774
|
+
const isValid = await readOnlyAccount.verify('Hello ERC-4337!', signature)
|
|
775
|
+
console.log('Signature valid:', isValid)
|
|
776
|
+
```
|
|
777
|
+
|
|
671
778
|
## 🌐 Supported Networks
|
|
672
779
|
|
|
673
780
|
This package works with any EVM-compatible blockchain that supports ERC-4337, including:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require('@nomicfoundation/hardhat-ethers')
|
|
2
|
+
|
|
3
|
+
/** @type {import('hardhat/config').HardhatUserConfig} */
|
|
4
|
+
module.exports = {
|
|
5
|
+
networks: {
|
|
6
|
+
hardhat: {
|
|
7
|
+
chainId: 1,
|
|
8
|
+
accounts: {
|
|
9
|
+
mnemonic: 'test test test test test test test test test test test junk',
|
|
10
|
+
path: "m/44'/60'/0'/0",
|
|
11
|
+
initialIndex: 0,
|
|
12
|
+
count: 20,
|
|
13
|
+
accountsBalance: '10000000000000000000000'
|
|
14
|
+
},
|
|
15
|
+
forking: {
|
|
16
|
+
url: 'https://ethereum-rpc.publicnode.com',
|
|
17
|
+
blockNumber: 22897572,
|
|
18
|
+
enabled: true
|
|
19
|
+
},
|
|
20
|
+
mining: {
|
|
21
|
+
autoMine: true,
|
|
22
|
+
interval: [0, 0]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict'
|
|
16
16
|
|
|
17
|
+
/** @typedef {import('@tetherto/wdk-safe-relay-kit').UserOperationReceipt} UserOperationReceipt */
|
|
18
|
+
|
|
17
19
|
/** @typedef {import('@tetherto/wdk-wallet-evm').FeeRates} FeeRates */
|
|
18
20
|
|
|
19
21
|
/** @typedef {import('@tetherto/wdk-wallet-evm').KeyPair} KeyPair */
|
|
@@ -31,3 +33,5 @@ export { default } from './src/wallet-manager-evm-erc-4337.js'
|
|
|
31
33
|
export { default as WalletAccountReadOnlyEvmErc4337 } from './src/wallet-account-read-only-evm-erc-4337.js'
|
|
32
34
|
|
|
33
35
|
export { default as WalletAccountEvmErc4337 } from './src/wallet-account-evm-erc-4337.js'
|
|
36
|
+
|
|
37
|
+
export { ConfigurationError } from './src/errors.js'
|
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.4",
|
|
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",
|
|
@@ -21,23 +21,39 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build:types": "tsc",
|
|
23
23
|
"lint": "standard",
|
|
24
|
-
"lint:fix": "standard --fix"
|
|
24
|
+
"lint:fix": "standard --fix",
|
|
25
|
+
"test": "npm run test:integration",
|
|
26
|
+
"test:integration-wait": "wait-on http://localhost:8545 && cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration --forceExit",
|
|
27
|
+
"test:integration-wait:coverage": "wait-on http://localhost:8545 && cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration --coverage --forceExit",
|
|
28
|
+
"test:integration": "concurrently -k -s first -n \"NODE,TEST\" -c \"black,green\" --hide NODE \"npx hardhat node\" \"npm run test:integration-wait\"",
|
|
29
|
+
"test:integration:coverage": "concurrently -k -s first -n \"NODE,TEST\" -c \"black,green\" --hide NODE \"npx hardhat node\" \"npm run test:integration-wait:coverage\""
|
|
25
30
|
},
|
|
26
31
|
"dependencies": {
|
|
27
|
-
"@tetherto/wdk-wallet": "
|
|
28
|
-
"@tetherto/wdk-wallet-evm": "
|
|
29
|
-
"@wdk-safe-
|
|
30
|
-
"bare-node-runtime": "1.
|
|
32
|
+
"@tetherto/wdk-wallet": "1.0.0-beta.7",
|
|
33
|
+
"@tetherto/wdk-wallet-evm": "1.0.0-beta.6",
|
|
34
|
+
"@tetherto/wdk-safe-relay-kit": "4.1.5",
|
|
35
|
+
"bare-node-runtime": "^1.1.4",
|
|
31
36
|
"ethers": "6.14.4"
|
|
32
37
|
},
|
|
33
38
|
"devDependencies": {
|
|
39
|
+
"@nomicfoundation/hardhat-ethers": "3.1.0",
|
|
40
|
+
"@pimlico/alto": "0.0.19",
|
|
41
|
+
"@pimlico/mock-paymaster": "0.0.4",
|
|
42
|
+
"concurrently": "9.2.0",
|
|
43
|
+
"cross-env": "7.0.3",
|
|
44
|
+
"hardhat": "2.28.4",
|
|
45
|
+
"jest": "29.7.0",
|
|
46
|
+
"prool": "0.0.23",
|
|
34
47
|
"standard": "17.1.2",
|
|
35
|
-
"typescript": "5.8.3"
|
|
48
|
+
"typescript": "5.8.3",
|
|
49
|
+
"wait-on": "8.0.4"
|
|
36
50
|
},
|
|
37
51
|
"overrides": {
|
|
38
|
-
"axios": "1.
|
|
52
|
+
"axios": "1.13.5",
|
|
39
53
|
"cookie": "1.0.2",
|
|
54
|
+
"tar": "7.5.7",
|
|
40
55
|
"tmp": "0.2.5",
|
|
56
|
+
"undici": "7.21.0",
|
|
41
57
|
"ws": "8.18.3"
|
|
42
58
|
},
|
|
43
59
|
"exports": {
|
|
@@ -60,4 +76,4 @@
|
|
|
60
76
|
"tests/**/*.js"
|
|
61
77
|
]
|
|
62
78
|
}
|
|
63
|
-
}
|
|
79
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
'use strict'
|
|
16
|
+
|
|
17
|
+
export class ConfigurationError extends Error {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new configuration error.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} message - The error message.
|
|
22
|
+
*/
|
|
23
|
+
constructor (message) {
|
|
24
|
+
super(message)
|
|
25
|
+
|
|
26
|
+
this.name = 'ConfigurationError'
|
|
27
|
+
}
|
|
28
|
+
}
|