EIPs Explained

ERC-3525 · Final · ERC · 2020-12-01

ERC-3525: Semi-Fungible Token

A semi-fungible token standard: ERC-721-compatible tokens that each carry a slot and a value, where value can be split and moved between tokens of the same slot like an ERC-20 balance.

What problem does it solve?

Some assets are partly unique and partly quantitative. Think of a bond: every position in the same issue (same maturity, same coupon) is interchangeable by amount, but different issues are not. Vesting schedules, vouchers and other financial positions look similar.

  • With ERC-20 you would need one contract per issue, which multiplies quickly.
  • With ERC-721 each token is indivisible: you cannot send "half" of an NFT position.

ERC-3525 combines both. Each token is an ERC-721 NFT, so wallets and marketplaces can already display and transfer it, and each also holds an amount that can be split and merged.

How it works

Every token is described by the triple <ID, SLOT, VALUE>:

  • ID – the ERC-721 token ID; ownerOf, transferFrom(from, to, tokenId) and friends work as usual.
  • SLOT – a category. Values in tokens with the same slot are fungible with each other.
  • VALUE – a quantity, like an ERC-20 balance but held by the token rather than the address. valueDecimals() says how to display it (named this way to avoid clashing with ERC-20's decimals()).

New functions (ERC-165 interface ID 0xd5358140):

Function Purpose
balanceOf(tokenId) Value held by a token
slotOf(tokenId) Its slot
transferFrom(fromId, toId, value) Move value between two tokens of the same slot
transferFrom(fromId, to, value) Move value to an address; the contract creates or picks a token of the same slot for to and returns its ID
approve(tokenId, operator, value) / allowance(tokenId, operator) Value-level approvals

Events TransferValue, ApprovalValue and SlotChanged sit alongside ERC-721's Transfer/Approval. Approvals stack in four levels: all tokens (setApprovalForAll), per slot (optional setApprovalForSlot), per token ID, and per value.

Instead of separate "safe" transfer functions, the contract must call onERC3525Received whenever the recipient is a contract that implements it, and revert unless it returns 0x009ce20b. Optional extensions add slot enumeration and metadata (contractURI, slotURI), with on-chain JSON metadata recommended.

Sample code

Splitting a position and sending part of it (ethers v6). The overloaded transferFrom must be called by full signature:

import { Contract, Wallet, JsonRpcProvider, parseUnits } from "ethers";

const abi = [
  "function valueDecimals() view returns (uint8)",
  "function balanceOf(uint256 tokenId) view returns (uint256)",
  "function slotOf(uint256 tokenId) view returns (uint256)",
  "function transferFrom(uint256 fromTokenId, address to, uint256 value) payable returns (uint256)",
  "event TransferValue(uint256 indexed _fromTokenId, uint256 indexed _toTokenId, uint256 _value)",
];
const signer = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));
const sft = new Contract(process.env.SFT!, abi, signer);

const tokenId = 42n;
const decimals = await sft.valueDecimals();
console.log("slot", await sft.slotOf(tokenId), "value", await sft.balanceOf(tokenId));

const tx = await sft["transferFrom(uint256,address,uint256)"](
  tokenId,
  "0x000000000000000000000000000000000000bEEF",
  parseUnits("250", decimals),
);
await tx.wait(); // recipient receives value in a token with the same slot

Things to know

  • Status: Final.
  • Value approvals are separate from ERC-721 approvals. Approving a token ID lets the operator move its value, but approving its whole value does not let the operator transfer the token itself.
  • Tools that only understand ERC-721 will show the NFT but not its value. Transferring the NFT with ERC-721 transferFrom moves the whole token, value included.
  • Value transfers to an address may mint a new token ID, so the recipient's token count can grow.
  • Compared with ERC-1155, where amounts of an ID are fungible balances per address, here each holding is its own NFT with its own value.

#token #semi-fungible #nft #erc721 #defi

Details

Authors
Will Wang (@will42w), Mike Meng <[email protected]>, Yi Cai (@YeeTsai) <[email protected]>, Ryan Chow <[email protected]>, Zhongxin Wu (@Nerverwind), AlvisDu (@AlvisDu)
Status
Final
Type
Standards Track / ERC
Created
2020-12-01
Requires
Required by

Machine-readable: Markdown · JSON