@circle-fin/adapter-ethers-v6 0.0.2-alpha.7 → 1.0.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 (5) hide show
  1. package/README.md +39 -13
  2. package/index.cjs.js +154 -246
  3. package/index.d.ts +29 -96
  4. package/index.mjs +96 -188
  5. package/package.json +4 -4
package/index.d.ts CHANGED
@@ -1168,6 +1168,14 @@ interface CCTPv2ActionMap {
1168
1168
  * Destination chain definition where tokens will be minted.
1169
1169
  */
1170
1170
  readonly toChain: ChainDefinitionWithCCTPv2;
1171
+ /**
1172
+ * Optional destination wallet address on the destination chain to receive minted USDC.
1173
+ *
1174
+ * When provided (e.g., for Solana), the mint instruction will derive the
1175
+ * recipient's Associated Token Account (ATA) from this address instead of
1176
+ * the adapter's default address.
1177
+ */
1178
+ readonly destinationAddress?: string;
1171
1179
  };
1172
1180
  /**
1173
1181
  * Initiate a cross-chain USDC transfer using a custom bridge contract with preapproval funnel.
@@ -1525,7 +1533,7 @@ interface USDCActionMap {
1525
1533
  /**
1526
1534
  * Central registry of all available action namespaces and their operations.
1527
1535
  *
1528
- * Define the complete action map structure used throughout the bridging kit.
1536
+ * Define the complete action map structure used throughout the bridge kit.
1529
1537
  * Each top-level key represents a namespace (e.g., 'token', 'usdc') containing
1530
1538
  * related operations. The structure supports arbitrary nesting depth through
1531
1539
  * the recursive utility types provided in this module.
@@ -1618,7 +1626,7 @@ type NestedValue<T, K extends string> = K extends `${infer First}.${infer Rest}`
1618
1626
  *
1619
1627
  * @remarks
1620
1628
  * This type serves as the canonical source for all valid action identifiers
1621
- * in the bridging kit. It ensures compile-time validation of action keys
1629
+ * in the bridge kit. It ensures compile-time validation of action keys
1622
1630
  * and enables type-safe action dispatching throughout the application.
1623
1631
  *
1624
1632
  * @see {@link ActionPayload} for extracting parameter types
@@ -1987,26 +1995,6 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
1987
1995
  * ```
1988
1996
  */
1989
1997
  capabilities?: TAdapterCapabilities;
1990
- /**
1991
- * Default chain for operations when none is explicitly provided.
1992
- *
1993
- * This allows adapters to have sensible defaults for chain operations,
1994
- * reducing the need for explicit chain specification in every call.
1995
- *
1996
- * @remarks
1997
- * This is optional for backward compatibility and because some adapter types
1998
- * (like developer-controlled adapters) may not have meaningful defaults.
1999
- *
2000
- * @example
2001
- * ```typescript
2002
- * // User-controlled adapter with default chain
2003
- * defaultChain = Ethereum
2004
- *
2005
- * // Developer-controlled adapter (no default)
2006
- * defaultChain = undefined
2007
- * ```
2008
- */
2009
- defaultChain?: ChainDefinition;
2010
1998
  /**
2011
1999
  * Registry of available actions for this adapter.
2012
2000
  *
@@ -2120,16 +2108,6 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
2120
2108
  * @returns A promise that resolves to the blockchain address as a string.
2121
2109
  */
2122
2110
  abstract getAddress(chain?: ChainDefinition): Promise<string>;
