@circle-fin/bridge-kit 1.1.0 → 1.1.2

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/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/index.d.ts CHANGED
@@ -596,10 +596,11 @@ interface EvmPreparedChainRequest {
596
596
  * Estimate the gas cost for the contract execution.
597
597
  *
598
598
  * @param overrides - Optional parameters to override the default estimation behavior
599
+ * @param fallback - Optional fallback gas information to use if the estimation fails
599
600
  * @returns A promise that resolves to the estimated gas information
600
601
  * @throws If the estimation fails
601
602
  */
602
- estimate(overrides?: EvmEstimateOverrides): Promise<EstimatedGas>;
603
+ estimate(overrides?: EvmEstimateOverrides, fallback?: EstimatedGas): Promise<EstimatedGas>;
603
604
  /**
604
605
  * Execute the prepared contract call.
605
606
  *
@@ -677,7 +678,7 @@ interface SolanaPreparedChainRequest {
677
678
  /** The type of the chain request. */
678
679
  type: 'solana';
679
680
  /** Estimate the compute units and fee for the transaction. */
680
- estimate(overrides?: SolanaEstimateOverrides): Promise<EstimatedGas>;
681
+ estimate(overrides?: SolanaEstimateOverrides, fallback?: EstimatedGas): Promise<EstimatedGas>;
681
682
  /** Execute the prepared transaction. */
682
683
  execute(overrides?: SolanaExecuteOverrides): Promise<string>;
683
684
  }
@@ -709,7 +710,7 @@ interface NoopPreparedChainRequest {
709
710
  * Placeholder for the estimate method.
710
711
  * @returns The estimated gas cost.
711
712
  */
712
- estimate: () => Promise<EstimatedGas>;
713
+ estimate: (overrides?: EvmEstimateOverrides | SolanaEstimateOverrides, fallback?: EstimatedGas) => Promise<EstimatedGas>;
713
714
  /**
714
715
  * Placeholder for the execute method.
715
716
  * @returns The transaction hash.
@@ -1178,6 +1179,14 @@ interface CCTPv2ActionMap {
1178
1179
  * the adapter's default address.
1179
1180
  */
1180
1181
  readonly destinationAddress?: string;
1182
+ /**
1183
+ * The mint recipient address from the decoded CCTP message.
1184
+ *
1185
+ * This is the actual address encoded in the burn message where tokens will be minted.
1186
+ * For Solana, this is already the Associated Token Account (ATA) address, not the owner.
1187
+ * For EVM chains, this is the recipient's wallet address.
1188
+ */
1189
+ readonly mintRecipient?: string;
1181
1190
  };
1182
1191
  /**
1183
1192
  * Initiate a cross-chain USDC transfer using a custom bridge contract with preapproval funnel.
@@ -1967,10 +1976,23 @@ interface AdapterCapabilities {
1967
1976
  */
1968
1977
  declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
1969
1978
  /**
1970
- * The type of the chain.
1971
- * @example 'evm', 'solana'
1979
+ * The type of the chain for this adapter.
1980
+ *
1981
+ * - For concrete adapters, this should be a real chain type (e.g., `'evm'`, `'solana'`, etc.) from the ChainType union.
1982
+ * - For hybrid adapters (adapters that route to concrete adapters supporting multiple ecosystems),
1983
+ * set this property to the string literal `'hybrid'`.
1984
+ *
1985
+ * Note: `'hybrid'` is not a legal ChainType and should only be used as a marker for multi-ecosystem adapters.
1986
+ * Hybrid adapters do not interact directly with any chain, but instead route requests to a concrete underlying adapter.
1987
+ *
1988
+ * @example
1989
+ * // For an EVM-only adapter:
1990
+ * chainType = 'evm'
1991
+ *
1992
+ * // For a hybrid adapter:
1993
+ * chainType = 'hybrid'
1972
1994
  */
1973
- abstract chainType: ChainType;
1995
+ abstract chainType: ChainType | 'hybrid';
1974
1996
  /**
1975
1997
  * Capabilities of this adapter, defining address control model and supported chains.
1976
1998
  *
@@ -2052,7 +2074,7 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
2052
2074
  * })
2053
2075
  * ```
2054
2076
  */
2055
- prepareAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, ctx?: OperationContext<TAdapterCapabilities>): Promise<PreparedChainRequest>;
2077
+ prepareAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<PreparedChainRequest>;
2056
2078
  /**
2057
2079
  * Prepares a transaction for future gas estimation and execution.
2058
2080
  *
@@ -2106,10 +2128,10 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
2106
2128
  * This address is used as the default sender for transactions
2107
2129
  * and interactions initiated by this adapter.
2108
2130
  *
2109
- * @param chain - Optional chain definition for chain-specific address resolution (used by EVM adapters)
2131
+ * @param chain - The chain to use for address resolution.
2110
2132
  * @returns A promise that resolves to the blockchain address as a string.
2111
2133
  */
