ERC20Custody
Git Source (opens in a new tab)
Inherits: IERC20Custody, ReentrancyGuard, AccessControl, Pausable
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.
State Variables
gateway
Gateway contract.
IGatewayEVM public immutable 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");
Functions
constructor
Constructor for ERC20Custody.
Set admin as default admin and pauser, and tssAddress as tss role.
constructor(address gateway_, address tssAddress_, address admin_);
pause
Pause contract.
function pause() external onlyRole(PAUSER_ROLE);
unpause
Unpause contract.
function unpause() external onlyRole(PAUSER_ROLE);
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
Name | Type | Description |
---|---|---|
token | address | address of ERC20 token |
unwhitelist
Unwhitelist ERC20 token.
function unwhitelist(address token) external onlyRole(WHITELISTER_ROLE);
Parameters
Name | Type | Description |
---|---|---|
token | address | address 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
Name | Type | Description |
---|---|---|
to | address | Destination address for the tokens. |
token | address | Address of the ERC20 token. |
amount | uint256 | Amount 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(
address to,
address token,
uint256 amount,
bytes calldata data
)
public
nonReentrant
onlyRole(WITHDRAWER_ROLE)
whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
to | address | Address of the contract to call. |
token | address | Address of the ERC20 token. |
amount | uint256 | Amount of tokens to withdraw. |
data | bytes | Calldata 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
Name | Type | Description |
---|---|---|
to | address | Address of the contract to call. |
token | address | Address of the ERC20 token. |
amount | uint256 | Amount of tokens to withdraw. |
data | bytes | Calldata to pass to the contract call. |
revertContext | RevertContext | Revert 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;