@circle-fin/bridge-kit 1.1.2 → 1.3.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
2
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
3
3
  *
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  *
@@ -400,10 +400,16 @@ type KitContractType = 'bridge';
400
400
  */
401
401
  type KitContracts = Partial<Record<KitContractType, string>>;
402
402
  /**
403
- * Enumeration of all blockchains supported by this library.
403
+ * Enumeration of all blockchains known to this library.
404
+ *
405
+ * This enum contains every blockchain that has a chain definition, regardless
406
+ * of whether bridging is currently supported. For chains that support bridging
407
+ * via CCTPv2, see {@link BridgeChain}.
408
+ *
404
409
  * @enum
405
410
  * @category Enums
406
- * @description Provides string identifiers for each supported blockchain.
411
+ * @description Provides string identifiers for each blockchain with a definition.
412
+ * @see {@link BridgeChain} for the subset of chains that support CCTPv2 bridging.
407
413
  */
408
414
  declare enum Blockchain {
409
415
  Algorand = "Algorand",
@@ -462,6 +468,143 @@ declare enum Blockchain {
462
468
  ZKSync_Era = "ZKSync_Era",
463
469
  ZKSync_Sepolia = "ZKSync_Sepolia"
464
470
  }
471
+ /**
472
+ * Enumeration of blockchains that support cross-chain bridging via CCTPv2.
473
+ *
474
+ * The enum is derived from the full {@link Blockchain} enum but filtered to only
475
+ * include chains with active CCTPv2 support. When new chains gain CCTPv2 support,
476
+ * they are added to this enum.
477
+ *
478
+ * @enum
479
+ * @category Enums
480
+ *
481
+ * @remarks
482
+ * - This enum is the **canonical source** of bridging-supported chains.
483
+ * - Use this enum (or its string literals) in `kit.bridge()` calls for type safety.
484
+ * - Attempting to use a chain not in this enum will produce a TypeScript compile error.
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * import { BridgeKit, BridgeChain } from '@circle-fin/bridge-kit'
489
+ *
490
+ * const kit = new BridgeKit()
491
+ *
492
+ * // ✅ Valid - autocomplete suggests only supported chains
493
+ * await kit.bridge({
494
+ * from: { adapter, chain: BridgeChain.Ethereum },
495
+ * to: { adapter, chain: BridgeChain.Base },
496
+ * amount: '100'
497
+ * })
498
+ *
499
+ * // ✅ Also valid - string literals work with autocomplete
500
+ * await kit.bridge({
501
+ * from: { adapter, chain: 'Ethereum_Sepolia' },
502
+ * to: { adapter, chain: 'Base_Sepolia' },
503
+ * amount: '100'
504
+ * })
505
+ *
506
+ * // ❌ Compile error - Algorand is not in BridgeChain
507
+ * await kit.bridge({
508
+ * from: { adapter, chain: 'Algorand' }, // TypeScript error!
509
+ * to: { adapter, chain: 'Base' },
510
+ * amount: '100'
511
+ * })
512
+ * ```
513
+ *
514
+ * @see {@link Blockchain} for the complete list of all known blockchains.
515
+ * @see {@link BridgeChainIdentifier} for the type that accepts these values.
516
+ */
517
+ declare enum BridgeChain {
518
+ Arbitrum = "Arbitrum",
519
+ Avalanche = "Avalanche",
520
+ Base = "Base",
521
+ Codex = "Codex",
522
+ Ethereum = "Ethereum",
523
+ HyperEVM = "HyperEVM",
524
+ Ink = "Ink",
525
+ Linea = "Linea",
526
+ Optimism = "Optimism",
527
+ Plume = "Plume",
528
+ Polygon = "Polygon",
529
+ Sei = "Sei",
530
+ Solana = "Solana",
531
+ Sonic = "Sonic",
532
+ Unichain = "Unichain",
533
+ World_Chain = "World_Chain",
534
+ XDC = "XDC",
535
+ Arc_Testnet = "Arc_Testnet",
536
+ Arbitrum_Sepolia = "Arbitrum_Sepolia",
537
+ Avalanche_Fuji = "Avalanche_Fuji",
538
+ Base_Sepolia = "Base_Sepolia",
539
+ Codex_Testnet = "Codex_Testnet",
540
+ Ethereum_Sepolia = "Ethereum_Sepolia",
541
+ HyperEVM_Testnet = "HyperEVM_Testnet",
542
+ Ink_Testnet = "Ink_Testnet",
543
+ Linea_Sepolia = "Linea_Sepolia",
544
+ Optimism_Sepolia = "Optimism_Sepolia",
545
+ Plume_Testnet = "Plume_Testnet",
546
+ Polygon_Amoy_Testnet = "Polygon_Amoy_Testnet",
547
+ Sei_Testnet = "Sei_Testnet",
548
+ Solana_Devnet = "Solana_Devnet",
549
+ Sonic_Testnet = "Sonic_Testnet",
550
+ Unichain_Sepolia = "Unichain_Sepolia",
551
+ World_Chain_Sepolia = "World_Chain_Sepolia",
552
+ XDC_Apothem = "XDC_Apothem"
553
+ }
554
+ /**
555
+ * Type representing valid bridge chain identifiers.
556
+ *
557
+ * This type constrains chain parameters to only accept chains that support CCTPv2 bridging
558
+ *
559
+ * Accepts:
560
+ * - A {@link BridgeChain} enum value (e.g., `BridgeChain.Ethereum`)
561
+ * - A string literal matching a BridgeChain value (e.g., `'Ethereum'`)
562
+ * - A {@link ChainDefinition} object for a supported chain
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * import type { BridgeChainIdentifier } from '@circle-fin/bridge-kit'
567
+ * import { BridgeChain } from '@circle-fin/bridge-kit'
568
+ * import { Solana } from '@circle-fin/bridge-kit/chains'
569
+ *
570
+ * // All of these are valid BridgeChainIdentifier values:
571
+ * const chain1: BridgeChainIdentifier = BridgeChain.Ethereum
572
+ * const chain2: BridgeChainIdentifier = 'Base_Sepolia'
573
+ * const chain3: BridgeChainIdentifier = Solana // ChainDefinition
574
+ *
575
+ * // This will cause a TypeScript error:
576
+ * const chain4: BridgeChainIdentifier = 'Algorand' // Error!
577
+ * ```
578
+ *
579
+ * @see {@link BridgeChain} for the enum of supported chains.
580
+ * @see {@link ChainIdentifier} for the less restrictive type accepting all chains.
581
+ */
582
+ type BridgeChainIdentifier = ChainDefinition | BridgeChain | `${BridgeChain}`;
583
+
584
+ /**
585
+ * Resolves a flexible chain identifier to a ChainDefinition.
586
+ *
587
+ * This function handles all three supported formats:
588
+ * - ChainDefinition objects (passed through unchanged)
589
+ * - Blockchain enum values (resolved via getChainByEnum)
590
+ * - String literals of blockchain values (resolved via getChainByEnum)
591
+ *
592
+ * @param chainIdentifier - The chain identifier to resolve
593
+ * @returns The resolved ChainDefinition object
594
+ * @throws Error if the chain identifier cannot be resolved
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * import { resolveChainIdentifier } from '@core/chains'
599
+ * import { Blockchain, Ethereum } from '@core/chains'
600
+ *
601
+ * // All of these resolve to the same ChainDefinition:
602
+ * const chain1 = resolveChainIdentifier(Ethereum)
603
+ * const chain2 = resolveChainIdentifier(Blockchain.Ethereum)
604
+ * const chain3 = resolveChainIdentifier('Ethereum')
605
+ * ```
606
+ */
607
+ declare function resolveChainIdentifier(chainIdentifier: ChainIdentifier): ChainDefinition;
465
608
 
466
609
  /**
467
610
  * Core type definitions for blockchain transaction execution and gas estimation.
@@ -1878,10 +2021,9 @@ declare class ActionRegistry {
1878
2021
  * @param params - The parameters to pass to the action handler.
1879
2022
  * @param context - The resolved operation context with concrete chain and address values.
1880
2023
  * @returns A promise resolving to the prepared chain request.
1881
- *
1882
- * @throws {Error} When action parameter is not a valid string.
2024
+ * @throws {KitError} When the handler execution fails with a structured error.
1883
2025
  * @throws {Error} When no handler is registered for the specified action.
1884
- * @throws {Error} When the handler execution fails.
2026
+ * @throws {Error} When the handler execution fails with an unstructured error.
1885
2027
  *
1886
2028
  * @example
1887
2029
  * ```typescript
@@ -2591,6 +2733,14 @@ interface BridgeResult {
2591
2733
  address: string;
2592
2734
  /** The destination blockchain network */
2593
2735
  chain: ChainDefinition;
2736
+ /**
2737
+ * Optional custom recipient address for minted funds.
2738
+ *
2739
+ * When provided during the bridge operation, minted tokens are sent to this
2740
+ * address instead of the destination address. This field is preserved in the
2741
+ * result for retry operations to maintain consistency with the original burn.
2742
+ */
2743
+ recipientAddress?: string;
2594
2744
  };
