Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers ERC5725, a proposed vesting interface that uses NFTs to release ERC20 tokens gradually.
This explanation translates, summarizes, and expands on the following specification.
As of September 3, 2023, ERC5725 was at the Last Call stage.
Overview
This standard provides a mechanism for releasing underlying tokens, such as ERC20 tokens, gradually through NFTs (non-fungible tokens). Specifically, it enables tokens to become available to the recipient over a defined period. Instead of receiving all the tokens at once, the recipient can receive them as they vest over time.
The standard defines a common interface for NFT-related contracts. An NFT can represent properties important to its holder, including the vesting schedule and locked status of underlying tokens such as ERC20 tokens.
Motivation
Vesting and timelock contracts lack a standardized approach, resulting in many different implementations. Standardizing these contracts around a common interface enables related on-chain and off-chain tooling to form a unified ecosystem. Making vesting rights liquid in the form of non-fungible assets may also offer substantial improvements over traditional Simple Agreements for Future Tokens (SAFTs) and vesting tied to externally owned accounts (EOAs).
Simple Agreement for Future Tokens(SAFT) An agreement concerning tokens expected to be issued in the future. A SAFT establishes terms under which early investors fund a project and obtain the right to receive tokens when the project actually issues them.
Specifically, investors provide funding before the project has issued its tokens. The funds are used for development and operations, and investors obtain the right to receive tokens once they are issued. Under the agreement, investors can exercise their entitlement and receive tokens upon issuance.
Projects may use a SAFT to establish the legal and financial arrangements for token issuance. Investors fund a project in anticipation of a potential increase in the future value of its tokens and receive tokens in return. However, the timing and conditions of actual issuance vary according to the SAFT agreement.
SAFTs have been widely used in token sales and project fundraising.
Vesting positions can therefore release tokens over time, remain transferable, and carry metadata in the same way as conventional NFTs.
Standardization provides a much-needed standard for locking ERC20 tokens and enables secondary markets specializing in semi-liquid SAFT positions.
The standard also makes it possible to implement various vesting curves.
- Linear vesting
- Cliff vesting
- Exponential vesting
- Custom deterministic vesting
Linear vesting Tokens are released at a uniform rate throughout the vesting period. Consider the following example.
Suppose you join a project and are promised a token allocation. The project adopts linear vesting over one year. Under linear vesting, tokens are released uniformly over the period, with the entire allocation vested by the end of the year.
For example, if you are promised 1,200 tokens over 12 months, 100 tokens become available each month.
You receive 100 tokens in the first month, another 100 in the second month, and the final 100 in the twelfth month.
Because tokens are released progressively, project participants receive them over an extended period. Linear vesting may be used when a project anticipates steady growth in token value or seeks to encourage long-term participation.
Cliff vesting No tokens are released until a specified waiting period has elapsed, after which the designated amount is released at once. Consider the following example.
Suppose you join a new project and are promised tokens. The project uses a one-year vesting period with a six-month cliff (waiting period). In this particular example, no tokens are released during the first six months, and the entire allocation is released at the cliff.
For example, if you are promised 1,000 tokens, none are released during the first six months, and all 1,000 become available at month six.
You therefore wait six months without receiving tokens and then receive the entire allocation at once.
Cliff vesting may be used to encourage participants to make a sustained commitment to a project or strengthen their expectations about its future success. Because no tokens are released during the cliff period, it may encourage participants to remain involved. The subsequent release provides participants with their allocated tokens at once.
Exponential vesting The amount of tokens released increases rapidly over time. Consider the following example.
Suppose you join a new project and are promised tokens. The project uses exponential vesting over one year. Under this schedule, token releases begin at a low rate and accelerate over time.
For example, for an allocation of 1,000 tokens, relatively few tokens are released in the early months, such as 10 in the first month and 20 in the second.
As time passes, releases increase exponentially and may reach, for example, 200 tokens in a month toward the end of the period.
Exponential vesting thus starts with small releases and accelerates toward the end of the vesting period. This approach may be used to encourage long-term commitment from project members and investors.
Custom deterministic vesting Tokens are released according to a custom schedule. This allows vesting schedules to be tailored to the needs of projects and investors. Consider the following example.
Suppose you join a project and are promised tokens subject to specified conditions. The project uses a custom deterministic vesting schedule.
For example, an allocation of 1,000 tokens may be released according to a schedule agreed between the project and its investors.
A custom schedule might release nothing for the first three months, then release 100 tokens each month.
Another example is a schedule tied to the achievement of project milestones. Tokens could become available as specified development milestones are reached, allowing participants to receive tokens as the project progresses. Such conditional schedules need to be reconciled with the standard's deterministic time-based interface.
Custom vesting allows release schedules to accommodate particular needs and circumstances, supporting arrangements tailored to individual projects and investors.
This enables flexible vesting schedules.
Use cases
Vesting frameworks
A framework for progressively releasing tokens over time can support various NFT-based financial products, including bonds and Treasury bills.
Representing SAFT agreements as standardized, semi-liquid vesting NFTs
SAFTs are generally arranged off-chain, while existing on-chain implementations are predominantly address-based. A standardized representation can make it easier to distribute vesting shares among many recipients and simplify otherwise complex processes.
Standardizing vesting and token timelock contracts
These contracts vary widely in their interfaces and implementations.
Dedicated marketplaces for vesting NFTs
Common standards for token vesting NFTs enable the development of new interfaces and analytics tools.
Integrating vesting NFTs with other services
Standardization allows services such as Safe Wallet to integrate with these contracts through a consistent interface.
Transparency and fundraising
Standardization enables more transparent sales of vesting positions, such as SAFTs, and more general fundraising implementations.
Exposing vesting information
Tools, frontend applications, and aggregators can display a comprehensive view of users' vesting positions and their properties. Currently, each project must visualize its own schedules. With standardization, third-party tools can aggregate vesting NFTs across projects, display their schedules, and help users perform aggregated vesting actions.
ERC165 support
Tools can easily check compliance using the ERC165 supportsInterface(interfaceId) mechanism.
A single wrapping implementation can also be applied across vesting standards to support features such as multiple recipients or periodic rental of vesting rights.
Specification
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
/**
* @title Non-Fungible Vesting Token Standard.
* @notice A non-fungible token standard used to vest ERC-20 tokens over a vesting release curve
* scheduled using timestamps.
* @dev Because this standard relies on timestamps for the vesting schedule, it's important to keep track of the
* tokens claimed per Vesting NFT so that a user cannot withdraw more tokens than allotted for a specific Vesting NFT.
* @custom:interface-id 0xbd3a202b
*/
interface IERC5725 is IERC721 {
/**
* This event is emitted when the payout is claimed through the claim function.
* @param tokenId the NFT tokenId of the assets being claimed.
* @param recipient The address which is receiving the payout.
* @param claimAmount The amount of tokens being claimed.
*/
event PayoutClaimed(uint256 indexed tokenId, address indexed recipient, uint256 claimAmount);
/**
* This event is emitted when an `owner` sets an address to manage token claims for all tokens.
* @param owner The address setting a manager to manage all tokens.
* @param spender The address being permitted to manage all tokens.
* @param approved A boolean indicating whether the spender is approved to claim for all tokens.
*/
event ClaimApprovalForAll(address indexed owner, address indexed spender, bool approved);
/**
* This event is emitted when an `owner` sets an address to manage token claims for a `tokenId`.
* @param owner The `owner` of `tokenId`.
* @param spender The address being permitted to manage a tokenId.
* @param tokenId The unique identifier of the token being managed.
* @param approved A boolean indicating whether the spender is approved to claim for `tokenId`.
*/
event ClaimApproval(address indexed owner, address indexed spender, uint256 indexed tokenId, bool approved);
/**
* @notice Claim the pending payout for the NFT.
* @dev MUST grant the claimablePayout value at the time of claim being called to `msg.sender`.
* MUST revert if not called by the token owner or approved users.
* MUST emit PayoutClaimed.
* SHOULD revert if there is nothing to claim.
* @param tokenId The NFT token id.
*/
function claim(uint256 tokenId) external;
/**
* @notice Number of tokens for the NFT which have been claimed at the current timestamp.
* @param tokenId The NFT token id.
* @return payout The total amount of payout tokens claimed for this NFT.
*/
function claimedPayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice Number of tokens for the NFT which can be claimed at the current timestamp.
* @dev It is RECOMMENDED that this is calculated as the `vestedPayout()` subtracted from `payoutClaimed()`.
* @param tokenId The NFT token id.
* @return payout The amount of unlocked payout tokens for the NFT which have not yet been claimed.
*/
function claimablePayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice Total amount of tokens which have been vested at the current timestamp.
* This number also includes vested tokens which have been claimed.
* @dev It is RECOMMENDED that this function calls `vestedPayoutAtTime`
* with `block.timestamp` as the `timestamp` parameter.
* @param tokenId The NFT token id.
* @return payout Total amount of tokens which have been vested at the current timestamp.
*/
function vestedPayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice Total amount of vested tokens at the provided timestamp.
* This number also includes vested tokens which have been claimed.
* @dev `timestamp` MAY be both in the future and in the past.
* Zero MUST be returned if the timestamp is before the token was minted.
* @param tokenId The NFT token id.
* @param timestamp The timestamp to check on, can be both in the past and the future.
* @return payout Total amount of tokens which have been vested at the provided timestamp.
*/
function vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) external view returns (uint256 payout);
/**
* @notice Number of tokens for an NFT which are currently vesting.
* @dev The sum of vestedPayout and vestingPayout SHOULD always be the total payout.
* @param tokenId The NFT token id.
* @return payout The number of tokens for the NFT which are vesting until a future date.
*/
function vestingPayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice The start and end timestamps for the vesting of the provided NFT.
* MUST return the timestamp where no further increase in vestedPayout occurs for `vestingEnd`.
* @param tokenId The NFT token id.
* @return vestingStart The beginning of the vesting as a unix timestamp.
* @return vestingEnd The ending of the vesting as a unix timestamp.
*/
function vestingPeriod(uint256 tokenId) external view returns (uint256 vestingStart, uint256 vestingEnd);
/**
* @notice Token which is used to pay out the vesting claims.
* @param tokenId The NFT token id.
* @return token The token which is used to pay out the vesting claims.
*/
function payoutToken(uint256 tokenId) external view returns (address token);
/**
* @notice Sets a global `operator` with permission to manage all tokens owned by the current `msg.sender`.
* @param operator The address to let manage all tokens.
* @param approved A boolean indicating whether the spender is approved to claim for all tokens.
*/
function setClaimApprovalForAll(address operator, bool approved) external;
/**
* @notice Sets a tokenId `operator` with permission to manage a single `tokenId` owned by the `msg.sender`.
* @param operator The address to let manage a single `tokenId`.
* @param tokenId the `tokenId` to be managed.
* @param approved A boolean indicating whether the spender is approved to claim for all tokens.
*/
function setClaimApproval(address operator, bool approved, uint256 tokenId) external;
/**
* @notice Returns true if `owner` has set `operator` to manage all `tokenId`s.
* @param owner The owner allowing `operator` to manage all `tokenId`s.
* @param operator The address who is given permission to spend tokens on behalf of the `owner`.
*/
function isClaimApprovedForAll(address owner, address operator) external view returns (bool isClaimApproved);
/**
* @notice Returns the operating address for a `tokenId`.
* If `tokenId` is not managed, then returns the zero address.
* @param tokenId The NFT `tokenId` to query for a `tokenId` manager.
*/
function getClaimApproved(uint256 tokenId) external view returns (address operator);
}Additional considerations
Terminology
Vesting
Tokens allocated to a vesting NFT that are scheduled to become available by a specified future date.
Vested
The total amount of tokens that have vested for an NFT.
Claimable
The amount of vested tokens currently available to claim from an NFT.
Claimed
The total amount of tokens already claimed from a vesting NFT.
Timestamp
A Unix timestamp in seconds used to express vesting dates.
Vesting functions
vestingPayout and vestedPayout
vestingPayout(uint256 tokenId) represents the total amount payable over the full schedule, while vestedPayout(uint256 tokenId) represents the amount vested as of the current timestamp.
The total allocation is the full amount of tokens represented by the vesting NFT.
Using type(uint256).max as the timestamp in vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) should return the total vesting allocation.
These functions make it possible to track both the allocated and vested tokens accurately. The vesting curve is intended to be deterministic throughout the vesting period, simplifying NFT integrations. For example, a vesting schedule can be sampled to visualize the curve on-chain or off-chain.
vestedPayout, claimedPayout, and claimablePayout
vestedPayout - claimedPayout - claimablePayout = lockedPayoutvestedPayout(uint256 tokenId) provides the total vested amount, including the amount reported by claimedPayout(uint256 tokenId).
claimedPayout(uint256 tokenId) reports the total amount of payout tokens already claimed.
claimablePayout(uint256 tokenId) reports the amount of payout tokens that can currently be claimed.
These functions serve the following purposes.
vestedPayout(uint256 tokenId)must equalvestedPayoutAtTime(uint256 tokenId, uint256 timestamp)whenblock.timestampis used as the timestamp.claimablePayout(uint256 tokenId)makes the currently claimable amount easy to inspect and may return zero before a specified timestamp to implement a cliff.claimedPayout(uint256 tokenId)reports the amount already withdrawn and can be used to calculate vested but still locked payout tokens:vestedPayout - claimedPayout - claimablePayout = lockedPayout. The result depends on how the vesting curve and claim restrictions are implemented.
vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) allows the release curve to be visualized by sampling the interval returned by vestingPeriod(uint256 tokenId).
The release curve is intended to be deterministic within the vesting period.
Timestamps
In Solidity development, using block timestamps (block.timestamp) for sensitive state-dependent conditions requires care.
This is because block producers can influence timestamps within the applicable consensus rules.
This standard uses timestamps rather than block numbers to maintain consistency across Ethereum Virtual Machine (EVM)-compatible networks.
Different networks generally have different block times, and consensus rules reject block proposals with invalid timestamps, limiting the scope for manipulation.
Using timestamps simplifies cross-chain integration. Internally, however, payouts for each vesting NFT must be tracked so that claims cannot exceed the amount allocated under its vesting conditions.
Scope limitations
Historical claims
Historical vesting schedules can be determined on-chain through vestedPayoutAtTime(uint256 tokenId, uint256 timestamp), but historical claims must be reconstructed using past transaction data.
Query PayoutClaimed events to collect historical claim data and construct a historical claim chart.
Possible extensions
The following features are not part of the current base standard, but extensions could support them.
Custom vesting curves
The standard is intended to return deterministic vested amounts given an NFT's tokenId and timestamp.
This preserves flexibility in the internal implementation of vesting curves and allows projects to build complex smart contract vesting architectures.
NFT rentals
A mechanism for renting vesting NFTs could enable more complex DeFi tooling.
These features are currently excluded to keep the base standard concise, but may be added through future extensions.
Backward compatibility
Compatibility
The vesting NFT standard is designed to be compatible with existing ERC721 integrations and marketplaces. Vesting NFTs can therefore be integrated into existing ERC721 tooling and traded through compatible marketplaces.
ERC165 interface support
The vesting NFT standard also supports ERC165 interface detection. This allows callers to detect compliance with the vesting NFT interface as well as EIP721. ERC165 provides a standard way to determine whether a contract supports a particular interface.
Reference implementation
The implementation is available at the following location.
Source: https://eips.ethereum.org/assets/eip-5725/
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "./IERC5725.sol";
abstract contract ERC5725 is IERC5725, ERC721 {
using SafeERC20 for IERC20;
/// @dev mapping for claimed payouts
mapping(uint256 => uint256) /*tokenId*/ /*claimed*/ internal _payoutClaimed;
/// @dev Mapping from token ID to approved tokenId operator
mapping(uint256 => address) private _tokenIdApprovals;
/// @dev Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) /* owner */ /*(operator, isApproved)*/ internal _operatorApprovals;
/**
* @notice Checks if the tokenId exists and its valid
* @param tokenId The NFT token id
*/
modifier validToken(uint256 tokenId) {
require(_exists(tokenId), "ERC5725: invalid token ID");
_;
}
/**
* @dev See {IERC5725}.
*/
function claim(uint256 tokenId) external override(IERC5725) validToken(tokenId) {
require(isApprovedClaimOrOwner(msg.sender, tokenId), "ERC5725: not owner or operator");
uint256 amountClaimed = claimablePayout(tokenId);
require(amountClaimed > 0, "ERC5725: No pending payout");
emit PayoutClaimed(tokenId, msg.sender, amountClaimed);
_payoutClaimed[tokenId] += amountClaimed;
IERC20(payoutToken(tokenId)).safeTransfer(msg.sender, amountClaimed);
}
/**
* @dev See {IERC5725}.
*/
function setClaimApprovalForAll(address operator, bool approved) external override(IERC5725) {
_setClaimApprovalForAll(operator, approved);
emit ClaimApprovalForAll(msg.sender, operator, approved);
}
/**
* @dev See {IERC5725}.
*/
function setClaimApproval(
address operator,
bool approved,
uint256 tokenId
) external override(IERC5725) validToken(tokenId) {
_setClaimApproval(operator, tokenId);
emit ClaimApproval(msg.sender, operator, tokenId, approved);
}
/**
* @dev See {IERC5725}.
*/
function vestedPayout(uint256 tokenId) public view override(IERC5725) returns (uint256 payout) {
return vestedPayoutAtTime(tokenId, block.timestamp);
}
/**
* @dev See {IERC5725}.
*/
function vestedPayoutAtTime(
uint256 tokenId,
uint256 timestamp
) public view virtual override(IERC5725) returns (uint256 payout);
/**
* @dev See {IERC5725}.
*/
function vestingPayout(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 payout) {
return _payout(tokenId) - vestedPayout(tokenId);
}
/**
* @dev See {IERC5725}.
*/
function claimablePayout(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 payout) {
return vestedPayout(tokenId) - _payoutClaimed[tokenId];
}
/**
* @dev See {IERC5725}.
*/
function claimedPayout(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 payout) {
return _payoutClaimed[tokenId];
}
/**
* @dev See {IERC5725}.
*/
function vestingPeriod(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 vestingStart, uint256 vestingEnd) {
return (_startTime(tokenId), _endTime(tokenId));
}
/**
* @dev See {IERC5725}.
*/
function payoutToken(uint256 tokenId) public view override(IERC5725) validToken(tokenId) returns (address token) {
return _payoutToken(tokenId);
}
/**
* @dev See {IERC165-supportsInterface}.
* IERC5725 interfaceId = 0xbd3a202b
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC721, IERC165) returns (bool supported) {
return interfaceId == type(IERC5725).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC5725}.
*/
function getClaimApproved(uint256 tokenId) public view returns (address operator) {
return _tokenIdApprovals[tokenId];
}
/**
* @dev Returns true if `owner` has set `operator` to manage all `tokenId`s.
* @param owner The owner allowing `operator` to manage all `tokenId`s.
* @param operator The address who is given permission to spend tokens on behalf of the `owner`.
*/
function isClaimApprovedForAll(address owner, address operator) public view returns (bool isClaimApproved) {
return _operatorApprovals[owner][operator];
}
/**
* @dev Public view which returns true if the operator has permission to claim for `tokenId`
* @notice To remove permissions, set operator to zero address.
*
* @param operator The address that has permission for a `tokenId`.
* @param tokenId The NFT `tokenId`.
*/
function isApprovedClaimOrOwner(address operator, uint256 tokenId) public view virtual returns (bool) {
address owner = ownerOf(tokenId);
return (operator == owner || isClaimApprovedForAll(owner, operator) || getClaimApproved(tokenId) == operator);
}
/**
* @dev Internal function to set the operator status for a given owner to manage all `tokenId`s.
* @notice To remove permissions, set approved to false.
*
* @param operator The address who is given permission to spend vested tokens.
* @param approved The approved status.
*/
function _setClaimApprovalForAll(address operator, bool approved) internal virtual {
_operatorApprovals[msg.sender][operator] = approved;
}
/**
* @dev Internal function to set the operator status for a given tokenId.
* @notice To remove permissions, set operator to zero address.
*
* @param operator The address who is given permission to spend vested tokens.
* @param tokenId The NFT `tokenId`.
*/
function _setClaimApproval(address operator, uint256 tokenId) internal virtual {
require(ownerOf(tokenId) == msg.sender, "ERC5725: not owner of tokenId");
_tokenIdApprovals[tokenId] = operator;
}
/**
* @dev Internal function to hook into {IERC721-_afterTokenTransfer}, when a token is being transferred.
* Removes permissions to _tokenIdApprovals[tokenId] when the tokenId is transferred, burnt, but not on mint.
*
* @param from The address from which the tokens are being transferred.
* @param to The address to which the tokens are being transferred.
* @param firstTokenId The first tokenId in the batch that is being transferred.
* @param batchSize The number of tokens being transferred in this batch.
*/
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (from != address(0)) {
delete _tokenIdApprovals[firstTokenId];
}
}
/**
* @dev Internal function to get the payout token of a given vesting NFT
*
* @param tokenId on which to check the payout token address
* @return address payout token address
*/
function _payoutToken(uint256 tokenId) internal view virtual returns (address);
/**
* @dev Internal function to get the total payout of a given vesting NFT.
* @dev This is the total that will be paid out to the NFT owner, including historical tokens.
*
* @param tokenId to check
* @return uint256 the total payout of a given vesting NFT
*/
function _payout(uint256 tokenId) internal view virtual returns (uint256);
/**
* @dev Internal function to get the start time of a given vesting NFT
*
* @param tokenId to check
* @return uint256 the start time in epoch timestamp
*/
function _startTime(uint256 tokenId) internal view virtual returns (uint256);
/**
* @dev Internal function to get the end time of a given vesting NFT
*
* @param tokenId to check
* @return uint256 the end time in epoch timestamp
*/
function _endTime(uint256 tokenId) internal view virtual returns (uint256);
}_payoutClaimed
mapping(uint256 => uint256) internal _payoutClaimed;Overview A mapping storing the claimed payout amount for each NFT token ID.
Details
The NFT token ID is the key, and the amount already claimed for that token (uint256) is the value.
It is used when a token owner claims payouts.
Parameters
- tokenId
- NFT token ID.
_tokenIdApprovals
mapping(uint256 => address) private _tokenIdApprovals;Overview A mapping storing the address approved to claim payouts for each NFT token ID.
Details The NFT token ID is the key, and the address authorized to claim its payouts is the value. It is used when the token owner grants claim authority to a particular address.
Parameters
- tokenId
- NFT token ID.
_operatorApprovals
mapping(address => mapping(address => bool)) internal _operatorApprovals;Overview A mapping recording approvals between an owner and an operator authorized to claim payouts.
Details The owner address is the first key, the authorized operator address is the second key, and the Boolean value indicates whether that owner has approved the operator. Owners use this mapping to authorize another address to perform claim operations.
Parameters
- owner
- NFT owner address.
- operator
- Operator address.
validToken
modifier validToken(uint256 tokenId) {
require(_exists(tokenId), "ERC5725: invalid token ID");
_;
}Overview A modifier checking that a token ID exists and is valid.
Details It verifies token existence before function execution and reverts with an error for an invalid token ID. It is used to validate tokens before operations such as claims.
Parameters
- tokenId
- NFT token ID to check.
claim
function claim(uint256 tokenId) external override(IERC5725) validToken(tokenId) {
require(isApprovedClaimOrOwner(msg.sender, tokenId), "ERC5725: not owner or operator");
uint256 amountClaimed = claimablePayout(tokenId);
require(amountClaimed > 0, "ERC5725: No pending payout");
emit PayoutClaimed(tokenId, msg.sender, amountClaimed);
_payoutClaimed[tokenId] += amountClaimed;
IERC20(payoutToken(tokenId)).safeTransfer(msg.sender, amountClaimed);
}Overview Claims a payout for a specified token ID.
Details
Called by the owner or an authorized operator to claim available payouts for the specified token ID.
Checks that the claimable amount is greater than 0.
A PayoutClaimed event is then emitted, and the claimed amount is sent to the caller.
Parameters
tokenId- Token ID for which to claim a payout.
setClaimApprovalForAll
function setClaimApprovalForAll(address operator, bool approved) external override(IERC5725) {
_setClaimApprovalForAll(operator, approved);
emit ClaimApprovalForAll(msg.sender, operator, approved);
}Overview Sets claim approval for an operator.
Details
The caller grants or revokes claim approval for the operator.
A ClaimApprovalForAll event is emitted when the operation completes.
Parameters
operator- Address of the operator authorized to claim payouts.
approved- Boolean indicating whether approval is granted.
setClaimApproval
function setClaimApproval(
address operator,
bool approved,
uint256 tokenId
) external override(IERC5725) validToken(tokenId) {
_setClaimApproval(operator, tokenId);
emit ClaimApproval(msg.sender, operator, tokenId, approved);
}Overview Sets claim approval for a specific token ID.
Details
The owner grants or revokes claim approval for the specified token ID.
A ClaimApproval event is emitted when the operation completes.
Parameters
operator- Address of the operator authorized to claim payouts.
approved- Boolean indicating whether approval is granted.
tokenId- Token ID for which claim approval is set.
vestedPayout
function vestedPayout(uint256 tokenId) public view override(IERC5725) returns (uint256 payout) {
return vestedPayoutAtTime(tokenId, block.timestamp);
}Overview Retrieves the vested payout for a specified token ID.
Details Calculates the vested payout for the specified token ID based on the current block timestamp.
Parameters
tokenId- Token ID whose vested payout is requested.
Return values
payout- Vested payout amount.
vestedPayoutAtTime
function vestedPayoutAtTime(
uint256 tokenId,
uint256 timestamp
) public view virtual override(IERC5725) returns (uint256 payout);Overview Retrieves the vested payout for a specified token ID at a given timestamp.
Details Calculates and returns the amount vested for the specified token ID at the supplied timestamp.
Parameters
tokenId- Token ID whose vested payout is requested.
timestamp- Timestamp.
Return values
payout- Vested payout amount.
vestingPayout
function vestingPayout(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 payout) {
return _payout(tokenId) - vestedPayout(tokenId);
}Overview Retrieves the total payout over the vesting period for a specified token ID.
Parameters
tokenId- Token ID whose total vesting payout is requested.
Return values
payout- Total payout over the vesting period.
claimablePayout
function claimablePayout(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 payout) {
return vestedPayout(tokenId) - _payoutClaimed[tokenId];
}Overview Retrieves the payout amount currently available to claim for a specified token ID.
Parameters
tokenId- Token ID whose claimable payout is requested.
Return values
payout- Claimable payout amount.
claimedPayout
function claimedPayout(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 payout) {
return _payoutClaimed[tokenId];
}Overview Retrieves the amount already claimed for a specified token ID.
Parameters
tokenId- Token ID whose claimed payout is requested.
Return values
payout- Claimed payout amount.
vestingPeriod
function vestingPeriod(
uint256 tokenId
) public view override(IERC5725) validToken(tokenId) returns (uint256 vestingStart, uint256 vestingEnd) {
return (_startTime(tokenId), _endTime(tokenId));
}Overview Retrieves the vesting period for a specified token ID.
Details Returns the start and end timestamps of the vesting period for the specified token ID.
Parameters
tokenId- Token ID whose vesting period is requested.
Return values
vestingStart- Vesting start timestamp.
vestingEnd- Vesting end timestamp.
payoutToken
function payoutToken(uint256 tokenId) public view override(IERC5725) validToken(tokenId) returns (address token) {
return _payoutToken(tokenId);
}Overview Retrieves the payout token address for a specified token ID.
Parameters
tokenId- Token ID whose payout token address is requested.
Return values
token- Payout token address.
supportsInterface
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC721, IERC165) returns (bool supported) {
return interfaceId == type(IERC5725).interfaceId || super.supportsInterface(interfaceId);
}Overview Indicates whether a specified interface is supported.
Details
Checks whether the supplied interface ID equals the IERC5725 interface ID or whether the parent contract's supportsInterface function reports support.
Parameters
interfaceId- Interface ID.
Return values
supported- Boolean indicating whether the interface is supported.
getClaimApproved
function getClaimApproved(uint256 tokenId) public view returns (address operator) {
return _tokenIdApprovals[tokenId];
}Overview Retrieves the operator approved to claim payouts for a specified token ID.
Parameters
tokenId- Token ID whose approved claim operator is requested.
Return values
operator- Address of the approved claim operator.
isClaimApprovedForAll
function isClaimApprovedForAll(address owner, address operator) public view returns (bool isClaimApproved) {
return _operatorApprovals[owner][operator];
}Overview Checks whether an owner has granted claim approval to an operator.
Parameters
owner- Owner address.
operator- Claim operator address.
Return values
isClaimApproved- Boolean indicating whether claim approval has been granted.
isApprovedClaimOrOwner
function isApprovedClaimOrOwner(address operator, uint256 tokenId) public view virtual returns (bool) {
address owner = ownerOf(tokenId);
return (operator == owner || isClaimApprovedForAll(owner, operator) || getClaimApproved(tokenId) == operator);
}Overview Checks whether a specified operator is authorized to claim a token's payout.
Details A claim is permitted if the operator is the token owner, is approved for all claims by the owner, or matches the approved claim operator for that token.
Parameters
operator- Address of the operator requesting the claim.
tokenId- Token ID for which to claim a payout.
Return values
bool- Boolean indicating whether the claim is authorized.
_setClaimApprovalForAll
function _setClaimApprovalForAll(address operator, bool approved) internal virtual {
_operatorApprovals[msg.sender][operator] = approved;
}Overview Sets claim approval for an operator designated by the owner.
Details Grants or revokes the owner's claim approval for the specified operator.
Parameters
operator- Address of the operator authorized to claim payouts.
approved- Boolean indicating whether approval is granted.
_setClaimApproval
function _setClaimApproval(address operator, uint256 tokenId) internal virtual {
require(ownerOf(tokenId) == msg.sender, "ERC5725: not owner of tokenId");
_tokenIdApprovals[tokenId] = operator;
}Overview Sets claim approval for a token ID designated by its owner.
Details Grants or revokes the claim approval for the specified token ID.
Parameters
operator- Address of the operator authorized to claim payouts.
tokenId- Token ID for which claim approval is set.
_beforeTokenTransfer
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (from != address(0)) {
delete _tokenIdApprovals[firstTokenId];
}
}Overview A hook invoked before a token transfer.
Details Resets claim approval for the specified token ID before transfer. This runs when a token is transferred or burned.
Parameters
from- Address from which the token is transferred.
to- Address to which the token is transferred.
firstTokenId- First token ID in the batch.
batchSize- Size of the token transfer batch.
_payoutToken
function _payoutToken(uint256 tokenId) internal view virtual returns (address)Overview Retrieves the payout token address of a specified vesting NFT.
Details Retrieves the address of the payout token associated with the specified vesting NFT token ID.
Parameters
tokenId- Token ID whose payout token is requested.
Return values
address- Payout token address.
_payout
function _payout(uint256 tokenId) internal view virtual returns (uint256)Overview Retrieves the total payout of a specified vesting NFT.
Details Retrieves the total payout allocated to the specified vesting NFT token ID. This includes previous payouts.
Parameters
tokenId- Token ID whose total payout is requested.
Return values
uint256- Total payout allocated to the vesting NFT.
_startTime
function _startTime(uint256 tokenId) internal view virtual returns (uint256)Overview Retrieves the start time of a specified vesting NFT.
Details Returns the vesting start time for the specified token ID as a Unix timestamp.
Parameters
tokenId- Token ID whose start time is requested.
Return values
uint256- Vesting NFT start time (Unix timestamp).
_endTime
function _endTime(uint256 tokenId) internal view virtual returns (uint256)Overview Retrieves the end time of a specified vesting NFT.
Details Returns the vesting end time for the specified token ID as a Unix timestamp.
Parameters
tokenId- Token ID whose end time is requested.
Return values
uint256- Vesting NFT end time (Unix timestamp).
Security considerations
Timestamps
Vesting schedules are based on timestamps.
This allows implementations to determine how many tokens will have vested by a specified future date.
Care is required, however.
The total amount claimed must never exceed the amount allocated to the vesting NFT.
For example, vestedPayoutAtTime(tokenId, type(uint256).max) should return the entire payout for the specified tokenId.
Approvals
If ERC721 transfer approval is granted for a vesting NFT, the operator can transfer that NFT to itself and subsequently obtain the right to claim its vested tokens. Appropriate access controls and monitoring are important to prevent misuse of this authority. If ERC5725 claim approval is granted, the operator may claim vested tokens but does not gain authority to transfer the NFT away from its owner.
These security considerations are important for operating vesting NFTs safely and protecting users' assets. Careful design and appropriate safeguards can help prevent unauthorized access and misuse of tokens.
References
Apeguru (@Apegurus), Marco De Vries marco@paladinsec.co, Mario mario@paladinsec.co, DeFiFoFum (@DeFiFoFum), Elliott Green (@elliott-green), "ERC-5725: Transferable Vesting NFT [DRAFT]," Ethereum Improvement Proposals, no. 5725, September 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5725.
Conclusion
This article covered ERC5725, a proposed vesting interface that uses NFTs to release ERC20 tokens gradually. I hope it helped clarify the mechanism.
If you have questions, feel free to reach out via Twitter DM.

