@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.
- package/README.md +39 -13
- package/index.cjs.js +154 -246
- package/index.d.ts +29 -96
- package/index.mjs +96 -188
- package/package.json +4 -4
package/index.mjs
CHANGED
|
@@ -2441,6 +2441,11 @@ const baseChainDefinitionSchema = z.object({
|
|
|
2441
2441
|
eurcAddress: z.string().nullable(),
|
|
2442
2442
|
usdcAddress: z.string().nullable(),
|
|
2443
2443
|
cctp: z.any().nullable(), // We'll accept any CCTP config structure
|
|
2444
|
+
kitContracts: z
|
|
2445
|
+
.object({
|
|
2446
|
+
bridge: z.string().optional(),
|
|
2447
|
+
})
|
|
2448
|
+
.optional(),
|
|
2444
2449
|
});
|
|
2445
2450
|
/**
|
|
2446
2451
|
* Zod schema for validating EVM chain definitions specifically.
|
|
@@ -2472,13 +2477,15 @@ const baseChainDefinitionSchema = z.object({
|
|
|
2472
2477
|
* }
|
|
2473
2478
|
* ```
|
|
2474
2479
|
*/
|
|
2475
|
-
const evmChainDefinitionSchema = baseChainDefinitionSchema
|
|
2480
|
+
const evmChainDefinitionSchema = baseChainDefinitionSchema
|
|
2481
|
+
.extend({
|
|
2476
2482
|
type: z.literal('evm'),
|
|
2477
2483
|
chainId: z.number({
|
|
2478
2484
|
required_error: 'EVM chains must have a chainId. Please provide a valid EVM chain ID.',
|
|
2479
2485
|
invalid_type_error: 'EVM chain ID must be a number.',
|
|
2480
2486
|
}),
|
|
2481
|
-
})
|
|
2487
|
+
})
|
|
2488
|
+
.strict(); //// Reject any additional properties not defined in the schema
|
|
2482
2489
|
/**
|
|
2483
2490
|
* Zod schema for validating non-EVM chain definitions.
|
|
2484
2491
|
* This schema extends the base schema with non-EVM specific properties.
|
|
@@ -2498,7 +2505,7 @@ const nonEvmChainDefinitionSchema = baseChainDefinitionSchema
|
|
|
2498
2505
|
'polkadot',
|
|
2499
2506
|
]),
|
|
2500
2507
|
})
|
|
2501
|
-
.strict(); // Reject additional properties
|
|
2508
|
+
.strict(); // Reject any additional properties not defined in the schema
|
|
2502
2509
|
/**
|
|
2503
2510
|
* Discriminated union schema for all chain definitions.
|
|
2504
2511
|
* This schema validates different chain types based on their 'type' field.
|
|
@@ -2980,67 +2987,37 @@ class KitError extends Error {
|
|
|
2980
2987
|
}
|
|
2981
2988
|
|
|
2982
2989
|
/**
|
|
2983
|
-
* Standardized error
|
|
2990
|
+
* Standardized error definitions for INPUT type errors.
|
|
2991
|
+
*
|
|
2992
|
+
* Each entry combines the numeric error code with its corresponding
|
|
2993
|
+
* string name to ensure consistency when creating error instances.
|
|
2984
2994
|
*
|
|
2985
2995
|
* Error codes follow a hierarchical numbering scheme where the first digit
|
|
2986
2996
|
* indicates the error category (1 = INPUT) and subsequent digits provide
|
|
2987
2997
|
* specific error identification within that category.
|
|
2988
2998
|
*
|
|
2999
|
+
*
|
|
2989
3000
|
* @example
|
|
2990
3001
|
* ```typescript
|
|
2991
|
-
* import {
|
|
3002
|
+
* import { InputError } from '@core/errors'
|
|
2992
3003
|
*
|
|
2993
3004
|
* const error = new KitError({
|
|
2994
|
-
*
|
|
2995
|
-
* name: InputErrorName.NETWORK_MISMATCH,
|
|
3005
|
+
* ...InputError.NETWORK_MISMATCH,
|
|
2996
3006
|
* recoverability: 'FATAL',
|
|
2997
3007
|
* message: 'Source and destination networks must be different'
|
|
2998
3008
|
* })
|
|
2999
|
-
* ```
|
|
3000
|
-
*/
|
|
3001
|
-
var InputErrorCode;
|
|
3002
|
-
(function (InputErrorCode) {
|
|
3003
|
-
/** Network type mismatch between chains (mainnet vs testnet) */
|
|
3004
|
-
InputErrorCode[InputErrorCode["NETWORK_MISMATCH"] = 1001] = "NETWORK_MISMATCH";
|
|
3005
|
-
/** Invalid amount format or value (negative, zero, or malformed) */
|
|
3006
|
-
InputErrorCode[InputErrorCode["INVALID_AMOUNT"] = 1002] = "INVALID_AMOUNT";
|
|
3007
|
-
/** Unsupported or invalid bridge route configuration */
|
|
3008
|
-
InputErrorCode[InputErrorCode["UNSUPPORTED_ROUTE"] = 1003] = "UNSUPPORTED_ROUTE";
|
|
3009
|
-
/** Invalid wallet or contract address format */
|
|
3010
|
-
InputErrorCode[InputErrorCode["INVALID_ADDRESS"] = 1004] = "INVALID_ADDRESS";
|
|
3011
|
-
/** Invalid or unsupported chain identifier */
|
|
3012
|
-
InputErrorCode[InputErrorCode["INVALID_CHAIN"] = 1005] = "INVALID_CHAIN";
|
|
3013
|
-
/** General validation failure for complex validation rules */
|
|
3014
|
-
InputErrorCode[InputErrorCode["VALIDATION_FAILED"] = 1098] = "VALIDATION_FAILED";
|
|
3015
|
-
})(InputErrorCode || (InputErrorCode = {}));
|
|
3016
|
-
/**
|
|
3017
|
-
* Standardized error names for INPUT type errors.
|
|
3018
|
-
*
|
|
3019
|
-
* These names correspond 1:1 with InputErrorCode and should always
|
|
3020
|
-
* be used together to ensure consistency across error instances.
|
|
3021
3009
|
*
|
|
3022
|
-
*
|
|
3023
|
-
*
|
|
3024
|
-
*
|
|
3025
|
-
*
|
|
3026
|
-
* // Use matching code and name enums
|
|
3027
|
-
* const error = new KitError({
|
|
3028
|
-
* code: InputErrorCode.NETWORK_MISMATCH,
|
|
3029
|
-
* name: InputErrorName.NETWORK_MISMATCH,
|
|
3030
|
-
* recoverability: 'FATAL',
|
|
3031
|
-
* message: 'Network mismatch detected'
|
|
3032
|
-
* })
|
|
3010
|
+
* // Access code and name individually if needed
|
|
3011
|
+
* console.log(InputError.NETWORK_MISMATCH.code) // 1001
|
|
3012
|
+
* console.log(InputError.NETWORK_MISMATCH.name) // 'INPUT_NETWORK_MISMATCH'
|
|
3033
3013
|
* ```
|
|
3034
3014
|
*/
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
InputErrorName["INVALID_CHAIN"] = "INPUT_INVALID_CHAIN";
|
|
3042
|
-
InputErrorName["VALIDATION_FAILED"] = "INPUT_VALIDATION_FAILED";
|
|
3043
|
-
})(InputErrorName || (InputErrorName = {}));
|
|
3015
|
+
const InputError = {
|
|
3016
|
+
/** Unsupported or invalid bridge route configuration */
|
|
3017
|
+
UNSUPPORTED_ROUTE: {
|
|
3018
|
+
code: 1003,
|
|
3019
|
+
name: 'INPUT_UNSUPPORTED_ROUTE',
|
|
3020
|
+
}};
|
|
3044
3021
|
|
|
3045
3022
|
/**
|
|
3046
3023
|
* Creates error for unsupported bridge route.
|
|
@@ -3062,8 +3039,7 @@ var InputErrorName;
|
|
|
3062
3039
|
*/
|
|
3063
3040
|
function createUnsupportedRouteError(source, destination) {
|
|
3064
3041
|
const errorDetails = {
|
|
3065
|
-
|
|
3066
|
-
name: InputErrorName.UNSUPPORTED_ROUTE,
|
|
3042
|
+
...InputError.UNSUPPORTED_ROUTE,
|
|
3067
3043
|
recoverability: 'FATAL',
|
|
3068
3044
|
message: `Route from ${source} to ${destination} is not supported.`,
|
|
3069
3045
|
cause: {
|
|
@@ -3112,26 +3088,6 @@ class Adapter {
|
|
|
3112
3088
|
* ```
|
|
3113
3089
|
*/
|
|
3114
3090
|
capabilities;
|
|
3115
|
-
/**
|
|
3116
|
-
* Default chain for operations when none is explicitly provided.
|
|
3117
|
-
*
|
|
3118
|
-
* This allows adapters to have sensible defaults for chain operations,
|
|
3119
|
-
* reducing the need for explicit chain specification in every call.
|
|
3120
|
-
*
|
|
3121
|
-
* @remarks
|
|
3122
|
-
* This is optional for backward compatibility and because some adapter types
|
|
3123
|
-
* (like developer-controlled adapters) may not have meaningful defaults.
|
|
3124
|
-
*
|
|
3125
|
-
* @example
|
|
3126
|
-
* ```typescript
|
|
3127
|
-
* // User-controlled adapter with default chain
|
|
3128
|
-
* defaultChain = Ethereum
|
|
3129
|
-
*
|
|
3130
|
-
* // Developer-controlled adapter (no default)
|
|
3131
|
-
* defaultChain = undefined
|
|
3132
|
-
* ```
|
|
3133
|
-
*/
|
|
3134
|
-
defaultChain;
|
|
3135
3091
|
/**
|
|
3136
3092
|
* Registry of available actions for this adapter.
|
|
3137
3093
|
*
|
|
@@ -3203,17 +3159,14 @@ class Adapter {
|
|
|
3203
3159
|
* - **Browser wallet adapters**: Request chain switch via EIP-1193 or equivalent
|
|
3204
3160
|
* - **Multi-entity adapters**: Validate chain support (operations are contextual)
|
|
3205
3161
|
*
|
|
3206
|
-
* @param chain - The target chain for operations.
|
|
3162
|
+
* @param chain - The target chain for operations.
|
|
3207
3163
|
* @returns A promise that resolves when the adapter is operating on the specified chain.
|
|
3208
3164
|
* @throws When the target chain is not supported or chain switching fails.
|
|
3209
3165
|
*
|
|
3210
3166
|
* @remarks
|
|
3211
|
-
* This method
|
|
3212
|
-
*
|
|
3213
|
-
*
|
|
3214
|
-
* **Backward Compatibility**: The default implementation provides basic validation but
|
|
3215
|
-
* doesn't perform actual chain switching. Concrete adapter implementations should override
|
|
3216
|
-
* this method to provide proper chain switching logic.
|
|
3167
|
+
* This method always calls `switchToChain()` to ensure consistency across all adapter types.
|
|
3168
|
+
* The underlying implementations handle idempotent switching efficiently (e.g., browser wallets
|
|
3169
|
+
* gracefully handle switching to the current chain, private key adapters recreate lightweight clients).
|
|
3217
3170
|
*
|
|
3218
3171
|
* @example
|
|
3219
3172
|
* ```typescript
|
|
@@ -3227,25 +3180,9 @@ class Adapter {
|
|
|
3227
3180
|
* await circleWalletsAdapter.ensureChain(Ethereum)
|
|
3228
3181
|
* ```
|
|
3229
3182
|
*/
|
|
3230
|
-
async ensureChain(
|
|
3231
|
-
const targetChain = chain ?? this.defaultChain;
|
|
3232
|
-
if (!targetChain) {
|
|
3233
|
-
return;
|
|
3234
|
-
}
|
|
3183
|
+
async ensureChain(targetChain) {
|
|
3235
3184
|
this.validateChainSupport(targetChain);
|
|
3236
|
-
//
|
|
3237
|
-
if (this.capabilities?.addressContext !== 'developer-controlled') {
|
|
3238
|
-
try {
|
|
3239
|
-
const currentChain = await this.getChain();
|
|
3240
|
-
if (currentChain.chain === targetChain.chain) {
|
|
3241
|
-
return; // Already on the correct chain
|
|
3242
|
-
}
|
|
3243
|
-
}
|
|
3244
|
-
catch {
|
|
3245
|
-
// If getChain() fails, we'll proceed with switching anyway
|
|
3246
|
-
}
|
|
3247
|
-
}
|
|
3248
|
-
// Delegate actual switching to the concrete implementation
|
|
3185
|
+
// Always delegate to switchToChain - implementations handle idempotent switching
|
|
3249
3186
|
try {
|
|
3250
3187
|
await this.switchToChain(targetChain);
|
|
3251
3188
|
}
|
|
@@ -3808,7 +3745,6 @@ base58StringSchema.refine((value) => value.length >= 86 && value.length <= 88, '
|
|
|
3808
3745
|
const adapterSchema = z.object({
|
|
3809
3746
|
prepare: z.function(),
|
|
3810
3747
|
waitForTransaction: z.function(),
|
|
3811
|
-
getChain: z.function(),
|
|
3812
3748
|
getAddress: z.function(),
|
|
3813
3749
|
});
|
|
3814
3750
|
|
|
@@ -8444,7 +8380,6 @@ const abiSchema = z
|
|
|
8444
8380
|
* - A chainType property set to 'evm'
|
|
8445
8381
|
* - An actionRegistry with registerHandlers method and actionHandlers record
|
|
8446
8382
|
* - A prepare method for creating chain requests
|
|
8447
|
-
* - A getChain method for retrieving chain configuration
|
|
8448
8383
|
*
|
|
8449
8384
|
* @throws \{ValidationError\} If validation fails, with details about which properties failed
|
|
8450
8385
|
*
|
|
@@ -8461,7 +8396,6 @@ const abiSchema = z
|
|
|
8461
8396
|
* }
|
|
8462
8397
|
* },
|
|
8463
8398
|
* prepare: async (request: any) => ({}),
|
|
8464
|
-
* getChain: async () => ({ name: 'Ethereum', type: 'evm' as const })
|
|
8465
8399
|
* }
|
|
8466
8400
|
*
|
|
8467
8401
|
* const result = evmAdapterSchema.safeParse(validAdapter)
|
|
@@ -8563,6 +8497,44 @@ const evmTransactionHashSchema = z
|
|
|
8563
8497
|
.refine((hash) => /^0x[0-9a-fA-F]{64}$/.test(hash), (hash) => ({
|
|
8564
8498
|
message: `Transaction hash "${hash}" contains invalid characters. Only hexadecimal characters (0-9, a-f, A-F) are allowed after '0x'.`,
|
|
8565
8499
|
}));
|
|
8500
|
+
/**
|
|
8501
|
+
* Zod schema for validating EVM private keys.
|
|
8502
|
+
*
|
|
8503
|
+
* This schema validates private key strings to ensure they are properly formatted:
|
|
8504
|
+
* - Accepts private keys with or without '0x' prefix
|
|
8505
|
+
* - Automatically normalizes by adding '0x' prefix if missing
|
|
8506
|
+
* - Validates that the key is exactly 64 hexadecimal characters (32 bytes)
|
|
8507
|
+
* - Ensures only valid hexadecimal characters (0-9, a-f, A-F) are used
|
|
8508
|
+
*
|
|
8509
|
+
* @remarks
|
|
8510
|
+
* This is a shared schema used by both ethers.v6 and viem.v2 adapters to ensure
|
|
8511
|
+
* consistent private key validation across all EVM adapters.
|
|
8512
|
+
*
|
|
8513
|
+
* @throws \{ValidationError\} If validation fails, with details about the issue
|
|
8514
|
+
*
|
|
8515
|
+
* @example
|
|
8516
|
+
* ```typescript
|
|
8517
|
+
* import { evmPrivateKeySchema } from '@core/adapter-evm/validation'
|
|
8518
|
+
*
|
|
8519
|
+
* // Both formats are accepted and normalized
|
|
8520
|
+
* const keyWithPrefix = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
|
8521
|
+
* const keyWithoutPrefix = '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
|
8522
|
+
*
|
|
8523
|
+
* const result1 = evmPrivateKeySchema.safeParse(keyWithPrefix)
|
|
8524
|
+
* const result2 = evmPrivateKeySchema.safeParse(keyWithoutPrefix)
|
|
8525
|
+
*
|
|
8526
|
+
* // Both succeed and produce the same normalized result with '0x' prefix
|
|
8527
|
+
* ```
|
|
8528
|
+
*/
|
|
8529
|
+
const evmPrivateKeySchema = z
|
|
8530
|
+
.string({
|
|
8531
|
+
required_error: 'Private key is required. Please provide a valid private key.',
|
|
8532
|
+
invalid_type_error: 'Private key must be a string. Please provide a valid private key.',
|
|
8533
|
+
})
|
|
8534
|
+
.transform((val) => (val.startsWith('0x') ? val : `0x${val}`))
|
|
8535
|
+
.pipe(z.string().regex(/^0x[0-9a-fA-F]{64}$/, {
|
|
8536
|
+
message: 'Private key must be a valid 64-character hex string. Please provide a valid private key with or without "0x" prefix.',
|
|
8537
|
+
}));
|
|
8566
8538
|
|
|
8567
8539
|
const assertEvmPreparedChainRequestParamsSymbol = Symbol('assertEvmPreparedChainRequestParams');
|
|
8568
8540
|
/**
|
|
@@ -9331,7 +9303,7 @@ const ethersAdapterOptionsSchema = z.object({
|
|
|
9331
9303
|
* Zod schema for validating parameters to create an EthersAdapter from a private key.
|
|
9332
9304
|
*
|
|
9333
9305
|
* @remarks
|
|
9334
|
-
* - `privateKey`
|
|
9306
|
+
* - `privateKey` can be provided with or without the "0x" prefix. The schema automatically normalizes keys by adding the "0x" prefix if missing before validation.
|
|
9335
9307
|
* - `getProvider` is optional and, if provided, must be a function accepting an object with a `chain` parameter and returning any value.
|
|
9336
9308
|
* - `capabilities` is optional and allows partial overrides with smart defaults.
|
|
9337
9309
|
*
|
|
@@ -9339,27 +9311,22 @@ const ethersAdapterOptionsSchema = z.object({
|
|
|
9339
9311
|
* ```typescript
|
|
9340
9312
|
* import { createAdapterFromPrivateKeyParamsSchema } from '@circle-fin/adapter-ethers-v6/validation'
|
|
9341
9313
|
*
|
|
9342
|
-
*
|
|
9314
|
+
* // Both formats are supported:
|
|
9315
|
+
* const paramsWithPrefix = {
|
|
9343
9316
|
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
|
9344
9317
|
* }
|
|
9345
9318
|
*
|
|
9346
|
-
* const
|
|
9347
|
-
*
|
|
9348
|
-
* console.log('Parameters are valid')
|
|
9349
|
-
* } else {
|
|
9350
|
-
* console.error('Validation failed:', result.error)
|
|
9319
|
+
* const paramsWithoutPrefix = {
|
|
9320
|
+
* privateKey: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
|
9351
9321
|
* }
|
|
9322
|
+
*
|
|
9323
|
+
* const result1 = createAdapterFromPrivateKeyParamsSchema.safeParse(paramsWithPrefix)
|
|
9324
|
+
* const result2 = createAdapterFromPrivateKeyParamsSchema.safeParse(paramsWithoutPrefix)
|
|
9325
|
+
* // Both succeed and produce the same normalized result
|
|
9352
9326
|
* ```
|
|
9353
9327
|
*/
|
|
9354
9328
|
const createAdapterFromPrivateKeyParamsSchema = z.object({
|
|
9355
|
-
privateKey:
|
|
9356
|
-
.string({
|
|
9357
|
-
required_error: 'Private key is required. Please provide a valid private key.',
|
|
9358
|
-
invalid_type_error: 'Private key must be a string. Please provide a valid private key.',
|
|
9359
|
-
})
|
|
9360
|
-
.regex(/^0x[0-9a-fA-F]{64}$/, {
|
|
9361
|
-
message: 'Private key must be a 64-character hexadecimal string prefixed with "0x".',
|
|
9362
|
-
}),
|
|
9329
|
+
privateKey: evmPrivateKeySchema,
|
|
9363
9330
|
getProvider: z
|
|
9364
9331
|
.function()
|
|
9365
9332
|
.args(z.object({ chain: z.unknown() }))
|
|
@@ -9468,28 +9435,6 @@ z.object({
|
|
|
9468
9435
|
function validateEthersAdapterOptions(options) {
|
|
9469
9436
|
validate(options, ethersAdapterOptionsSchema, 'EthersAdapterOptions');
|
|
9470
9437
|
}
|
|
9471
|
-
/**
|
|
9472
|
-
* Validates parameters for creating an Ethers adapter from a private key.
|
|
9473
|
-
*
|
|
9474
|
-
* This function validates the parameters used by the createAdapterFromPrivateKey
|
|
9475
|
-
* factory function for the Ethers adapter.
|
|
9476
|
-
*
|
|
9477
|
-
* @param params - The parameters to validate. Must include a `privateKey` string and optionally a `getProvider` function and `capabilities`.
|
|
9478
|
-
* @throws \{ValidationError\} If validation fails.
|
|
9479
|
-
* @example
|
|
9480
|
-
* ```typescript
|
|
9481
|
-
* import { validateCreateAdapterFromPrivateKeyParams } from '@circle-fin/adapter-ethers-v6/validation'
|
|
9482
|
-
*
|
|
9483
|
-
* const params = {
|
|
9484
|
-
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
|
9485
|
-
* }
|
|
9486
|
-
*
|
|
9487
|
-
* validateCreateAdapterFromPrivateKeyParams(params) // throws if invalid
|
|
9488
|
-
* ```
|
|
9489
|
-
*/
|
|
9490
|
-
function validateCreateAdapterFromPrivateKeyParams(params) {
|
|
9491
|
-
validate(params, createAdapterFromPrivateKeyParamsSchema, 'CreateAdapterFromPrivateKeyParams');
|
|
9492
|
-
}
|
|
9493
9438
|
/**
|
|
9494
9439
|
* Validates parameters for creating an Ethers adapter from an EIP-1193 provider.
|
|
9495
9440
|
*
|
|
@@ -10046,45 +9991,6 @@ class EthersAdapter extends EvmAdapter {
|
|
|
10046
9991
|
const address = await signer.getAddress();
|
|
10047
9992
|
return address;
|
|
10048
9993
|
}
|
|
10049
|
-
/**
|
|
10050
|
-
* Gets the current chain definition.
|
|
10051
|
-
*
|
|
10052
|
-
* TEMP This method is temporary and will be removed once all adapters migrate to the OperationContext pattern.
|
|
10053
|
-
*
|
|
10054
|
-
* **Migration Guide:**
|
|
10055
|
-
*
|
|
10056
|
-
* With the OperationContext pattern, chain information is provided explicitly in each operation
|
|
10057
|
-
* rather than queried from the adapter. This eliminates ambiguity and enables seamless multi-chain
|
|
10058
|
-
* operations with a single adapter instance.
|
|
10059
|
-
*
|
|
10060
|
-
* **Before (Deprecated):**
|
|
10061
|
-
* ```typescript
|
|
10062
|
-
* const chain = await adapter.getChain()
|
|
10063
|
-
* const prepared = await adapter.prepare(params) // Uses cached chain
|
|
10064
|
-
* ```
|
|
10065
|
-
*
|
|
10066
|
-
* **After (OperationContext):**
|
|
10067
|
-
* ```typescript
|
|
10068
|
-
* // Chain specified explicitly per operation
|
|
10069
|
-
* const prepared = await adapter.prepare(params, { chain: 'Ethereum' })
|
|
10070
|
-
*
|
|
10071
|
-
* // Multi-chain operations with same adapter
|
|
10072
|
-
* const ethPrepared = await adapter.prepare(params, { chain: 'Ethereum' })
|
|
10073
|
-
* const basePrepared = await adapter.prepare(params, { chain: 'Base' })
|
|
10074
|
-
* ```
|
|
10075
|
-
*
|
|
10076
|
-
* @returns A promise that resolves to the first supported chain from capabilities
|
|
10077
|
-
* @throws Error when no supported chains are configured
|
|
10078
|
-
*/
|
|
10079
|
-
async getChain() {
|
|
10080
|
-
// Fallback: return first supported chain (deprecated - only for backward compatibility)
|
|
10081
|
-
const firstChain = this.capabilities?.supportedChains?.[0];
|
|
10082
|
-
if (!firstChain) {
|
|
10083
|
-
throw new Error('No supported chains configured. ' +
|
|
10084
|
-
'This method is deprecated - use OperationContext pattern instead.');
|
|
10085
|
-
}
|
|
10086
|
-
return await Promise.resolve(firstChain);
|
|
10087
|
-
}
|
|
10088
9994
|
/**
|
|
10089
9995
|
* Waits for a transaction to be mined and confirmed on the blockchain.
|
|
10090
9996
|
*
|
|
@@ -10359,16 +10265,17 @@ class EthersAdapter extends EvmAdapter {
|
|
|
10359
10265
|
* ```typescript
|
|
10360
10266
|
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
|
|
10361
10267
|
*
|
|
10362
|
-
* //
|
|
10363
|
-
* const
|
|
10364
|
-
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
|
10365
|
-
*
|
|
10366
|
-
*
|
|
10367
|
-
*
|
|
10268
|
+
* // Both private key formats are supported (with or without '0x' prefix):
|
|
10269
|
+
* const adapter1 = createAdapterFromPrivateKey({
|
|
10270
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' // With prefix
|
|
10271
|
+
* })
|
|
10272
|
+
*
|
|
10273
|
+
* const adapter2 = createAdapterFromPrivateKey({
|
|
10274
|
+
* privateKey: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' // Without prefix (automatically normalized)
|
|
10368
10275
|
* })
|
|
10369
10276
|
*
|
|
10370
10277
|
* // Chain specified per-operation via OperationContext
|
|
10371
|
-
* const prepared = await
|
|
10278
|
+
* const prepared = await adapter1.prepare({
|
|
10372
10279
|
* address: '0x...',
|
|
10373
10280
|
* abi: contractAbi,
|
|
10374
10281
|
* functionName: 'transfer',
|
|
@@ -10427,9 +10334,9 @@ class EthersAdapter extends EvmAdapter {
|
|
|
10427
10334
|
* ```
|
|
10428
10335
|
*/
|
|
10429
10336
|
function createAdapterFromPrivateKey(params) {
|
|
10430
|
-
//
|
|
10431
|
-
|
|
10432
|
-
const {
|
|
10337
|
+
// Parse and validate input parameters at runtime (normalizes the private key by adding '0x' prefix if missing)
|
|
10338
|
+
const { privateKey } = createAdapterFromPrivateKeyParamsSchema.parse(params);
|
|
10339
|
+
const { getProvider, capabilities } = params;
|
|
10433
10340
|
// Resolve capabilities with default configuration
|
|
10434
10341
|
const resolvedCapabilities = createAdapterCapabilities('evm', capabilities);
|
|
10435
10342
|
// Validate that capabilities are appropriate for private key adapters
|
|
@@ -10444,6 +10351,7 @@ function createAdapterFromPrivateKey(params) {
|
|
|
10444
10351
|
const getProviderFn = getProvider ?? getDefaultProviderUtil(new Map());
|
|
10445
10352
|
// Create wallet WITHOUT provider (lazy initialization)
|
|
10446
10353
|
// The wallet will be connected to a provider when ensureChain is called
|
|
10354
|
+
// Type assertion safe because we normalized the private key in the schema
|
|
10447
10355
|
const wallet = new Wallet(privateKey);
|
|
10448
10356
|
// Create and return the adapter
|
|
10449
10357
|
return new EthersAdapter({
|
|
@@ -10552,13 +10460,13 @@ function createAdapterFromPrivateKey(params) {
|
|
|
10552
10460
|
* ```typescript
|
|
10553
10461
|
* // Cross-chain transfer using a single adapter
|
|
10554
10462
|
* import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
|
|
10555
|
-
* import {
|
|
10463
|
+
* import { BridgeKit } from '@circle-fin/bridge-kit'
|
|
10556
10464
|
*
|
|
10557
10465
|
* const adapter = await createAdapterFromProvider({
|
|
10558
10466
|
* provider: window.ethereum
|
|
10559
10467
|
* })
|
|
10560
10468
|
*
|
|
10561
|
-
* const kit = new
|
|
10469
|
+
* const kit = new BridgeKit()
|
|
10562
10470
|
*
|
|
10563
10471
|
* // Use the same adapter for both source and destination
|
|
10564
10472
|
* const result = await kit.bridge({
|
|
@@ -10621,5 +10529,5 @@ const createAdapterFromProvider = async (params) => {
|
|
|
10621
10529
|
}, resolvedCapabilities);
|
|
10622
10530
|
};
|
|
10623
10531
|
|
|
10624
|
-
export { EthersAdapter, createAdapterFromPrivateKey, createAdapterFromProvider, validateAdapterCapabilities };
|
|
10532
|
+
export { Blockchain, EthersAdapter, createAdapterFromPrivateKey, createAdapterFromProvider, validateAdapterCapabilities };
|
|
10625
10533
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@circle-fin/adapter-ethers-v6",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"main": "./index.cjs.js",
|
|
5
5
|
"module": "./index.mjs",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"abitype": "^1.1.0",
|
|
9
|
+
"@solana/web3.js": "^1.98.4",
|
|
10
10
|
"zod": "3.25.67",
|
|
11
11
|
"@ethersproject/address": "^5.8.0",
|
|
12
12
|
"@ethersproject/bytes": "^5.8.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"bs58": "6.0.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"ethers": "6.
|
|
17
|
+
"ethers": "^6.11.0"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
"./package.json": "./package.json",
|