@circle-fin/provider-cctp-v2 1.3.0 → 1.3.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @circle-fin/provider-cctp-v2
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix for native token balance validation fails for Gas Station–enabled wallets when either the source or destination chain has zero native token balance
8
+
3
9
  ## 1.3.0
4
10
 
5
11
  ### Minor Changes
package/index.cjs CHANGED
@@ -3742,12 +3742,6 @@ const BalanceError = {
3742
3742
  code: 9001,
3743
3743
  name: 'BALANCE_INSUFFICIENT_TOKEN',
3744
3744
  type: 'BALANCE',
3745
- },
3746
- /** Insufficient native token (ETH/SOL/etc) for gas fees */
3747
- INSUFFICIENT_GAS: {
3748
- code: 9002,
3749
- name: 'BALANCE_INSUFFICIENT_GAS',
3750
- type: 'BALANCE',
3751
3745
  }};
3752
3746
  /**
3753
3747
  * Standardized error definitions for ONCHAIN type errors.
@@ -4034,49 +4028,6 @@ function createInsufficientTokenBalanceError(chain, token, trace) {
4034
4028
  },
4035
4029
  });
4036
4030
  }
4037
- /**
4038
- * Creates error for insufficient gas funds.
4039
- *
4040
- * This error is thrown when a wallet does not have enough native tokens
4041
- * (ETH, SOL, etc.) to pay for transaction gas fees. The error is FATAL
4042
- * as it requires user intervention to add gas funds.
4043
- *
4044
- * @param chain - The blockchain network where the gas check failed
4045
- * @param trace - Optional trace context to include in error (can include rawError and additional debugging data)
4046
- * @returns KitError with insufficient gas details
4047
- *
4048
- * @example
4049
- * ```typescript
4050
- * import { createInsufficientGasError } from '@core/errors'
4051
- *
4052
- * throw createInsufficientGasError('Ethereum')
4053
- * // Message: "Insufficient gas funds on Ethereum"
4054
- * ```
4055
- *
4056
- * @example
4057
- * ```typescript
4058
- * // With trace context for debugging
4059
- * throw createInsufficientGasError('Ethereum', {
4060
- * rawError: error,
4061
- * gasRequired: '21000',
4062
- * gasAvailable: '10000',
4063
- * walletAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
4064
- * })
4065
- * ```
4066
- */
4067
- function createInsufficientGasError(chain, trace) {
4068
- return new KitError({
4069
- ...BalanceError.INSUFFICIENT_GAS,
4070
- recoverability: 'FATAL',
4071
- message: `Insufficient gas funds on ${chain}`,
4072
- cause: {
4073
- trace: {
4074
- ...trace,
4075
- chain,
4076
- },
4077
- },
4078
- });
4079
- }
4080
4031
 
