@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.mjs
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
|
*
|
|
@@ -270,6 +270,40 @@ function validateErrorDetails(details) {
|
|
|
270
270
|
* stays within KitError's constraints.
|
|
271
271
|
*/
|
|
272
272
|
const MAX_MESSAGE_LENGTH = 950;
|
|
273
|
+
/**
|
|
274
|
+
* Standard error message for invalid amount format.
|
|
275
|
+
*
|
|
276
|
+
* The SDK enforces strict dot-decimal notation for amount values. This constant
|
|
277
|
+
* provides a consistent error message when users provide amounts with:
|
|
278
|
+
* - Comma decimals (e.g., "1,5")
|
|
279
|
+
* - Thousand separators (e.g., "1,000.50")
|
|
280
|
+
* - Non-numeric characters
|
|
281
|
+
* - Invalid format
|
|
282
|
+
*/
|
|
283
|
+
const AMOUNT_FORMAT_ERROR_MESSAGE = 'Amount must be a numeric string with dot (.) as decimal separator (e.g., "10.5", "100"), with no thousand separators or comma decimals';
|
|
284
|
+
/**
|
|
285
|
+
* Error message for amounts that must be greater than zero.
|
|
286
|
+
*/
|
|
287
|
+
const AMOUNT_GREATER_THAN_ZERO_MESSAGE = 'Amount must be greater than 0';
|
|
288
|
+
/**
|
|
289
|
+
* Error message for amounts exceeding maximum decimal places.
|
|
290
|
+
*
|
|
291
|
+
* USDC uses 6 decimal places, so amounts with more precision are invalid.
|
|
292
|
+
*/
|
|
293
|
+
const AMOUNT_MAX_DECIMAL_PLACES_MESSAGE = 'Maximum supported decimal places: 6';
|
|
294
|
+
/**
|
|
295
|
+
* Error message for amounts that must be non-negative.
|
|
296
|
+
*
|
|
297
|
+
* Used when validating amounts that can be zero or positive but not negative.
|
|
298
|
+
*/
|
|
299
|
+
const AMOUNT_NON_NEGATIVE_MESSAGE = 'Amount must be non-negative';
|
|
300
|
+
/**
|
|
301
|
+
* Error message for invalid maxFee format.
|
|
302
|
+
*
|
|
303
|
+
* Used when validating the maxFee configuration parameter. The maxFee can be zero
|
|
304
|
+
* or positive and must follow strict dot-decimal notation.
|
|
305
|
+
*/
|
|
306
|
+
const MAX_FEE_FORMAT_ERROR_MESSAGE = 'maxFee must be a numeric string with dot (.) as decimal separator (e.g., "1", "0.5", ".5", "1.5"), with no thousand separators or comma decimals';
|
|
273
307
|
|
|
274
308
|
/**
|
|
275
309
|
* Structured error class for Stablecoin Kit operations.
|
|
@@ -453,6 +487,158 @@ const InputError = {
|
|
|
453
487
|
type: 'INPUT',
|
|
454
488
|
},
|
|
455
489
|
};
|
|
490
|
+
/**
|
|
491
|
+
* Standardized error definitions for BALANCE type errors.
|
|
492
|
+
*
|
|
493
|
+
* BALANCE errors indicate insufficient funds or allowance issues
|
|
494
|
+
* that prevent transaction execution.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* import { BalanceError } from '@core/errors'
|
|
499
|
+
*
|
|
500
|
+
* const error = new KitError({
|
|
501
|
+
* ...BalanceError.INSUFFICIENT_TOKEN,
|
|
502
|
+
* recoverability: 'FATAL',
|
|
503
|
+
* message: 'Insufficient USDC balance on Ethereum',
|
|
504
|
+
* cause: { trace: { required: '100', available: '50' } }
|
|
505
|
+
* })
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
const BalanceError = {
|
|
509
|
+
/** Insufficient token balance for transaction */
|
|
510
|
+
INSUFFICIENT_TOKEN: {
|
|
511
|
+
code: 9001,
|
|
512
|
+
name: 'BALANCE_INSUFFICIENT_TOKEN',
|
|
513
|
+
type: 'BALANCE',
|
|
514
|
+
},
|
|
515
|
+
/** Insufficient native token (ETH/SOL/etc) for gas fees */
|
|
516
|
+
INSUFFICIENT_GAS: {
|
|
517
|
+
code: 9002,
|
|
518
|
+
name: 'BALANCE_INSUFFICIENT_GAS',
|
|
519
|
+
type: 'BALANCE',
|
|
520
|
+
},
|
|
521
|
+
/** Insufficient allowance for token transfer */
|
|
522
|
+
INSUFFICIENT_ALLOWANCE: {
|
|
523
|
+
code: 9003,
|
|
524
|
+
name: 'BALANCE_INSUFFICIENT_ALLOWANCE',
|
|
525
|
+
type: 'BALANCE',
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Standardized error definitions for ONCHAIN type errors.
|
|
530
|
+
*
|
|
531
|
+
* ONCHAIN errors occur during transaction execution, simulation,
|
|
532
|
+
* or interaction with smart contracts on the blockchain.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```typescript
|
|
536
|
+
* import { OnchainError } from '@core/errors'
|
|
537
|
+
*
|
|
538
|
+
* const error = new KitError({
|
|
539
|
+
* ...OnchainError.SIMULATION_FAILED,
|
|
540
|
+
* recoverability: 'FATAL',
|
|
541
|
+
* message: 'Simulation failed: ERC20 transfer amount exceeds balance',
|
|
542
|
+
* cause: { trace: { reason: 'ERC20: transfer amount exceeds balance' } }
|
|
543
|
+
* })
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
const OnchainError = {
|
|
547
|
+
/** Transaction reverted on-chain after execution */
|
|
548
|
+
TRANSACTION_REVERTED: {
|
|
549
|
+
code: 5001,
|
|
550
|
+
name: 'ONCHAIN_TRANSACTION_REVERTED',
|
|
551
|
+
type: 'ONCHAIN',
|
|
552
|
+
},
|
|
553
|
+
/** Pre-flight transaction simulation failed */
|
|
554
|
+
SIMULATION_FAILED: {
|
|
555
|
+
code: 5002,
|
|
556
|
+
name: 'ONCHAIN_SIMULATION_FAILED',
|
|
557
|
+
type: 'ONCHAIN',
|
|
558
|
+
},
|
|
559
|
+
/** Transaction ran out of gas during execution */
|
|
560
|
+
OUT_OF_GAS: {
|
|
561
|
+
code: 5003,
|
|
562
|
+
name: 'ONCHAIN_OUT_OF_GAS',
|
|
563
|
+
type: 'ONCHAIN',
|
|
564
|
+
},
|
|
565
|
+
/** Transaction exceeds block gas limit */
|
|
566
|
+
GAS_LIMIT_EXCEEDED: {
|
|
567
|
+
code: 5004,
|
|
568
|
+
name: 'ONCHAIN_GAS_LIMIT_EXCEEDED',
|
|
569
|
+
type: 'ONCHAIN',
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* Standardized error definitions for RPC type errors.
|
|
574
|
+
*
|
|
575
|
+
* RPC errors occur when communicating with blockchain RPC providers,
|
|
576
|
+
* including endpoint failures, invalid responses, and provider-specific issues.
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```typescript
|
|
580
|
+
* import { RpcError } from '@core/errors'
|
|
581
|
+
*
|
|
582
|
+
* const error = new KitError({
|
|
583
|
+
* ...RpcError.ENDPOINT_ERROR,
|
|
584
|
+
* recoverability: 'RETRYABLE',
|
|
585
|
+
* message: 'RPC endpoint unavailable on Ethereum',
|
|
586
|
+
* cause: { trace: { endpoint: 'https://mainnet.infura.io' } }
|
|
587
|
+
* })
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
const RpcError = {
|
|
591
|
+
/** RPC endpoint returned error or is unavailable */
|
|
592
|
+
ENDPOINT_ERROR: {
|
|
593
|
+
code: 4001,
|
|
594
|
+
name: 'RPC_ENDPOINT_ERROR',
|
|
595
|
+
type: 'RPC',
|
|
596
|
+
},
|
|
597
|
+
/** Invalid or unexpected RPC response format */
|
|
598
|
+
INVALID_RESPONSE: {
|
|
599
|
+
code: 4002,
|
|
600
|
+
name: 'RPC_INVALID_RESPONSE',
|
|
601
|
+
type: 'RPC',
|
|
602
|
+
},
|
|
603
|
+
/** Nonce-related errors from RPC provider */
|
|
604
|
+
NONCE_ERROR: {
|
|
605
|
+
code: 4003,
|
|
606
|
+
name: 'RPC_NONCE_ERROR',
|
|
607
|
+
type: 'RPC',
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Standardized error definitions for NETWORK type errors.
|
|
612
|
+
*
|
|
613
|
+
* NETWORK errors indicate connectivity issues at the network layer,
|
|
614
|
+
* including DNS failures, connection timeouts, and unreachable endpoints.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* import { NetworkError } from '@core/errors'
|
|
619
|
+
*
|
|
620
|
+
* const error = new KitError({
|
|
621
|
+
* ...NetworkError.CONNECTION_FAILED,
|
|
622
|
+
* recoverability: 'RETRYABLE',
|
|
623
|
+
* message: 'Failed to connect to Ethereum network',
|
|
624
|
+
* cause: { trace: { error: 'ECONNREFUSED' } }
|
|
625
|
+
* })
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
const NetworkError = {
|
|
629
|
+
/** Network connection failed or unreachable */
|
|
630
|
+
CONNECTION_FAILED: {
|
|
631
|
+
code: 3001,
|
|
632
|
+
name: 'NETWORK_CONNECTION_FAILED',
|
|
633
|
+
type: 'NETWORK',
|
|
634
|
+
},
|
|
635
|
+
/** Network request timeout */
|
|
636
|
+
TIMEOUT: {
|
|
637
|
+
code: 3002,
|
|
638
|
+
name: 'NETWORK_TIMEOUT',
|
|
639
|
+
type: 'NETWORK',
|
|
640
|
+
},
|
|
641
|
+
};
|
|
456
642
|
|
|
457
643
|
/**
|
|
458
644
|
* Creates error for network type mismatch between source and destination.
|
|
@@ -3413,6 +3599,114 @@ function isRetryableError(error) {
|
|
|
3413
3599
|
function isInputError(error) {
|
|
3414
3600
|
return isKitError(error) && error.type === ERROR_TYPES.INPUT;
|
|
3415
3601
|
}
|
|
3602
|
+
/**
|
|
3603
|
+
* Type guard to check if error is KitError with BALANCE type.
|
|
3604
|
+
*
|
|
3605
|
+
* BALANCE errors indicate insufficient funds or allowance issues
|
|
3606
|
+
* that prevent transaction execution. These errors are always FATAL
|
|
3607
|
+
* and require the user to add funds or approve more tokens.
|
|
3608
|
+
*
|
|
3609
|
+
* @param error - Unknown error to check
|
|
3610
|
+
* @returns True if error is KitError with BALANCE type
|
|
3611
|
+
*
|
|
3612
|
+
* @example
|
|
3613
|
+
* ```typescript
|
|
3614
|
+
* import { isBalanceError } from '@core/errors'
|
|
3615
|
+
*
|
|
3616
|
+
* try {
|
|
3617
|
+
* await kit.bridge(params)
|
|
3618
|
+
* } catch (error) {
|
|
3619
|
+
* if (isBalanceError(error)) {
|
|
3620
|
+
* console.log('Insufficient funds:', error.message)
|
|
3621
|
+
* showAddFundsUI()
|
|
3622
|
+
* }
|
|
3623
|
+
* }
|
|
3624
|
+
* ```
|
|
3625
|
+
*/
|
|
3626
|
+
function isBalanceError(error) {
|
|
3627
|
+
return isKitError(error) && error.type === ERROR_TYPES.BALANCE;
|
|
3628
|
+
}
|
|
3629
|
+
/**
|
|
3630
|
+
* Type guard to check if error is KitError with ONCHAIN type.
|
|
3631
|
+
*
|
|
3632
|
+
* ONCHAIN errors occur during transaction execution or simulation,
|
|
3633
|
+
* including reverts, gas issues, and smart contract failures.
|
|
3634
|
+
* These errors are typically FATAL.
|
|
3635
|
+
*
|
|
3636
|
+
* @param error - Unknown error to check
|
|
3637
|
+
* @returns True if error is KitError with ONCHAIN type
|
|
3638
|
+
*
|
|
3639
|
+
* @example
|
|
3640
|
+
* ```typescript
|
|
3641
|
+
* import { isOnchainError } from '@core/errors'
|
|
3642
|
+
*
|
|
3643
|
+
* try {
|
|
3644
|
+
* await kit.bridge(params)
|
|
3645
|
+
* } catch (error) {
|
|
3646
|
+
* if (isOnchainError(error)) {
|
|
3647
|
+
* console.log('Transaction failed:', error.message)
|
|
3648
|
+
* showTransactionErrorUI()
|
|
3649
|
+
* }
|
|
3650
|
+
* }
|
|
3651
|
+
* ```
|
|
3652
|
+
*/
|
|
3653
|
+
function isOnchainError(error) {
|
|
3654
|
+
return isKitError(error) && error.type === ERROR_TYPES.ONCHAIN;
|
|
3655
|
+
}
|
|
3656
|
+
/**
|
|
3657
|
+
* Type guard to check if error is KitError with RPC type.
|
|
3658
|
+
*
|
|
3659
|
+
* RPC errors occur when communicating with blockchain RPC providers.
|
|
3660
|
+
* These errors are typically RETRYABLE as they often indicate
|
|
3661
|
+
* temporary provider issues.
|
|
3662
|
+
*
|
|
3663
|
+
* @param error - Unknown error to check
|
|
3664
|
+
* @returns True if error is KitError with RPC type
|
|
3665
|
+
*
|
|
3666
|
+
* @example
|
|
3667
|
+
* ```typescript
|
|
3668
|
+
* import { isRpcError } from '@core/errors'
|
|
3669
|
+
*
|
|
3670
|
+
* try {
|
|
3671
|
+
* await kit.bridge(params)
|
|
3672
|
+
* } catch (error) {
|
|
3673
|
+
* if (isRpcError(error)) {
|
|
3674
|
+
* console.log('RPC error:', error.message)
|
|
3675
|
+
* retryWithBackoff()
|
|
3676
|
+
* }
|
|
3677
|
+
* }
|
|
3678
|
+
* ```
|
|
3679
|
+
*/
|
|
3680
|
+
function isRpcError(error) {
|
|
3681
|
+
return isKitError(error) && error.type === ERROR_TYPES.RPC;
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* Type guard to check if error is KitError with NETWORK type.
|
|
3685
|
+
*
|
|
3686
|
+
* NETWORK errors indicate connectivity issues at the network layer.
|
|
3687
|
+
* These errors are typically RETRYABLE as they often indicate
|
|
3688
|
+
* temporary network problems.
|
|
3689
|
+
*
|
|
3690
|
+
* @param error - Unknown error to check
|
|
3691
|
+
* @returns True if error is KitError with NETWORK type
|
|
3692
|
+
*
|
|
3693
|
+
* @example
|
|
3694
|
+
* ```typescript
|
|
3695
|
+
* import { isNetworkError } from '@core/errors'
|
|
3696
|
+
*
|
|
3697
|
+
* try {
|
|
3698
|
+
* await kit.bridge(params)
|
|
3699
|
+
* } catch (error) {
|
|
3700
|
+
* if (isNetworkError(error)) {
|
|
3701
|
+
* console.log('Network issue:', error.message)
|
|
3702
|
+
* retryWithBackoff()
|
|
3703
|
+
* }
|
|
3704
|
+
* }
|
|
3705
|
+
* ```
|
|
3706
|
+
*/
|
|
3707
|
+
function isNetworkError(error) {
|
|
3708
|
+
return isKitError(error) && error.type === ERROR_TYPES.NETWORK;
|
|
3709
|
+
}
|
|
3416
3710
|
/**
|
|
3417
3711
|
* Safely extracts error message from any error type.
|
|
3418
3712
|
*
|
|
@@ -3702,7 +3996,6 @@ function convertZodErrorToStructured(zodError, params) {
|
|
|
3702
3996
|
function createValidationFailedError(zodError) {
|
|
3703
3997
|
return createValidationErrorFromZod(zodError, 'parameters');
|
|
3704
3998
|
}
|
|
3705
|
-
const AMOUNT_FORMAT_ERROR_MESSAGE = 'Amount must be a numeric string with dot (.) as decimal separator, with no thousand separators or comma decimals';
|
|
3706
3999
|
/**
|
|
3707
4000
|
* Handles amount-related validation errors from Zod.
|
|
3708
4001
|
*
|
|
@@ -3752,7 +4045,7 @@ function handleAmountError(path, code, message, paramsObj) {
|
|
|
3752
4045
|
*/
|
|
3753
4046
|
function handleNegativeAmountError(code, message, amount) {
|
|
3754
4047
|
if (code === 'too_small' || message.includes('greater than')) {
|
|
3755
|
-
return createInvalidAmountError(amount,
|
|
4048
|
+
return createInvalidAmountError(amount, AMOUNT_GREATER_THAN_ZERO_MESSAGE);
|
|
3756
4049
|
}
|
|
3757
4050
|
return null;
|
|
3758
4051
|
}
|
|
@@ -3774,10 +4067,10 @@ function handleCustomAmountError(code, message, amount) {
|
|
|
3774
4067
|
if (code !== 'custom')
|
|
3775
4068
|
return null;
|
|
3776
4069
|
if (message.includes('non-negative')) {
|
|
3777
|
-
return createInvalidAmountError(amount,
|
|
4070
|
+
return createInvalidAmountError(amount, AMOUNT_NON_NEGATIVE_MESSAGE);
|
|
3778
4071
|
}
|
|
3779
4072
|
if (message.includes('greater than 0')) {
|
|
3780
|
-
return createInvalidAmountError(amount,
|
|
4073
|
+
return createInvalidAmountError(amount, AMOUNT_GREATER_THAN_ZERO_MESSAGE);
|
|
3781
4074
|
}
|
|
3782
4075
|
if (message.includes('decimal places')) {
|
|
3783
4076
|
return createInvalidAmountError(amount, message);
|
|
@@ -3810,7 +4103,7 @@ function handleInvalidStringAmountError(code, message, amount) {
|
|
|
3810
4103
|
return null;
|
|
3811
4104
|
// Check for decimal places validation
|
|
3812
4105
|
if (isDecimalPlacesError(message)) {
|
|
3813
|
-
return createInvalidAmountError(amount,
|
|
4106
|
+
return createInvalidAmountError(amount, AMOUNT_MAX_DECIMAL_PLACES_MESSAGE);
|
|
3814
4107
|
}
|
|
3815
4108
|
// Check for numeric format validation
|
|
3816
4109
|
if (isNumericFormatError(message)) {
|
|
@@ -4335,7 +4628,7 @@ const parseAmount = (params) => {
|
|
|
4335
4628
|
};
|
|
4336
4629
|
|
|
4337
4630
|
var name = "@circle-fin/bridge-kit";
|
|
4338
|
-
var version = "1.
|
|
4631
|
+
var version = "1.3.0";
|
|
4339
4632
|
var pkg = {
|
|
4340
4633
|
name: name,
|
|
4341
4634
|
version: version};
|
|
@@ -4701,41 +4994,46 @@ var TransferSpeed;
|
|
|
4701
4994
|
* - regexMessage: error message when the basic numeric format fails.
|
|
4702
4995
|
* - maxDecimals: maximum number of decimal places allowed (e.g., 6 for USDC).
|
|
4703
4996
|
*/
|
|
4704
|
-
const createDecimalStringValidator = (options) => (schema) =>
|
|
4705
|
-
|
|
4706
|
-
.
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
return;
|
|
4714
|
-
}
|
|
4715
|
-
// Check decimal precision if maxDecimals is specified
|
|
4716
|
-
if (options.maxDecimals !== undefined) {
|
|
4717
|
-
const decimalPart = val.split('.')[1];
|
|
4718
|
-
if (decimalPart && decimalPart.length > options.maxDecimals) {
|
|
4997
|
+
const createDecimalStringValidator = (options) => (schema) => {
|
|
4998
|
+
// Capitalize first letter of attribute name for error messages
|
|
4999
|
+
const capitalizedAttributeName = options.attributeName.charAt(0).toUpperCase() +
|
|
5000
|
+
options.attributeName.slice(1);
|
|
5001
|
+
return schema
|
|
5002
|
+
.regex(/^-?(?:\d+(?:\.\d+)?|\.\d+)$/, options.regexMessage)
|
|
5003
|
+
.superRefine((val, ctx) => {
|
|
5004
|
+
const amount = Number.parseFloat(val);
|
|
5005
|
+
if (Number.isNaN(amount)) {
|
|
4719
5006
|
ctx.addIssue({
|
|
4720
5007
|
code: z.ZodIssueCode.custom,
|
|
4721
|
-
message:
|
|
5008
|
+
message: options.regexMessage,
|
|
4722
5009
|
});
|
|
4723
5010
|
return;
|
|
4724
5011
|
}
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
5012
|
+
// Check decimal precision if maxDecimals is specified
|
|
5013
|
+
if (options.maxDecimals !== undefined) {
|
|
5014
|
+
const decimalPart = val.split('.')[1];
|
|
5015
|
+
if (decimalPart && decimalPart.length > options.maxDecimals) {
|
|
5016
|
+
ctx.addIssue({
|
|
5017
|
+
code: z.ZodIssueCode.custom,
|
|
5018
|
+
message: `Maximum supported decimal places: ${options.maxDecimals.toString()}`,
|
|
5019
|
+
});
|
|
5020
|
+
return;
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
5023
|
+
if (options.allowZero && amount < 0) {
|
|
5024
|
+
ctx.addIssue({
|
|
5025
|
+
code: z.ZodIssueCode.custom,
|
|
5026
|
+
message: `${capitalizedAttributeName} must be non-negative`,
|
|
5027
|
+
});
|
|
5028
|
+
}
|
|
5029
|
+
else if (!options.allowZero && amount <= 0) {
|
|
5030
|
+
ctx.addIssue({
|
|
5031
|
+
code: z.ZodIssueCode.custom,
|
|
5032
|
+
message: `${capitalizedAttributeName} must be greater than 0`,
|
|
5033
|
+
});
|
|
5034
|
+
}
|
|
5035
|
+
});
|
|
5036
|
+
};
|
|
4739
5037
|
/**
|
|
4740
5038
|
* Schema for validating chain definitions.
|
|
4741
5039
|
* This ensures the basic structure of a chain definition is valid.
|
|
@@ -4895,7 +5193,7 @@ z.object({
|
|
|
4895
5193
|
.min(1, 'Required')
|
|
4896
5194
|
.pipe(createDecimalStringValidator({
|
|
4897
5195
|
allowZero: false,
|
|
4898
|
-
regexMessage:
|
|
5196
|
+
regexMessage: AMOUNT_FORMAT_ERROR_MESSAGE,
|
|
4899
5197
|
attributeName: 'amount',
|
|
4900
5198
|
maxDecimals: 6,
|
|
4901
5199
|
})(z.string())),
|
|
@@ -4908,7 +5206,7 @@ z.object({
|
|
|
4908
5206
|
.string()
|
|
4909
5207
|
.pipe(createDecimalStringValidator({
|
|
4910
5208
|
allowZero: true,
|
|
4911
|
-
regexMessage:
|
|
5209
|
+
regexMessage: MAX_FEE_FORMAT_ERROR_MESSAGE,
|
|
4912
5210
|
attributeName: 'maxFee',
|
|
4913
5211
|
maxDecimals: 6,
|
|
4914
5212
|
})(z.string()))
|
|
@@ -4917,11 +5215,6 @@ z.object({
|
|
|
4917
5215
|
}),
|
|
4918
5216
|
});
|
|
4919
5217
|
|
|
4920
|
-
/**
|
|
4921
|
-
* Error message constants for validation
|
|
4922
|
-
*/
|
|
4923
|
-
const AMOUNT_VALIDATION_MESSAGE = 'Amount must be a numeric string with dot (.) as decimal separator (e.g., "0.1", ".1", "10.5", "1000.50"), with no thousand separators or comma decimals.';
|
|
4924
|
-
const MAX_FEE_VALIDATION_MESSAGE = 'maxFee must be a numeric string with dot (.) as decimal separator (e.g., "1", "0.5", ".5", "1.5"), with no thousand separators or comma decimals.';
|
|
4925
5218
|
/**
|
|
4926
5219
|
* Schema for validating AdapterContext for bridge operations.
|
|
4927
5220
|
* Must always contain both adapter and chain explicitly.
|
|
@@ -5016,7 +5309,7 @@ const bridgeParamsWithChainIdentifierSchema = z.object({
|
|
|
5016
5309
|
.min(1, 'Required')
|
|
5017
5310
|
.pipe(createDecimalStringValidator({
|
|
5018
5311
|
allowZero: false,
|
|
5019
|
-
regexMessage:
|
|
5312
|
+
regexMessage: AMOUNT_FORMAT_ERROR_MESSAGE,
|
|
5020
5313
|
attributeName: 'amount',
|
|
5021
5314
|
maxDecimals: 6,
|
|
5022
5315
|
})(z.string())),
|
|
@@ -5029,7 +5322,7 @@ const bridgeParamsWithChainIdentifierSchema = z.object({
|
|
|
5029
5322
|
.min(1, 'Required')
|
|
5030
5323
|
.pipe(createDecimalStringValidator({
|
|
5031
5324
|
allowZero: true,
|
|
5032
|
-
regexMessage:
|
|
5325
|
+
regexMessage: MAX_FEE_FORMAT_ERROR_MESSAGE,
|
|
5033
5326
|
attributeName: 'maxFee',
|
|
5034
5327
|
maxDecimals: 6,
|
|
5035
5328
|
})(z.string()))
|
|
@@ -5290,6 +5583,8 @@ const getAmountTransformer = (formatDirection) => formatDirection === 'to-human-
|
|
|
5290
5583
|
: (params) => parseAmount(params).toString();
|
|
5291
5584
|
/**
|
|
5292
5585
|
* Format the bridge result into human-readable string values for the user or bigint string values for internal use.
|
|
5586
|
+
*
|
|
5587
|
+
* @typeParam T - The specific result type (must extend BridgeResult or EstimateResult). Preserves the exact type passed in.
|
|
5293
5588
|
* @param result - The bridge result to format.
|
|
5294
5589
|
* @param formatDirection - The direction to format the result in.
|
|
5295
5590
|
* - If 'to-human-readable', the result will be converted to human-readable string values.
|
|
@@ -5319,7 +5614,9 @@ const formatBridgeResult = (result, formatDirection) => {
|
|
|
5319
5614
|
return {
|
|
5320
5615
|
...result,
|
|
5321
5616
|
amount: transform({ value: result.amount, token: result.token }),
|
|
5322
|
-
...(
|
|
5617
|
+
...('config' in result &&
|
|
5618
|
+
result.config &&
|
|
5619
|
+
Object.keys(result.config).length > 0 && {
|
|
5323
5620
|
config: {
|
|
5324
5621
|
...result.config,
|
|
5325
5622
|
...(result.config.maxFee && {
|
|
@@ -5331,12 +5628,12 @@ const formatBridgeResult = (result, formatDirection) => {
|
|
|
5331
5628
|
...(result.config.customFee && {
|
|
5332
5629
|
customFee: {
|
|
5333
5630
|
...result.config.customFee,
|
|
5334
|
-
|
|
5335
|
-
|
|
5631
|
+
...(result.config.customFee.value && {
|
|
5632
|
+
value: transform({
|
|
5336
5633
|
value: result.config.customFee.value,
|
|
5337
5634
|
token: result.token,
|
|
5338
|
-
})
|
|
5339
|
-
|
|
5635
|
+
}),
|
|
5636
|
+
}),
|
|
5340
5637
|
},
|
|
5341
5638
|
}),
|
|
5342
5639
|
},
|
|
@@ -5604,8 +5901,8 @@ class BridgeKit {
|
|
|
5604
5901
|
const finalResolvedParams = await this.mergeCustomFeeConfig(resolvedParams);
|
|
5605
5902
|
// Find a provider that supports this route
|
|
5606
5903
|
const provider = this.findProviderForRoute(finalResolvedParams);
|
|
5607
|
-
// Estimate the transfer using the provider
|
|
5608
|
-
return provider.estimate(finalResolvedParams);
|
|
5904
|
+
// Estimate the transfer using the provider and format amounts to human-readable strings
|
|
5905
|
+
return formatBridgeResult(await provider.estimate(finalResolvedParams), 'to-human-readable');
|
|
5609
5906
|
}
|
|
5610
5907
|
/**
|
|
5611
5908
|
* Get all chains supported by any provider in the kit.
|
|
@@ -5824,5 +6121,5 @@ class BridgeKit {
|
|
|
5824
6121
|
// Auto-register this kit for user agent tracking
|
|
5825
6122
|
registerKit(`${pkg.name}/${pkg.version}`);
|
|
5826
6123
|
|
|
5827
|
-
export { Blockchain, BridgeChain, BridgeKit, KitError, TransferSpeed, bridgeParamsWithChainIdentifierSchema, getErrorCode, getErrorMessage, isFatalError, isInputError, isKitError, isRetryableError, resolveChainIdentifier, setExternalPrefix };
|
|
6124
|
+
export { BalanceError, Blockchain, BridgeChain, BridgeKit, InputError, KitError, NetworkError, OnchainError, RpcError, TransferSpeed, bridgeParamsWithChainIdentifierSchema, getErrorCode, getErrorMessage, isBalanceError, isFatalError, isInputError, isKitError, isNetworkError, isOnchainError, isRetryableError, isRpcError, resolveChainIdentifier, setExternalPrefix };
|
|
5828
6125
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@circle-fin/bridge-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "SDK for seamless cross-chain stablecoin bridging",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"circle",
|
|
7
|
+
"cctp",
|
|
8
|
+
"usdc",
|
|
9
|
+
"stablecoin",
|
|
10
|
+
"bridge",
|
|
11
|
+
"bridging",
|
|
12
|
+
"cross-chain",
|
|
13
|
+
"sdk",
|
|
14
|
+
"typescript",
|
|
15
|
+
"bridge-kit"
|
|
16
|
+
],
|
|
5
17
|
"engines": {
|
|
6
18
|
"node": ">=16.0.0"
|
|
7
19
|
},
|
|
@@ -10,7 +22,7 @@
|
|
|
10
22
|
"types": "./index.d.ts",
|
|
11
23
|
"dependencies": {
|
|
12
24
|
"zod": "3.25.67",
|
|
13
|
-
"@circle-fin/provider-cctp-v2": "^1.0
|
|
25
|
+
"@circle-fin/provider-cctp-v2": "^1.1.0",
|
|
14
26
|
"abitype": "^1.1.0",
|
|
15
27
|
"@solana/web3.js": "^1.98.4",
|
|
16
28
|
"@ethersproject/address": "^5.8.0",
|