Initia 백서

Initia

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 38쪽 중 37쪽

rns (address evm_address); ``` #### Parameters | Name | Type | Description | | ---------------- | --------------- | ----------------------------- | | `cosmos_address` | `string memory` | The Cosmos address to convert | #### Returns | Type | Description | | --------- | ----------------------------- | | `address` | The corresponding EVM address | ### `to_denom` Converts an ERC20 address to a Cosmos coin denom. ```solidity theme={null} function to_denom(address erc20_address) external returns (string memory denom); ``` #### Parameters | Name | Type | Description | | --------------- | --------- | ---------------------------- | | `erc20_address` | `address` | The ERC20 address to convert | #### Returns | Type | Description | | --------------- | ------------------------------ | | `string memory` | The corresponding Cosmos denom | ### `to_erc20` Converts a Cosmos coin denom to an ERC20 address. ```solidity theme={null} function to_erc20(string memory denom) external returns (address erc20_address); ``` #### Parameters | Name | Type | Description | | ------- | --------------- | --------------------------- | | `denom` | `string memory` | The Cosmos denom to convert | #### Returns | Type | Description | | --------- | ------------------------------- | | `address` | The corresponding ERC20 address | ### `execute_cosmos` Records a Cosmos message to be executed after the current message execution. The message must be in JSON string format. ```solidity theme={null} function execute_cosmos(string memory msg) external returns (bool dummy); ``` #### Parameters | Name | Type | Description | | ----- | --------------- | --------------------------------- | | `msg` | `string memory` | The Cosmos message in JSON format | #### Returns | Type | Description | | ------ | ------------------ | | `bool` | Dummy return value | ### `query_cosmos` Executes a whitelisted Cosmos SDK query. ```solidity theme={null} function query_cosmos(string memory path, string memory req) external returns (string memory result); ``` #### Parameters | Name | Type | Description | | ------ | --------------- | -------------------------------- | | `path` | `string memory` | The query path | | `req` | `string memory` | The query request in JSON format | #### Returns | Type | Description | | --------------- | ------------------------------- | | `string memory` | The query result in JSON format | # ERC20ACL Source: https://docs.initia.xyz/resources/developer/contract-references/evm/erc20-acl GitHub: [ERC20ACL](https://github.com/initia-labs/initia-evm-contracts/blob/main/src/ERC20ACL.sol) ## Overview The `ERC20ACL` contract provides access control mechanisms for ERC20 token operations. It includes modifiers to restrict certain actions based on conditions such as whether an address is a module address or a blocked address. ## Constants ### `CHAIN_ADDRESS` The address of the chain signer. ```solidity theme={null} address constant CHAIN_ADDRESS = 0x0000000000000000000000000000000000000001; ``` ## Modifiers ### `onlyChain` Restricts the function so it can be called only by the chain signer. ```solidity theme={null} modifier onlyChain() { require(msg.sender == CHAIN_ADDRESS, "ERC20: caller is not the chain"); _; } ``` ### `burnable` Restricts the function to ensure the sender is not a module address. ```solidity theme={null} modifier burnable(address from) { require(!COSMOS_CONTRACT.is_module_address(from), "ERC20: burn from module address"); _; } ``` #### Parameters | Name | Type | Description | | ------ | --------- | --------------------- | | `from` | `address` | The address to check. | ### `mintable` Restricts the function to ensure the recipient is not a blocked address. ```solidity theme={null} modifier mintable(address to) { require(!COSMOS_CONTRACT.is_blocked_address(to), "ERC20: mint to blocked address"); _; } ``` #### Parameters | Name | Type | Description | | ---- | --------- | --------------------- | | `to` | `address` | The address to check. | ### `transferable` Restricts the function to ensure the recipient is not a blocked address. ```solidity theme={null} modifier transferable(address to) { require(!COSMOS_CONTRACT.is_blocked_address(to), "ERC20: transfer to blocked address"); _; } ``` #### Parameters | Name | Type | Description | | ---- | --------- | --------------------- | | `to` | `address` | The address to check. | # ERC20Factory Source: https://docs.initia.xyz/resources/developer/contract-references/evm/erc20-factory GitHub: [ERC20Factory](https://github.com/initia-labs/initia-evm-contracts/blob/main/src/ERC20Factory.sol) ## Overview The `ERC20Factory` contract creates new InitiaERC20 tokens and registers them with the MiniEVM's ERC20Registry. ## Imports * [InitiaERC20.sol](/resources/developer/contract-references/evm/initia-erc20): Contains the implementation of the ERC20 token. * [ERC20Registry.sol](/resources/developer/contract-references/evm/erc20-registry): Contains the implementation of the ERC20 registry. ## Events ### `ERC20Created` Emitted when a new ERC20 token is created. | Parameter | Type | Description | | --------- | ----------------- | ---------------------------------------------------------- | | `erc20` | `address indexed` | The address of the newly created ERC20 token. | | `owner` | `address indexed` | The address of the owner of the newly created ERC20 token. | ## Functions ### `createERC20` Creates a new ERC20 token and registers it with the ERC20 registry. ```solidity theme={null} function createERC20(string memory name, string memory symbol, uint8 decimals) external returns (address) ``` #### Parameters | Name | Type | Description | | ---------- | --------------- | --------------------------------------------- | | `name` | `string memory` | The name of the new ERC20 token. | | `symbol` | `string memory` | The symbol of the new ERC20 token. | | `decimals` | `uint8` | The decimal precision of the new ERC20 token. | #### Returns | Type | Description | | --------- | --------------------------------------------- | | `address` | The address of the newly created ERC20 token. | #### Emits * [ERC20Created](#erc20created) # ERC20Registry Source: https://docs.initia.xyz/resources/developer/contract-references/evm/erc20-registry GitHub: [ERC20Registry](https://github.com/initia-labs/initia-evm-contracts/blob/main/src/ERC20Registry.sol) ## Overview The `ERC20Registry` contract provides modifiers for registering ERC20 tokens and their associated stores. Registration allows the token to be recognized and made interoperable with other parts of the MiniEVM rollup functionality. ## Modifiers ### `register_erc20` Registers an ERC20 token with the ERC20 registry. This is done to allow the token to be recognized and interoperable with other parts of the MiniEVM rollup. ```solidity theme={null} modifier register_erc20() { ERC20_REGISTRY_CONTRACT.register_erc20(); _; } ``` ### `register_erc20_store` Registers an ERC20 store for a given account with the ERC20 registry if it is not already registered. This is done to keep track of which accounts are associated with which ERC20 tokens. ```solidity theme={null} modifier register_erc20_store(address account) { if (!ERC20_REGISTRY_CONTRACT.is_erc20_store_registered(account)) { ERC20_REGISTRY_CONTRACT.register_erc20_store(account); } _; } ``` #### Parameters | Name | Type | Description | | --------- | --------- | ------------------------------------------------------------------------------- | | `account` | `address` | The address of the ERC20 store to check and register if not already registered. | # InitiaCustomERC20 Source: https://docs.initia.xyz/resources/developer/contract-references/evm/initia-custom-erc20 GitHub: [InitiaCustomERC20](https://github.com/initia-labs/initia-evm-contracts/blob/main/src/InitiaCustomERC20.sol) ## Overview The `InitiaCustomERC20` contract is a custom implementation of the ERC20 token standard. It includes additional access control mechanisms and registry functionalities to allow for better integration with the rollup's underlying Cosmos SDK stack. This is the main ERC20 token contract that developers should use to create their own custom ERC20 tokens on the MiniEVM. ## Inheritance * `IERC20`: Interface for ERC20 standard functions. * `Ownable`: Provides ownership control. * `ERC20Registry`: Handles ERC20 registry functionalities. * `ERC165`: Supports interface identification. * `ERC20ACL`: Provides access control mechanisms. ## State Variables * `mapping(address => uint256) public balanceOf`: Tracks the balance of each address. * `mapping(address => mapping(address => uint256)) public allowance`: Tracks the allowance each address has given to another address. * `string public name`: The name of the token. * `string public symbol`: The symbol of the token. * `uint8 public decimals`: The number of decimals the token uses. * `uint256 public totalSupply`: The total supply of the token. ## Constructor Initializes the contract with the token's name, symbol, and decimals. It also registers the ERC20 token with the ERC20Registry. ```solidity theme={null} constructor(string memory _name, string memory _symbol, uint8 _decimals) register_erc20 { name = _name; symbol = _symbol; decimals = _decimals; } ``` #### Parameters | Name | Type | Description | | ----------- | --------------- | -------------------------------------- | | `_name` | `string memory` | The name of the token. | | `_symbol` | `string memory` | The symbol of the token. | | `_decimals` | `uint8` | The number of decimals the token uses. | ## Functions ### `supportsInterface` Checks if the contract supports a given interface. ```solidity theme={null} function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165) returns (bool) ``` #### Parameters | Name | Type | Description | | ------------- | -------- | ------------------------- | | `interfaceId` | `bytes4` | The interface identifier. | #### Returns | Type | Description | | ------ | -------------------------------------------------------- | | `bool` | `true` if the interface is supported, `false` otherwise. | ### `_transfer` Transfers tokens from one address to another and registers the recipient's ERC20 store if necessary. ```solidity theme={null} function _transfer(address sender, address recipient, uint256 amount) internal register_erc20_store(recipient) ``` #### Parameters | Name | Type | Description | | ----------- | --------- | --------------------------------- | | `sender` | `address` | The address sending the tokens. | | `recipient` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to transfer. | ### `_mint` Mints new tokens and assigns them to an address, registering the recipient's ERC20 store if necessary. ```solidity theme={null} function _mint(address to, uint256 amount) internal register_erc20_store(to) ``` #### Parameters | Name | Type | Description | | -------- | --------- | --------------------------------- | | `to` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to mint. | ### `_burn` Burns tokens from an address. ```solidity theme={null} function _burn(address from, uint256 amount) internal ``` #### Parameters | Name | Type | Description | | -------- | --------- | ---------------------------------------- | | `from` | `address` | The address whose tokens will be burned. | | `amount` | `uint256` | The amount of tokens to burn. | ### `transfer` Transfers tokens to a recipient, ensuring the recipient is not a blocked address. ```solidity theme={null} function transfer(address recipient, uint256 amount) external transferable(recipient) returns (bool) ``` #### Parameters | Name | Type | Description | | ----------- | --------- | --------------------------------- | | `recipient` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to transfer. | #### Returns | Type | Description | | ------ | -------------------------------------- | | `bool` | `true` if the transfer was successful. | ### `approve` Approves an address to spend a specified amount of tokens on behalf of the caller. ```solidity theme={null} function approve(address spender, uint256 amount) external returns (bool) ``` #### Parameters | Name | Type | Description | | --------- | --------- | ---------------------------------------- | | `spender` | `address` | The address allowed to spend the tokens. | | `amount` | `uint256` | The amount of tokens to approve. | #### Returns | Type | Description | | ------ | -------------------------------------- | | `bool` | `true` if the approval was successful. | ### `transferFrom` Transfers tokens from one address to another on behalf of the sender, ensuring the recipient is not a blocked address. ```solidity theme={null} function transferFrom(address sender, address recipient, uint256 amount) external transferable(recipient) returns (bool) ``` #### Parameters | Name | Type | Description | | ----------- | --------- | --------------------------------- | | `sender` | `address` | The address sending the tokens. | | `recipient` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to transfer. | #### Returns | Type | Description | | ------ | -------------------------------------- | | `bool` | `true` if the transfer was successful. | ### `mint` Mints new tokens to a specified address, ensuring the recipient is not a blocked address. This function can only be called by the owner. ```solidity theme={null} function mint(address to, uint256 amount) external mintable(to) onlyOwner ``` #### Parameters | Name | Type | Description | | -------- | --------- | --------------------------------- | | `to` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to mint. | ### `burn` Burns tokens from a specified address, ensuring the sender is not a module address. This function can only be called by the owner. ```solidity theme={null} function burn(address from, uint256 amount) external burnable(from) onlyOwner ``` #### Parameters | Name | Type | Description | | -------- | --------- | ------------------------------------ | | `from` | `address` | The address whose tokens are burned. | | `amount` | `uint256` | The amount of tokens to burn. | ### `sudoTransfer` Transfers tokens from one address to another, bypassing the usual access control checks. This function can only be called by the chain signer. ```solidity theme={null} function sudoTransfer(address sender, address recipient, uint256 amount) external onlyChain ``` #### Parameters | Name | Type | Description | | ----------- | --------- | --------------------------------- | | `sender` | `address` | The address sending the tokens. | | `recipient` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to transfer. | # InitiaERC20 Source: https://docs.initia.xyz/resources/developer/contract-references/evm/initia-erc20 GitHub: [InitiaERC20](https://github.com/initia-labs/initia-evm-contracts/blob/main/src/InitiaERC20.sol) ## Overview The `InitiaERC20` contract is an implementation of the ERC20 token standard with additional functionalities such as access control, registry integration, and support for Cosmos blockchain interactions. This contract inherits from multiple contracts including `IERC20`, `Ownable`, `ERC20Registry`, `ERC165`, and `ERC20ACL`. <Warning> The InitiaERC20 contract is only meant to be used by the [ERC20Factory](/resources/developer/contract-references/evm/erc20-factory) contract. It is not meant to be used directly and does not have the necessary modifiers for full compatibility with the MiniEVM. To deploy a custom ERC20 token, developers should use the [InitiaCustomERC20](/resources/developer/contract-references/evm/initia-custom-erc20) contract instead. </Warning> ## Inheritance * `IERC20`: Interface for ERC20 standard functions. * `Ownable`: Provides ownership control. * `ERC20Registry`: Handles ERC20 registry functionalities. * `ERC165`: Supports interface identification. * `ERC20ACL`: Provides access control mechanisms. ## Events * `Transfer`: Emitted when tokens are transferred from one address to another. * `address indexed from`: The address sending the tokens. * `address indexed to`: The address receiving the tokens. * `uint256 value`: The amount of tokens transferred. * `Approval`: Emitted when an address approves another address to spend tokens on its behalf. * `address indexed owner`: The address granting the approval. * `address indexed spender`: The address receiving the approval. * `uint256 value`: The amount of tokens approved. ## State Variables * `mapping(address => uint256) public balanceOf`: Tracks the balance of each address. * `mapping(address => mapping(address => uint256)) public allowance`: Tracks the allowance each address has given to another address. * `string public name`: The name of the token. * `string public symbol`: The symbol of the token. * `uint8 public decimals`: The number of decimals the token uses. * `uint256 public totalSupply`: The total supply of the token. ## Constructor Initializes the contract with the token's name, symbol, and decimals. ```solidity theme={null} constructor(string memory _name, string memory _symbol, uint8 _decimals) { name = _name; symbol = _symbol; decimals = _decimals; } ``` #### Parameters | Name | Type | Description | | ----------- | --------------- | -------------------------------------- | | `_name` | `string memory` | The name of the token. | | `_symbol` | `string memory` | The symbol of the token. | | `_decimals` | `uint8` | The number of decimals the token uses. | ## Functions ### `supportsInterface` Checks if the contract supports a given interface. ```solidity theme={null} function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) ``` #### Parameters | Name | Type | Description | | ------------- | -------- | ------------------------- | | `interfaceId` | `bytes4` | The interface identifier. | #### Returns | Type | Description | | ------ | -------------------------------------------------------- | | `bool` | `true` if the interface is supported, `false` otherwise. | ### `_transfer` Transfers tokens from one address to another and registers the recipient's ERC20 store if necessary. ```solidity theme={null} function _transfer(address sender, address recipient, uint256 amount) internal register_erc20_store(recipient) ``` #### Parameters | Name | Type | Description | | ----------- | --------- | --------------------------------- | | `sender` | `address` | The address sending the tokens. | | `recipient` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to transfer. | ### `_mint` Mints new tokens and assigns them to an address, registering the recipient's ERC20 store if necessary. ```solidity theme={null} function _mint(address to, uint256 amount) internal register_erc20_store(to) ``` #### Parameters | Name | Type | Description | | -------- | --------- | --------------------------------- | | `to` | `address` | The address receiving the tokens. | | `amount` | `uint256` | The amount of tokens to mint. | ### `_burn` Burns tokens from an address. ```solidity theme={null} function _burn(address from, uint256 amount) internal ``` #### Parameters | Name | Type | Description | | -------- | --------- | ---------------------------------------- | | `from` | `address` | The address whose tokens will be burned. | | `amount` | `uint256` | The amount of tokens to burn. | ### `transfer` Transfers tokens to a recipient, ensuring the recipient is not a blocked address. ```solidity theme={null} function transfer(address recipient, uint256 amount) external transferable(recip
프로젝트로 돌아가기