deposit
Function Type: external payable
Function Signature: deposit(address,uint256)
Returns: void
Deposits host chain coins or ERC20 tokens from the host blockchain into the EVVM virtual blockchain. The function transfers assets from the user's wallet on the host blockchain to the Treasury contract and credits the equivalent balance in the EVVM system.
Parameters
| Parameter | Type | Description |
|---|---|---|
token | address | Token contract address or address(0) for host chain coin |
amount | uint256 | Amount to deposit (must match msg.value for host chain coin) |
Workflow
Host Chain Coin Deposit Flow (when token == address(0)):
- Zero Check: Ensures
msg.value > 0. Reverts withDepositAmountMustBeGreaterThanZero()if zero host chain coin is sent. - Amount Validation: Verifies that
amountexactly matchesmsg.value. Reverts withInvalidDepositAmount()if they don't match. - EVVM Balance Credit: Calls
addAmountToUser(msg.sender, address(0), msg.value)in the EVVM core contract to credit the user's internal host chain coin balance in the virtual blockchain.
ERC20 Deposit Flow (when token != address(0)):
- Host Chain Coin Validation: Ensures
msg.value == 0(no host chain coin should be sent with ERC20 deposits). Reverts withInvalidDepositAmount()if host chain coin is sent. - Amount Validation: Ensures
amount > 0. Reverts withDepositAmountMustBeGreaterThanZero()if amount is zero. - Host Blockchain Transfer: Executes
transferFrom(msg.sender, address(this), amount)to move tokens from user to Treasury contract on the host blockchain. - EVVM Balance Credit: Calls
addAmountToUser(msg.sender, token, amount)in the EVVM core contract to credit the user's internal token balance in the virtual blockchain.
Errors
DepositAmountMustBeGreaterThanZero()— Reverted when attempting to deposit zero host chain coin or zero ERC20 amount.InvalidDepositAmount()— Reverted whenamountdoes not matchmsg.valuefor native coin deposits, or when native coin is sent alongside an ERC20 deposit.
Security & Notes
- ERC20 transfers use
IERC20(token).transferFrom(msg.sender, address(this), amount)in the current implementation. Some tokens do not strictly follow the ERC20 spec (they may returnfalseon failure or not return a boolean), so using a safe transfer helper (e.g.,SafeTransferLib.safeTransferFrom) or validating the return value in tests is recommended. - The ERC20 transfer occurs before calling
addAmountToUser(...). Be aware that non-standard tokens (or ERC777 hooks) could attempt reentrancy; tests should cover malicious token behaviour. - When depositing native coin (
address(0)), the function requiresmsg.value == amount— theamountparameter is validated againstmsg.valueto avoid ambiguity. Consider callingdeposit(address(0), msg.value)for clarity in integrations.