2123
- /**
2124
- * Retrieves the {@link ChainDefinition} object that describes the blockchain
2125
- * this adapter is configured to interact with.
2126
- *
2127
- * This includes information such as the chain ID, name, native currency, etc.,
2128
- * as defined by the `ChainDefinition` type.
2129
- *
2130
- * @returns A promise that resolves to the {@link ChainDefinition} for the current chain.
2131
- */
2132
- abstract getChain(): Promise<ChainDefinition>;
2133
2111
  /**
2134
2112
  * Switches the adapter to operate on the specified chain.
2135
2113
  *
@@ -2174,17 +2152,14 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
2174
2152
  * - **Browser wallet adapters**: Request chain switch via EIP-1193 or equivalent
2175
2153
  * - **Multi-entity adapters**: Validate chain support (operations are contextual)
2176
2154
  *
2177
- * @param chain - The target chain for operations. If not provided, uses the adapter's defaultChain.
2155
+ * @param chain - The target chain for operations.
2178
2156
  * @returns A promise that resolves when the adapter is operating on the specified chain.
2179
2157
  * @throws When the target chain is not supported or chain switching fails.
2180
2158
  *
2181
2159
  * @remarks
2182
- * This method replaces the pattern of calling `getChain()` to check current chain and then
2183
- * manually switching. It provides a declarative "ensure this chain" interface for operations.
2184
- *
2185
- * **Backward Compatibility**: The default implementation provides basic validation but
2186
- * doesn't perform actual chain switching. Concrete adapter implementations should override
2187
- * this method to provide proper chain switching logic.
2160
+ * This method always calls `switchToChain()` to ensure consistency across all adapter types.
2161
+ * The underlying implementations handle idempotent switching efficiently (e.g., browser wallets
2162
+ * gracefully handle switching to the current chain, private key adapters recreate lightweight clients).
2188
2163
  *
2189
2164
  * @example
2190
2165
  * ```typescript
@@ -2198,7 +2173,7 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
2198
2173
  * await circleWalletsAdapter.ensureChain(Ethereum)
2199
2174
  * ```
2200
2175
  */
2201
- ensureChain(chain?: ChainDefinition): Promise<void>;
2176
+ ensureChain(targetChain: ChainDefinition): Promise<void>;
2202
2177
  /**
2203
2178
  * Validate that the target chain is supported by this adapter.
2204
2179
  *
@@ -2386,19 +2361,6 @@ declare abstract class EvmAdapter<TAdapterCapabilities extends AdapterCapabiliti
2386
2361
  * The type of chain this adapter is for.
2387
2362
  */
2388
2363
  chainType: ChainType;
2389
- /**
2390
- * Cached EVM chain definition.
2391
- *
2392
- * This property holds the most recently synchronized EVM chain definition for the adapter.
2393
- * It is automatically set by `getChain()` and updated via `syncChain()` when provider events
2394
- * (such as wallet chain changes) are detected. Setting this property to `undefined` clears
2395
- * the cached chain, which is useful when resetting adapter state or handling disconnects.
2396
- *
2397
- * @remarks
2398
- * This property narrows the base Adapter's `cachedChain` to the EVM-specific type,
2399
- * ensuring type safety for EVM operations and consumers.
2400
- */
2401
- cachedChain?: EVMChainDefinition;
2402
2364
  /**
2403
2365
  * Cached gas price for the current network.
2404
2366
  */
