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
Standard bridge data containing transaction details
cBridge-specific bridging parameters
Maximum allowed slippage (in basis points)
Unique nonce for the transfer
swapAndStartBridgeTokensViaCBridge
Performs a token swap on the source chain before bridging via cBridge.
function swapAndStartBridgeTokensViaCBridge(
BridgeData _bridgeData,
SwapData[] _swapData,
CBridgeData _cBridgeData
) external payable
Array of swap operations to execute before bridging
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
cBridge contract address to call
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