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

EIP-5007: Time NFT, EIP-721 Time Extension Source

Add start time and end time to EIP-721 tokens.

作者 Anders, Lance, Shrug
讨论-To https://ethereum-magicians.org/t/eip-5007-eip-721-time-extension/8924
状态 Last Call
最后征集期限 2022-09-25
类型 Standards Track
分类 ERC
创建日期 2022-04-13
依赖 165, 721
英文版 https://eips.ethereum.org/EIPS/eip-5007

Abstract

This standard is an extension of EIP-721. It proposes some additional functions (startTime, endTime) to help with on-chain time management.

Motivation

Some NFTs have a defined usage period and cannot be used outside of that period. With traditional NFTs that do not include time information, if you want to mark a token as invalid or enable it at a specific time, you need to actively submit a transaction—a process both cumbersome and expensive.

Some existing NFTs contain time functions, but their interfaces are not consistent, so it is difficult to develop third-party platforms for them.

By introducing these functions (startTime, endTime), it is possible to enable and disable NFTs automatically on chain.

Specification

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.

/**
 * @dev the EIP-165 identifier for this interface is 0x7a0cdf92.
 */
interface IERC5007 /* is IERC721 */ {
    /**
     * @dev Returns the start time of the NFT as a UNIX timestamp.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function startTime(uint256 tokenId) external view returns (int64);

    /**
     * @dev Returns the end time of the NFT as a UNIX timestamp.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function endTime(uint256 tokenId) external view returns (int64);

}

The composable extension is OPTIONAL for this standard. This allows your NFT to be minted from an existing NFT or to merge two NFTs into one NFT.

/**
 * @dev the EIP-165 identifier for this interface is 0x620063db.
 */
interface IERC5007Composable /* is IERC5007 */ {
    /**
     * @dev Returns the ancestor token id of the NFT.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function rootTokenId(uint256 tokenId) external view returns (uint256);

    /**
     * @dev  Mint a new token from an old token.
     * The rootTokenId of the new token is the same as the rootTokenId of the old token
     *
     * Requirements:
     *
     * - `oldTokenId` must exist.
     * - `newTokenId` must not exist.
     * - `newTokenOwner` cannot be the zero address.
     * - `newTokenStartTime`  require(oldTokenStartTime < newTokenStartTime && newTokenStartTime <= oldTokenEndTime)
     */
    function split(
        uint256 oldTokenId,
        uint256 newTokenId,
        address newTokenOwner,
        int64 newTokenStartTime
    ) external;

    /**
     * @dev  Merge the first token and second token into the new token.
     *
     * Requirements:
     *
     * - `firstTokenId` must exist.
     * - `secondTokenId` must exist. require((firstToken.endTime + 1) == secondToken.startTime)
     * - `newTokenOwner` cannot be the zero address.
     * - `newTokenId` must not exist.
     */
    function merge(
        uint256 firstTokenId,
        uint256 secondTokenId,
        address newTokenOwner,
        uint256 newTokenId
    ) external;
}

Rationale

Time Data Type

The max value of int64 is 9,223,372,036,854,775,807. As a timestamp, 9,223,372,036,854,775,807 is about year 292,471,210,648. uint256 is too big for C, C++, Java, Go, etc, and int64 is natively supported by mainstream programming languages.

向后兼容性

This standard is fully EIP-721 compatible.

测试用例

Test cases are included in test.js.

Run in terminal:

cd ../assets/eip-5007
npm install
truffle test

Reference Implementation

See ERC5007.sol.

Security Considerations

No security issues found.

Copyright and related rights waived via CC0.

参考文献

Please cite this document as:

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