CCTPBridge
Inherits: BaseBridge, CCTPHelper, IBridge, ReentrancyGuard
Title: CCTPBridge
Author: Malda Protocol
Cross-chain bridge that uses Circle CCTP v2
State Variables
REBALANCER
The Rebalancer contract allowed to initiate bridging actions.
address public immutable REBALANCER
chainIdToDomain
Maps EVM chainId -> CCTP domain id.
mapping(uint32 chainId => uint32 cctpDomain) public chainIdToDomain
domainSet
Tracks whether a domain mapping exists for a given EVM chainId.
mapping(uint32 chainId => bool isSet) public domainSet
Functions
constructor
Constructor for the CCTPBridge contract.
constructor(address _roles, address _tokenMessenger, address _messageTransmitter, address _rebalancer)
BaseBridge(_roles)
CCTPHelper(_tokenMessenger, _messageTransmitter);
Parameters
| Name | Type | Description |
|---|---|---|
_roles | address | Address of the Roles contract. |
_tokenMessenger | address | Address of the TokenMessenger contract. |
_messageTransmitter | address | Address of the MessageTransmitter contract. |
_rebalancer | address | Address of the Rebalancer contract. |
setDomainMapping
Sets the CCTP domain id for a given EVM chainId.
function setDomainMapping(uint32 chainId, uint32 domain) external onlyBridgeConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
chainId | uint32 | The EVM chainId to set. |
domain | uint32 | The corresponding CCTP domain id. |
setAcceptedToken
Enables or disables a token for use with CCTP burns.
function setAcceptedToken(address token, bool allowed) external onlyBridgeConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The token address. |
allowed | bool | True to enable, false to disable. |
sendMsg
Burns tokens and creates a CCTP message for the destination chain.
function sendMsg(
uint256 _extractedAmount,
address _market,
uint32 _dstChainId,
address _token,
bytes calldata _unused1,
bytes calldata _unused2
) external payable override onlyRebalancer;
Parameters
| Name | Type | Description |
|---|---|---|
_extractedAmount | uint256 | Amount to burn. |
_market | address | Destination market address (encoded into the CCTP hook payload). |
_dstChainId | uint32 | Destination EVM chainId. |
_token | address | Token to burn (e.g., USDC). |
_unused1 | bytes | Unused parameter kept for IBridge compatibility. |
_unused2 | bytes | Unused parameter kept for IBridge compatibility. |
handleCCTPMessage
Receives a CCTP message+attestation and forwards received tokens to the encoded destination market.
function handleCCTPMessage(bytes calldata cctpMessage, bytes calldata attestation) external nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
cctpMessage | bytes | Raw CCTP message bytes. |
attestation | bytes | Circle attestation proving message validity. |
getFee
computes fee for bridge operation
function getFee(uint32, bytes calldata, bytes calldata) external pure override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
<none> | uint32 | |
<none> | bytes | |
<none> | bytes |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | fee Computed bridge fee |
Events
Rebalanced
Emitted when bridged funds are forwarded to a destination market.
event Rebalanced(address indexed market, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
market | address | The destination market that received the funds. |
amount | uint256 | The amount of tokens forwarded to the market. |
DomainMappingUpdated
Emitted when a chainId -> CCTP domain mapping is updated.
event DomainMappingUpdated(uint32 indexed chainId, uint32 indexed domain);
Parameters
| Name | Type | Description |
|---|---|---|
chainId | uint32 | The EVM chainId. |
domain | uint32 | The CCTP domain id. |
TokenAccepted
Emitted when a token is enabled or disabled for CCTP burns.
event TokenAccepted(address indexed token, bool status);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The token address. |
status | bool | True if enabled, false if disabled. |
Errors
CCTPBridge_AddressNotValid
error CCTPBridge_AddressNotValid();
CCTPBridge_InvalidReceiver
error CCTPBridge_InvalidReceiver();
CCTPBridge_TokenMismatch
error CCTPBridge_TokenMismatch();
CCTPBridge_NotImplemented
error CCTPBridge_NotImplemented();
CCTPBridge_DomainNotSet
error CCTPBridge_DomainNotSet();