@circle-fin/bridge-kit 1.2.0 → 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/CHANGELOG.md +13 -0
- package/chains.cjs +1 -1
- package/chains.d.ts +1 -1
- package/chains.mjs +1 -1
- package/index.cjs +359 -53
- package/index.d.ts +354 -3
- package/index.mjs +351 -54
- package/package.json +14 -2
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*
|
|
@@ -2750,15 +2750,39 @@ interface BridgeResult {
|
|
|
2750
2750
|
*
|
|
2751
2751
|
* This interface provides detailed information about the expected costs
|
|
2752
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.
|
|
2753
2755
|
*
|
|
2754
2756
|
* @example
|
|
2755
2757
|
* ```typescript
|
|
2756
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)
|
|
2757
2761
|
* console.log('Total gas fees:', estimate.gasFees.length)
|
|
2758
2762
|
* console.log('Protocol fees:', estimate.fees.length)
|
|
2759
2763
|
* ```
|
|
2760
2764
|
*/
|
|
2761
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
|
+
};
|
|
2762
2786
|
/** Array of gas fees required for the transfer on different blockchains */
|
|
2763
2787
|
gasFees: {
|
|
2764
2788
|
/** The name of the step */
|
|
@@ -4466,6 +4490,233 @@ declare class KitError extends Error implements ErrorDetails {
|
|
|
4466
4490
|
constructor(details: ErrorDetails);
|
|
4467
4491
|
}
|
|
4468
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
|
+
|
|
4469
4720
|
/**
|
|
4470
4721
|
* Type guard to check if an error is a KitError instance.
|
|
4471
4722
|
*
|
|
@@ -4568,6 +4819,106 @@ declare function isRetryableError(error: unknown): boolean;
|
|
|
4568
4819
|
* ```
|
|
4569
4820
|
*/
|
|
4570
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;
|
|
4571
4922
|
/**
|
|
4572
4923
|
* Safely extracts error message from any error type.
|
|
4573
4924
|
*
|
|
@@ -4619,5 +4970,5 @@ declare function getErrorMessage(error: unknown): string;
|
|
|
4619
4970
|
*/
|
|
4620
4971
|
declare function getErrorCode(error: unknown): number | null;
|
|
4621
4972
|
|
|
4622
|
-
export { Blockchain, BridgeChain, BridgeKit, KitError, TransferSpeed, bridgeParamsWithChainIdentifierSchema, getErrorCode, getErrorMessage, isFatalError, isInputError, isKitError, isRetryableError, resolveChainIdentifier, setExternalPrefix };
|
|
4623
|
-
export type { ActionHandler, AdapterContext, BridgeChainIdentifier, 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 };
|