Alert Source Discuss
Standards Track: ERC

ERC-5007: 时间 NFT,ERC-721 时间扩展

向 ERC-721 代币添加开始时间和结束时间。

Authors Anders (@0xanders), Lance (@LanceSnow), Shrug <shrug@emojidao.org>
Created 2022-04-13
Requires EIP-165, EIP-721

摘要

本标准是 ERC-721 的扩展。它提出了一些额外的函数(startTimeendTime)以帮助链上时间管理。

动机

一些 NFT 具有明确的使用期限,并且不能在该期限之外使用。对于不包含时间信息的传统 NFT,如果你想将一个代币标记为无效或在特定时间启用它,你需要主动提交一个交易 —— 这个过程既繁琐又昂贵。

一些现有的 NFT 包含时间函数,但它们的接口不一致,因此很难为它们开发第三方平台。

通过引入这些函数(startTimeendTime),可以自动在链上启用和禁用 NFT。

规范

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

/**
 * @dev the ERC-165 identifier for this interface is 0xf140be0d.
 */
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 (uint64);
    
    /**
     * @dev Returns the end time of the NFT as a UNIX timestamp.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function endTime(uint256 tokenId) external view returns (uint64);

}

可组合扩展对于此标准是可选的。这允许你的 NFT 从现有的 NFT 中铸造,或者将两个 NFT 合并为一个 NFT。

/**
 * @dev the ERC-165 identifier for this interface is 0x75cf3842.
 */
interface IERC5007Composable /* is IERC5007 */ {
    /**
     * @dev Returns the asset id of the time NFT.
     * Only NFTs with same asset id can be merged.
     * 
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function assetId(uint256 tokenId) external view returns (uint256);

    /**
     * @dev Split an old token to two new tokens.
     * The assetId of the new token is the same as the assetId of the old token
     *
     * Requirements:
     *
     * - `oldTokenId` must exist.
     * - `newToken1Id` must not exist.
     * - `newToken1Owner` cannot be the zero address.
     * - `newToken2Id` must not exist.
     * - `newToken2Owner` cannot be the zero address.
     * - `splitTime`  require(oldToken.startTime <= splitTime && splitTime < oldToken.EndTime)
     */
    function split(
        uint256 oldTokenId,
        uint256 newToken1Id,
        address newToken1Owner,
        uint256 newToken2Id,
        address newToken2Owner,
        uint64 splitTime
    ) 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)
     * - require((firstToken.assetId()) == secondToken.assetId())
     * - `newTokenOwner` cannot be the zero address.
     * - `newTokenId` must not exist.
     */
    function merge(
        uint256 firstTokenId,
        uint256 secondTokenId,
        address newTokenOwner,
        uint256 newTokenId
    ) external;
}

原理

时间数据类型

uint64 的最大值是 18,446,744,073,709,551,615。作为时间戳,18,446,744,073,709,551,615 大约是 584,942,419,325 年。uint256 对于 C、C++、Java、Go 等来说太大了,而 uint64 则被主流编程语言原生支持。

向后兼容性

此标准与 ERC-721 完全兼容。

测试用例

测试用例包含在 test.js 中。

在终端中运行:

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

参考实现

请参阅 ERC5007.sol

安全注意事项

未发现安全问题。

版权

CC0 下放弃版权和相关权利。

Citation

Please cite this document as:

Anders (@0xanders), Lance (@LanceSnow), Shrug <shrug@emojidao.org>, "ERC-5007: 时间 NFT,ERC-721 时间扩展," Ethereum Improvement Proposals, no. 5007, April 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5007.