Skip to main content

Overview

The CBridgeFacet enables cross-chain token transfers using Celer’s cBridge, a decentralized and non-custodial cross-chain asset transfer network.

Contract Interface

Functions

startBridgeTokensViaCBridge

Bridges tokens to another chain using cBridge.
function startBridgeTokensViaCBridge(
  BridgeData _bridgeData,
  CBridgeData _cBridgeData
) external payable
_bridgeData
BridgeData
Standard bridge data containing transaction details
_cBridgeData
CBridgeData
cBridge-specific bridging parameters

swapAndStartBridgeTokensViaCBridge

Performs a token swap on the source chain before bridging via cBridge.
function swapAndStartBridgeTokensViaCBridge(
  BridgeData _bridgeData,
  SwapData[] _swapData,
  CBridgeData _cBridgeData
) external payable
_bridgeData
BridgeData
Standard bridge data
_swapData
SwapData[]
Array of swap operations to execute before bridging
_cBridgeData
CBridgeData
cBridge-specific parameters

triggerRefund

Triggers a refund for a failed cBridge transfer.
function triggerRefund(
  address _callTo,
  bytes _callData,
  address _assetAddress,
  address _to,
  uint256 _amount
) external
_callTo
address
cBridge contract address to call
_callData
bytes
Encoded refund call data
_assetAddress
address
Token address to refund
_to
address
Recipient of the refund
_amount
uint256
Amount to refund

Data Structures

CBridgeData

struct CBridgeData {
  uint32 maxSlippage;  // Maximum slippage in basis points (e.g., 5000 = 50%)
  uint64 nonce;        // Unique nonce for transfer
}

Usage Example

import { CBridgeFacet } from '@lifi/contract-types';

const cBridgeFacet = CBridgeFacet__factory.connect(facetAddress, signer);

const bridgeData = {
  transactionId: '0x...',
  bridge: 'cbridge',
  integrator: 'my-dapp',
  referrer: '0x0000000000000000000000000000000000000000',
  sendingAssetId: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  receiver: '0x...',
  minAmount: ethers.utils.parseUnits('100', 6),
  destinationChainId: 56, // BSC
  hasSourceSwaps: false,
  hasDestinationCall: false
};

const cBridgeData = {
  maxSlippage: 5000, // 50% max slippage (in basis points)
  nonce: Date.now() // Use timestamp as nonce
};

const tx = await cBridgeFacet.startBridgeTokensViaCBridge(
  bridgeData,
  cBridgeData,
  { value: 0 }
);

await tx.wait();

Refund Example

If a cBridge transfer fails, you can trigger a refund:
const refundTx = await cBridgeFacet.triggerRefund(
  cBridgeContractAddress,
  refundCallData,
  tokenAddress,
  recipientAddress,
  amountToRefund
);

await refundTx.wait();

Events

  • LiFiTransferStarted(BridgeData bridgeData)
  • CBridgeRefund(address _assetAddress, address _to, uint256 amount) - Emitted when refund is triggered
  • AssetSwapped (when using swapAndStart variant)

Notes

  • The maxSlippage parameter is specified in basis points (10000 = 100%)
  • Each transfer requires a unique nonce to prevent replay attacks
  • cBridge uses liquidity pools, so availability may vary by route
  • Transfers may take several minutes to complete depending on network conditions

See Also

Build docs developers (and LLMs) love