2112
- abstract getAddress(chain?: ChainDefinition): Promise<string>;
2134
+ abstract getAddress(chain: ChainDefinition): Promise<string>;
2113
2135
  /**
2114
2136
  * Switches the adapter to operate on the specified chain.
2115
2137
  *
@@ -2180,7 +2202,7 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
2180
2202
  * Validate that the target chain is supported by this adapter.
2181
2203
  *
2182
2204
  * @param targetChain - The chain to validate.
2183
- * @throws Error if the chain is not supported.
2205
+ * @throws KitError with INVALID_CHAIN code if the chain is not supported by this adapter.
2184
2206
  */
2185
2207
  validateChainSupport(targetChain: ChainDefinition): void;
2186
2208
  /**
@@ -2434,6 +2456,49 @@ TChainDefinition extends ChainDefinition = ChainDefinition> {
2434
2456
  */
2435
2457
  chain: TChainDefinition;
2436
2458
  }
2459
+ /**
2460
+ * Wallet context for bridge destinations with optional custom recipient.
2461
+ *
2462
+ * Extends WalletContext to support scenarios where the recipient address
2463
+ * differs from the signer address (e.g., bridging to a third-party wallet).
2464
+ * The signer address is used for transaction authorization, while the
2465
+ * recipient address specifies where the minted funds should be sent.
2466
+ *
2467
+ * @typeParam TAdapterCapabilities - The adapter capabilities type to use for the wallet context.
2468
+ * @typeParam TChainDefinition - The chain definition type to use for the wallet context.
2469
+ *
2470
+ * @example
2471
+ * ```typescript
2472
+ * import type { DestinationWalletContext } from '@core/provider'
2473
+ * import { adapter, blockchain } from './setup'
2474
+ *
2475
+ * // Bridge to a custom recipient address
2476
+ * const destination: DestinationWalletContext = {
2477
+ * adapter,
2478
+ * address: '0x1234...abcd', // Signer address
2479
+ * chain: blockchain,
2480
+ * recipientAddress: '0x9876...fedc' // Custom recipient
2481
+ * }
2482
+ * ```
2483
+ */
2484
+ interface DestinationWalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
2485
+ /**
2486
+ * The chain definition type to use for the wallet context.
2487
+ *
2488
+ * @defaultValue ChainDefinition
2489
+ */
2490
+ TChainDefinition extends ChainDefinition = ChainDefinition> extends WalletContext<TAdapterCapabilities, TChainDefinition> {
2491
+ /**
2492
+ * Optional custom recipient address for minted funds.
2493
+ *
2494
+ * When provided, minted tokens will be sent to this address instead of
2495
+ * the address specified in the wallet context. The wallet context address
2496
+ * is still used for transaction signing and authorization.
2497
+ *
2498
+ * Must be a valid address format for the specified blockchain.
2499
+ */
2500
+ recipientAddress?: string;
2501
+ }
2437
2502
  /**
2438
2503
  * Parameters for executing a cross-chain bridge operation.
2439
2504
  */
