Bridge Contract
The Bridge contract is a core component of the Compose Network that enables cross-chain token transfers between different rollups. It implements a burn-and-mint mechanism where tokens are burned on the source chain and minted on the destination chain.
Overview
The Bridge contract facilitates secure cross-chain token transfers by:
- Burning tokens on the source chain
- Sending cross-chain messages via the Mailbox
- Minting tokens on the destination chain upon confirmation
- Providing acknowledgment mechanisms for transfer completion
Contract Interface
contract Bridge is IBridge {
IMailbox public mailbox;
constructor(address _mailbox);
function send(...) external;
function receiveTokens(...) external returns (address token, uint256 amount);
function checkAck(...) external view returns (bytes memory);
}
Functions
send(otherChainId, token, sender, receiver, amount, sessionId, destBridge)
Description: Initiates a cross-chain token transfer by burning tokens on the source chain and sending a message to the destination chain.
| Parameter | Type | Description |
|---|---|---|
| otherChainId | uint256 | The chain ID of the destination chain |
| token | address | The address of the token contract to be transferred |
| sender | address | The address of the token sender on the source chain |
| receiver | address | The address of the token recipient on the destination chain |
| amount | uint256 | The amount of tokens to be bridged |
| sessionId | uint256 | Unique identifier for this transfer session |
| destBridge | address | The address of the Bridge contract on the destination chain |
Requirements:
sendermust be the same asmsg.sender(only the token owner can initiate the transfer)- The sender must have sufficient token balance
- The token contract must support the
burnfunction
Process:
- Validates that the caller is the token sender
- Burns the specified amount of tokens from the sender
- Encodes transfer data (sender, receiver, token, amount)
- Sends a cross-chain message via the Mailbox to the destination chain
- Emits a
DataWrittenevent
Events:
DataWritten(bytes data)
receiveTokens(otherChainId, sender, receiver, sessionId, srcBridge)
Description: Processes incoming token transfers on the destination chain by reading the cross-chain message and minting tokens to the receiver.
| Parameter | Type | Description |
|---|---|---|
| otherChainId | uint256 | The chain ID of the source chain where tokens were burned |
| sender | address | The original sender's address from the source chain |
| receiver | address | The recipient's address on this chain |
| sessionId | uint256 | The session ID that matches the original transfer |
| srcBridge | address | The address of the Bridge contract on the source chain |
Returns:
token(address): The address of the token that was transferredamount(uint256): The amount of tokens that were transferred
Requirements:
msg.sendermust be the same asreceiver(only the intended recipient can claim tokens)- A valid cross-chain message must exist in the Mailbox
- The message data must match the provided parameters
Process:
- Validates that the caller is the intended receiver
- Reads the cross-chain message from the Mailbox
- Decodes the message to extract transfer details
- Validates that the decoded data matches the provided parameters
- Mints the tokens to the receiver
- Sends an acknowledgment message back to the source chain
- Emits a
TokensReceivedevent
Events:
TokensReceived(address token, uint256 amount)
checkAck(chainDest, destBridge, sessionId)
Description: Checks if an acknowledgment message has been received from the destination chain, confirming that the token transfer was completed.
| Parameter | Type | Description |
|---|---|---|
| chainDest | uint256 | The chain ID of the destination chain |
| destBridge | address | The address of the Bridge contract on the destination chain |
| sessionId | uint256 | The session ID of the transfer to check |
Returns:
bytes memory: The acknowledgment message data, or empty bytes if no acknowledgment exists
Use Cases:
- Verify that a cross-chain transfer was successfully completed
- Implement UI feedback for transfer status
- Handle failed transfers or retry mechanisms
Events
DataWritten
event DataWritten(bytes data)
Emitted when a cross-chain message is sent via the Mailbox.
TokensReceived
event TokensReceived(address token, uint256 amount)
Emitted when tokens are successfully minted to the receiver on the destination chain.