@circle-fin/adapter-ethers-v6 1.1.0 → 1.2.0

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.
Files changed (6) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +64 -52
  3. package/index.cjs +1743 -628
  4. package/index.d.ts +307 -69
  5. package/index.mjs +1742 -629
  6. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @circle-fin/adapter-ethers-v6
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Clearer ethers factory names eliminate aliasing when using multiple adapters. Prefer `createEthersAdapterFromProvider` and `createEthersAdapterFromPrivateKey` over the deprecated generic `createAdapterFromProvider` and `createAdapterFromPrivateKey`. Existing code works unchanged.
8
+
9
+ ### Patch Changes
10
+
11
+ - Validation errors now use standardized error codes for consistent error handling. All validation failures return the same `KitError` structure as other SDK errors.
12
+
13
+ **Migration:** If you're catching validation errors, update your error handling:
14
+ - Check `error.code === 1098` instead of `instanceof ValidationError`
15
+ - Access details via `error.cause?.trace?.validationErrors` instead of `error.errors`
16
+
17
+ The legacy `ValidationError` class remains available for backward compatibility.
18
+
19
+ - Fixed an issue where custom RPC URLs were not fully respected in Ethers adapter, ensuring users can now properly configure alternative RPC endpoints.
20
+ - Fixed unnecessary chain switching in EthersAdapter that was causing redundant provider reconnections and wallet prompts. The adapter now checks the current chain ID before attempting to switch, skipping the operation when already on the target chain. This improves performance for dev-controlled wallets and reduces unnecessary wallet prompts for browser users (MetaMask, WalletConnect, etc.) when performing multiple operations on the same chain.
21
+
22
+ ## 1.1.1
23
+
24
+ ### Patch Changes
25
+
26
+ - Fixed adapter `getAddress()` types to match function logic by requiring a `chain` parameter, and updated documentation accordingly.
27
+ - Improved error handling with more informative and consistent error messages.
28
+
29
+ Errors now include:
30
+ - Specific error codes for programmatic handling
31
+ - Error type categorization (BALANCE, ONCHAIN, RPC, NETWORK)
32
+ - Recoverability information (FATAL vs RETRYABLE)
33
+ - Clearer error messages with chain context
34
+ - Original error details preserved for debugging
35
+
36
+ - Fixed bug where tokens could be burned when bridging to unsupported chains. Bridge operations now fail immediately if the adapter doesn't support the source or destination chain, before any tokens are approved or burned. Error messages now clearly list all supported chains when an unsupported chain is used, and chain validation errors use the correct `INVALID_CHAIN` error code instead of `UNSUPPORTED_ROUTE`.
37
+
3
38
  ## 1.1.0
4
39
 
5
40
  ### Minor Changes
package/README.md CHANGED
@@ -14,34 +14,46 @@ _Seamlessly interact with 16+ EVM networks using a single, strongly-typed interf
14
14
 
15
15
  ## Table of Contents
16
16
 
