EIPs Explained

ERC-5744 · Stagnant · ERC · 2022-09-29

ERC-5744: Latent Fungible Token

An ERC-20 extension for tokens that start out locked per mint and only become freely fungible after a maturity delay, useful for vesting and minimum-deposit receipts.

What problem does it solve?

Some tokens should not be fully usable the moment they are minted:

  • Vesting tokens that must not be transferred until a vesting period ends.
  • Receipt tokens from a lending or insurance protocol that enforce a minimum deposit duration.

Projects build this with custom logic, but wallets and integrators have no standard way to ask "how much of this balance is actually usable now?". ERC-5744 ("Latent Fungible Token") defines that interface on top of ERC-20.

How it works

A latent fungible token is a normal ERC-20 with two additions:

  • balanceOfMatured(user) returns only the matured (fungible) part of a balance. balanceOf and totalSupply still count everything, matured or not.
  • getMints(user) returns every mint for a user as MintMetadata { amount, time, delay }: how much was minted, when (timestamp in seconds), and the delay in seconds until it matures. If maturity depends on something other than elapsed time, delay must be type(uint256).max.

An optional mints(user, id) returns a single mint by an implementation-defined ID.

Implementations may make transfer, transferFrom and burns revert for immature tokens. A vesting token would do that; a receipt token might allow transfers at any time and only use maturity elsewhere. The token must implement ERC-20's optional name / symbol, and they must reflect the underlying token in some way.

The spec lists ERC-2612 (permit) as a requirement.

Sample code

Reading usable vs. total balance (ethers v6):

import { Contract, JsonRpcProvider, formatUnits } from "ethers";

const abi = [
  "function balanceOf(address) view returns (uint256)",
  "function balanceOfMatured(address) view returns (uint256)",
  "function getMints(address) view returns (tuple(uint256 amount, uint256 time, uint256 delay)[])",
  "function decimals() view returns (uint8)",
];

const provider = new JsonRpcProvider(process.env.RPC_URL);
const token = new Contract(process.env.TOKEN!, abi, provider);

const user = process.env.USER_ADDRESS!;
const [total, matured, mints, dec] = await Promise.all([
  token.balanceOf(user),
  token.balanceOfMatured(user),
  token.getMints(user),
  token.decimals(),
]);

console.log("total  :", formatUnits(total, dec));
console.log("usable :", formatUnits(matured, dec));

const MAX = (1n << 256n) - 1n;
for (const m of mints) {
  const when = m.delay === MAX ? "condition-based" : new Date(Number(m.time + m.delay) * 1000).toISOString();
  console.log(formatUnits(m.amount, dec), "matures:", when);
}

Things to know

  • Status is Stagnant: no recent activity, and it may never be finalized.
  • Do not assume balanceOf is spendable. Integrators (DEXs, lending markets) should use balanceOfMatured when the token may block immature transfers.
  • getMints returns an unbounded array. Iterating it on-chain can exceed the block gas limit; the spec suggests a paginated variant if a user may accumulate many mints.
  • Fully backward compatible with ERC-20 tools, which simply see the total balance.

#token #erc20 #vesting #defi #extension

Details

Authors
Cozy Finance (@cozyfinance), Tony Sheng (@tonysheng), Matt Solomon (@mds1), David Laprade (@davidlaprade), Payom Dousti (@payomdousti), Chad Fleming (@chad-js), Franz Chen (@Dendrimer)
Status
Stagnant
Type
Standards Track / ERC
Created
2022-09-29
Requires

Machine-readable: Markdown · JSON