ERC-3475 · Final(最终) · ERC · 2021-04-05
ERC-3475: Abstract Storage Bonds
面向债券和其他债务的代币标准:每个 class/nonce 组合都是独立的代币类型,带有链上元数据、供应量追踪,以及批量发行、转移和赎回。
它解决什么问题?
流动性提供者份额和类似的债权通常是普通的 ERC-20 代币。对于单一的同质化头寸,这样做可行,但债券的结构更复杂:发行条件、到期日、赎回规则,以及可能在不同时间发行的许多档次(tranche)。用 ERC-20 来表达,意味着每个档次一个合约,并把元数据放在链下。
ERC-3475 定义了一个可以容纳多种债券类型的合约,每种类型都有自己的元数据和供应量数据,任何钱包或交易所都可以通过同一接口读取。
它如何运作
- Class(
classId):债券类型,例如「6 个月固定」。Class 带有符号或风险信息等元数据。 - Nonce(
nonceId):class 内的一次发行,例如某个特定的发行日期。每个(classId, nonceId)组合都有自己的余额、供应量和元数据。同一 nonce 内的单位是同质化的。 - 批量操作接受
Transaction { classId, nonceId, _amount }数组,因此一次调用可以转移多种债券类型:issue(to, txs)、redeem(from, txs)、burn(from, txs):仅限发行实体(规范称之为「Bank」);transferFrom(from, to, txs)、transferAllowanceFrom(from, to, txs);- 按 class/nonce 的
approve(spender, txs),以及面向运营者的setApprovalFor(operator, approved)。
- 按 class/nonce 的供应量视图:
totalSupply、activeSupply、redeemedSupply、burnedSupply,以及balanceOf(account, classId, nonceId)。 - 到期:
getProgress(classId, nonceId)返回距离赎回已达成和剩余的进度(时间、流动性,或发行方定义的任何指标)。 - 抽象元数据:
classMetadata/nonceMetadata描述字段(title、_type、description),classValues/nonceValues以通用的Values结构体(string、uint、address、bool、bytes)返回值。这样避免了固定的存储布局。 - 事件:
Issue、Redeem、Transfer、ApprovalFor,以及一个销毁事件。
示例代码
核心类型和几个函数:
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
interface IERC3475Core {
struct Transaction { uint256 classId; uint256 nonceId; uint256 _amount; }
struct Metadata { string title; string _type; string description; }
struct Values { string stringValue; uint uintValue; address addressValue; bool boolValue; bytes bytesValue; }
event Transfer(address indexed _operator, address indexed _from, address indexed _to, Transaction[] _transactions);
function transferFrom(address _from, address _to, Transaction[] calldata _transactions) external;
function balanceOf(address _account, uint256 classId, uint256 nonceId) external view returns (uint256);
function activeSupply(uint256 classId, uint256 nonceId) external view returns (uint256);
function getProgress(uint256 classId, uint256 nonceId)
external view returns (uint256 progressAchieved, uint256 progressRemaining);
}
一次调用转移两个档次(ethers v6):
await bond.transferFrom(me, buyer, [
{ classId: 1n, nonceId: 14n, _amount: 500n },
{ classId: 1n, nonceId: 15n, _amount: 200n },
]);
需要注意
- 状态:Final。
- 尽管把 ERC-20、ERC-721 和 ERC-1155 列为要求,它仍是一个独立的接口:ERC-20 或 ERC-1155 钱包若无明确支持,就无法显示或转移这些债券。
- 规范文本在示例、参数名和注释之间存在不一致(例如示例中的 class/nonce 值和数量并不总是与所示调用一致,部分签名在 docstring 与函数之间也不同)。请以参考实现为准,而不要只看文字描述。
- 元数据模式定义在随附的
Metadata.md资源中,而不是主规范文本里。 issue、redeem和burn属于特权操作。持有者依赖发行方的合约正确执行到期条件;标准只规定赎回必须在这些条件满足之后进行。