4081
4032
  /**
4082
4033
  * Creates error for transaction simulation failures.
@@ -6721,58 +6672,6 @@ const validateBalanceForTransaction = async (params) => {
6721
6672
  }
6722
6673
  };
6723
6674
 
6724
- /**
6725
- * Validate that the adapter has sufficient native token balance for transaction fees.
6726
- *
6727
- * This function checks if the adapter's current native token balance (ETH, SOL, etc.)
6728
- * is greater than zero. It throws a KitError with code 9002 (BALANCE_INSUFFICIENT_GAS)
6729
- * if the balance is zero, indicating the wallet cannot pay for transaction fees.
6730
- *
6731
- * @param params - The validation parameters containing adapter and operation context.
6732
- * @returns A promise that resolves to void if validation passes.
6733
- * @throws {KitError} When the adapter's native balance is zero (code: 9002).
6734
- *
6735
- * @example
6736
- * ```typescript
6737
- * import { validateNativeBalanceForTransaction } from '@core/adapter'
6738
- * import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
6739
- * import { isKitError, ERROR_TYPES } from '@core/errors'
6740
- *
6741
- * const adapter = createViemAdapterFromPrivateKey({
6742
- * privateKey: '0x...',
6743
- * chain: 'Ethereum',
6744
- * })
6745
- *
6746
- * try {
6747
- * await validateNativeBalanceForTransaction({
6748
- * adapter,
6749
- * operationContext: { chain: 'Ethereum' },
6750
- * })
6751
- * console.log('Native balance validation passed')
6752
- * } catch (error) {
6753
- * if (isKitError(error) && error.type === ERROR_TYPES.BALANCE) {
6754
- * console.error('Insufficient gas funds:', error.message)
6755
- * }
6756
- * }
6757
- * ```
6758
- */
6759
- const validateNativeBalanceForTransaction = async (params) => {
6760
- const { adapter, operationContext } = params;
6761
- const balancePrepared = await adapter.prepareAction('native.balanceOf', {
6762
- walletAddress: operationContext.address,
6763
- }, operationContext);
6764
- const balance = await balancePrepared.execute();
6765
- if (BigInt(balance) === 0n) {
6766
- // Extract chain name from operationContext
6767
- const chainName = extractChainInfo(operationContext.chain).name;
6768
- // Create KitError with rich context in trace
6769
- throw createInsufficientGasError(chainName, {
6770
- balance: '0',
6771
- walletAddress: operationContext.address,
6772
- });
6773
- }
6774
- };
6775
-
6776
6675
  /**
6777
6676
  * CCTP bridge step names that can occur in the bridging flow.
6778
6677
  *
@@ -7823,7 +7722,7 @@ class CCTPV2BridgingProvider extends BridgingProvider {
7823
7722
  async bridge(params) {
7824
7723
  // CCTP-specific bridge params validation (includes base validation)
7825
7724
  assertCCTPv2BridgeParams(params);
7826
- const { source, destination, amount, token } = params;
7725
+ const { source, amount, token } = params;
7827
7726
  // Extract operation context from source wallet context for balance validation
7828
7727
  const sourceOperationContext = this.extractOperationContext(source);
7829
7728
  // Validate USDC balance for transaction on source chain
@@ -7834,18 +7733,6 @@ class CCTPV2BridgingProvider extends BridgingProvider {
7834
7733
  tokenAddress: source.chain.usdcAddress,
7835
7734
  operationContext: sourceOperationContext,
7836
7735
  });
7837
- // Validate native balance > 0 for gas fees on source chain
7838
- await validateNativeBalanceForTransaction({
7839
- adapter: source.adapter,
7840
- operationContext: sourceOperationContext,
7841
- });
7842
- // Extract operation context from destination wallet context
7843
- const destinationOperationContext = this.extractOperationContext(destination);
7844
- // Validate native balance > 0 for gas fees on destination chain
7845
- await validateNativeBalanceForTransaction({
7846
- adapter: destination.adapter,
7847
- operationContext: destinationOperationContext,
7848
- });
7849
7736
  return bridge(params, this);
7850
7737
  }
7851
7738
  /**
package/index.mjs CHANGED
@@ -3736,12 +3736,6 @@ const BalanceError = {
3736
3736
  code: 9001,
3737
3737
  name: 'BALANCE_INSUFFICIENT_TOKEN',
3738
3738
  type: 'BALANCE',
3739
- },
3740
- /** Insufficient native token (ETH/SOL/etc) for gas fees */
3741
- INSUFFICIENT_GAS: {
3742
- code: 9002,
3743
- name: 'BALANCE_INSUFFICIENT_GAS',
3744
- type: 'BALANCE',
3745
3739
  }};
3746
3740
  /**
3747
3741
  * Standardized error definitions for ONCHAIN type errors.
@@ -4028,49 +4022,6 @@ function createInsufficientTokenBalanceError(chain, token, trace) {
4028
4022
  },
4029
4023
  });
4030
4024
  }
4031
- /**
4032
- * Creates error for insufficient gas funds.
4033
- *
4034
- * This error is thrown when a wallet does not have enough native tokens
4035
- * (ETH, SOL, etc.) to pay for transaction gas fees. The error is FATAL
4036
- * as it requires user intervention to add gas funds.
4037
- *
4038
- * @param chain - The blockchain network where the gas check failed
4039
- * @param trace - Optional trace context to include in error (can include rawError and additional debugging data)
4040
- * @returns KitError with insufficient gas details
4041
- *
4042
- * @example
4043
- * ```typescript
4044
- * import { createInsufficientGasError } from '@core/errors'
4045
- *
4046
- * throw createInsufficientGasError('Ethereum')
4047
- * // Message: "Insufficient gas funds on Ethereum"
4048
- * ```
4049
- *
4050
- * @example
4051
- * ```typescript
4052
- * // With trace context for debugging
4053
- * throw createInsufficientGasError('Ethereum', {
4054
- * rawError: error,
4055
- * gasRequired: '21000',
4056
- * gasAvailable: '10000',
4057
- * walletAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
4058
- * })
4059
- * ```
4060
- */
4061
- function createInsufficientGasError(chain, trace) {
4062
- return new KitError({
4063
- ...BalanceError.INSUFFICIENT_GAS,
4064
- recoverability: 'FATAL',
4065
- message: `Insufficient gas funds on ${chain}`,
4066
- cause: {
4067
- trace: {
4068
- ...trace,
4069
- chain,
4070
- },
4071
- },
4072
- });
4073
- }
4074
4025
 
