Overview
TheTokenMinter contract manages the minting and burning of tokens for cross-chain transfers. It maintains a registry of local mintable tokens and their corresponding tokens on remote domains, enabling the system to determine which token to mint on the local domain for a burned token on a remote domain, and vice versa. All local and remote tokens are assumed to be fungible at a constant 1:1 exchange rate.
State Variables
Local TokenMessenger with permission to call mint and burn on this TokenMinter. Only this address can trigger minting and burning operations.
Functions
mint
Mints tokens corresponding to a burn on a remote domain.Source domain where
burnToken was burnedBurned token address as bytes32
Address to receive minted tokens corresponding to
burnToken on this domainAmount of tokens to mint. Must be less than or equal to the minterAllowance of this TokenMinter for the given mint token.
address - The address of the token that was minted
Access Control:
- Only callable by the local TokenMessenger
- Only executable when contract is not paused
- Looks up the local token address using
getLocalToken(sourceDomain, burnToken) - Validates the local token exists (is not address(0))
- Calls the
mint()function on the local token contract - Returns the minted token address
- Caller is not the local TokenMessenger
- Contract is paused
- The (sourceDomain, burnToken) pair does not map to a nonzero local token address
- The mint operation on the token contract fails
You can query the local token address for a given (sourceDomain, burnToken) pair using the
getLocalToken() view function.burn
Burns tokens owned by this TokenMinter.Burnable token address
Amount of tokens to burn. Must be greater than 0 and less than or equal to the maximum burn amount per message.
- Only callable by the local TokenMessenger
- Only executable when contract is not paused
- Must be within burn limit for the token
- Validates burn amount is within the per-message burn limit
- Calls the
burn()function on the token contract - Burns tokens from the TokenMinter’s balance
- Caller is not the local TokenMessenger
- Contract is paused
- burnAmount is 0
- burnAmount exceeds the maximum burn amount per message for the token
- The burn operation on the token contract fails
addLocalTokenMessenger
Adds a TokenMessenger for the local domain. Only this TokenMessenger has permission to callmint() and burn() on this TokenMinter.
The address of the new TokenMessenger on the local domain. Must be nonzero.
- Only callable by the contract owner
- newLocalTokenMessenger is address(0)
- A local TokenMessenger is already set
- Emits
LocalTokenMessengerAddedevent
removeLocalTokenMessenger
Removes the TokenMessenger for the local domain.- Only callable by the contract owner
- No local TokenMessenger is set
- Emits
LocalTokenMessengerRemovedevent
setTokenController
Sets the token controller to a new address.Address of new token controller. Must be nonzero.
- Only callable by the contract owner
- Updates the token controller address
- Emits
SetTokenControllerevent
- newTokenController is address(0)
The token controller is responsible for managing token pair mappings and burn limits. This is inherited from the
TokenController role.getLocalToken
Gets the local token address associated with a given remote domain and token.Remote domain identifier
Remote token address as bytes32
address - Local token address, or address(0) if no mapping exists
Usage:
- Query this function to determine which local token will be minted for a given remote token
- Returns address(0) if the remote token is not supported on this domain
Burn Limits
The TokenMinter inherits fromTokenController, which manages per-message burn limits for each token. These limits ensure that no single transaction can burn an excessive amount of tokens.
Per-Message Burn Limits
- Each token has a maximum burn amount per message
- The
burn()function enforces this limit via theonlyWithinBurnLimitmodifier - Burn limits are managed by the token controller
- Limits help protect against potential exploits and maintain system stability
Token Management
The TokenMinter maintains a registry that maps remote tokens to local tokens:- Token Pair Registry: Maps (remoteDomain, remoteToken) → localToken
- 1:1 Exchange Rate: All token pairs are assumed to be fungible at a 1:1 ratio
- Token Controller: Manages the token pair mappings and burn limits
Adding Token Support
To support a new token for cross-chain transfers:- The token controller must add a mapping between the remote token and local token
- Set appropriate burn limits for the token
- Ensure the TokenMinter has sufficient minter allowance on the local token contract
Events
LocalTokenMessengerAdded
Emitted when a local TokenMessenger is added.Address of local TokenMessenger
LocalTokenMessengerRemoved
Emitted when a local TokenMessenger is removed.Address of local TokenMessenger that was removed
Access Control
The TokenMinter implements strict access control:- Owner: Can add/remove local TokenMessenger and set token controller
- Local TokenMessenger: Can call mint() and burn() functions
- Token Controller: Manages token pair mappings and burn limits
Modifier: onlyLocalTokenMessenger
Ensures that only the registered local TokenMessenger can call protected functions.Integration with TokenMessenger
The TokenMinter works in tandem with the TokenMessenger:- Burn Flow: TokenMessenger transfers tokens to TokenMinter, then calls
burn() - Mint Flow: TokenMessenger calls
mint()when receiving a cross-chain message - Access Control: Only the registered TokenMessenger can trigger minting/burning