Skip to content

Token Vault

This vault holds all ERC20 tokens (but not Ether) that users have deposited. It also manages the mapping between canonical ERC20 tokens and their bridged tokens.

Ether is held by Bridges on L1 and by the EtherVault on L2, not TokenVaults.

struct CanonicalERC20 {
uint256 chainId;
address addr;
uint8 decimals;
string symbol;
string name;
}
struct MessageDeposit {
address token;
uint256 amount;
}
mapping(address => bool) isBridgedToken
mapping(address => struct TokenVault.CanonicalERC20) bridgedToCanonical
mapping(uint256 => mapping(address => address)) canonicalToBridged
mapping(bytes32 => struct TokenVault.MessageDeposit) messageDeposits
event BridgedERC20Deployed(uint256 srcChainId, address canonicalToken, address bridgedToken, string canonicalTokenSymbol, string canonicalTokenName, uint8 canonicalTokenDecimal)
event EtherSent(bytes32 msgHash, address from, address to, uint256 destChainId, uint256 amount)
event ERC20Sent(bytes32 msgHash, address from, address to, uint256 destChainId, address token, uint256 amount)
event ERC20Released(bytes32 msgHash, address from, address token, uint256 amount)
event ERC20Received(bytes32 msgHash, address from, address to, uint256 srcChainId, address token, uint256 amount)
error TOKENVAULT_INVALID_TO()
error TOKENVAULT_INVALID_VALUE()
error TOKENVAULT_INVALID_CALL_VALUE()
error TOKENVAULT_INVALID_TOKEN()
error TOKENVAULT_INVALID_AMOUNT()
error TOKENVAULT_CANONICAL_TOKEN_NOT_FOUND()
error TOKENVAULT_INVALID_OWNER()
error TOKENVAULT_INVALID_SRC_CHAIN_ID()
error TOKENVAULT_MESSAGE_NOT_FAILED()
error TOKENVAULT_INVALID_SENDER()
function init(address addressManager) external
function sendEther(uint256 destChainId, address to, uint256 gasLimit, uint256 processingFee, address refundAddress, string memo) external payable

Receives Ether and constructs a Bridge message. Sends the Ether and message along to the Bridge.

NameTypeDescription
destChainIduint256@custom:see IBridge.Message
toaddress@custom:see IBridge.Message
gasLimituint256@custom:see IBridge.Message
processingFeeuint256@custom:see IBridge.Message
refundAddressaddress@custom:see IBridge.Message
memostring@custom:see IBridge.Message
function sendERC20(uint256 destChainId, address to, address token, uint256 amount, uint256 gasLimit, uint256 processingFee, address refundAddress, string memo) external payable

Transfers ERC20 tokens to this vault and sends a message to the destination chain so the user can receive the same amount of tokens by invoking the message call.

NameTypeDescription
destChainIduint256@custom:see IBridge.Message
toaddress@custom:see IBridge.Message
tokenaddressThe address of the token to be sent.
amountuint256The amount of token to be transferred.
gasLimituint256@custom:see IBridge.Message
processingFeeuint256@custom:see IBridge.Message
refundAddressaddress@custom:see IBridge.Message
memostring@custom:see IBridge.Message
function releaseERC20(struct IBridge.Message message, bytes proof) external

Release deposited ERC20 back to the owner on the source TokenVault with a proof that the message processing on the destination Bridge has failed.

NameTypeDescription
messagestruct IBridge.MessageThe message that corresponds the ERC20 deposit on the
source chain.
proofbytesThe proof from the destination chain to show the message
has failed.
function receiveMCH(address to, uint256 amount) external

This function can only be called by the bridge contract while receiving L2 eth

NameTypeDescription
toaddressThe destination address.
amountuint256The amount of tokens to be sent. 0 is a valid value.
function receiveERC20(struct TokenVault.CanonicalERC20 canonicalToken, address from, address to, uint256 amount) external

This function can only be called by the bridge contract while invoking a message call. See sendERC20, which sets the data to invoke this function.

NameTypeDescription
canonicalTokenstruct TokenVault.CanonicalERC20The canonical ERC20 token which may or may not

live on this chain. If not, a BridgedERC20 contract will be deployed. | | from | address | The source address. | | to | address | The destination address. | | amount | uint256 | The amount of tokens to be sent. 0 is a valid value. |