Alert Source Discuss
Standards Track: ERC

ERC-4400: EIP-721 可消费扩展

EIP-721 消费者角色的接口扩展

Authors Daniel Ivanov (@Daniel-K-Ivanov), George Spasov (@Perseverance)
Created 2021-10-30
Requires EIP-165, EIP-721

摘要

本规范定义了 EIP-721 实例的 consumer(消费者)角色的标准函数。实现允许读取给定 NFT(tokenId)的当前 consumer,以及 consumer 发生更改时的标准化事件。该提案依赖并扩展了现有的 EIP-721

动机

许多 EIP-721 合约引入了他们自己的自定义角色,该角色授予使用/消费给定 NFT 实例的权限。对该角色的需求源于以下事实:除了拥有 NFT 实例之外,还可以对 NFT 执行其他操作。例如,各种元宇宙对 Land (EIP-721) 使用 operator(操作员)/ contributor(贡献者)角色,以便土地所有者可以授权其他地址向其部署场景(例如,委托服务公司开发场景)。

NFT 通常具有所有权之外的实用性。话虽如此,它需要一个单独的标准化的消费者角色,允许与用户界面和合约兼容,从而管理这些合约。

拥有 consumer 角色将使协议能够集成并构建在发布 EIP-721 代币的 dApp 之上。一个例子是创建通用/通用的 NFT 租赁市场。

可以从该标准中受益的合约和应用程序的示例包括:

  • 元宇宙,在这些元宇宙中拥有土地和其他类型的数字资产(在土地上部署场景,租用土地/角色/衣服/参加活动的通行证等)
  • 基于 NFT 的挖矿。 采用该标准使“staker”(NFT 的所有者)即使在将其 NFT 转移到 staking 合约后,也能获得效用收益

规范

本文档中的关键词“MUST”、“MUST NOT”、“REQUIRED”、“SHALL”、“SHALL NOT”、“SHOULD”、“SHOULD NOT”、“RECOMMENDED”、“MAY”和“OPTIONAL”应按照 RFC 2119 中的描述进行解释。

每个符合 EIP721Consumable 扩展的合约都必须实现 IEIP721Consumable 接口。 consumer 扩展对于 EIP-721 合约是 OPTIONAL 的。

/// @title EIP-721 Consumer Role extension
/// @title EIP-721 消费者角色扩展
///  Note: the EIP-165 identifier for this interface is 0x953c8dfa
interface IEIP721Consumable /* is EIP721 */ {

    /// @notice Emitted when `owner` changes the `consumer` of an NFT
    /// @notice 当 `owner` 更改 NFT 的 `consumer` 时发出
    /// The zero address for consumer indicates that there is no consumer address
    /// consumer 的零地址表示没有 consumer 地址
    /// When a Transfer event emits, this also indicates that the consumer address
    /// 当发出 Transfer 事件时,这也表明该 NFT 的 consumer 地址(如果有)设置为 none
    event ConsumerChanged(address indexed owner, address indexed consumer, uint256 indexed tokenId);

    /// @notice Get the consumer address of an NFT
    /// @notice 获取 NFT 的 consumer 地址
    /// @dev The zero address indicates that there is no consumer
    /// @dev 零地址表示没有 consumer
    /// Throws if `_tokenId` is not a valid NFT
    /// 如果 `_tokenId` 不是有效的 NFT,则抛出异常
    /// @param _tokenId The NFT to get the consumer address for
    /// @param _tokenId 要获取 consumer 地址的 NFT
    /// @return The consumer address for this NFT, or the zero address if there is none
    /// @return 此 NFT 的 consumer 地址,如果没有,则返回零地址
    function consumerOf(uint256 _tokenId) view external returns (address);

    /// @notice Change or reaffirm the consumer address for an NFT
    /// @notice 更改或重申 NFT 的 consumer 地址
    /// @dev The zero address indicates there is no consumer address
    /// @dev 零地址表示没有 consumer 地址
    /// Throws unless `msg.sender` is the current NFT owner, an authorised
    /// 除非 `msg.sender` 是当前 NFT 所有者、授权
    /// operator of the current owner or approved address
    /// 当前所有者的 operator 或批准的地址,否则抛出
    /// Throws if `_tokenId` is not valid NFT
    /// 如果 `_tokenId` 不是有效的 NFT,则抛出异常
    /// @param _consumer The new consumer of the NFT
    /// @param _consumer NFT 的新 consumer
    function changeConsumer(address _consumer, uint256 _tokenId) external;
}

每个实现 EIP721Consumable 扩展的合约都可以自由定义 consumer 的权限(例如,consumer 被允许在其系统中做什么),但只有一个例外——根据 EIP-721 规范,consumer 不得被视为所有者、授权的 operator 或批准的地址。 因此,他们不得执行转账和批准。

consumerOf(uint256 _tokenId) 函数可以实现为 pureview

changeConsumer(address _consumer, uint256 _tokenId) 函数可以实现为 publicexternal

当 consumer 更改时,必须发出 ConsumerChanged 事件。

在每次 transfer 时,consumer 必须更改为默认地址。 建议实施者使用 address(0) 作为该默认地址。

当使用 0x953c8dfa 调用 supportsInterface 方法时,必须返回 true

理由

影响该标准的关键因素:

  • 尽量减少接口中的函数数量,以防止合约膨胀
  • 简单性
  • Gas 效率
  • 不重用或重载其他已存在的角色(例如所有者、operator、批准的地址)

名字

选择的名称与其存在的目的产生共鸣。消费者可以被认为是利用代币实例的实体,而无需拥有其所有权。

考虑过的角色的另一个名称是 operator,但它已经在 EIP-721 标准中定义和使用。

权限限制

在许多用例中,需要一个 NFT 的独特角色,该角色不得具有所有者权限。实现 consumer 角色并授予 consumer 所有权权限的合约会使该标准毫无意义。

向后兼容性

此标准与当前的 EIP-721 标准兼容。 没有其他标准为 NFT 定义类似的角色,并且名称 (consumer) 不被其他与 EIP-721 相关的标准使用。

测试用例

测试用例可在参考实现 here 中找到。

参考实现

参考实现可以在 here 找到。

安全考虑

EIP721Consumable 标准的实施者必须彻底考虑他们授予 consumers 的权限。 即使他们正确地实施该标准并且不允许转让/销毁 NFT,他们仍然可以向 consumers 提供他们可能不想提供的权限,并且应仅限于 owners

版权

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

Citation

Please cite this document as:

Daniel Ivanov (@Daniel-K-Ivanov), George Spasov (@Perseverance), "ERC-4400: EIP-721 可消费扩展," Ethereum Improvement Proposals, no. 4400, October 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4400.