CCTPBridge

Git Source

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

NameTypeDescription
_rolesaddressAddress of the Roles contract.
_tokenMessengeraddressAddress of the TokenMessenger contract.
_messageTransmitteraddressAddress of the MessageTransmitter contract.
_rebalanceraddressAddress of the Rebalancer contract.

setDomainMapping

Sets the CCTP domain id for a given EVM chainId.

function setDomainMapping(uint32 chainId, uint32 domain) external onlyBridgeConfigurator;

Parameters

NameTypeDescription
chainIduint32The EVM chainId to set.
domainuint32The corresponding CCTP domain id.

setAcceptedToken

Enables or disables a token for use with CCTP burns.

function setAcceptedToken(address token, bool allowed) external onlyBridgeConfigurator;

Parameters

NameTypeDescription
tokenaddressThe token address.
allowedboolTrue 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

NameTypeDescription
_extractedAmountuint256Amount to burn.
_marketaddressDestination market address (encoded into the CCTP hook payload).
_dstChainIduint32Destination EVM chainId.
_tokenaddressToken to burn (e.g., USDC).
_unused1bytesUnused parameter kept for IBridge compatibility.
_unused2bytesUnused 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

NameTypeDescription
cctpMessagebytesRaw CCTP message bytes.
attestationbytesCircle attestation proving message validity.

getFee

computes fee for bridge operation

function getFee(uint32, bytes calldata, bytes calldata) external pure override returns (uint256);

Parameters

NameTypeDescription
<none>uint32
<none>bytes
<none>bytes

Returns

NameTypeDescription
<none>uint256fee Computed bridge fee

Events

Rebalanced

Emitted when bridged funds are forwarded to a destination market.

event Rebalanced(address indexed market, uint256 amount);

Parameters

NameTypeDescription
marketaddressThe destination market that received the funds.
amountuint256The 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

NameTypeDescription
chainIduint32The EVM chainId.
domainuint32The CCTP domain id.

TokenAccepted

Emitted when a token is enabled or disabled for CCTP burns.

event TokenAccepted(address indexed token, bool status);

Parameters

NameTypeDescription
tokenaddressThe token address.
statusboolTrue 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();