NexisDAO solves the illiquidity problem when CKB were deposited in Nervos DAO

Translated from this post of NexisDao

Nervos DAO is a system smart contract on Nervos and the most important component of CKBtoken economics (Economics | Nervos CKB): CKB holders can deposit CKB in Nervos DAO at any time and will accrue interest at a rate directly proportional to that of Secondary Issuance. In other words, if you locked your CKB in Nervos Dao, you are just like holding BTC with a hard-cap.

However, Nervos DAO is a term deposit with a minimum deposit period (at least 180 epoch or around 30 days) and the holder can only make withdrawals after a full deposit period.

In order to solve the inliquidity problem of CKB locked in Nervos Dao. Nexis Dao introduced dCKB - After CKB is deposited in Nervos DAO, users can simultaneously mint the same amount of dCKB. In this way, both Nervos DAO’s fixed income and dCKB’s liquidity are available, and dCKB can be traded freely.

When you withdraw CKB from Nervos DAO, you’ll need to destroy the corresponding dCKB. These functions are implemented based on smart contracts(script) on Nervos CKB. On Nervos DAO, when the user deposits CKB, the deposit receipt owner is the user. dCKB’s deposit receipt is owned by a smart contract(script), which issues the user another deposit receipt. At the same time, based on the xUDT standard,dCKB are minted (the amount is equal to the number of CKB on the deposit certificate). If the user wants to withdraw CKB from the Nervos DAO, the dCKB and the receipt are required to be destroyed too.

Deposit process:

In a normal Nervos DAO transaction

Input1: Cell: {
            capacity: 10000
            lock: User
            type: null
            data: null
        } 
Output1: Cell: {
            capacity: 10000
            lock: User
            type: Nervos DAO
            data: 0x0000000000000000
        }

the transaction of dCKB

Input: Cell: {
            capacity: 10300
            lock: User
            type: null
            data: null
        } 
Output1: Cell: {
            capacity: 10000
            lock: // special ock
            type: Nervos DAO
            data: 0x0000000000000000
        }
Output2: Cell: {
            capacity: 150
            lock: User
            type: DAO Info
            data: 10000
        }
Output3: Cell: {
            capacity: 150
            lock: User
            type: dCKB(xUDT)
            data: 10000
        }

From the code, we can found that the original lock of Nervos DAO was replaced with a special lock and there have been two extra cells in the transaction.

DAO Info: the deposit information of the user, which is used for minting/destruction of dCKB and processing the deposit and withdrawal process. Its owner is the user. So only the user can withdraw.

dCKB: Tokens minted by the DAO Info cell’s smart contract. Users can use them randomly, such as transferring , trading, etc.

Smart Contract validation logic:

  1. “DAO Info” requires that the lock of output1 is “special lock”
  2. “DAO Info” requires that the type script of output1 is “Nervos DAO”
  3. “DAO Info” requires that the number of dCKB stored in the data is “dCKB”
  4. “DAO Info” requires that the added number of dCKBS is equal to the number of deposited CKB
  5. “DAO Info” requires “Nervos DAO” to be in the deposit process
  6. “dCKB” should be xUDT whose args should be DAO Info
  7. “Nervos DAO” : Verify the corresponding deposit process

Withdrawals

The user can send a transaction to apply to withdraw the stored CKB from the Nervos DAO at any time (but there is a lockup period to determine when the CKB can be unlocked). The interest earned by a Nervos DAO Cell is only paid during the withdrawal and unolck phase. It means that for a transaction of Nervos DAO withdrawal, the total Capacity of all Output cells may exceed the total Capacity of all Input cells.
Unlike the deposit process, withdrawing from the Nervos DAO requires two steps:

  1. In Phase 1, transform Nervos DAO deposit cell into Nervos DAO withdrawing cell
  2. In Phase2 , the second transaction is to withdraw deposited tokens together with compensation from Nervos DAO.

Default Nervos DAO process:

Input1: Cell: {
            capacity: 10000
            lock: User
            type: Nervos DAO
            data: 0x0000000000000000
        }
Output1: Cell: {
            capacity: 10000
            lock: User
            type: Nervos DAO
            data: 0x0012300000000000
        }

the process of dCKB’s withdraw from NervosDao

Input1: Cell: {
            capacity: 10000
            lock: // special lock
            type: Nervos DAO
            data: 0x0000000000000000
        }
Input2: Cell: {
            capacity: 150
            lock: User
            type: DAO Info
            data: 10000
        }
Input3: Cell: {
            capacity: 150
            lock: User
            type: dCKB(UDT)
            data: 10000
        }
Output1: Cell: {
            capacity: 10000
            lock: User
            type: Nervos DAO
            data: 0x0012300000000000
        }
Output2: Cell: {
            capacity: 300
            lock: User
            type: null
            data: null
        }

Through the above transaction comparison, it can be found that the withdrawal process of dCKB requires the user to provide both the deposit receipt of “DAO Info” and dCKB. The phase 1 withdrawal of Nervos DAO is implemented by destroying the recipient and dCKB. The corresponding cell is handed over to the user, and the subsequent formal withdrawal follows the default process.

Smart Contract validation logic:

  1. “special lock” : verify the “DAO Info” of the Input cell
  2. “DAO Info” : verify that input1 is Nervos DAO cell
  3. DAO Info: verify that the TX_hash values of input1 and Input2 are consistent
  4. “DAO Info” : verify that Nervos DAO process is in “withdrawal Phase 1”
  5. “DAO Info” : verify that the number of dCKB destroyed is equal to the number of CKB deposits
  6. “Nervos DAO” : Verify the corresponding withdrawal process

Withdrawal Phase 2
The phase 2 transaction takes out the deposited CKB and interest from the Nervos DAO. Unlike the Phase1 transaction, the user can send the Phase 1 transaction at any time, but in the second stage transaction, the Nervos DAO requires the deposit cycle (180 epochs) to actually withdraw CKB. The current period is about one month. If you execute “Withdrawal Phase 1” half a month, you will need to wait half a month before you can execute “Withdrawal Phase 2”.

The process of Phase2 follows the logic of the Nervos DAO contract completely, with no modifications on the dCKB side.

Super thanks for JaneWu’s review,you make this translation article far more elegant !