Build
Architecture
contracts
contracts
zevm
ZRC20.sol
Contract.zrc20

Git Source (opens in a new tab)

Inherits: IZRC20, IZRC20Metadata, ZRC20Errors

FUNGIBLE_MODULE_ADDRESS

Fungible address is always the same, maintained at the protocol level

address public constant FUNGIBLE_MODULE_ADDRESS = 0x735b14BB79463307AAcBED86DAf3322B1e6226aB;

CHAIN_ID

Chain id.abi

uint256 public immutable CHAIN_ID;

COIN_TYPE

Coin type, checkout Interfaces.sol.

CoinType public immutable COIN_TYPE;

SYSTEM_CONTRACT_ADDRESS

System contract address.

address public SYSTEM_CONTRACT_ADDRESS;

GAS_LIMIT

Gas limit.

uint256 public GAS_LIMIT;

PROTOCOL_FLAT_FEE

Protocol flat fee.

uint256 public PROTOCOL_FLAT_FEE;

_balances

mapping(address => uint256) private _balances;

_allowances

mapping(address => mapping(address => uint256)) private _allowances;

_totalSupply

uint256 private _totalSupply;

_name

string private _name;

_symbol

string private _symbol;

_decimals

uint8 private _decimals;

_msgSender

function _msgSender() internal view virtual returns (address);

_msgData

function _msgData() internal view virtual returns (bytes calldata);

onlyFungible

Only fungible module modifier.

modifier onlyFungible();

constructor

The only one allowed to deploy new ZRC20 is fungible address.

constructor(
    string memory name_,
    string memory symbol_,
    uint8 decimals_,
    uint256 chainid_,
    CoinType coinType_,
    uint256 gasLimit_,
    address systemContractAddress_
);

name

ZRC20 name

function name() public view virtual override returns (string memory);

Returns

NameTypeDescription
<none>stringname as string

symbol

ZRC20 symbol.

function symbol() public view virtual override returns (string memory);

Returns

NameTypeDescription
<none>stringsymbol as string.

decimals

ZRC20 decimals.

function decimals() public view virtual override returns (uint8);

Returns

NameTypeDescription
<none>uint8returns uint8 decimals.

totalSupply

ZRC20 total supply.

function totalSupply() public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256returns uint256 total supply.

balanceOf

Returns ZRC20 balance of an account.

function balanceOf(address account) public view virtual override returns (uint256);

Parameters

NameTypeDescription
accountaddress

Returns

NameTypeDescription
<none>uint256uint256 account balance.

transfer

Returns ZRC20 balance of an account.

function transfer(address recipient, uint256 amount) public virtual override returns (bool);

Parameters

NameTypeDescription
recipientaddress
amountuint256

Returns

NameTypeDescription
<none>booltrue/false if transfer succeeded/failed.

allowance

Returns token allowance from owner to spender.

function allowance(address owner, address spender) public view virtual override returns (uint256);

Parameters

NameTypeDescription
owneraddress
spenderaddress

Returns

NameTypeDescription
<none>uint256uint256 allowance.

approve

Approves amount transferFrom for spender.

function approve(address spender, uint256 amount) public virtual override returns (bool);

Parameters

NameTypeDescription
spenderaddress
amountuint256

Returns

NameTypeDescription
<none>booltrue/false if succeeded/failed.

transferFrom

Transfers tokens from sender to recipient.

function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool);

Parameters

NameTypeDescription
senderaddress
recipientaddress
amountuint256

Returns

NameTypeDescription
<none>booltrue/false if succeeded/failed.

burn

Burns an amount of tokens.

function burn(uint256 amount) external returns (bool);

Parameters

NameTypeDescription
amountuint256

Returns

NameTypeDescription
<none>booltrue/false if succeeded/failed.

_transfer

function _transfer(address sender, address recipient, uint256 amount) internal virtual;

_mint

function _mint(address account, uint256 amount) internal virtual;

_burn

function _burn(address account, uint256 amount) internal virtual;

_approve

function _approve(address owner, address spender, uint256 amount) internal virtual;

deposit

Deposits corresponding tokens from external chain, only callable by Fungible module.

function deposit(address to, uint256 amount) external override returns (bool);

Parameters

NameTypeDescription
toaddress
amountuint256

Returns

NameTypeDescription
<none>booltrue/false if succeeded/failed.

withdrawGasFee

Withdraws gas fees.

function withdrawGasFee() public view override returns (address, uint256);

Returns

NameTypeDescription
<none>addressreturns the ZRC20 address for gas on the same chain of this ZRC20, and calculates the gas fee for withdraw()
<none>uint256

withdraw

Withraws ZRC20 tokens to external chains, this function causes cctx module to send out outbound tx to the outbound chain this contract should be given enough allowance of the gas ZRC20 to pay for outbound tx gas fee.

function withdraw(bytes memory to, uint256 amount) external override returns (bool);

Parameters

NameTypeDescription
tobytes
amountuint256

Returns

NameTypeDescription
<none>booltrue/false if succeeded/failed.

updateSystemContractAddress

Updates system contract address. Can only be updated by the fungible module.

function updateSystemContractAddress(address addr) external onlyFungible;

Parameters

NameTypeDescription
addraddress

updateGasLimit

Updates gas limit. Can only be updated by the fungible module.

function updateGasLimit(uint256 gasLimit) external onlyFungible;

Parameters

NameTypeDescription
gasLimituint256

updateProtocolFlatFee

Updates protocol flat fee. Can only be updated by the fungible module.

function updateProtocolFlatFee(uint256 protocolFlatFee) external onlyFungible;

Parameters

NameTypeDescription
protocolFlatFeeuint256