Alert Source Discuss
⚠️ Draft Standards Track: ERC

ERC-7196: 简单 Token,简化版 ERC-20

专为智能合约钱包设计,此提案从 ERC-20 Token 中移除 transferFrom、approve 和 allowance 函数。

Authors Xiang (@wenzhenxiang), Ben77 (@ben2077), Mingshi S. (@newnewsms)
Created 2023-06-21
Discussion Link https://ethereum-magicians.org/t/simple-token-designed-for-smart-contract-wallet-aa/14757
Requires EIP-20

摘要

这个 ERC 是一种基于用户合约钱包(包括账户抽象)设计的新型资产,并且向前兼容 ERC-20。为了保持 Token 资产的简单性,此 ERC 移除了 ERC-20 的 transferFromapproveallowance 函数。

动机

ERC-20 定义了基于以太坊的可交易和转移的标准 Token,但 ERC-20 的本质是基于外部拥有账户(EOA)钱包的设计。EOA 钱包没有状态和代码存储,这与智能合约钱包不同。

几乎所有与 Token 相关的 ERC 都在添加功能,但我们的观点恰恰相反。我们认为 Token 合约应该更简单,更多的功能由智能合约钱包来负责。

我们的提案是基于智能合约钱包设计一个更简单的 Token 资产。

其旨在实现以下目标:

  1. 保持资产合约的简单性:仅负责 transfer 函数。
  2. approveallowance 函数不由 Token 合约管理,而是这些权限在用户级别进行管理,为用户提供更大的灵活性和控制权。此更改不仅增强了用户的自主性,还减轻了与 ERC-20 合约实现的这些功能相关的某些风险。
  3. 移除 transferFrom 函数。调用对方 Token 资产的更好方法是访问对方自己的合约,而不是直接访问 Token 资产合约。
  4. 与 ERC-20 的向前兼容意味着所有同质化 Token 都可以兼容此提案。

规范

本文档中的关键词 “MUST”(必须),”MUST NOT”(禁止),”REQUIRED”(需要),”SHALL”(应该),”SHALL NOT”(不应该),”SHOULD”(应该),”SHOULD NOT”(不应该),”RECOMMENDED”(推荐),”NOT RECOMMENDED”(不推荐),”MAY”(可以)和 “OPTIONAL”(可选)应按照 RFC 2119 和 RFC 8174 中的描述进行解释。

符合标准的合约必须实现以下接口:

pragma solidity ^0.8.20;

/**
 * @title ERC7196 Simple token interface
 * @dev See https://ercs.ethereum.org/ERCS/erc-7196
 */
interface IERC7196 {
    /**
     * @notice Used to notify transfer tokens.
     * @param from Address of the from
     * @param to Address of the receive
     * @param value The transaction amount
     */
    event Transfer(
        address indexed from,
        address indexed to,
        uint256 value
    );
	
    /**
     * @notice Get the total supply
     * @return total The total supply amount
     */
    function totalSupply() 
        external  
        view
        returns (uint256 total);
	  
    /**
     * @notice get the balance of owenr address
     * @param owner Address of the owner
     * @return balance The balance of the owenr address
     */
    function balanceOf(address owner) 
        external
        view
        returns (uint256 balance);

    /**
     * @notice Transfer token
     * @param to Address of the to
     * @param value The transaction amount
     * @return success The bool value returns whether the transfer is successful
     */
    function transfer(address to, uint256 value)
        external
        returns (bool success);

}

理由

该提案旨在通过移除 transferFromapproveallowance 函数来简化 Token 标准。这种简化旨在提高安全性、降低复杂性和提高效率,使该标准更适合智能合约钱包环境,同时保持基本功能。

向后兼容性

正如开头提到的,此 ERC 向前兼容 ERC-20,ERC-20 向后兼容此 ERC。

参考实现

向前兼容 ERC-20

pragma solidity ^0.8.20;

import "./IERC7196.sol";
import "../../math/SafeMath.sol";

/**
 * @title Standard ERC7196 token
 * @dev Note: the ERC-165 identifier for this interface is 0xc1b31357
 * @dev Implementation of the basic standard token.
 */
contract ERC7196 is IERC7196 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    uint256 private _totalSupply;

    function totalSupply() external view returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address owner) external view returns (uint256) {
        return _balances[owner];
    }

    function transfer(address to, uint256 value) external returns (bool) {
        require(value <= _balances[msg.sender]);
        require(to != address(0));

        _balances[msg.sender] = _balances[msg.sender].sub(value);
        _balances[to] = _balances[to].add(value);
        emit Transfer(msg.sender, to, value);
        return true;
    }

}

安全考虑

应该注意的是,此 ERC 与 ERC-20 不向后兼容,因此会与现有的 Dapp 产生不兼容性。

版权

版权及相关权利通过 CC0 放弃。

Citation

Please cite this document as:

Xiang (@wenzhenxiang), Ben77 (@ben2077), Mingshi S. (@newnewsms), "ERC-7196: 简单 Token,简化版 ERC-20 [DRAFT]," Ethereum Improvement Proposals, no. 7196, June 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7196.