17
- - [Overview](#overview)
18
- - [Why Ethers v6 Adapter?](#why-ethers-v6-adapter)
19
- - [When to Use This Adapter](#when-to-use-this-adapter)
20
- - [Installation](#installation)
21
- - [Quick Start](#quick-start)
22
- - [Zero-Config Setup (Recommended)](#zero-config-setup-recommended)
23
- - [Production Setup](#production-setup)
24
- - [Browser Wallet Setup](#browser-wallet-setup)
25
- - [OperationContext Pattern](#operationcontext-pattern)
26
- - [Why OperationContext?](#why-operationcontext)
27
- - [Basic Usage](#basic-usage)
28
- - [Multi-Chain Operations](#multi-chain-operations)
29
- - [Address Context Guide](#address-context-guide)
30
- - [User-Controlled (Recommended)](#user-controlled-recommended)
31
- - [Developer-Controlled (Advanced)](#developer-controlled-advanced)
32
- - [Decision Matrix](#decision-matrix)
33
- - [Usage Examples](#usage-examples)
34
- - [Contract Interactions](#contract-interactions)
35
- - [EIP-712 Signatures](#eip-712-signatures)
36
- - [Cross-Chain Bridging](#cross-chain-bridging)
37
- - [API Reference](#api-reference)
38
- - [Factory Functions](#factory-functions)
39
- - [Core Methods](#core-methods)
40
- - [Token Operations](#token-operations)
41
- - [Migration Guide](#migration-guide)
42
- - [Supported Chains](#supported-chains)
43
- - [Development](#development)
44
- - [License](#license)
17
+ - [Ethers v6 Adapter](#ethers-v6-adapter)
18
+ - [Table of Contents](#table-of-contents)
19
+ - [Overview](#overview)
20
+ - [Why Ethers v6 Adapter?](#why-ethers-v6-adapter)
21
+ - [When to Use This Adapter](#when-to-use-this-adapter)
22
+ - [For Kit Users](#for-kit-users)
23
+ - [For Kit Provider Developers](#for-kit-provider-developers)
24
+ - [Installation](#installation)
25
+ - [Peer Dependencies](#peer-dependencies)
26
+ - [Troubleshooting Version Conflicts](#troubleshooting-version-conflicts)
27
+ - [Quick Start](#quick-start)
28
+ - [Zero-Config Setup (Recommended)](#zero-config-setup-recommended)
29
+ - [Production Setup](#production-setup)
30
+ - [Browser Wallet Setup](#browser-wallet-setup)
31
+ - [OperationContext Pattern](#operationcontext-pattern)
32
+ - [Why OperationContext?](#why-operationcontext)
33
+ - [Basic Usage](#basic-usage)
34
+ - [Multi-Chain Operations](#multi-chain-operations)
35
+ - [Address Context Guide](#address-context-guide)
36
+ - [User-Controlled (Recommended)](#user-controlled-recommended)
37
+ - [Developer-Controlled (Advanced)](#developer-controlled-advanced)
38
+ - [Usage Examples](#usage-examples)
39
+ - [Contract Interactions](#contract-interactions)
40
+ - [EIP-712 Signatures](#eip-712-signatures)
41
+ - [Cross-Chain Bridging](#cross-chain-bridging)
42
+ - [API Reference](#api-reference)
43
+ - [Factory Functions](#factory-functions)
44
+ - [`createEthersAdapterFromPrivateKey(params)`](#createethersadapterfromprivatekeyparams)
45
+ - [`createEthersAdapterFromProvider(params)`](#createethersadapterfromproviderparams)
46
+ - [Core Methods](#core-methods)
47
+ - [`prepare(params, ctx)`](#prepareparams-ctx)
48
+ - [`signTypedData(typedData, ctx)`](#signtypeddatatypeddata-ctx)
49
+ - [`waitForTransaction(txHash, config?)`](#waitfortransactiontxhash-config)
50
+ - [`getAddress(chain)`](#getaddresschain)
51
+ - [Token Operations](#token-operations)
52
+ - [Supported Chains \& Routes](#supported-chains--routes)
53
+ - [Mainnet Chains (17 chains)](#mainnet-chains-17-chains)
54
+ - [Testnet Chains (17 chains)](#testnet-chains-17-chains)
55
+ - [Development](#development)
56
+ - [License](#license)
45
57
 
46
58
  ## Overview
47
59
 
@@ -65,16 +77,16 @@ If you're using the Bridge Kit or other Stablecoin Kits for cross-chain operatio
65
77
  ```typescript
66
78
  // Single adapter instance for multi-chain operations
67
79
  // Note: Private keys can be provided with or without '0x' prefix
68
- const adapter = createAdapterFromPrivateKey({
80
+ const adapter = createEthersAdapterFromPrivateKey({
69
81
  privateKey: process.env.PRIVATE_KEY as `0x${string}`, // Both '0x...' and '...' work
70
82
  })
71
83
 
72
84
  // Both formats are automatically normalized:
73
- const adapter1 = createAdapterFromPrivateKey({
85
+ const adapter1 = createEthersAdapterFromPrivateKey({
74
86
  privateKey: '0x1234...', // With prefix ✅
75
87
  })
76
88
 
77
- const adapter2 = createAdapterFromPrivateKey({
89
+ const adapter2 = createEthersAdapterFromPrivateKey({
78
90
  privateKey: '1234...', // Without prefix ✅ (automatically normalized)
79
91
  })
80
92
  ```
@@ -119,11 +131,11 @@ If you encounter peer dependency warnings:
119
131
  The simplest way to get started with lazy initialization. Default configuration handles adapter setup automatically.
120
132
 
121
133
  ```typescript
122
- import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
134
+ import { createEthersAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
123
135
 
124
136
  // Minimal configuration with lazy initialization
125
137
  // Note: Private keys work with or without '0x' prefix
126
- const adapter = createAdapterFromPrivateKey({
138
+ const adapter = createEthersAdapterFromPrivateKey({
127
139
  privateKey: process.env.PRIVATE_KEY as `0x${string}`, // Both '0x...' and '...' work
128
140
  // Defaults applied:
129
141
  // - addressContext: 'user-controlled'
@@ -150,12 +162,12 @@ const txHash = await prepared.execute()
150
162
  For production use, provide custom RPC endpoints for better reliability and performance:
151
163
 
152
164
  ```typescript
153
- import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
165
+ import { createEthersAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
154
166
  import { JsonRpcProvider } from 'ethers'
155
167
  import { Ethereum, Base, Polygon } from '@core/chains'
156
168
 
157
169
  // Production-ready with custom RPC endpoints and lazy initialization
158
- const adapter = createAdapterFromPrivateKey({
170
+ const adapter = createEthersAdapterFromPrivateKey({
159
171
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
160
172
  // Custom RPC provider with explicit chain mapping
161
173
  getProvider: ({ chain }) => {
@@ -188,10 +200,10 @@ const adapter = createAdapterFromPrivateKey({
188
200
  For browser environments with MetaMask or WalletConnect:
189
201
 
190
202
  ```typescript
191
- import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
203
+ import { createEthersAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
192
204
 
193
205
  // Minimal browser wallet configuration
194
- const adapter = await createAdapterFromProvider({
206
+ const adapter = await createEthersAdapterFromProvider({
195
207
  provider: window.ethereum,
196
208
  // Default capabilities applied automatically
197
209
  })
@@ -227,10 +239,10 @@ The OperationContext pattern is the modern approach for multi-chain operations.
227
239
  Every operation accepts an `OperationContext` parameter that specifies the chain:
228
240
 
229
241
  ```typescript
230
- import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
242
+ import { createEthersAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
231
243
 
232
244
  // Create adapter without specifying a chain - true lazy initialization
233
- const adapter = createAdapterFromPrivateKey({
245
+ const adapter = createEthersAdapterFromPrivateKey({
234
246
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
235
247
  })
236
248
 
@@ -255,7 +267,7 @@ Use a single adapter instance for operations across multiple chains:
255
267
 
256
268
  ```typescript
257
269
  // Create adapter once for use across multiple chains
258
- const adapter = createAdapterFromPrivateKey({
270
+ const adapter = createEthersAdapterFromPrivateKey({
259
271
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
260
272
  })
261
273
 
@@ -305,7 +317,7 @@ The adapter supports two address control patterns. Choose the one that fits your
305
317
 
306
318
  ```typescript
307
319
  // User-controlled adapter (default for factory functions)
308
- const adapter = createAdapterFromPrivateKey({
320
+ const adapter = createEthersAdapterFromPrivateKey({
309
321
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
310
322
  // addressContext: 'user-controlled' is the default
311
323
  })
@@ -373,11 +385,11 @@ const prepared = await adapter.prepare(
373
385
  **Transfer USDC** across different chains with the same adapter:
374
386
 
375
387
  ```typescript
376
- import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
388
+ import { createEthersAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
377
389
  import { parseAbi } from 'ethers'
378
390
 
379
391
  // Create adapter with lazy initialization
380
- const adapter = createAdapterFromPrivateKey({
392
+ const adapter = createEthersAdapterFromPrivateKey({
381
393
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
382
394
  })
383
395
 
@@ -409,9 +421,9 @@ console.log('Transaction hash:', txHash)
409
421
  **Sign permit approvals** for gasless token approvals:
410
422
 
411
423
  ```typescript
412
- import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
424
+ import { createEthersAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
413
425
 
414
- const adapter = createAdapterFromPrivateKey({
426
+ const adapter = createEthersAdapterFromPrivateKey({
415
427
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
416
428
  })
417
429
 
@@ -454,11 +466,11 @@ console.log('Permit signature:', signature)
454
466
  **Bridge USDC** using the Bridge Kit with OperationContext:
455
467
 
456
468
  ```typescript
457
- import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
469
+ import { createEthersAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
458
470
  import { BridgeKit } from '@circle-fin/bridge-kit'
459
471
 
460
472
  // Create adapter for multi-chain operations
461
- const adapter = createAdapterFromPrivateKey({
473
+ const adapter = createEthersAdapterFromPrivateKey({
462
474
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
463
475
  })
464
476
 
@@ -479,7 +491,7 @@ console.log('Bridge transaction:', result.transactionHash)
479
491
 
480
492
  ### Factory Functions
481
493
 
482
- #### `createAdapterFromPrivateKey(params)`
494
+ #### `createEthersAdapterFromPrivateKey(params)`
483
495
 
484
496
  Creates an adapter from a private key for server-side use.
485
497
 
@@ -494,12 +506,12 @@ Creates an adapter from a private key for server-side use.
494
506
  **Note:** No chain required at creation time. The adapter connects to chains lazily on first operation.
495
507
 
496
508
  ```typescript
497
- const adapter = createAdapterFromPrivateKey({
509
+ const adapter = createEthersAdapterFromPrivateKey({
498
510
  privateKey: '0x...',
499
511
  })
500
512
  ```
501
513
 
502
- #### `createAdapterFromProvider(params)`
514
+ #### `createEthersAdapterFromProvider(params)`
503
515
 
504
516
  Creates an adapter from a browser wallet provider (MetaMask, WalletConnect, etc.).
505
517
 
@@ -512,7 +524,7 @@ Creates an adapter from a browser wallet provider (MetaMask, WalletConnect, etc.
512
524
  **Returns:** `Promise<EthersAdapter>` instance
513
525
 
514
526
  ```typescript
515
- const adapter = await createAdapterFromProvider({
527
+ const adapter = await createEthersAdapterFromProvider({
516
528
  provider: window.ethereum,
517
529
  })
518
530
  ```
@@ -574,7 +586,7 @@ Waits for transaction confirmation.
574
586
  const receipt = await adapter.waitForTransaction('0x...')
575
587
  ```
576
588
 
577
- #### `getAddress(chain?)`
589
+ #### `getAddress(chain)`
578
590
 
579
591
  Gets the connected wallet address. Chain parameter is provided automatically by OperationContext resolution.
580
592