Skip to content

MakerDao Deep Dive #9

@maxisacoder

Description

@maxisacoder

Overview of MakerDao

  • Rune Christensen
  • 2015.8: first github commit
  • 2017.12: single-collateral live on Mainnet
  • MKR: 7w BTC, rank 22, target of ICO, Total token supply: 1,000,000 MKR
  • DAI: 1w BTC

CDP work flow

  • Creating the CDP and depositing collateral PETH
  • Generating Dai from the collateralized CDP
    • Pooled ETH: 1:1 ETH
    • DAI price is peged with 1USD
  • Paying down the debt and Stability Fee
    • The Stability Fee can only be paid in MKR
    • Once the user sends the requisite Dai and MKR to the CDP, paying down the debt and Stability Fee, the CDP becomes debt free
  • Withdrawing collateral and closing the CDP

Stability Mechanism

The TRFM is prominently described in their current white paper, but it is now no longer meant to be part of the Dai protocol.

Stability Mechanisms (Dai is not redeemable)

  • Global settlement expectations
    • why? a last resort for guaranteeing Dai’s pegged price
    • when?
      • if the Dai price goes too far off the peg for too long
      • long term market irrationality,
      • hacking or security breaches,
      • system upgrades.
    • who? Triggered by global settlers, who are elected by MKR holders
    • comments: depends on elections and human actions, there is a lot of uncertainty around when and if it will happen
  • Stabilizing speculation (套利)
    • downwards stabilization,
    • upwards stabilization
    • Comments: a second-order stabilization mechanism
  • Price manipulation by CDP creators
    • this stabilization mechanism is secondary
    • when DAI is failing
      • buy DAI
      • wipe and close CDP
    • when DAI is rising
      • open CDP
      • sell DAI
  • Off-Chain Stabilization
    • MKR token currently has a much larger market cap than Dai
    • buy walls
    • sell walls
    • counterparty risk
    • scale problem

Criticism: Dai Does Not Scale Well

  • Demand for CDP debt is limited
    • use case:
      • debt
      • leverage
    • Currently only eth, more type of token need to be supported.
    • Overcoming the competition from other issuers of collateralized debt
      • On-chain lending has low counterparty risk.
      • Dai has very low interest rates, pay 0.5% annually.
      • Low maximum leverage. (3x)
      • Lack of standard margin calls (在爆仓前不会提示用户)
      • Auto-liquidation penalty.
    • solution: offer nagetive interest rate for CDP
      • dilute MKR and pay for CDP
      • Pay less DAI, make system undercollateralized
      • Direct tax to hold Dai
  • Diversification Further Limits Dai’s Supply
    • they must either sacrifice Dai’s resilience or its scalability.

Resilient to crashes

  • Really bad for CDP holders to get auto-liquidated
    • 13% penalty
    • keep track of when their collateral value drops and to do what they can to increase their collateralization ratio when it happens
    • by buying and adding more collateral or by buying up Dai to pay off their debt
  • there is a decent buffer between the liquidation ratio of 150% and the point where Dai becomes undercollateralized at less than 100% overall backing
  • diversified collateral backing

Oracle Set Design

MakerDao目前有两个版本的Oracle。一种为直接的喂价加中位数机制,另外一种利用signed message进行链下的计算并上链。

方案一

该方案的代码在一下3个repo,同时也是现行方案

Independent price feed operators constanly monitor the reference price across a number of external sources and will submit updates to the blockchain when:

  • Source price differs to the most recently submitted price by more than the defined amount (currently 1%)
  • Last price update was more than 6 hours ago.

简单画了流程图如下:
11291540278713_ pic_hd
可以看到,上图中的operator是服务器上的中心化程序,实时监控币价波动,在满足上述时间或者波动幅度条件的情况下,调用合约的poke方法,以更新medianizer合约中的最新价格中位数。上述的预言机设计和代码对我们的参考价值很大,初步我们可以直接借鉴这种设计来实现我们的预言机机制。

方案二

该方案的代码在一下2个repo,是未来的makerdao的预言机系统,主要使用了链下的签名消息来节约手续费,目前还没有上线主网,安全性有待检验。时间所限,只把repo列出,详细的原理和代码视makerdao上线后的实际效果后续跟进。

Liquadation Process

MakerDao的平仓机制,只支持一种抵押物的Sai中,和在支持多种抵押物的Dss中,是完全不同的。由于dss现在系统还处于不成熟阶段,我们主要介绍Sai的liquadation流程。

