Build
Architecture
protocol
contracts
evm
ERC20Custody.sol
Contract.erc20custody

Git Source (opens in a new tab)

Inherits: Initializable, UUPSUpgradeable, IERC20Custody, ReentrancyGuardUpgradeable, AccessControlUpgradeable, PausableUpgradeable

Holds the ERC20 tokens deposited on ZetaChain and includes functionality to call a contract.

This contract does not call smart contracts directly, it passes through the Gateway contract.

gateway

Gateway contract.

IGatewayEVM public gateway;

whitelisted

Mapping of whitelisted tokens => true/false.

mapping(address => bool) public whitelisted;

tssAddress

The address of the TSS (Threshold Signature Scheme) contract.

address public tssAddress;

supportsLegacy

Used to flag if contract supports legacy methods (eg. deposit).

bool public supportsLegacy;

PAUSER_ROLE

New role identifier for pauser role.

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

WITHDRAWER_ROLE

New role identifier for withdrawer role.

bytes32 public constant WITHDRAWER_ROLE = keccak256("WITHDRAWER_ROLE");

WHITELISTER_ROLE

New role identifier for whitelister role.

bytes32 public constant WHITELISTER_ROLE = keccak256("WHITELISTER_ROLE");

initialize

Initializer for ERC20Custody.

Set admin as default admin and pauser, and tssAddress as tss role.

function initialize(address gateway_, address tssAddress_, address admin_) public initializer;

_authorizeUpgrade

Authorizes the upgrade of the contract, sender must be owner.

function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
newImplementationaddressAddress of the new implementation.

pause

Pause contract.

function pause() external onlyRole(PAUSER_ROLE);

unpause

Unpause contract.

function unpause() external onlyRole(PAUSER_ROLE);

updateTSSAddress

Update tss address

function updateTSSAddress(address newTSSAddress) external onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
newTSSAddressaddressnew tss address

setSupportsLegacy

Unpause contract.

function setSupportsLegacy(bool _supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE);

whitelist

Whitelist ERC20 token.

function whitelist(address token) external onlyRole(WHITELISTER_ROLE);

Parameters

NameTypeDescription
tokenaddressaddress of ERC20 token

unwhitelist

Unwhitelist ERC20 token.

function unwhitelist(address token) external onlyRole(WHITELISTER_ROLE);

Parameters

NameTypeDescription
tokenaddressaddress of ERC20 token

withdraw

Withdraw directly transfers the tokens to the destination address without contract call.

This function can only be called by the TSS address.

function withdraw(
    address to,
    address token,
    uint256 amount
)
    external
    nonReentrant
    onlyRole(WITHDRAWER_ROLE)
    whenNotPaused;

Parameters

NameTypeDescription
toaddressDestination address for the tokens.
tokenaddressAddress of the ERC20 token.
amountuint256Amount of tokens to withdraw.

withdrawAndCall

WithdrawAndCall transfers tokens to Gateway and call a contract through the Gateway.

This function can only be called by the TSS address.

function withdrawAndCall(
    MessageContext calldata messageContext,
    address to,
    address token,
    uint256 amount,
    bytes calldata data
)
    public
    nonReentrant
    onlyRole(WITHDRAWER_ROLE)
    whenNotPaused;

Parameters

NameTypeDescription
messageContextMessageContextMessage context containing sender.
toaddressAddress of the contract to call.
tokenaddressAddress of the ERC20 token.
amountuint256Amount of tokens to withdraw.
databytesCalldata to pass to the contract call.

withdrawAndRevert

WithdrawAndRevert transfers tokens to Gateway and call a contract with a revert functionality through the Gateway.

This function can only be called by the TSS address.

function withdrawAndRevert(
    address to,
    address token,
    uint256 amount,
    bytes calldata data,
    RevertContext calldata revertContext
)
    public
    nonReentrant
    onlyRole(WITHDRAWER_ROLE)
    whenNotPaused;

Parameters

NameTypeDescription
toaddressAddress of the contract to call.
tokenaddressAddress of the ERC20 token.
amountuint256Amount of tokens to withdraw.
databytesCalldata to pass to the contract call.
revertContextRevertContextRevert context to pass to onRevert.

deposit

Deposits asset to custody and pay fee in zeta erc20.

function deposit(
    bytes calldata recipient,
    IERC20 asset,
    uint256 amount,
    bytes calldata message
)
    external
    nonReentrant
    whenNotPaused;