@@ -2858,37 +2820,6 @@ declare class EthersAdapter<TAdapterCapabilities extends AdapterCapabilities = A
2858
2820
  * ```
2859
2821
  */
2860
2822
  getAddress(chain?: EVMChainDefinition): Promise<string>;
2861
- /**
2862
- * Gets the current chain definition.
2863
- *
2864
- * TEMP This method is temporary and will be removed once all adapters migrate to the OperationContext pattern.
2865
- *
2866
- * **Migration Guide:**
2867
- *
2868
- * With the OperationContext pattern, chain information is provided explicitly in each operation
2869
- * rather than queried from the adapter. This eliminates ambiguity and enables seamless multi-chain
2870
- * operations with a single adapter instance.
2871
- *
2872
- * **Before (Deprecated):**
2873
- * ```typescript
2874
- * const chain = await adapter.getChain()
2875
- * const prepared = await adapter.prepare(params) // Uses cached chain
2876
- * ```
2877
- *
2878
- * **After (OperationContext):**
2879
- * ```typescript
2880
- * // Chain specified explicitly per operation
2881
- * const prepared = await adapter.prepare(params, { chain: 'Ethereum' })
2882
- *
2883
- * // Multi-chain operations with same adapter
2884
- * const ethPrepared = await adapter.prepare(params, { chain: 'Ethereum' })
2885
- * const basePrepared = await adapter.prepare(params, { chain: 'Base' })
2886
- * ```
2887
- *
2888
- * @returns A promise that resolves to the first supported chain from capabilities
2889
- * @throws Error when no supported chains are configured
2890
- */
2891
- getChain(): Promise<ChainDefinition>;
2892
2823
  /**
2893
2824
  * Waits for a transaction to be mined and confirmed on the blockchain.
2894
2825
  *
@@ -3040,9 +2971,10 @@ declare class EthersAdapter<TAdapterCapabilities extends AdapterCapabilities = A
3040
2971
  interface CreateAdapterFromPrivateKeyParams<TCapabilities extends Partial<AdapterCapabilities> = AdapterCapabilities> {
3041
2972
  /**
3042
2973
  * The private key to use for wallet derivation.
3043
- * Must be a valid 32-byte hex string prefixed with '0x'.
2974
+ * Must be a valid 32-byte hex string, with or without '0x' prefix.
2975
+ * If the prefix is omitted, it will be added automatically during validation.
3044
2976
  */
3045
- privateKey: `0x${string}`;
2977
+ privateKey: string;
3046
2978
  /**
3047
2979
  * Optional function to create providers for different chains.
3048
2980
  * If not provided, a default implementation using JsonRpcProvider will be used.
@@ -3115,16 +3047,17 @@ interface CreateAdapterFromPrivateKeyParams<TCapabilities extends Partial<Adapte
3115
3047
  * ```typescript
3116
3048
  * import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
3117
3049
  *
3118
- * // Minimal configuration with lazy initialization
3119
- * const adapter = createAdapterFromPrivateKey({
3120
- * privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
3121
- * // Defaults applied:
3122
- * // - addressContext: 'user-controlled'
3123
- * // - supportedChains: all EVM chains (~29 networks)
3050
+ * // Both private key formats are supported (with or without '0x' prefix):
3051
+ * const adapter1 = createAdapterFromPrivateKey({
3052
+ * privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' // With prefix
3053
+ * })
3054
+ *
3055
+ * const adapter2 = createAdapterFromPrivateKey({
3056
+ * privateKey: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' // Without prefix (automatically normalized)
3124
3057
  * })
3125
3058
  *
3126
3059
  * // Chain specified per-operation via OperationContext
3127
- * const prepared = await adapter.prepare({
3060
+ * const prepared = await adapter1.prepare({
3128
3061
  * address: '0x...',
3129
3062
  * abi: contractAbi,
3130
3063
  * functionName: 'transfer',
@@ -3397,13 +3330,13 @@ interface CreateAdapterFromProviderParams {
3397
3330
  * ```typescript
3398
3331
  * // Cross-chain transfer using a single adapter
3399
3332
  * import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
3400
- * import { BridgingKit } from '@circle-fin/bridging-kit'
3333
+ * import { BridgeKit } from '@circle-fin/bridge-kit'
3401
3334
  *
3402
3335
  * const adapter = await createAdapterFromProvider({
3403
3336
  * provider: window.ethereum
3404
3337
  * })
3405
3338
  *
3406
- * const kit = new BridgingKit()
3339
+ * const kit = new BridgeKit()
3407
3340
  *
3408
3341
  * // Use the same adapter for both source and destination
3409
3342
  * const result = await kit.bridge({
@@ -3471,5 +3404,5 @@ declare const createAdapterFromProvider: (params: CreateAdapterFromProviderParam
3471
3404
  */
3472
3405
  declare function validateAdapterCapabilities(capabilities: AdapterCapabilities): void;
3473
3406
 
3474
- export { EthersAdapter, createAdapterFromPrivateKey, createAdapterFromProvider, validateAdapterCapabilities };
3407
+ export { Blockchain, EthersAdapter, createAdapterFromPrivateKey, createAdapterFromProvider, validateAdapterCapabilities };
3475
3408
  export type { ChainIdentifier, CreateAdapterFromPrivateKeyParams, CreateAdapterFromProviderParams, EthersAdapterOptions };