兼容的实现 MUST 继承自 ERC-20 的接口,并且 MUST 具有以下所有函数,并且所有函数行为 MUST 符合规范。
// SPDX-License-Identifier: CC0-1.0
pragmasolidity>=0.8.0<0.9.0;/**
* @title ERC-7818 interface
* @dev Interface for adding expirable functionality to ERC20 tokens.
*/import"./IERC20.sol";interfaceIERC7818isIERC20{/**
* @dev Enum represents the types of `epoch` that can be used.
* @notice The implementing contract may use one of these types to define how the `epoch` is measured.
*/enumEPOCH_TYPE{BLOCKS_BASED,// measured in the number of blocks (e.g., 1000 blocks)
TIME_BASED// measured in seconds (UNIX time) (e.g., 1000 seconds)
}/**
* @dev Retrieves the balance of a specific `epoch` owned by an account.
* @param epoch The `epoch for which the balance is checked.
* @param account The address of the account.
* @return uint256 The balance of the specified `epoch`.
* @notice "MUST" return 0 if the specified `epoch` is expired.
*/functionbalanceOfAtEpoch(uint256epoch,addressaccount)externalviewreturns(uint256);/**
* @dev Retrieves the latest epoch currently tracked by the contract.
* @return uint256 The latest epoch of the contract.
*/functioncurrentEpoch()externalviewreturns(uint256);/**
* @dev Retrieves the duration of a single epoch.
* @return uint256 The duration of a single epoch.
* @notice The unit of the epoch length is determined by the `validityPeriodType` function.
*/functionepochLength()externalviewreturns(uint256);/**
* @dev Returns the type of the epoch.
* @return EPOCH_TYPE Enum value indicating the unit of an epoch.
*/functionepochType()externalviewreturns(EPOCH_TYPE);/**
* @dev Retrieves the validity duration in `epoch` counts.
* @return uint256 The validity duration in `epoch` counts.
*/functionvalidityDuration()externalviewreturns(uint256);/**
* @dev Checks whether a specific `epoch` is expired.
* @param epoch The `epoch` to check.
* @return bool True if the token is expired, false otherwise.
* @notice Implementing contracts "MUST" define and document the logic for determining expiration,
* typically by comparing the latest epoch with the given `epoch` value,
* based on the `EPOCH_TYPE` measurement (e.g., block count or time duration).
*/functionisEpochExpired(uint256epoch)externalviewreturns(bool);/**
* @dev Transfers a specific `epoch` and value to a recipient.
* @param epoch The `epoch` for the transfer.
* @param to The recipient address.
* @param value The amount to transfer.
* @return bool True if the transfer succeeded, otherwise false.
*/functiontransferAtEpoch(uint256epoch,addressto,uint256value)externalreturns(bool);/**
* @dev Transfers a specific `epoch` and value from one account to another.
* @param epoch The `epoch` for the transfer.
* @param from The sender's address.
* @param to The recipient's address.
* @param value The amount to transfer.
* @return bool True if the transfer succeeded, otherwise false.
*/functiontransferFromAtEpoch(uint256epoch,addressfrom,addressto,uint256value)externalreturns(bool);}
行为规范
balanceOfMUST 返回帐户持有的仍然有效(即尚未过期)的代币总余额。 这包括与特定 epochs 关联的任何代币,前提是它们保持在其有效期内。 过期的代币 MUST NOT 包含在返回的余额中,以确保结果中仅反映有效可用的代币。