Overview
The HopFacet enables cross-chain token transfers using the Hop Protocol. Hop provides fast and efficient bridging between Ethereum and Layer 2 networks.
Contract Interface
Configuration Functions
initHop
Initializes Hop bridge configurations for supported assets.
function initHop ( Config [] configs ) external
Array of asset-to-bridge mappings Hop bridge contract address
registerBridge
Registers a new Hop bridge for a specific asset.
function registerBridge ( address assetId , address bridge ) external
Token address to register
Hop bridge contract address
Bridging Functions
startBridgeTokensViaHop
Bridges tokens to another chain using Hop Protocol.
function startBridgeTokensViaHop (
BridgeData _bridgeData ,
HopData _hopData
) external payable
Standard bridge data containing transaction details
Hop-specific bridging parameters Minimum amount on destination
Deadline on destination chain
Relayer address (optional)
swapAndStartBridgeTokensViaHop
Performs a token swap on the source chain before bridging via Hop.
function swapAndStartBridgeTokensViaHop (
BridgeData _bridgeData ,
SwapData [] _swapData ,
HopData _hopData
) external payable
Array of swap operations to execute before bridging
Data Structures
HopData
struct HopData {
uint256 bonderFee ; // Fee for the bonder
uint256 amountOutMin ; // Minimum amount out on source
uint256 deadline ; // Source chain deadline
uint256 destinationAmountOutMin ; // Min amount on destination
uint256 destinationDeadline ; // Destination deadline
address relayer ; // Relayer address
uint256 relayerFee ; // Relayer service fee
uint256 nativeFee ; // Native token fee
}
Config
struct Config {
address assetId ; // Token address
address bridge ; // Hop bridge address
}
Usage Example
import { HopFacet } from '@lifi/contract-types' ;
const hopFacet = HopFacet__factory . connect ( facetAddress , signer );
const bridgeData = {
transactionId: '0x...' ,
bridge: 'hop' ,
integrator: 'my-dapp' ,
referrer: '0x0000000000000000000000000000000000000000' ,
sendingAssetId: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' , // USDC
receiver: '0x...' ,
minAmount: ethers . utils . parseUnits ( '100' , 6 ),
destinationChainId: 137 , // Polygon
hasSourceSwaps: false ,
hasDestinationCall: false
};
const hopData = {
bonderFee: ethers . utils . parseUnits ( '0.5' , 6 ),
amountOutMin: ethers . utils . parseUnits ( '99' , 6 ),
deadline: Math . floor ( Date . now () / 1000 ) + 3600 ,
destinationAmountOutMin: ethers . utils . parseUnits ( '99' , 6 ),
destinationDeadline: Math . floor ( Date . now () / 1000 ) + 7200 ,
relayer: '0x0000000000000000000000000000000000000000' ,
relayerFee: 0 ,
nativeFee: 0
};
const tx = await hopFacet . startBridgeTokensViaHop (
bridgeData ,
hopData ,
{ value: hopData . nativeFee }
);
await tx . wait ();
Events
HopInitialized(Config[] configs) - Emitted when Hop is initialized
HopBridgeRegistered(address assetId, address bridge) - Emitted when a bridge is registered
LiFiTransferStarted(BridgeData bridgeData) - Standard transfer event
AssetSwapped (when using swapAndStart variant)
See Also