📢 本 EIP 正处于最后一次征集审查阶段。作者希望最后确定 EIP,并感谢反馈。

EIP-5006: Rental NFT, NFT User Extension Source

Add a user role with restricted permissions to EIP-1155 tokens

作者 Lance, Anders, Shrug
讨论-To https://ethereum-magicians.org/t/eip5006-erc-1155-usage-rights-extension/8941
状态 Last Call
最后征集期限 2022-08-01
类型 Standards Track
分类 ERC
创建日期 2022-04-12
依赖 165, 1155
英文版 https://eips.ethereum.org/EIPS/eip-5006

摘要

This standard is an extension of EIP-1155. It proposes an additional role (user) which can be granted to addresses that represent a user of the assets rather than an owner.

动机

Like EIP-721, EIP-1155 tokens may have utility of some kind. The people who “use” the token may be different than the people who own it (such as in a rental). Thus, it would be useful to have separate roles for the “owner” and the “user” so that the “user” would not be able to take actions that the owner could (for example, transferring ownership).

规范

The keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY” and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

interface IERC5006 {
    struct UserRecord {
        uint256 tokenId;
        address owner;
        uint64 amount;
        address user;
        uint64 expiry;
    }

    /**
     * @dev Emitted when permission for `user` to use `amount` of `tokenId` token owned by `owner`
     * until `expiry` are given.
     */
    event CreateUserRecord(
        uint256 recordId,
        uint256 tokenId,
        uint64  amount,
        address owner,
        address user,
        uint64  expiry
    );

    /**
     * @dev Emitted when record of `recordId` are deleted.
     */
    event DeleteUserRecord(uint256 recordId);

    /**
     * @dev Returns the usable amount of `tokenId` tokens  by `account`.
     */
    function usableBalanceOf(address account, uint256 tokenId)
        external
        view
        returns (uint256);

    /**
     * @dev Returns the amount of frozen tokens of token type `id` by `account`.
     */
    function frozenBalanceOf(address account, uint256 tokenId)
        external
        view
        returns (uint256);

    /**
     * @dev Returns the `UserRecord` of `recordId`.
     */
    function userRecordOf(uint256 recordId)
        external
        view
        returns (UserRecord memory);

    /**
     * @dev Gives permission to `user` to use `amount` of `tokenId` token owned by `owner` until `expiry`.
     *
     * Emits a {CreateUserRecord} event.
     *
     * Requirements:
     *
     * - If the caller is not `owner`, it must be have been approved to spend ``owner``'s tokens
     * via {setApprovalForAll}.
     * - `owner` must have a balance of tokens of type `id` of at least `amount`.
     * - `user` cannot be the zero address.
     * - `amount` must be greater than 0.
     * - `expiry` must after the block timestamp.
     */
    function createUserRecord(
        address owner,
        address user,
        uint256 tokenId,
        uint64 amount,
        uint64 expiry
    ) external returns (uint256);

    /**
     * @dev Atomically delete `record` of `recordId` by the caller.
     *
     * Emits a {DeleteUserRecord} event.
     *
     * Requirements:
     *
     * - the caller must have allowance.
     */
    function deleteUserRecord(uint256 recordId) external;
}

The supportsInterface method MUST return true when called with 0xc26d96cc.

基本原理

This model is intended to facilitate easy implementation. The following are some problems that are solved by this standard:

Clear Rights Assignment

With Dual “owner” and “user” roles, it becomes significantly easier to manage what lenders and borrowers can and cannot do with the NFT (in other words, their rights).  For example, for the right to transfer ownership, the project simply needs to check whether the address taking the action represents the owner or the user and prevent the transaction if it is the user.  Additionally, owners can control who the user is and it is easy for other projects to assign their own rights to either the owners or the users.

Easy Third-Party Integration

In the spirit of permissionless interoperability, this standard makes it easier for third-party protocols to manage NFT usage rights without permission from the NFT issuer or the NFT application. Once a project has adopted the additional user role, any other project can directly interact with these features and implement their own type of transaction. For example, a PFP NFT using this standard can be integrated into both a rental platform where users can rent the NFT for 30 days AND, at the same time, a mortgage platform where users can use the NFT while eventually buying ownership of the NFT with installment payments. This would all be done without needing the permission of the original PFP project.

向后兼容性

As mentioned in the specifications section, this standard can be fully ERC compatible by adding an extension function set, and there are no conflicts between EIP-5006 and EIP-1155.

In addition, new functions introduced in this standard have many similarities with the existing functions in EIP-1155. This allows developers to easily adopt the standard quickly.

测试用例

Test cases are included in test.js.

Run in terminal:

  1. cd ../assets/eip-5006
  2. npm install
  3. npx hardhat test

Reference Implementation

See ERC5006.sol.

Security Considerations

This EIP standard can completely protect the rights of the owner, the owner can change the NFT user, the user can not transfer the NFT.

版权声明

Copyright and related rights waived via CC0.

参考文献

Please cite this document as:

Lance, Anders, Shrug, "EIP-5006: Rental NFT, NFT User Extension [DRAFT]," Ethereum Improvement Proposals, no. 5006, April 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5006.