Skip to main 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.

CanonicalERC20

struct CanonicalERC20 {
uint256 chainId;
address addr;
uint8 decimals;
string symbol;
string name;
}

MessageDeposit

struct MessageDeposit {
address token;
uint256 amount;
}

isBridgedToken

mapping(address => bool) isBridgedToken

bridgedToCanonical

mapping(address => struct TokenVault.CanonicalERC20) bridgedToCanonical

canonicalToBridged

mapping(uint256 => mapping(address => address)) canonicalToBridged

messageDeposits

mapping(bytes32 => struct TokenVault.MessageDeposit) messageDeposits

BridgedERC20Deployed

event BridgedERC20Deployed(uint256 srcChainId, address canonicalToken, address bridgedToken, string canonicalTokenSymbol, string canonicalTokenName, uint8 canonicalTokenDecimal)

EtherSent

event EtherSent(bytes32 msgHash, address from, address to, uint256 destChainId, uint256 amount)

ERC20Sent

event ERC20Sent(bytes32 msgHash, address from, address to, uint256 destChainId, address token, uint256 amount)

ERC20Released

event ERC20Released(bytes32 msgHash, address from, address token, uint256 amount)

ERC20Received

event ERC20Received(bytes32 msgHash, address from, address to, uint256 srcChainId, address token, uint256 amount)

TOKENVAULT_INVALID_TO

error TOKENVAULT_INVALID_TO()

TOKENVAULT_INVALID_VALUE

error TOKENVAULT_INVALID_VALUE()

TOKENVAULT_INVALID_CALL_VALUE

error TOKENVAULT_INVALID_CALL_VALUE()

TOKENVAULT_INVALID_TOKEN

error TOKENVAULT_INVALID_TOKEN()

TOKENVAULT_INVALID_AMOUNT

error TOKENVAULT_INVALID_AMOUNT()

TOKENVAULT_CANONICAL_TOKEN_NOT_FOUND

error TOKENVAULT_CANONICAL_TOKEN_NOT_FOUND()

TOKENVAULT_INVALID_OWNER

error TOKENVAULT_INVALID_OWNER()

TOKENVAULT_INVALID_SRC_CHAIN_ID

error TOKENVAULT_INVALID_SRC_CHAIN_ID()

TOKENVAULT_MESSAGE_NOT_FAILED

error TOKENVAULT_MESSAGE_NOT_FAILED()

TOKENVAULT_INVALID_SENDER

error TOKENVAULT_INVALID_SENDER()

init

function init(address addressManager) external

sendEther

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.

Parameters

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

sendERC20

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.

Parameters

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

releaseERC20

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.

Parameters

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.

receiveMXC

function receiveMXC(address to, uint256 amount) external

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

Parameters

NameTypeDescription
toaddressThe destination address.
amountuint256The amount of tokens to be sent. 0 is a valid value.

receiveERC20

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.

Parameters

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. |