ERC4626-Tokenized Vault Standard
July 7th, 2022

概念

ERC4626标准允许为代表单一底层ERC-20代币份额的代币金库实现一个标准的API,通过拓展ERC20协议,提供了存入和提取代币以及读取余额的基本功能。(金库标准化)

前沿发展

  1. mStable已经整合了ERC 4626
  2. balancer linear pools在整合ERC 4626
  3. Yearn V3在整合 ERC 4626
  4. Yield Protocal在整合4626
  5. openzeppelin也已经支持了4626了(merged into master)

为什么需要金库标准化

收益聚合器(例如Yearn、Rari 和Idle)、借贷市场(例如Compound, Aave和 Fuse)和原生收益代币(例如xSUSHI )通常在实施时略有不同。对于需要符合许多标准的协议,这使得在聚合器或插件层的集成变得困难,这迫使每个协议编写Adapter,而这些适配器容易出错并会浪费开发资源。

(1)就是为了使一切变得标准化、简单化,这使得任何有收益的代币都可以与任何 DeFi 应用程序兼容,从而增强多个网络中的收益金库的可组合性和可访问性。

View方法

(1)asset: 返回underlyingToken

- name: asset
  type: function
  stateMutability: view

  inputs: []

  outputs:
    - name: assetTokenAddress
      type: address

(2) totalAssets: 返回underlyingToken的总量

- name: totalAssets
  type: function
  stateMutability: view

  inputs: []

  outputs:
    - name: totalManagedAssets
      type: uint256

(3) convertToShares: 在满足所有条件的理想情况下,能换到shareToken的数量

- name: convertToShares
  type: function
  stateMutability: view

  inputs:
    - name: assets
      type: uint256

  outputs:
    - name: shares
      type: uint256

(4) maxDeposit: 通过存款通知,可以为接收方存入保险库的标的资产的最大数量。

- name: maxDeposit
  type: function
  stateMutability: view

  inputs:
    - name: receiver
      type: address

  outputs:
    - name: maxAssets
      type: uint256

(5) previewDeposit: 估算 Deposit 的结果

- name: previewDeposit
  type: function
  stateMutability: view

  inputs:
    - name: assets
      type: uint256

  outputs:
    - name: shares
      type: uint256

(6) maxMint: 从金库发送给接收者铸币的最大数量。

- name: maxMint
  type: function
  stateMutability: view

  inputs:
    - name: receiver
      type: address

  outputs:
    - name: maxShares
      type: uint256

(7) previewMint: 允许链上或链下用户在给定当前链上条件的情况下模拟其铸币在当前区块的效果

- name: previewMint
  type: function
  stateMutability: view

  inputs:
    - name: shares
      type: uint256

  outputs:
    - name: assets
      type: uint256

Write 方法

  • (1) deposit
    • 【作用】Mint 出 shareToken给receiver
    • 要对传入的金额进行检查,判断是不是等于assets。注意,所以所有的砍头币都不适合ERC4626。
- name: Deposit
  type: event

  inputs:
    - name: sender
      indexed: true
      type: address
    - name: owner
      indexed: true
      type: address
    - name: assets
      indexed: false
      type: uint256
    - name: shares
      indexed: false
      type: uint256

(2)withdraw

  • 燃烧掉 share Token,给receiver发送底层资产
  • 必须支持在所有者是msg.sender的情况下直接从所有者那里烧毁shareToken的提款流程。
  • 必须支持一个提款流程,即当msg.sender拥有对所有者股份的ERC-20批准时,shareToken直接从所有者那里烧掉。
  • 可能支持一个额外的流程,其中shareToken在提款执行前被转移到Vault合约。
- name: Withdraw
  type: event

  inputs:
    - name: sender
      indexed: true
      type: address
    - name: receiver
      indexed: true
      type: address
    - name: owner
      indexed: true
      type: address
    - name: assets
      indexed: false
      type: uint256
    - name: shares
      indexed: false
      type: uint256

Solidity 接口实现

ERC4626 安全事项

(1)EOA账户

如果实施者打算直接支持EOA账户访问,他们应该考虑为deposit/mint/withdraw/redeem添加一个额外的函数调用,并有办法适应滑点损失或意外的存款/提款限制,因为他们没有其他办法在没有达到确切的输出金额时恢复交易。

(2)预览方法返回值问题

  1. totalAssets、convertToShares和convertToAssets等方法是用于显示的估计值,一般不用于这些方法underlying资产数量。(0.09 ~ 1.01)
  2. 预览方法返回的值尽可能地接近精确。由于这个原因,它们可以通过改变链上的条件而被操纵,并且不一定能安全地用作价格信标。本规范包括允许不精确的转换方法,因此可以作为稳健的价格标志来实现。例如,在资产和股票之间的转换中,使用时间加权平均价格来实现转换方法是正确的。

参考资料

Subscribe to shaneson.eth
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from shaneson.eth

Skeleton

Skeleton

Skeleton