Alert Source Discuss
⚠️ Draft Standards Track: ERC

ERC-7204: 合约钱包管理 Token

专注于智能合约钱包中的同质化 token 管理,提供增强的交易灵活性和安全性

Authors Xiang (@wenzhenxiang), Ben77 (@ben2077), Mingshi S. (@newnewsms)
Created 2023-06-21
Discussion Link https://ethereum-magicians.org/t/token-asset-management-interface-with-smart-contract-wallet/14759
Requires EIP-165

摘要

本提案介绍了一种基于智能合约钱包管理 token 的方法,重点是利用智能合约钱包的可编程特性进行资产管理。 此外,它还引入了诸如 tokenTransfertokenApprovetokenApproveForAlltokenIsApproveForAlltokenAllowance 等函数,这些函数提供了对 token 交易的增强控制。这种方法旨在通过利用智能合约钱包的内置功能来增强 token 管理,从而为管理 token 交易提供一种更具适应性、安全性和效率的方法。

动机

外部所有账户(EOA)钱包没有状态和代码存储,而智能合约钱包有。

账户抽象(AA)是智能合约钱包的一个发展方向,它围绕抽象账户工作。这个 ERC 也可以作为 ERC-4337 的扩展,或者作为钱包的插件。

智能合约钱包允许用户自己的账户拥有状态和代码,从而为钱包带来可编程性。我们认为有更多的方向可以扩展。例如,token 资产管理、token 交易的功能扩展等。

此 ERC 的智能合约钱包接口用于资产管理和资产批准。它支持 simpletoken ERC-X,并且 ERC-20 向后兼容 ERC-X,因此它可以兼容现有市场中所有同质化 token 的管理。

该提案旨在实现以下目标:

  1. 资产由钱包本身分配和管理,例如 approveallowance,由用户的合约钱包配置,而不是由 token 资产合约控制,以避免一些现有的 ERC-20 合约风险。
  2. 添加 tokenTransfer 函数,由非智能钱包本身发起的交易或将验证 allowance 金额。
  3. 添加 tokenApprovetokenAllowancetokenApproveForAlltokenIsApproveForAll 函数。用户钱包本身支持 approve 并为单个 token 资产和所有 token 资产提供 approve。
  4. 用户钱包可以选择批量 approve 和批量转移。
  5. 用户可以选择在他们的 tokenTransfer 之前和之后添加 hook 函数,以增加用户的更多可玩性。
  6. 用户可以选择实现 tokenReceive 函数。

规范

本文档中的关键词“必须”,“禁止”,“需要”,“应该”,“不应该”,“推荐”,“不推荐”,“可以”和“可选”应按照 RFC 2119 和 RFC 8174 中的描述进行解释。

** 合规合约必须实现 ERC-165 接口 **

/// @title ERC-7204
/// @dev See https://eips.ethereum.org/EIPS/eip-7204
/// @dev Note: the ERC-165 identifier for this interface is 0xf73edcda
pragma solidity ^0.8.20;

interface IERC7204 /* is ERC165 */ {

    /**
     * @notice Used to notify listeners that owner has granted approval to the user to manage assets tokens.
     * @param asset Address of the token
     * @param owner Address of the account that has granted the approval for token‘s assets
     * @param spender Address of the spender
     * @param value The amount allowed to spend
     */
    event TokenApproval(
        address indexed asset,
        address indexed owner, 
        address indexed spender, 
        uint256 value
    );

    /**
     * @notice Used to notify listeners that owner has granted approval to the spender to manage all token .
     * @param asset Address of the token
     * @param owner Address of the account that has granted the approval for token‘s assets
     * @param approved approve all token
     */
    event TokenApprovalForAll(
        address indexed owner, 
        address indexed spender,
        bool approved
    );

    /**
     * @notice Approve token
     * @dev Allows spender address to withdraw from your account multiple times, up to the value amount.
     * @dev If this function is called again it overwrites the current allowance with value.
     * @dev Emits an {TokenApproval} event.
     * @param asset Address of the token
     * @param spender Address of the spender
     * @param value The amount allowed to spend
     * @return success The bool value returns whether the approve is successful
     */
    function tokenApprove(address asset, address spender, uint256 value) 
        external 
        returns (bool success);

    /**
     * @notice read token allowance value
     * @param asset Address of the token
     * @param spender Address of the spender
     * @return remaining The asset amount which spender is still allowed to withdraw from owner.
     */
    function tokenAllowance(address asset, address spender) 
        external
        view
        returns (uint256 remaining);

    /**
     * @notice Approve all token
     * @dev Allows spender address to withdraw from your wallet all token.
     * @dev Emits an {TokenApprovalForAll} event.
     * @param spender Address of the spender
     * @param approved Approved all tokens
     * @return success The bool value returns whether the approve is successful
     */
    function tokenApproveForAll(address spender, bool approved) 
        external 
        returns (bool success);

    /**
     * @notice read spender approved value
     * @param spender Address of the spender
     * @return approved Whether to approved spender all tokens
     */
    function tokenIsApproveForAll(address spender) 
        external
        view
        returns (bool approved);

    /**
     * @notice Transfer token
     * @dev must call asset.transfer() inside the function
     * @dev If the caller is not wallet self, must verify the allowance and update the allowance value
     * @param asset Address of the token
     * @param to Address of the receive
     * @param value The transaction amount
     * @return success The bool value returns whether the transfer is successful
     */
    function tokenTransfer(address asset, address to, uint256 value) 
        external 
        returns (bool success); 
}

原理

本提案中的关键技术决策是:

改进的 Approve 机制

  • 当前 vs. 提议:在现有的 ERC-20 系统中,外部所有账户 (EOA) 直接与 token 合约交互以进行 approve。本提案中新的 tokenApprovetokenApproveForAll 函数可在钱包合约中更精确地控制 token 的使用,这是对传统方法的重大改进。
  • 增强的安全性:这种机制通过将 approve 控制权转移到用户的智能合约钱包来缓解 token 过度 approve 等风险。
  • 可编程性:用户可以设置高级 approve 策略,例如有条件或限时 approve,tokenApproveForAll 函数专门允许对所有 token 进行通用设置。这些在传统的 ERC-20 token 中是不可能的。

优化的转移流程

  • 效率和安全性tokenTransfer 函数简化了 token 转移过程,使交易更高效、更安全。
  • 灵活性:允许在转移前后集成自定义逻辑(hooks),从而实现额外的安全检查或为用户需求量身定制的特定操作。

支持批量操作

  • 提高效率:用户可以同时处理多个 approvetransfer 操作,从而显着提高交易效率。
  • 增强的用户体验:简化了对大量资产的管理,改善了拥有大量投资组合的用户的整体体验。

向后兼容性

此 ERC 可以用作 ERC-4337 的扩展,并且向后兼容 ERC-4337。

安全考虑

未发现安全方面的考虑。

版权

版权和相关权利已通过 CC0 放弃。

Citation

Please cite this document as:

Xiang (@wenzhenxiang), Ben77 (@ben2077), Mingshi S. (@newnewsms), "ERC-7204: 合约钱包管理 Token [DRAFT]," Ethereum Improvement Proposals, no. 7204, June 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7204.