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
core.addAmountToUser(msg.sender, address(0), msg.value)to credit the user's host chain coin balance in EVVM.
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 withDepositCoinWithToken()if host chain coin is sent. - Amount Validation: Ensures
amount > 0. Reverts withDepositAmountMustBeGreaterThanZero()if amount is zero. - Host Blockchain Transfer: Executes
IERC20(token).transferFrom(msg.sender, address(this), amount)to move tokens from user to Treasury contract. - EVVM Balance Credit: Calls
core.addAmountToUser(msg.sender, token, amount)to credit the user's token balance in EVVM.
Errors
DepositAmountMustBeGreaterThanZero()— Reverted when attempting to deposit zero host chain coin or zero ERC20 amount.InvalidDepositAmount()— Reverted whenamountdoes not matchmsg.valuefor native coin deposits.DepositCoinWithToken()— Reverted 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.