在MakerDao中,keeper这个角色会对所有链上CDP的抵押率做实时的监控。当发现某个CDP的抵押率低于150%的时候,调用tub合约的bite(cup)方法,其中tub合约的作用是 CDP record store, cup的参数是指某一个cdp的编号。 激励keeper角色去主动监控抵押率并调用bite方法的动力有以下两点:

  • The price discount for liquidated assets is 3%. (进入拍卖流程的PETH资产享有3%的价格优惠)
  • Keepers who flag CDPs for liquidation are not given the 13% penalty fee. The liquidation penalty is used to burn PETH tokens. (13%的penalty fee并非直接给到keeper,而是用来在整个PETH的池子中销毁等值的PETH,从而使PETH的持有者获益。)

在Maker的术语体系中,bite()方法完成了下面的事情。
image
其中涉及到的术语如下:
SIN: token DAI 的镜像,表示CDP中待偿还的token数目。
Tub: CDP record store
Tap: The Liquidator
woe: SIN balance, bad debt transferred from bite
fog: PETH balance, collateral pending liquidation
air: PETH backing CDPs
ice: SIN locked up with CDPs

代码如下

    function bite(bytes32 cup) public note {
        require(!safe(cup) || off); // 判断是否真的抵押率低于150%

        // Take on all of the debt, except unpaid fees
       // // 计算当前这个CDP中有多少未还的DAI,
       // 将这一部分用SIN表示的债转到tap合约中, 并清空CDP中的债务
        var rue = tab(cup);
        sin.mint(tap, rue);
        rum = sub(rum, cups[cup].art);
        cups[cup].art = 0;
        cups[cup].ire = 0;
       
        // Amount owed in SKR, including liquidation penalty
        // owe表示可以拍卖的peth数目,并将这部分peth转到tap合约中,
        // 计算后剩余的peth可以留给cdp的开单者提取
        var owe = rdiv(rmul(rmul(rue, axe), vox.par()), tag());

        if (owe > cups[cup].ink) {
            owe = cups[cup].ink;
        }

        skr.push(tap, owe);
        cups[cup].ink = sub(cups[cup].ink, owe);
    }

如上述代码,在bite方法被调用之后,tap合约中的 Sin 表示需要换上的DAI的数目,而SKR 表示可以卖的PETH数量,这两者的比例就可以算出一个拍卖池子中PETH的价格。当SIN归零的时候,表示整个系统中所有处于liquadation阶段的CDP欠下的债务都已经还清,也就完成了CDP的清算。

一点感慨

MakerDao是一个非常吸引我的项目,他在以下的几点都是有非常独特的价值:

  • 去中心化的稳定币中最能落地的,目前来看也是整个市值最大的去中心化稳定币。
  • MKR没有进行ICO,因为Rune这个人不希望通过ICO导致大量的投机客和断线投资者进入DAO,影响整个社区的风气。当然,在没有进行ICO的情况下,如何获得充足的项目经费,同时维持一个比较大的MKR的市值,是我们需要思考的问题。
  • 对安全的重视和形式化验证的技术。makerDao是一个非常复杂的系统,有着复杂的机制设计,从第一行代码到系统上线,花了3年的时间。这个系统是为了承载巨大的资产而设计,所以安全性是极其极其重要的。第一个版本的SAI,邀请了参与theDAO事件的白帽子组织WHG,和非常牛逼的区块链安全团队trailofbits做代码审计。同时对整个系统的上限做了限制,防止出现安全事件时候波及的资金过多。事实证明,对安全足够的重视,导致maker这个项目基本没有负面的事件发生。在第二个版本的多抵押物dss实现中,更是引入了形式化验证的技术,由dapphub团队对整个模型做了严格的形式化推倒(https://github.com/dapphub/k-dss/),从逻辑层面证明了系统的安全性,是区块链领域第一个进行完整证明的系统。
  • 最后吐槽一下,makerdao这个项目,两个版本之间的设计存在巨大割裂,文档也是缺乏更新,经常让人不知道描述的是哪个版本,无疑增加了研究他的难度。不过话说回来,开源项目,文档往往是最后一个去完善的,在代码还没有完全finalize的时候去做文档的工作,在contributor有限的情况下,往往是不经济的。但也从侧面说明了这个项目本身内在的复杂度导致社区参与的难度,不然文档这种工作很多时候都是社区contributor刷commit的好方法。

QA

  • NTF or FT?
  • 有没有加仓机制?
  • MKR如何增值
  • 对比chenxin的想法,有何异同?
  • how markerdao deal with btc

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions