EIPs Explained

ERC-7444 · Draft · ERC · 2023-06-05

ERC-7444: Time Locks Maturity

A one-function interface, getMaturity(id), that tells anyone the Unix timestamp at which a time-locked position unlocks, so locked assets can be valued and traded consistently.

What problem does it solve?

Time locks are everywhere in DeFi: vesting schedules, vote-escrowed tokens, locked liquidity, bonds. Very often the right to a locked position is itself transferable, for example as an ERC-721 or ERC-1155 token. To price such a position you need to know when it unlocks, because its value depends heavily on time remaining. Today every protocol exposes that date differently, if at all, so marketplaces, lending protocols and valuation tools must write custom code for each one.

ERC-7444 standardises the single piece of information they all need: the maturity date.

How it works

A compliant contract supports ERC-165 and implements:

function getMaturity(bytes32 id) external view returns (uint256 maturity);
  • id identifies a specific lock. How IDs are derived is up to the implementation (a hash, a token ID cast to bytes32, etc.).
  • maturity is a Unix timestamp in seconds, the same unit as block.timestamp.
  • For singleton contracts that lock one fungible asset with a single schedule, id should be ignored, and callers should pass 0x0.

The standard can be bolted onto existing NFT-based lock systems by deploying a separate contract that answers getMaturity for them.

The rationale points out that time to maturity is a key input in option-style pricing models such as Black-Scholes, which is why a common way to read it matters.

Sample code

A minimal locker that implements the interface:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC7444 {
    function getMaturity(bytes32 id) external view returns (uint256 maturity);
}

contract SimpleLocker is IERC7444 {
    struct Lock { address owner; uint256 amount; uint256 maturity; }

    IERC20 public immutable token;
    mapping(bytes32 => Lock) public locks;
    uint256 private nonce;

    constructor(IERC20 _token) { token = _token; }

    function deposit(uint256 amount, uint256 period) external returns (bytes32 id) {
        id = keccak256(abi.encode(msg.sender, nonce++));
        locks[id] = Lock(msg.sender, amount, block.timestamp + period);
        require(token.transferFrom(msg.sender, address(this), amount), "transfer");
    }

    function withdraw(bytes32 id) external {
        Lock memory l = locks[id];
        require(msg.sender == l.owner, "owner");
        require(block.timestamp >= l.maturity, "locked");
        delete locks[id];
        require(token.transfer(msg.sender, l.amount), "transfer");
    }

    function getMaturity(bytes32 id) external view returns (uint256) {
        return locks[id].maturity;
    }

    function supportsInterface(bytes4 i) external pure returns (bool) {
        return i == type(IERC7444).interfaceId || i == 0x01ffc9a7; // ERC-165
    }
}

Things to know

  • Status is Draft.
  • Some protocols let a lock be extended. getMaturity only reports the current value, so check it right before trading or lending against a position.
  • The reference implementation in the spec text has typos and an inverted maturity check in withdraw; treat it as illustrative and do not copy it directly.
  • A return value of 0 usually means the ID does not exist, but the spec does not define this, so do not rely on it across implementations.

#defi #timelock #vesting #interface

Details

Authors
Thanh Trinh (@thanhtrinh2003) <[email protected]>, Joshua Weintraub (@jhweintraub) <[email protected]>, Rob Montgomery (@RobAnon) <[email protected]>
Status
Draft
Type
Standards Track / ERC
Created
2023-06-05
Requires

Machine-readable: Markdown · JSON