Overview
TokenMessengerV2 is responsible for facilitating cross-chain USDC transfers by burning tokens on the source domain and minting them on the destination domain. V2 introduces fee mechanisms, finality thresholds, and optional hook execution.
Contract Location: src/v2/TokenMessengerV2.sol
Key Features
New Features vs V1
- Fee Mechanism: Support for destination domain fees with
maxFeeparameter - Minimum Fee Control: Configurable minimum fee requirements in basis points
- Finality Thresholds: Messages can specify minimum finality requirements
- Hook Execution: Optional
hookDatafor custom logic on destination domain - Destination Caller: Specify authorized caller on destination domain
- Denylist Support: Ability to denylist addresses from using the protocol
Constructor
Parameters
_messageTransmitter(address): Message transmitter address_messageBodyVersion(uint32): Message body version
Initialization
src/v2/TokenMessengerV2.sol:109
Parameters
roles(TokenMessengerV2Roles): Struct containing all role addressesowner: Owner address (cannot be zero)rescuer: Rescuer addressfeeRecipient: Address to receive collected feesdenylister: Address with permission to manage denylisttokenMinter: Local token minter addressminFeeController: Address with permission to set minimum fee
minFee_(uint256): Initial minimum fee (in 1/1000 basis points)remoteDomains_(uint32[]): Array of remote domain IDsremoteTokenMessengers_(bytes32[]): Array of remote TokenMessenger addresses (must match remoteDomains_ length)
Requirements
- Owner must be non-zero address
- Remote domains and remote token messengers arrays must have equal length
- All remote token messenger addresses must be non-zero
Core Functions
depositForBurn
src/v2/TokenMessengerV2.sol:166
Parameters
amount(uint256): Amount of tokens to burn (must be nonzero)destinationDomain(uint32): Destination domain to receive message onmintRecipient(bytes32): Address of mint recipient on destination domainburnToken(address): Token to burnamountof, on local domaindestinationCaller(bytes32): Authorized caller on the destination domain as bytes32. If equal tobytes32(0), any address can broadcast the messagemaxFee(uint256): Maximum fee to pay on the destination domain, specified in units of burnTokenminFinalityThreshold(uint32): The minimum finality at which the burn message will be attested to
Requirements
- Caller must not be denylisted
- Amount must be nonzero
- Mint recipient must be nonzero
- Burn token must be supported
- Destination domain must have a TokenMessenger registered
maxFeemust be less thanamountmaxFeemust be >=amount * minFee / MIN_FEE_MULTIPLIER(if minFee > 0)- Sender must have sufficient balance and approval
Events
depositForBurnWithHook
src/v2/TokenMessengerV2.sol:210
Parameters
Same asdepositForBurn, plus:
hookData(bytes): Hook data to append to burn message for interpretation on destination domain (must be non-empty)
Requirements
Same asdepositForBurn, plus:
hookDatamust have length > 0
handleReceiveFinalizedMessage
src/v2/TokenMessengerV2.sol:245
Parameters
remoteDomain(uint32): The domain where the message originated fromsender(bytes32): The sender of the message (remote TokenMessenger)finalityThresholdExecuted(uint32): The level of finality at which the message was attested (unused in finalized handler)messageBody(bytes): The message body bytes
Returns
success(bool): True if successful
Requirements
- Caller must be the local MessageTransmitter
- Sender must be a registered remote TokenMessenger for the given domain
handleReceiveUnfinalizedMessage
feeRecipient address.
Reference: src/v2/TokenMessengerV2.sol:274
Parameters
remoteDomain(uint32): The domain where the message originated fromsender(bytes32): The sender of the message (remote TokenMessenger)finalityThresholdExecuted(uint32): The level of finality at which the message was attested tomessageBody(bytes): The message body bytes
Returns
success(bool): True if successful
Requirements
- Caller must be the local MessageTransmitter
- Sender must be a registered remote TokenMessenger for the given domain
finalityThresholdExecutedmust be >=TOKEN_MESSENGER_MIN_FINALITY_THRESHOLD(500)
Fee Management Functions
getMinFeeAmount
src/v2/TokenMessengerV2.sol:299
Parameters
amount(uint256): The amount for which to calculate the minimum fee (must be > 1)
Returns
- Minimum fee for the given amount
Formula
MIN_FEE_MULTIPLIER = 10,000,000 (enables 1/1000 basis point precision)
setFeeRecipient
src/v2/BaseTokenMessenger.sol:222
Parameters
_feeRecipient(address): Address of fee recipient (cannot be zero address)
Events
setMinFeeController
src/v2/BaseTokenMessenger.sol:232
Parameters
_minFeeController(address): Address of minimum fee controller (cannot be zero address)
Events
setMinFee
src/v2/BaseTokenMessenger.sol:242
Parameters
_minFee(uint256): Minimum fee (must be < MIN_FEE_MULTIPLIER)
Events
Denylist Functions
addToDenylist
depositForBurn or depositForBurnWithHook.
removeFromDenylist
Remote TokenMessenger Management
addRemoteTokenMessenger
src/v2/BaseTokenMessenger.sol:171
removeRemoteTokenMessenger
src/v2/BaseTokenMessenger.sol:182
Local Minter Management
addLocalMinter
src/v2/BaseTokenMessenger.sol:200
removeLocalMinter
src/v2/BaseTokenMessenger.sol:208
State Variables
Immutable
localMessageTransmitter(address): Local Message Transmitter addressmessageBodyVersion(uint32): Version of message body format
Storage
localMinter(ITokenMinterV2): Local token minter contractremoteTokenMessengers(mapping(uint32 => bytes32)): Valid TokenMessengers on remote domainsfeeRecipient(address): Address to receive collected feesminFeeController(address): Minimum fee controller addressminFee(uint256): Minimum fee for all transfers in 1/1000 basis pointsMIN_FEE_MULTIPLIER(uint256): Constant value of 10,000,000 (1/1000 basis point precision)
Integration Example
Fee Calculation Example
IfminFee = 5000 (0.05%):
maxFee parameter must be >= minFeeAmount and < amount.
Event Signature Changes
The V2DepositForBurn event includes additional parameters compared to V1:
destinationCaller(bytes32): Authorized caller specificationmaxFee(uint256): Maximum fee willing to payminFinalityThreshold(uint32): Minimum finality requirement (indexed)hookData(bytes): Optional hook data
Security Considerations
- Fee Validation: Max fee is validated to be less than amount and meet minimum fee requirements
- Denylist Protection: Denylisted addresses cannot initiate burns
- Caller Authorization: Optional destination caller restriction
- Finality Thresholds: Minimum finality of 500 required for unfinalized messages
- Message Expiration: Burn messages can include expiration blocks