4075
4026
  /**
4076
4027
  * Creates error for transaction simulation failures.
@@ -6715,58 +6666,6 @@ const validateBalanceForTransaction = async (params) => {
6715
6666
  }
6716
6667
  };
6717
6668
 
6718
- /**
6719
- * Validate that the adapter has sufficient native token balance for transaction fees.
6720
- *
6721
- * This function checks if the adapter's current native token balance (ETH, SOL, etc.)
6722
- * is greater than zero. It throws a KitError with code 9002 (BALANCE_INSUFFICIENT_GAS)
6723
- * if the balance is zero, indicating the wallet cannot pay for transaction fees.
6724
- *
6725
- * @param params - The validation parameters containing adapter and operation context.
6726
- * @returns A promise that resolves to void if validation passes.
6727
- * @throws {KitError} When the adapter's native balance is zero (code: 9002).
6728
- *
6729
- * @example
6730
- * ```typescript
6731
- * import { validateNativeBalanceForTransaction } from '@core/adapter'
6732
- * import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
6733
- * import { isKitError, ERROR_TYPES } from '@core/errors'
6734
- *
6735
- * const adapter = createViemAdapterFromPrivateKey({
6736
- * privateKey: '0x...',
6737
- * chain: 'Ethereum',
6738
- * })
6739
- *
6740
- * try {
6741
- * await validateNativeBalanceForTransaction({
6742
- * adapter,
6743
- * operationContext: { chain: 'Ethereum' },
6744
- * })
6745
- * console.log('Native balance validation passed')
6746
- * } catch (error) {
6747
- * if (isKitError(error) && error.type === ERROR_TYPES.BALANCE) {
6748
- * console.error('Insufficient gas funds:', error.message)
6749
- * }
6750
- * }
6751
- * ```
6752
- */
6753
- const validateNativeBalanceForTransaction = async (params) => {
6754
- const { adapter, operationContext } = params;
6755
- const balancePrepared = await adapter.prepareAction('native.balanceOf', {
6756
- walletAddress: operationContext.address,
6757
- }, operationContext);
6758
- const balance = await balancePrepared.execute();
6759
- if (BigInt(balance) === 0n) {
6760
- // Extract chain name from operationContext
6761
- const chainName = extractChainInfo(operationContext.chain).name;
6762
- // Create KitError with rich context in trace
6763
- throw createInsufficientGasError(chainName, {
6764
- balance: '0',
6765
- walletAddress: operationContext.address,
6766
- });
6767
- }
6768
- };
6769
-
6770
6669
  /**
6771
6670
  * CCTP bridge step names that can occur in the bridging flow.
6772
6671
  *
@@ -7817,7 +7716,7 @@ class CCTPV2BridgingProvider extends BridgingProvider {
7817
7716
  async bridge(params) {
7818
7717
  // CCTP-specific bridge params validation (includes base validation)
7819
7718
  assertCCTPv2BridgeParams(params);
7820
- const { source, destination, amount, token } = params;
7719
+ const { source, amount, token } = params;
7821
7720
  // Extract operation context from source wallet context for balance validation
7822
7721
  const sourceOperationContext = this.extractOperationContext(source);
7823
7722
  // Validate USDC balance for transaction on source chain
@@ -7828,18 +7727,6 @@ class CCTPV2BridgingProvider extends BridgingProvider {
7828
7727
  tokenAddress: source.chain.usdcAddress,
7829
7728
  operationContext: sourceOperationContext,
7830
7729
  });
7831
- // Validate native balance > 0 for gas fees on source chain
7832
- await validateNativeBalanceForTransaction({
7833
- adapter: source.adapter,
7834
- operationContext: sourceOperationContext,
7835
- });
7836
- // Extract operation context from destination wallet context
7837
- const destinationOperationContext = this.extractOperationContext(destination);
7838
- // Validate native balance > 0 for gas fees on destination chain
7839
- await validateNativeBalanceForTransaction({
7840
- adapter: destination.adapter,
7841
- operationContext: destinationOperationContext,
7842
- });
7843
7730
  return bridge(params, this);
7844
7731
  }
7845
7732
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@circle-fin/provider-cctp-v2",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Circle's official Cross-Chain Transfer Protocol v2 provider for native USDC bridging",
5
5
  "keywords": [
6
6
  "circle",