EIPs Explained

ERC-7893 · Final(最终) · ERC · 2025-01-30

ERC-7893: DeFi Protocol Solvency Proof Mechanism

一个供 DeFi 协议发布其资产、负债和偿付能力比率的标准链上接口,带有历史记录和任何人都可监控的风险警报事件。

它解决什么问题?

每个 DeFi 协议报告财务健康状况的方式各不相同,有的甚至完全不报告。用户、审计方和风险仪表盘只能手工还原头寸,而当协议逐渐滑向资不抵债时,也没有统一的预警信号。

ERC-7893 定义了一个接口 ISolvencyProof,让任何协议都能公开相同的数据:持有什么、欠下什么、两者之间的比率、该比率随时间如何变化,以及比率越过风险阈值时的事件。

它如何运作

合约存储两份快照,每份由并行数组和一个时间戳组成:

  • ProtocolAssets 和 ProtocolLiabilities:tokens[]、amounts[](按代币 decimals)、values[](以 ETH 计,18 位小数)、timestamp。

关键规则:

  • 只有被授权的预言机可以调用 updateAssets / updateLiabilities;其他调用者必须回滚。数组长度必须相等,时间戳设为 block.timestamp。
  • 偿付能力比率为 totalAssets * 10000 / totalLiabilities(以基点计,因此 10500 = 105 %)。
  • verifySolvency() 根据实现的最低比率返回 (isSolvent, healthFactor)。
  • getSolvencyHistory(start, end) 返回该时间范围(含两端)内的所有快照。
  • 每次更新都会触发 SolvencyMetricsUpdated;突破阈值时应触发 RiskAlert(riskLevel, currentValue, threshold, timestamp)。
  • 合约必须支持 ERC-165,并对 ISolvencyProof 的接口 ID 返回 true。

规范推荐的分级:低于 105 % 为 CRITICAL,105–110 % 为 HIGH RISK,110–120 % 为 WARNING,120 % 及以上为 HEALTHY。

示例代码

读取协议的健康状况并监听警报(ethers v6):

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

const abi = [
  "function verifySolvency() view returns (bool isSolvent, uint256 healthFactor)",
  "function getProtocolAssets() view returns (tuple(address[] tokens, uint256[] amounts, uint256[] values, uint256 timestamp))",
  "event RiskAlert(string riskLevel, uint256 currentValue, uint256 threshold, uint256 timestamp)",
];

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

const [ok, hf] = await proof.verifySolvency();
console.log(`solvent=${ok} ratio=${Number(hf) / 100}%`);

const assets = await proof.getProtocolAssets();
const total = assets.values.reduce((a: bigint, v: bigint) => a + v, 0n);
console.log("assets (ETH):", formatEther(total));

proof.on("RiskAlert", (level, value, threshold) => {
  console.warn(`${level}: ratio ${value} below ${threshold}`);
});

需要注意

  • 状态为 Final。
  • 数字的可靠程度取决于写入它们的预言机。该标准并不以密码学方式证明储备,它标准化的是被授权方如何在链上报告储备。
  • 所有数值都以 18 位小数的 ETH 计价,因此主要持有稳定币的协议仍然需要通过价格源进行换算。
  • 如果总负债为零,实现应当返回一个"最大偿付能力"值,或者回滚;使用方应同时处理这两种情况。
  • getSolvencyHistory 在较长的范围内可能开销很大,只要文档中说明保留策略,实现可以让旧数据过期。

#defi #solvency #risk #oracle #interface

详细信息

作者
Sean Luis Guada Rodríguez (@SeanLuis) <[email protected]>
状态
Final(最终)
类型
Standards Track / ERC
创建日期
2025-01-30
依赖的提案

机器可读数据: Markdown · JSON