2595
2745
  /** Array of steps that were executed during the bridge process */
2596
2746
  steps: BridgeStep[];
@@ -2600,15 +2750,39 @@ interface BridgeResult {
2600
2750
  *
2601
2751
  * This interface provides detailed information about the expected costs
2602
2752
  * for a transfer, including gas fees on different chains and protocol fees.
2753
+ * It also includes the input context (token, amount, source, destination) to
2754
+ * provide a complete view of the transfer being estimated.
2603
2755
  *
2604
2756
  * @example
2605
2757
  * ```typescript
2606
2758
  * const estimate: EstimateResult = await provider.estimate(source, dest, '100')
2759
+ * console.log('Estimating transfer of', estimate.amount, estimate.token)
2760
+ * console.log('From', estimate.source.chain.name, 'to', estimate.destination.chain.name)
2607
2761
  * console.log('Total gas fees:', estimate.gasFees.length)
2608
2762
  * console.log('Protocol fees:', estimate.fees.length)
2609
2763
  * ```
2610
2764
  */
2611
2765
  interface EstimateResult {
2766
+ /** The token being transferred */
2767
+ token: 'USDC';
2768
+ /** The amount being transferred */
2769
+ amount: string;
2770
+ /** Information about the source chain and address */
2771
+ source: {
2772
+ /** The source wallet/contract address */
2773
+ address: string;
2774
+ /** The source blockchain network */
2775
+ chain: Blockchain;
2776
+ };
2777
+ /** Information about the destination chain and address */
2778
+ destination: {
2779
+ /** The destination wallet/contract address */
2780
+ address: string;
2781
+ /** The destination blockchain network */
2782
+ chain: Blockchain;
2783
+ /** Optional custom recipient address for minted funds. */
2784
+ recipientAddress?: string;
2785
+ };
2612
2786
  /** Array of gas fees required for the transfer on different blockchains */
2613
2787
  gasFees: {
2614
2788
  /** The name of the step */
@@ -2680,6 +2854,40 @@ interface BridgeConfig {
2680
2854
  maxFee?: string;
2681
2855
  /**
2682
2856
  * The custom fee to charge for the transfer.
2857
+ *
2858
+ * Whatever value you provide here is **added on top of the transfer amount**. The user must have
2859
+ * enough balance for `amount + customFee`, and the wallet signs for that total on the source
2860
+ * chain. The custom fee is split automatically:
2861
+ *
2862
+ * - 10% routes to Circle.
2863
+ * - 90% routes to your `recipientAddress`.
2864
+ *
2865
+ * The original transfer amount proceeds through CCTPv2 unchanged, and the protocol fee (1–14 bps
2866
+ * in FAST mode, 0% in STANDARD) is taken from that transfer amount.
2867
+ *
2868
+ * @example
2869
+ * ```typescript
2870
+ * import type { BridgeConfig } from '@core/provider'
2871
+ *
2872
+ * const config: BridgeConfig = {
2873
+ * customFee: {
2874
+ * value: '5', // 5 USDC developer fee
2875
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
2876
+ * },
2877
+ * }
2878
+ *
2879
+ * // Fee flow for a 100 USDC transfer with 5 USDC custom fee:
2880
+ * // Source chain (Ethereum):
2881
+ * // - Wallet debits: 105 USDC total (100 transfer + 5 custom fee)
2882
+ * // - Custom fee split: 0.5 USDC (10%) → Circle, 4.5 USDC (90%) → your recipientAddress
2883
+ * // - Amount sent to CCTPv2: 100 USDC (unchanged)
2884
+ * //
2885
+ * // Destination chain (Base):
2886
+ * // - CCTPv2 FAST fee (example: 1 bps): ~0.01 USDC deducted
2887
+ * // - User receives: ~99.99 USDC
2888
+ * //
2889
+ * // Note: Actual CCTP fees vary by route (1-14 bps for FAST, 0 bps for STANDARD)
2890
+ * ```
2683
2891
  */
2684
2892
  customFee?: CustomFee | undefined;
2685
2893
  }
@@ -2722,6 +2930,10 @@ interface CustomFee {
2722
2930
  * bridge transfer. The fee recipient address **must be a valid address for
2723
2931
  * the source chain** of the bridge transfer.
2724
2932
  *
2933
+ * @remarks
2934
+ * Circle automatically receives 10% of every custom fee; the remaining 90% is
2935
+ * sent to this `recipientAddress`.
2936
+ *
2725
2937
  * For example: if bridging from Ethereum to Solana, pass an EVM address like
2726
2938
  * `"0x1234567890123456789012345678901234567890"` because the source chain
2727
2939
  * is Ethereum.
@@ -2744,6 +2956,7 @@ interface CustomFee {
2744
2956
  * and address requirements are enforced at compile time based on adapter capabilities.
2745
2957
  *
2746
2958
  * @typeParam TAdapterCapabilities - The adapter capabilities type to derive address requirements from
2959
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
2747
2960
  *
2748
2961
  * @example
2749
2962
  * ```typescript
@@ -2762,11 +2975,11 @@ interface CustomFee {
2762
2975
  * }
2763
2976
  * ```
2764
2977
  */
2765
- type AdapterContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = {
2978
+ type AdapterContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier = ChainIdentifier> = {
2766
2979
  /** The adapter instance for blockchain operations */
2767
2980
  adapter: Adapter<TAdapterCapabilities>;
2768
2981
  /** The chain reference, which can be a ChainDefinition, Blockchain enum, or string literal */
2769
- chain: ChainIdentifier;
2982
+ chain: TChainIdentifier;
2770
2983
  } & AddressField<ExtractAddressContext<TAdapterCapabilities>>;
2771
2984
  /**
2772
2985
  * Represents a bridge destination with an explicit custom recipient address.
@@ -2777,6 +2990,7 @@ type AdapterContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCa
2777
2990
  * the destination adapter.
2778
2991
  *
2779
2992
  * @typeParam TCapabilities - The adapter capabilities type for the destination adapter
2993
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
2780
2994
  *
2781
2995
  * @remarks
2782
2996
  * The `recipientAddress` must be a valid address format for the destination chain
@@ -2797,7 +3011,7 @@ type AdapterContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCa
2797
3011
  * }
2798
3012
  * ```
2799
3013
  */
2800
- type BridgeDestinationWithAddress<TCapabilities extends AdapterCapabilities = AdapterCapabilities> = AdapterContext<TCapabilities> & {
3014
+ type BridgeDestinationWithAddress<TCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier = ChainIdentifier> = AdapterContext<TCapabilities, TChainIdentifier> & {
2801
3015
  /**
2802
3016
  * The custom recipient address on the destination chain.
2803
3017
  *
@@ -2809,8 +3023,11 @@ type BridgeDestinationWithAddress<TCapabilities extends AdapterCapabilities = Ad
2809
3023
  /**
2810
3024
  * Union type representing a bridge destination.
2811
3025
  * Can be either an AdapterContext (for default recipient) or BridgeDestinationWithAddress (for explicit recipient).
3026
+ *
3027
+ * @typeParam TAdapterCapabilities - The adapter capabilities type for the destination adapter
3028
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
2812
3029
  */
2813
- type BridgeDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = AdapterContext<TAdapterCapabilities> | BridgeDestinationWithAddress<TAdapterCapabilities>;
3030
+ type BridgeDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier = ChainIdentifier> = AdapterContext<TAdapterCapabilities, TChainIdentifier> | BridgeDestinationWithAddress<TAdapterCapabilities, TChainIdentifier>;
2814
3031
  /**
2815
3032
  * Context for retry operations containing source and destination adapter contexts.
2816
3033
  *
@@ -2953,7 +3170,7 @@ declare abstract class BridgingProvider<TProviderActions = Record<string, unknow
2953
3170
  * @param token - The token to bridge (currently only USDC is supported)
2954
3171
  * @param config - Optional bridge configuration including speed and fee settings
2955
3172
  * @returns Promise resolving to the bridge result with transaction details and steps
2956
- * @throws {ValidationError} If the parameters are invalid
3173
+ * @throws {KitError} If the parameters are invalid
2957
3174
  * @throws {UnsupportedRouteError} If the route is not supported
2958
3175
  * @throws {BridgeError} If the bridge operation fails
2959
3176
  *
@@ -2978,7 +3195,7 @@ declare abstract class BridgingProvider<TProviderActions = Record<string, unknow
2978
3195
  *
2979
3196
  * @param params - The bridge parameters for cost estimation
2980
3197
  * @returns Promise resolving to the cost estimate including gas and protocol fees
2981
- * @throws {ValidationError} If the parameters are invalid
3198
+ * @throws {KitError} If the parameters are invalid
2982
3199
  * @throws {UnsupportedRouteError} If the route is not supported
2983
3200
  *
2984
3201
  * @example
@@ -3104,44 +3321,62 @@ declare abstract class BridgingProvider<TProviderActions = Record<string, unknow
3104
3321
  analyzeStepsForRetry(steps: BridgeStep[]): StepAnalysisResult;
3105
3322
  }
3106
3323
 
3324
+ type FeeFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
3325
+ type FeeRecipientFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (feePayoutChain: ChainDefinition, params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
3107
3326
  /**
3108
3327
  * Custom fee policy for BridgeKit.
3109
3328
  *
3110
- * Provides hooks to calculate an absolute fee (in smallest unit string)
3111
- * and to resolve the fee recipient address on the source chain.
3329
+ * Provides hooks to calculate an absolute custom fee and resolve the fee recipient address
3330
+ * on the source chain. The returned fee is **added on top of the transfer amount** (the wallet signs for
3331
+ * `amount + customFee`). Once collected, the custom fee is split:
3332
+ *
3333
+ * - **10%** automatically routes to Circle.
3334
+ * - **90%** routes to your supplied `recipientAddress`.
3335
+ *
3336
+ * The entire transfer amount still flows through CCTPv2, which then charges its own protocol fee.
3337
+ *
3338
+ * Use `computeFee` (recommended) for human-readable amounts, or `calculateFee` (deprecated)
3339
+ * for smallest-unit amounts. Only one should be provided.
3112
3340
  *
3113
3341
  * @example
3114
3342
  * ```typescript
3115
3343
  * import type { CustomFeePolicy, BridgeParams } from '@circle-fin/bridge-kit'
3116
3344
  *
3117
3345
  * const policy: CustomFeePolicy = {
3118
- * // Charge 1 USDC on Solana, 0 on Ethereum, else 2 USDC
3119
- * calculateFee: (params: BridgeParams): string => {
3120
- * if (params.from.chain.type === 'solana') return '1000000'
3121
- * if (params.from.chain.name === 'Ethereum') return '0'
3122
- * return '2000000'
3123
- * },
3124
- * // Return a valid fee recipient for the source chain
3125
- * resolveFeeRecipientAddress: (feePayoutChain): string => {
3126
- * if (feePayoutChain.type === 'solana') {
3127
- * return 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
3128
- * }
3129
- * return '0x1234567890123456789012345678901234567890'
3346
+ * // computeFee receives human-readable amounts (e.g., '100' for 100 USDC)
3347
+ * computeFee: (params: BridgeParams) => {
3348
+ * const amount = parseFloat(params.amount)
3349
+ *
3350
+ * // 1% fee, capped between 5-50 USDC
3351
+ * const fee = Math.min(Math.max(amount * 0.01, 5), 50)
3352
+ * return fee.toFixed(6)
3130
3353
  * },
3354
+ * resolveFeeRecipientAddress: (feePayoutChain) =>
3355
+ * feePayoutChain.type === 'solana'
3356
+ * ? 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
3357
+ * : '0x1234567890123456789012345678901234567890',
3131
3358
  * }
3132
3359
  * ```
3133
3360
  */
3134
- interface CustomFeePolicy {
3361
+ type CustomFeePolicy = {
3135
3362
  /**
3136
3363
  * A function that returns the fee to charge for the bridge transfer.
3137
- * The value returned from the function represents an absolute fee in the smallest unit of the token.
3138
- * It **does not** represent a percentage fee, only an absolute value.
3364
+ * The value returned from the function represents an absolute fee.
3365
+ * The returned fee is **added on top of the transfer amount**. For example, returning
3366
+ * `'5'` (5 USDC) for a 100 USDC transfer causes the wallet to debit 105 USDC total.
3367
+ * CCTPv2 still processes the full 100 USDC transfer amount, while the custom fee is split
3368
+ * 10%/90% between Circle and your fee recipient.
3139
3369
  *
3140
- * For example: if you want to charge 1 USDC, you would return `'1000000'`.
3141
- *
3142
- * Note: returning `'0'` will result in no fee being charged.
3370
+ * @example
3371
+ * ```typescript
3372
+ * computeFee: (params) => {
3373
+ * const amount = parseFloat(params.amount)
3374
+ * return (amount * 0.01).toString() // 1% fee
3375
+ * }
3376
+ * ```
3143
3377
  */
3144
- calculateFee: <TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities>(params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
3378
+ computeFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
3379
+ calculateFee?: never;
3145
3380
  /**
3146
3381
  * A function that returns the fee recipient for a bridge transfer.
3147
3382
  * The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
@@ -3150,18 +3385,27 @@ interface CustomFeePolicy {
3150
3385
  * For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
3151
3386
  * because the source chain of the bridge transfer is Ethereum.
3152
3387
  */
3153
- resolveFeeRecipientAddress: <TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities>(
3388
+ resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
3389
+ } | {
3390
+ computeFee?: never;
3154
3391
  /**
3155
- * The chain definition for the chain on which the fee is paid (the source chain).
3156
- * For example, when bridging from Ethereum to Base, the fee payout chain is Ethereum,
3157
- * since the bridging originates on Ethereum and the fee is taken on the source chain.
3392
+ * Calculate the fee to charge for the bridge transfer using smallest-unit amounts.
3393
+ *
3394
+ * @deprecated Use `computeFee` instead, which receives human-readable amounts.
3395
+ *
3396
+ * The `params.amount` is in smallest units (e.g., `'100000000'` for 100 USDC).
3158
3397
  */
3159
- feePayoutChain: ChainDefinition,
3398
+ calculateFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
3160
3399
  /**
3161
- * The bridge parameters.
3400
+ * A function that returns the fee recipient for a bridge transfer.
3401
+ * The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
3402
+ * The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
3403
+ *
3404
+ * For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
3405
+ * because the source chain of the bridge transfer is Ethereum.
3162
3406
  */
3163
- params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
3164
- }
3407
+ resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
3408
+ };
3165
3409
  /**
3166
3410
  * Parameters for initiating a cross-chain USDC bridge transfer.
3167
3411
  *
@@ -3173,46 +3417,69 @@ interface CustomFeePolicy {
3173
3417
  * - The `config` field allows customization of bridge behavior (e.g., transfer speed).
3174
3418
  * - The `token` field is optional and defaults to 'USDC'; other tokens are not currently supported.
3175
3419
  *
3176
- * @typeParam TChainDefinition - The chain definition type for advanced usage (defaults to {@link ChainDefinition}).
3420
+ * @typeParam TFromAdapterCapabilities - The source adapter capabilities type.
3421
+ * @typeParam TToAdapterCapabilities - The destination adapter capabilities type.
3177
3422
  *
3178
3423
  * @example
3179
3424
  * ```typescript
3425
+ * import { BridgeKit, BridgeChain } from '@circle-fin/bridge-kit'
3426
+ *
3427
+ * const kit = new BridgeKit()
3428
+ *
3429
+ * // Using BridgeChain enum values (full autocomplete support)
3180
3430
  * const params: BridgeParams = {
3181
- * from: { adapter: sourceAdapter, chain: 'Ethereum' },
3182
- * to: { adapter: destAdapter, chain: 'Base' },
3431
+ * from: { adapter: sourceAdapter, chain: BridgeChain.Ethereum },
3432
+ * to: { adapter: destAdapter, chain: BridgeChain.Base },
3183
3433
  * amount: '10.5',
3184
- * // Optional:
3185
3434
  * config: { transferSpeed: 'FAST' },
3186
3435
  * token: 'USDC'
3187
3436
  * }
3188
3437
  *
3189
- * // Or with explicit recipient address:
3438
+ * // Using string literals (also works with autocomplete)
3439
+ * const params2: BridgeParams = {
3440
+ * from: { adapter: sourceAdapter, chain: 'Ethereum_Sepolia' },
3441
+ * to: { adapter: destAdapter, chain: 'Base_Sepolia' },
3442
+ * amount: '10.5'
3443
+ * }
3444
+ *
3445
+ * // With explicit recipient address:
3190
3446
  * const paramsWithAddress: BridgeParams = {
3191
- * from: { adapter: sourceAdapter, chain: 'Ethereum' },
3447
+ * from: { adapter: sourceAdapter, chain: BridgeChain.Ethereum },
3192
3448
  * to: {
3193
3449
  * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
3194
- * adapter: destAdapter, chain: 'Base'
3450
+ * adapter: destAdapter,
3451
+ * chain: BridgeChain.Base
3195
3452
  * },
3196
3453
  * amount: '10.5'
3197
3454
  * }
3455
+ *
3456
+ * // ❌ Compile error - Algorand is not a supported bridge chain
3457
+ * const invalidParams: BridgeParams = {
3458
+ * from: { adapter: sourceAdapter, chain: 'Algorand' }, // TypeScript error!
3459
+ * to: { adapter: destAdapter, chain: 'Base' },
3460
+ * amount: '10.5'
3461
+ * }
3198
3462
  * ```
3463
+ *
3464
+ * @see {@link BridgeChain} for the enum of supported chains.
3465
+ * @see {@link BridgeChainIdentifier} for the type of valid chain values.
3199
3466
  */
3200
3467
  interface BridgeParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
3201
3468
  /**
3202
3469
  * The source adapter context (wallet and chain) for the transfer.
3203
3470
  */
3204
- from: AdapterContext<TFromAdapterCapabilities>;
3471
+ from: AdapterContext<TFromAdapterCapabilities, BridgeChainIdentifier>;
3205
3472
  /**
3206
- * The destination for the transfer, supporting explicit or derived recipient addresses.
3473
+ * The destination for the transfer, supporting explicit or derived recipient addresses
3207
3474
  */
3208
- to: BridgeDestination<TToAdapterCapabilities>;
3475
+ to: BridgeDestination<TToAdapterCapabilities, BridgeChainIdentifier>;
3209
3476
  /**
3210
- * The amount to transfer.
3477
+ * The amount to transfer
3211
3478
  */
3212
3479
  amount: string;
3213
3480
  /**
3214
3481
  * Optional bridge configuration (e.g., transfer speed).
3215
- * If omitted, defaults will be used.
3482
+ * If omitted, defaults will be used
3216
3483
  */
3217
3484
  config?: BridgeConfig;
3218
3485
  /**
@@ -3250,8 +3517,9 @@ declare const getDefaultProviders: () => readonly [CCTPV2BridgingProvider];
3250
3517
  *
3251
3518
  * // Set custom fee policy using the setter method
3252
3519
  * kit.setCustomFeePolicy({
3253
- * calculateFee: (params: BridgeParams): string => {
3254
- * return '1000000' // 1 USDC
3520
+ * computeFee: (params: BridgeParams): string => {
3521
+ * const amount = parseFloat(params.amount)
3522
+ * return (amount * 0.01).toFixed(6) // 1% fee
3255
3523
  * },
3256
3524
  * resolveFeeRecipientAddress: (chain: ChainDefinition): string => {
3257
3525
  * return '0x1234567890123456789012345678901234567890'
@@ -3410,18 +3678,18 @@ type FlexibleBridgingProvider = BridgingProvider<any>;
3410
3678
  *
3411
3679
  * @param params - The bridge parameters containing source, destination, amount, and token
3412
3680
  * @returns Promise resolving to the bridge result with transaction details and steps
3413
- * @throws {ValidationError} If the parameters are invalid
3681
+ * @throws {KitError} If the parameters are invalid
3414
3682
  * @throws {BridgeError} If the bridging process fails
3415
3683
  * @throws {UnsupportedRouteError} If the route is not supported
3416
3684
  *
3417
3685
  * @example
3418
3686
  * ```typescript
3419
3687
  * import { BridgeKit } from '@circle-fin/bridge-kit'
3420
- * import { createAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
3688
+ * import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
3421
3689
  *
3422
3690
  * // Create kit with default CCTPv2 provider
3423
3691
  * const kit = new BridgeKit()
3424
- * const adapter = createAdapterFromPrivateKey({ privateKey: '0x...' })
3692
+ * const adapter = createViemAdapterFromPrivateKey({ privateKey: '0x...' })
3425
3693
  *
3426
3694
  * // Execute cross-chain transfer
3427
3695
  * const result = await kit.bridge({
@@ -3542,18 +3810,18 @@ declare class BridgeKit<TExtraProviders extends FlexibleBridgingProvider[] = []>
3542
3810
  *
3543
3811
  * @param params - The transfer parameters containing source, destination, amount, and token
3544
3812
  * @returns Promise resolving to the transfer result with transaction details and steps
3545
- * @throws {ValidationError} When any parameter validation fails.
3813
+ * @throws {KitError} When any parameter validation fails.
3546
3814
  * @throws {Error} When CCTPv2 does not support the specified route.
3547
3815
  *
3548
3816
  * @example
3549
3817
  * ```typescript
3550
3818
  * import { BridgeKit } from '@circle-fin/bridge-kit'
3551
- * import { createAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
3819
+ * import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
3552
3820
  *
3553
3821
  * const kit = new BridgeKit()
3554
3822
  *
3555
3823
  * // Create a single adapter that can work across chains
3556
- * const adapter = createAdapterFromPrivateKey({
3824
+ * const adapter = createViemAdapterFromPrivateKey({
3557
3825
  * privateKey: process.env.PRIVATE_KEY,
3558
3826
  * })
3559
3827
  *
@@ -3612,10 +3880,14 @@ declare class BridgeKit<TExtraProviders extends FlexibleBridgingProvider[] = []>
3612
3880
  * @example
3613
3881
  * ```typescript
3614
3882
  * import { BridgeKit } from '@circle-fin/bridge-kit'
3615
- * import { createAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
3883
+ * import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
3616
3884
  *
3617
3885
  * const kit = new BridgeKit()
3618
3886
  *
3887
+ * // Create adapters for source and destination chains
3888
+ * const sourceAdapter = createViemAdapterFromPrivateKey({ privateKey: '...' })
3889
+ * const destAdapter = createViemAdapterFromPrivateKey({ privateKey: '...' })
3890
+ *
3619
3891
  * // Assume we have a failed bridge result from a previous operation
3620
3892
  * const failedResult: BridgeResult = {
3621
3893
  * state: 'error',
@@ -3651,7 +3923,7 @@ declare class BridgeKit<TExtraProviders extends FlexibleBridgingProvider[] = []>
3651
3923
  * as the bridge method but stops before execution.
3652
3924
  * @param params - The bridge parameters for cost estimation
3653
3925
  * @returns Promise resolving to detailed cost breakdown including gas estimates
3654
- * @throws {ValidationError} When the parameters are invalid.
3926
+ * @throws {KitError} When the parameters are invalid.
3655
3927
  * @throws {UnsupportedRouteError} When the route is not supported.
3656
3928
  *
3657
3929
  * @example
@@ -3736,40 +4008,61 @@ declare class BridgeKit<TExtraProviders extends FlexibleBridgingProvider[] = []>
3736
4008
  */
3737
4009
  private mergeCustomFeeConfig;
3738
4010
  /**
3739
- * Sets the custom fee policy for the kit.
4011
+ * Resolve the custom fee for a bridge transfer.
4012
+ *
4013
+ * Checks which fee function the user provided and executes accordingly:
4014
+ * - `computeFee`: receives human-readable amounts, returns human-readable fee
4015
+ * - `calculateFee` (deprecated): receives smallest units, returns smallest units
4016
+ *
4017
+ * @param providerParams - The resolved bridge parameters (amounts in smallest units).
4018
+ * @returns The resolved fee in smallest units, or undefined if no fee policy is set.
4019
+ */
4020
+ private resolveFee;
4021
+ /**
4022
+ * Set the custom fee policy for the kit.
3740
4023
  *
3741
- * Ensures the fee is represented in the smallest unit of the token.
3742
- * - If the token is USDC, the fee is converted to base units (6 decimals).
3743
- * - If the token is not USDC, the fee is returned as is.
4024
+ * Use `computeFee` (recommended) for human-readable amounts, or `calculateFee`
4025
+ * (deprecated) for smallest-unit amounts. Only one should be provided.
3744
4026
  *
3745
- * This allows developers to specify the kit-level fee in base units (e.g., USDC: 1, ETH: 0.000001),
3746
- * and the kit will handle conversion to the smallest unit as needed.
4027
+ * ```text
4028
+ * Transfer amount (user input, e.g., 1,000 USDC)
4029
+ * ↓ Wallet signs for transfer + custom fee (e.g., 1,000 + 10 = 1,010 USDC)
4030
+ * ↓ Custom fee split (10% Circle, 90% your recipientAddress wallet)
4031
+ * ↓ Full transfer amount (1,000 USDC) forwarded to CCTPv2
4032
+ * ↓ CCTPv2 protocol fee (e.g., 0.1 USDC) deducted from transfer amount
4033
+ * ↓ User receives funds on destination chain (e.g., 999.9 USDC)
4034
+ * ```
3747
4035
  *
3748
4036
  * @param customFeePolicy - The custom fee policy to set.
3749
- * @throws {ValidationError} If the custom fee policy is invalid or missing required functions
4037
+ * @throws {KitError} If the custom fee policy is invalid or missing required functions
3750
4038
  *
3751
4039
  * @example
3752
4040
  * ```typescript
3753
4041
  * import { BridgeKit } from '@circle-fin/bridge-kit'
3754
- * import { Blockchain } from '@core/chains'
3755
4042
  *
3756
4043
  * const kit = new BridgeKit()
3757
4044
  *
3758
4045
  * kit.setCustomFeePolicy({
3759
- * calculateFee: (params) => {
3760
- * // Return decimal string - kit converts to smallest units automatically
3761
- * // '0.1' becomes '100000' (0.1 USDC with 6 decimals)
3762
- * return params.source.chain.chain === Blockchain.Ethereum_Sepolia
3763
- * ? '0.1' // 0.1 USDC
3764
- * : '0.2'; // 0.2 USDC
4046
+ * // computeFee receives human-readable amounts (e.g., '100' for 100 USDC)
4047
+ * computeFee: (params) => {
4048
+ * const amount = parseFloat(params.amount)
4049
+ *
4050
+ * // 1% fee, bounded to 5-50 USDC
4051
+ * const fee = Math.min(Math.max(amount * 0.01, 5), 50)
4052
+ * return fee.toFixed(6)
3765
4053
  * },
3766
- * resolveFeeRecipientAddress: (feePayoutChain, params) => {
3767
- * // Return valid address for the source chain
3768
- * return params.source.chain.chain === Blockchain.Ethereum_Sepolia
3769
- * ? '0x23f9a5BEA7B92a0638520607407BC7f0310aEeD4'
3770
- * : '0x1E1A18B7bD95bcFcFb4d6E245D289C1e95547b35';
4054
+ * resolveFeeRecipientAddress: (feePayoutChain) => {
4055
+ * return feePayoutChain.type === 'solana'
4056
+ * ? '9xQeWvG816bUx9EP9MnZ4buHh3A6E2dFQa4Xz6V7C7Gn'
4057
+ * : '0x23f9a5BEA7B92a0638520607407BC7f0310aEeD4'
3771
4058
  * },
3772
- * });
4059
+ * })
4060
+ *
4061
+ * // 100 USDC transfer + 5 USDC custom fee results:
4062
+ * // - Wallet signs for 105 USDC total.
4063
+ * // - Circle receives 0.5 USDC (10% share of the custom fee).
4064
+ * // - Your recipientAddress wallet receives 4.5 USDC.
4065
+ * // - CCTPv2 processes 100 USDC and later deducts its own protocol fee.
3773
4066
  * ```
3774
4067
  */
3775
4068
  setCustomFeePolicy(customFeePolicy: CustomFeePolicy): void;
@@ -4197,6 +4490,233 @@ declare class KitError extends Error implements ErrorDetails {
4197
4490
  constructor(details: ErrorDetails);
4198
4491
  }
4199
4492
 
4493
+ /**
4494
+ * Standardized error code ranges for consistent categorization:
4495
+ *
4496
+ * - 1000-1999: INPUT errors - Parameter validation, input format errors
4497
+ * - 3000-3999: NETWORK errors - Internet connectivity, DNS, connection issues
4498
+ * - 4000-4999: RPC errors - Blockchain provider issues, gas estimation, nonce errors
4499
+ * - 5000-5999: ONCHAIN errors - Transaction/simulation failures, gas exhaustion, reverts
4500
+ * - 9000-9999: BALANCE errors - Insufficient funds, token balance, allowance
4501
+ */
4502
+ /**
4503
+ * Standardized error definitions for INPUT type errors.
4504
+ *
4505
+ * Each entry combines the numeric error code, string name, and type
4506
+ * to ensure consistency when creating error instances.
4507
+ *
4508
+ * Error codes follow a hierarchical numbering scheme where the first digit
4509
+ * indicates the error category (1 = INPUT) and subsequent digits provide
4510
+ * specific error identification within that category.
4511
+ *
4512
+ *
4513
+ * @example
4514
+ * ```typescript
4515
+ * import { InputError } from '@core/errors'
4516
+ *
4517
+ * const error = new KitError({
4518
+ * ...InputError.NETWORK_MISMATCH,
4519
+ * recoverability: 'FATAL',
4520
+ * message: 'Source and destination networks must be different'
4521
+ * })
4522
+ *
4523
+ * // Access code, name, and type individually if needed
4524
+ * console.log(InputError.NETWORK_MISMATCH.code) // 1001
4525
+ * console.log(InputError.NETWORK_MISMATCH.name) // 'INPUT_NETWORK_MISMATCH'
4526
+ * console.log(InputError.NETWORK_MISMATCH.type) // 'INPUT'
4527
+ * ```
4528
+ */
4529
+ declare const InputError: {
4530
+ /** Network type mismatch between chains (mainnet vs testnet) */
4531
+ readonly NETWORK_MISMATCH: {
4532
+ readonly code: 1001;
4533
+ readonly name: "INPUT_NETWORK_MISMATCH";
4534
+ readonly type: ErrorType;
4535
+ };
4536
+ /** Invalid amount format or value (negative, zero, or malformed) */
4537
+ readonly INVALID_AMOUNT: {
4538
+ readonly code: 1002;
4539
+ readonly name: "INPUT_INVALID_AMOUNT";
4540
+ readonly type: ErrorType;
4541
+ };
4542
+ /** Unsupported or invalid bridge route configuration */
4543
+ readonly UNSUPPORTED_ROUTE: {
4544
+ readonly code: 1003;
4545
+ readonly name: "INPUT_UNSUPPORTED_ROUTE";
4546
+ readonly type: ErrorType;
4547
+ };
4548
+ /** Invalid wallet or contract address format */
4549
+ readonly INVALID_ADDRESS: {
4550
+ readonly code: 1004;
4551
+ readonly name: "INPUT_INVALID_ADDRESS";
4552
+ readonly type: ErrorType;
4553
+ };
4554
+ /** Invalid or unsupported chain identifier */
4555
+ readonly INVALID_CHAIN: {
4556
+ readonly code: 1005;
4557
+ readonly name: "INPUT_INVALID_CHAIN";
4558
+ readonly type: ErrorType;
4559
+ };
4560
+ /** General validation failure for complex validation rules */
4561
+ readonly VALIDATION_FAILED: {
4562
+ readonly code: 1098;
4563
+ readonly name: "INPUT_VALIDATION_FAILED";
4564
+ readonly type: ErrorType;
4565
+ };
4566
+ };
4567
+ /**
4568
+ * Standardized error definitions for BALANCE type errors.
4569
+ *
4570
+ * BALANCE errors indicate insufficient funds or allowance issues
4571
+ * that prevent transaction execution.
4572
+ *
4573
+ * @example
4574
+ * ```typescript
4575
+ * import { BalanceError } from '@core/errors'
4576
+ *
4577
+ * const error = new KitError({
4578
+ * ...BalanceError.INSUFFICIENT_TOKEN,
4579
+ * recoverability: 'FATAL',
4580
+ * message: 'Insufficient USDC balance on Ethereum',
4581
+ * cause: { trace: { required: '100', available: '50' } }
4582
+ * })
4583
+ * ```
4584
+ */
4585
+ declare const BalanceError: {
4586
+ /** Insufficient token balance for transaction */
4587
+ readonly INSUFFICIENT_TOKEN: {
4588
+ readonly code: 9001;
4589
+ readonly name: "BALANCE_INSUFFICIENT_TOKEN";
4590
+ readonly type: ErrorType;
4591
+ };
4592
+ /** Insufficient native token (ETH/SOL/etc) for gas fees */
4593
+ readonly INSUFFICIENT_GAS: {
4594
+ readonly code: 9002;
4595
+ readonly name: "BALANCE_INSUFFICIENT_GAS";
4596
+ readonly type: ErrorType;
4597
+ };
4598
+ /** Insufficient allowance for token transfer */
4599
+ readonly INSUFFICIENT_ALLOWANCE: {
4600
+ readonly code: 9003;
4601
+ readonly name: "BALANCE_INSUFFICIENT_ALLOWANCE";
4602
+ readonly type: ErrorType;
4603
+ };
4604
+ };
4605
+ /**
4606
+ * Standardized error definitions for ONCHAIN type errors.
4607
+ *
4608
+ * ONCHAIN errors occur during transaction execution, simulation,
4609
+ * or interaction with smart contracts on the blockchain.
4610
+ *
4611
+ * @example
4612
+ * ```typescript
4613
+ * import { OnchainError } from '@core/errors'
4614
+ *
4615
+ * const error = new KitError({
4616
+ * ...OnchainError.SIMULATION_FAILED,
4617
+ * recoverability: 'FATAL',
4618
+ * message: 'Simulation failed: ERC20 transfer amount exceeds balance',
4619
+ * cause: { trace: { reason: 'ERC20: transfer amount exceeds balance' } }
4620
+ * })
4621
+ * ```
4622
+ */
4623
+ declare const OnchainError: {
4624
+ /** Transaction reverted on-chain after execution */
4625
+ readonly TRANSACTION_REVERTED: {
4626
+ readonly code: 5001;
4627
+ readonly name: "ONCHAIN_TRANSACTION_REVERTED";
4628
+ readonly type: ErrorType;
4629
+ };
4630
+ /** Pre-flight transaction simulation failed */
4631
+ readonly SIMULATION_FAILED: {
4632
+ readonly code: 5002;
4633
+ readonly name: "ONCHAIN_SIMULATION_FAILED";
4634
+ readonly type: ErrorType;
4635
+ };
4636
+ /** Transaction ran out of gas during execution */
4637
+ readonly OUT_OF_GAS: {
4638
+ readonly code: 5003;
4639
+ readonly name: "ONCHAIN_OUT_OF_GAS";
4640
+ readonly type: ErrorType;
4641
+ };
4642
+ /** Transaction exceeds block gas limit */
4643
+ readonly GAS_LIMIT_EXCEEDED: {
4644
+ readonly code: 5004;
4645
+ readonly name: "ONCHAIN_GAS_LIMIT_EXCEEDED";
4646
+ readonly type: ErrorType;
4647
+ };
4648
+ };
4649
+ /**
4650
+ * Standardized error definitions for RPC type errors.
4651
+ *
4652
+ * RPC errors occur when communicating with blockchain RPC providers,
4653
+ * including endpoint failures, invalid responses, and provider-specific issues.
4654
+ *
4655
+ * @example
4656
+ * ```typescript
4657
+ * import { RpcError } from '@core/errors'
4658
+ *
4659
+ * const error = new KitError({
4660
+ * ...RpcError.ENDPOINT_ERROR,
4661
+ * recoverability: 'RETRYABLE',
4662
+ * message: 'RPC endpoint unavailable on Ethereum',
4663
+ * cause: { trace: { endpoint: 'https://mainnet.infura.io' } }
4664
+ * })
4665
+ * ```
4666
+ */
4667
+ declare const RpcError: {
4668
+ /** RPC endpoint returned error or is unavailable */
4669
+ readonly ENDPOINT_ERROR: {
4670
+ readonly code: 4001;
4671
+ readonly name: "RPC_ENDPOINT_ERROR";
4672
+ readonly type: ErrorType;
4673
+ };
4674
+ /** Invalid or unexpected RPC response format */
4675
+ readonly INVALID_RESPONSE: {
4676
+ readonly code: 4002;
4677
+ readonly name: "RPC_INVALID_RESPONSE";
4678
+ readonly type: ErrorType;
4679
+ };
4680
+ /** Nonce-related errors from RPC provider */
4681
+ readonly NONCE_ERROR: {
4682
+ readonly code: 4003;
4683
+ readonly name: "RPC_NONCE_ERROR";
4684
+ readonly type: ErrorType;
4685
+ };
4686
+ };
4687
+ /**
4688
+ * Standardized error definitions for NETWORK type errors.
4689
+ *
4690
+ * NETWORK errors indicate connectivity issues at the network layer,
4691
+ * including DNS failures, connection timeouts, and unreachable endpoints.
4692
+ *
4693
+ * @example
4694
+ * ```typescript
4695
+ * import { NetworkError } from '@core/errors'
4696
+ *
4697
+ * const error = new KitError({
4698
+ * ...NetworkError.CONNECTION_FAILED,
4699
+ * recoverability: 'RETRYABLE',
4700
+ * message: 'Failed to connect to Ethereum network',
4701
+ * cause: { trace: { error: 'ECONNREFUSED' } }
4702
+ * })
4703
+ * ```
4704
+ */
4705
+ declare const NetworkError: {
4706
+ /** Network connection failed or unreachable */
4707
+ readonly CONNECTION_FAILED: {
4708
+ readonly code: 3001;
4709
+ readonly name: "NETWORK_CONNECTION_FAILED";
4710
+ readonly type: ErrorType;
4711
+ };
4712
+ /** Network request timeout */
4713
+ readonly TIMEOUT: {
4714
+ readonly code: 3002;
4715
+ readonly name: "NETWORK_TIMEOUT";
4716
+ readonly type: ErrorType;
4717
+ };
4718
+ };
4719
+
4200
4720
  /**
4201
4721
  * Type guard to check if an error is a KitError instance.
4202
4722
  *
@@ -4299,6 +4819,106 @@ declare function isRetryableError(error: unknown): boolean;
4299
4819
  * ```
4300
4820
  */
4301
4821
  declare function isInputError(error: unknown): error is KitError;
4822
+ /**
4823
+ * Type guard to check if error is KitError with BALANCE type.
4824
+ *
4825
+ * BALANCE errors indicate insufficient funds or allowance issues
4826
+ * that prevent transaction execution. These errors are always FATAL
4827
+ * and require the user to add funds or approve more tokens.
4828
+ *
4829
+ * @param error - Unknown error to check
4830
+ * @returns True if error is KitError with BALANCE type
4831
+ *
4832
+ * @example
4833
+ * ```typescript
4834
+ * import { isBalanceError } from '@core/errors'
4835
+ *
4836
+ * try {
4837
+ * await kit.bridge(params)
4838
+ * } catch (error) {
4839
+ * if (isBalanceError(error)) {
4840
+ * console.log('Insufficient funds:', error.message)
4841
+ * showAddFundsUI()
4842
+ * }
4843
+ * }
4844
+ * ```
4845
+ */
4846
+ declare function isBalanceError(error: unknown): error is KitError;
4847
+ /**
4848
+ * Type guard to check if error is KitError with ONCHAIN type.
4849
+ *
4850
+ * ONCHAIN errors occur during transaction execution or simulation,
4851
+ * including reverts, gas issues, and smart contract failures.
4852
+ * These errors are typically FATAL.
4853
+ *
4854
+ * @param error - Unknown error to check
4855
+ * @returns True if error is KitError with ONCHAIN type
4856
+ *
4857
+ * @example
4858
+ * ```typescript
4859
+ * import { isOnchainError } from '@core/errors'
4860
+ *
4861
+ * try {
4862
+ * await kit.bridge(params)
4863
+ * } catch (error) {
4864
+ * if (isOnchainError(error)) {
4865
+ * console.log('Transaction failed:', error.message)
4866
+ * showTransactionErrorUI()
4867
+ * }
4868
+ * }
4869
+ * ```
4870
+ */
4871
+ declare function isOnchainError(error: unknown): error is KitError;
4872
+ /**
4873
+ * Type guard to check if error is KitError with RPC type.
4874
+ *
4875
+ * RPC errors occur when communicating with blockchain RPC providers.
4876
+ * These errors are typically RETRYABLE as they often indicate
4877
+ * temporary provider issues.
4878
+ *
4879
+ * @param error - Unknown error to check
4880
+ * @returns True if error is KitError with RPC type
4881
+ *
4882
+ * @example
4883
+ * ```typescript
4884
+ * import { isRpcError } from '@core/errors'
4885
+ *
4886
+ * try {
4887
+ * await kit.bridge(params)
4888
+ * } catch (error) {
4889
+ * if (isRpcError(error)) {
4890
+ * console.log('RPC error:', error.message)
4891
+ * retryWithBackoff()
4892
+ * }
4893
+ * }
4894
+ * ```
4895
+ */
4896
+ declare function isRpcError(error: unknown): error is KitError;
4897
+ /**
4898
+ * Type guard to check if error is KitError with NETWORK type.
4899
+ *
4900
+ * NETWORK errors indicate connectivity issues at the network layer.
4901
+ * These errors are typically RETRYABLE as they often indicate
4902
+ * temporary network problems.
4903
+ *
4904
+ * @param error - Unknown error to check
4905
+ * @returns True if error is KitError with NETWORK type
4906
+ *
4907
+ * @example
4908
+ * ```typescript
4909
+ * import { isNetworkError } from '@core/errors'
4910
+ *
4911
+ * try {
4912
+ * await kit.bridge(params)
4913
+ * } catch (error) {
4914
+ * if (isNetworkError(error)) {
4915
+ * console.log('Network issue:', error.message)
4916
+ * retryWithBackoff()
4917
+ * }
4918
+ * }
4919
+ * ```
4920
+ */
4921
+ declare function isNetworkError(error: unknown): error is KitError;
4302
4922
  /**
4303
4923
  * Safely extracts error message from any error type.
4304
4924
  *
@@ -4350,5 +4970,5 @@ declare function getErrorMessage(error: unknown): string;
4350
4970
  */
4351
4971
  declare function getErrorCode(error: unknown): number | null;
4352
4972
 
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 };
4973
+ export { BalanceError, Blockchain, BridgeChain, BridgeKit, InputError, KitError, NetworkError, OnchainError, RpcError, TransferSpeed, bridgeParamsWithChainIdentifierSchema, getErrorCode, getErrorMessage, isBalanceError, isFatalError, isInputError, isKitError, isNetworkError, isOnchainError, isRetryableError, isRpcError, resolveChainIdentifier, setExternalPrefix };
4974
+ export type { ActionHandler, AdapterContext, BaseChainDefinition, BridgeChainIdentifier, BridgeConfig, BridgeKitConfig, BridgeParams, BridgeResult, CCTPConfig, CCTPContracts, CCTPMergedConfig, CCTPSplitConfig, ChainDefinition, ChainIdentifier, Currency, CustomFeePolicy, EVMChainDefinition, ErrorDetails, EstimateResult, EstimatedGas, KitContractType, KitContracts, NonEVMChainDefinition, Recoverability, RetryContext, VersionConfig };