@@ -2447,7 +2512,7 @@ TChainDefinition extends ChainDefinition = ChainDefinition> {
2447
2512
  /** The source adapter containing wallet and chain information */
2448
2513
  source: WalletContext<TFromCapabilities, TChainDefinition>;
2449
2514
  /** The destination adapter containing wallet and chain information */
2450
- destination: WalletContext<TToCapabilities, TChainDefinition>;
2515
+ destination: DestinationWalletContext<TToCapabilities, TChainDefinition>;
2451
2516
  /** The amount to transfer (as a string to avoid precision issues) */
2452
2517
  amount: string;
2453
2518
  /** The token to transfer (currently only USDC is supported) */
@@ -4004,6 +4069,15 @@ declare const RECOVERABILITY_VALUES: readonly ["RETRYABLE", "RESUMABLE", "FATAL"
4004
4069
  * - RESUMABLE errors are returned when a flow fails mid-execution but can be continued
4005
4070
  */
4006
4071
  type Recoverability = (typeof RECOVERABILITY_VALUES)[number];
4072
+ /**
4073
+ * Array of valid error type values for validation.
4074
+ * Derived from ERROR_TYPES const object.
4075
+ */
4076
+ declare const ERROR_TYPE_VALUES: ("INPUT" | "BALANCE" | "ONCHAIN" | "RPC" | "NETWORK")[];
4077
+ /**
4078
+ * Error type indicating the category of the error.
4079
+ */
4080
+ type ErrorType = (typeof ERROR_TYPE_VALUES)[number];
4007
4081
  /**
4008
4082
  * Structured error details with consistent properties for programmatic handling.
4009
4083
  *
@@ -4015,7 +4089,8 @@ type Recoverability = (typeof RECOVERABILITY_VALUES)[number];
4015
4089
  * ```typescript
4016
4090
  * const error: ErrorDetails = {
4017
4091
  * code: 1001,
4018
- * name: "NETWORK_MISMATCH",
4092
+ * name: "INPUT_NETWORK_MISMATCH",
4093
+ * type: "INPUT",
4019
4094
  * recoverability: "FATAL",
4020
4095
  * message: "Source and destination networks must be different",
4021
4096
  * cause: {
@@ -4023,15 +4098,31 @@ type Recoverability = (typeof RECOVERABILITY_VALUES)[number];
4023
4098
  * }
4024
4099
  * }
4025
4100
  * ```
4101
+ *
4102
+ * @example
4103
+ * ```typescript
4104
+ * const error: ErrorDetails = {
4105
+ * code: 9001,
4106
+ * name: "BALANCE_INSUFFICIENT_TOKEN",
4107
+ * type: "BALANCE",
4108
+ * recoverability: "FATAL",
4109
+ * message: "Insufficient USDC balance on Ethereum",
4110
+ * cause: {
4111
+ * trace: { token: "USDC", chain: "Ethereum" }
4112
+ * }
4113
+ * }
4114
+ * ```
4026
4115
  */
4027
4116
  interface ErrorDetails {
4028
- /** Numeric identifier following standardized ranges (1000+ for INPUT errors) */
4117
+ /** Numeric identifier following standardized ranges (see error code registry) */
4029
4118
  code: number;
4030
- /** Human-readable ID (e.g., "NETWORK_MISMATCH") */
4119
+ /** Human-readable ID (e.g., "INPUT_NETWORK_MISMATCH", "BALANCE_INSUFFICIENT_TOKEN") */
4031
4120
  name: string;
4121
+ /** Error category indicating where the error originated */
4122
+ type: ErrorType;
4032
4123
  /** Error handling strategy */
4033
4124
  recoverability: Recoverability;
4034
- /** User-friendly explanation with network context */
4125
+ /** User-friendly explanation with context */
4035
4126
  message: string;
4036
4127
  /** Raw error details, context, or the original error that caused this one. */
4037
4128
  cause?: {
@@ -4088,6 +4179,8 @@ declare class KitError extends Error implements ErrorDetails {
4088
4179
  readonly code: number;
4089
4180
  /** Human-readable ID (e.g., "NETWORK_MISMATCH") */
4090
4181
  readonly name: string;
4182
+ /** Error category indicating where the error originated */
4183
+ readonly type: ErrorType;
4091
4184
  /** Error handling strategy */
4092
4185
  readonly recoverability: Recoverability;
4093
4186
  /** Raw error details, context, or the original error that caused this one. */
@@ -4182,31 +4275,25 @@ declare function isFatalError(error: unknown): boolean;
4182
4275
  */
4183
4276
  declare function isRetryableError(error: unknown): boolean;
4184
4277
  /**
4185
- * Combined type guard to check if error is KitError with INPUT type.
4278
+ * Type guard to check if error is KitError with INPUT type.
4186
4279
  *
4187
- * INPUT errors have error codes in the 1000-1099 range and represent
4188
- * validation failures, invalid parameters, or user input problems.
4189
- * These errors are always FATAL and require the user to correct their
4190
- * input before retrying.
4280
+ * INPUT errors represent validation failures, invalid parameters,
4281
+ * or user input problems. These errors are always FATAL and require
4282
+ * the user to correct their input before retrying.
4191
4283
  *
4192
4284
  * @param error - Unknown error to check
4193
- * @returns True if error is KitError with INPUT error code range
4285
+ * @returns True if error is KitError with INPUT type
4194
4286
  *
4195
4287
  * @example
4196
4288
  * ```typescript
4197
4289
  * import { isInputError } from '@core/errors'
4198
- * import { createBridgeKit } from '@core/bridge'
4199
- *
4200
- * async function handleBridge() {
4201
- * const kit = createBridgeKit(config)
4202
- * const params = { amount: '100', from: 'ethereum', to: 'polygon' }
4203
4290
  *
4204
- * try {
4205
- * await kit.bridge(params)
4206
- * } catch (error) {
4207
- * if (isInputError(error)) {
4208
- * console.log(`Input error: ${error.message} (code: ${error.code})`)
4209
- * }
4291
+ * try {
4292
+ * await kit.bridge(params)
4293
+ * } catch (error) {
4294
+ * if (isInputError(error)) {
4295
+ * console.log('Validation error:', error.message)
4296
+ * showValidationUI()
4210
4297
  * }
4211
4298
  * }
4212
4299
  * ```
@@ -4263,5 +4350,5 @@ declare function getErrorMessage(error: unknown): string;
4263
4350
  */
4264
4351
  declare function getErrorCode(error: unknown): number | null;
4265
4352
 
4266
- export { Blockchain, BridgeKit, KitError, bridgeParamsWithChainIdentifierSchema, getErrorCode, getErrorMessage, isFatalError, isInputError, isKitError, isRetryableError, setExternalPrefix };
4267
- export type { ActionHandler, BridgeKitConfig, BridgeParams, BridgeResult, ChainDefinition, ChainIdentifier, ErrorDetails, Recoverability };
4353
+ export { Blockchain, BridgeKit, KitError, TransferSpeed, bridgeParamsWithChainIdentifierSchema, getErrorCode, getErrorMessage, isFatalError, isInputError, isKitError, isRetryableError, setExternalPrefix };
4354
+ export type { ActionHandler, AdapterContext, BridgeConfig, BridgeKitConfig, BridgeParams, BridgeResult, ChainDefinition, ChainIdentifier, CustomFeePolicy, ErrorDetails, EstimateResult, Recoverability };