Development Details
The key components of Davos's functions lie between a set of smart contracts that interact across blockchains and existing contracts. Davos created its customized smart contracts based on a fork of the MakerDAO smart contract set.
Modules
Davos consists of 2 main modules:
- The core module (a MakerDAO fork and Davos's Interaction contract) — provide collateral, borrow DAVOS, repay DAVOS, withdraw collateral, liquidate collateralized assets.
- The rewards module — claim rewards in DGT.
Requirements
- Minimum borrowing limit — 50 DAVOS.
- Liquidation incentive — 5 DAVOS.
Fees
- Borrowing interest — an interest paid to Davos for borrowing DAVOS. The rate is a fixed number set by the Davos governance platform.
- Liquidation penalty — a percentage fee added to the user's debt in a Dutch auction during the liquidation process. Fixed by Davos governance; current value is 13% of the debt.
Ratios
Collateral ratio — a percentage of the user's collateral value ratio that determines the maximum borrowing limit for the user. Different assets will have different collateral ratios dependent on the asset's volatility. The collateral ratio is used as a liquidation bar to decide when a liquidation event should happen.
Rewards
- The borrowing reward — users get rewards for borrowing DAVOS, in DGT — the Davos governance token. Rewards are calculated dynamically and are the product of the rewards rate and the total user’s debt in DAVOS. The rewards rate is a fixed amount set by Davos.
- The auction start reward — anybody who triggers the liquidation event of a CDP, i.e., start of a Dutch auction, receives a flat fee (tip) and a percentage fee (chip) for just initiating the process. The tip and chip are paid by Davos from the Davos reserves.
- The auction restart reward — anybody who restarts the Dutch auction, which is part of the liquidation process, receives a flat fee (tip) and a percentage fee (chip). An EOA can restart the auction when the auction time limit is reached or the price decrease has reached a certain threshold. These two limits are set by the Davos governance. The tip and chip are paid by Davos from Davos reserves.
Liquidation Model
The liquidation model is best described by the following example:
Step/Variable | Value |
---|---|
Price of 1 unit of collateral | $2 |
Liquidation ratio | 66% |
Price of collateral with liquidation ratio | $1.32 |
User deposits 10 units of collateral | 10 * 2 = $20 |
Borrow limit | user_deposit * liquidation_ratio = 20 * 0.66 = $13.2 |
User borrows $13 of DAVOS | 13 DAVOS |
Price of 1 unit of collateral decreases and now is | $1.8 |
Collateral unit price, with safety margin | _current_price_of_collateral_unit * liquidation_ratio = 1.8 * 0.66 = $1.188 |
Current worth of collateral, with safety margin | price_of_colatteral_with_safety_margin * amount_of_collateral = 1.188 * 10 = $11.88 |
Trigger for liquidation | borrowed_amount - current_worth_of_colateral = 13 - 11.88 = $1.12, which is >$0 |
Somebody starts a Dutch auction to liquidate the collateral. Starter is sent tip + chip as a reward for it, from Davos reserves | 5 + (14.69 * 0) = $5 |
User collateral that goes to Dutch auction | 10 units |
Liquidation penalty (fixed by Davos governance) | 13% of the debt |
Debt to cover in the auction | borrowed_amount * liquidation_penalty = 13 * 1.13 = $14.69 |
buf (percentage similar to liquidation penalty, fixed by Davos governance) | 2% |
top (start auction price of 1 unit of collateral) | current_price_of_collateral_unit * buf = 1.8 * 1.02 = $1.836 |
Auction starts and price gradually decreases. Anybody can come and buy any amount of the liquidated collateral | |
tau (time in seconds until price is 0; fixed by Davos governance) | 21600 |
dur (time in seconds elapsed since the auction start; fixed by Davos governance) | e.g. 600 |
Linear decrease of price of 1 unit of collateral | top * ((tau - dur) / tau) = 1.836 * ((21600 - 600) / 21600) = $1.785 after 600s of the auction |
Somebody restarts the auction based on: — tail (specific amount of time elapsed; fixed by Davos governance) OR — cusp (% of price drop; fixed by Davos governance) | — — 40% of top = 0.40 = $0.7344 |
tip (flat fee given as a reward to auction starter/restarter; fixed by Davos governance) | 5 DAVOS |
chip (dynamic fee given as a reward to auction starter/restarter; fixed by Davos governance) | 0 |
Restarter is sent tip + chip as a reward, from Davos reserves | 5 + (14.69 * 0) = $5 |
Smart Contracts
The smart contracts that implement Davos are:
- MakerDAO set — the Maker Protocol, also known as the Multi-Collateral Dai (MCD) system, allowing users to generate DAVOS by leveraging collateralized assets. DAVOS is a decentralized, unbiased, collateral-backed cryptocurrency soft-pegged to the US Dollar.
- ABACI — price decrease function for Dutch auctions during the liquidation process of user's assets.
- CLIP — liquidation v2.0 mechanics.
- DOG — starts Dutch auctions during the liquidation process of user's assets.
- JOIN — ERC-20 token adapters.
- DavosJoin — adapter for connecting DAVOS and MakerDAO.
- JOIN (ceMATIC) — adapter for connecting the collateral and MakerDAO.
- JUG — collects Davos's borrowing interest for lending DAVOS to the user.
- DAVOS — stable asset DAVOS users can borrow from Davos.
- SPOT — oracle that fetches the price of ankrMATIC, which is an intermediate token used during the process of collateralizing user's assets.
- VAT — сore vault for collateralized debt positions (CDP).
- VOW — vault balance sheet. Keeps track of debt or surplus of DAVOS.
- DGTRewards — rewards distribution, in the DGT rewards token.
- DGTToken — ERC-20 compatible rewards token DGT given to the user for borrowing DAVOS.
- DavosOracle — oracle for the DAVOS rewards token.
- DavosProvider — wraps MATIC into ceMATICc via
cerosRouter
. - cerosRouter — finds the best way to obtain ankrMATIC, which is an intermediate token used during the process of collateralizing user's assets.
- cerosYieldStrategy — deposits and withdraws wMATIC into yeildConverter; generates yield for Davos.
- swapPool — swaps wMATIC for ankrMATIC if this option is cheaper than exchanging on DEX.
- waitingPool — keeps track of pending MATIC withdraw requests and fulfills them when liquidity becomes available.
- masterVault — wraps MATIC into wMATIC; mints or burns ceMATIC, which is the underlying collateral token inside MakerDAO.
- CeVault — stores obtained ankrMATIC, which is an intermediate token used during the process of collateralizing user's assets.
- Interaction — proxy for the MakerDAO contracts. Provides deposit, withdraw, borrow, payback, and liquidation functions to the end users.
- AuctionProxy — entrypoint for Dutch auction methods, which is part of the liquidation process of user's assets. Allow users to start and participate in auctions.
- Jar — staking contract to stake DAVOS get staking rewards in the DAVOS token.
- ankrMATIC — liquid yield-bearing token used during the process of collateralizing user's assets.
- dMATIC — token minted for the user as a deposit receipt for their collateral.
Workflow
Here are the main Davos's operations described in high-level detail.
Collateralize User’s Assets to Borrow DAVOS
- User transfers MATIC to Davos via
DavosProvider::provide({value: amount})
. DavosProvider
mints dMATIC for the user as a deposit receipt for their collateral.DavosProvider
gets ceMATIC, running the following logic inside:- Deposit the user's MATIC to
masterVault
viamasterVault::depositETH({value: amount)
. masterVault
mints ceMATIC forDavosProvider
.masterVault
wraps MATIC minting wMATIC.masterVault
manager triggers themasterVault::allocate()
to deposit the wMATIC tocerosYieldStrategy
based on the strategy allocation.cerosYieldStrategy
forwards wMATIC tocerosRouter
which exchanges wMATIC for ankrMATIC through the cheapest swapping option (on DEX or viaswapPool
), viacerosRouter::depositwMatic(amount)
.cerosRouter
sends the obtained ankrMATIC toCeVault
for storing, viaCeVault::depositFor(msg.sender, amount after exchange)
.msg.sender
—DavosProvider
address andamount after exchange
— the amount of exchanged ankrMATIC.
- Deposit the user's MATIC to
DavosProvider
collateralizes ceMATIC viaInteraction::deposit(account, address(ceMATIC), amount)
.account
— user's account address,address(ceMATIC)
— address of ceMATIC smart contract,amount
— MATIC initially collateralized by the user.Interaction
runs the following logic inside:- Transfers ceMATIC, which is an ERC-20 token, to the
Interaction
smart contract, via thetransfer()
function of the ERC-20 token smart contract. - Transfers the assets to the MakerDAO vault via
gem::join()
. For more information, refer to the Join docs. - Makes the
VAT
smart contract fully trust theInteraction
smart contract viaVAT::behalf()
. - Locks the assets inside MakerDAO via
VAT::frob()
, effectively collateralizing them. For more information, refer to the VAT docs. - Emits a deposit event.
- Transfers ceMATIC, which is an ERC-20 token, to the
Borrow DAVOS
- Borrow DAVOS via
Interaction::borrow()
. After the transaction is sent,Interaction
runs the following logic inside:- Calculate the current DAVOS value inside MakerDAO, fed via the Chainlink price feed. While calculating take into consideration the borrowing limit, which is the price of the assets collateralized by the user * collateral ratio (fixed amount set by Davos governance).
- Indebt the user equal to the borrowed DAVOS amount via
VAT::frob()
. For more information, refer to the VAT docs. - Transfer the borrowed DAVOS via
JOIN::exit()
. For more information, refer to the Join docs. - Emit a borrow event.
Repay DAVOS
- Repay Davos the borrowed DAVOS via
Interaction::payback()
. After the transaction is sent,Interaction
runs the following logic inside:- Transfer the DAVOS to the
Interaction
smart contract, via thetransfer()
function of the ERCs-20 token smart contract. - Transfer the DAVOS to the MakerDAO vault via
DavosJoin::join()
. For more information, refer to the Join docs. - Calculate the current DAVOS value inside MakerDAO, fed via the Chainlink price feed.
- Subtract the repaid DAVOS amount from the user’s debt via
VAT::frob()
. For more information, refer to the VAT docs. - Emit a payback event.
- Transfer the DAVOS to the
Withdraw Collateral
- User makes a withdrawal request via
DavosProvider::release(recipient, amount)
. DavosProvider
requests ceMATIC to be sent tomasterVault
viaInteraction::withdraw(account, address(ceMATIC), amount)
.account
— user's account address,address(ceMATIC)
— address of ceMATIC smart contract,amount
— MATIC initiallly collateralized by the user.Interaction
runs the following logic inside:- Unlock the assets via
VAT::frob()
. For more information, refer to the VAT docs. - Transfer the assets from the CDP engine to the MakerDAO vault via
VAT::flux()
. For more information, refer to the VAT docs. - Transfer the assets to the user’s wallet via
gem::exit()
. For more information, refer to the Join docs.
- Unlock the assets via
DavosProvider
request MATIC frommasterVault
.masterVault
checks if the amount is available inmasterVault
contract. If yes,masterVault
burnsceMATIC
and sends the MATIC toDavosProvider
, andDavosProvider
burns the dMATIC. I no,masterVault
withdraws the MATIC throughcerosYieldStrategy
, sends it toDavosProvider
, andDavosProvider
burns the sMATIC; if no liquiditycerosYieldStrategy
,masterVault
submits the withdraw request towaitingPool
,DavosProvider
still burns the sMATIC, and next time anyone deposits MATIC,masteVault
fulfills the withdraw request sending MATIC towaitingPool
, andwaitingPool
sends MATIC further to the user.
Claim Rewards
- For borrowing DAVOS, claim rewards in DGT to the user’s wallet, via
DGTRewards::claim()
. After the transaction is sent,DGTRewards
runs the following logic inside:- Update the rewards pool size and rewards rate.
- Transfer the pending user rewards to the user’s wallet via
DGTToken::transfer()
.
Liquidation
- When the current worth of collateral (obtained from the Chainlink price feed) with safety margin < borrowed amount of DAVOS, the liquidation process can be triggered by anybody via Interaction::startAuction(token, user, keeper), where token — address of the liquidated assets, user — address of user whose collateral is being liquidated, keeper — address of the user who gets a reward (tip + chip) for starting the auction. Then Interaction runs the following logic inside:
- Start a Dutch auction:
- Set the starting auction price for the liquidated collateral to be equal (current_collaterral_unit_price * buf).
- Let anybody come and buy via buyFromAuction(token, auctionId, collateralAmount, maxPrice, receiverAddress) to buy any amount > than dust (currently 1 USD). token — address of the liquidated assets, auctionId — ID of the auction, collateralAmount — amount to buy, maxPrice — price to pay , receiverAddress — address of the buyer.
- If the maxPrice is > current_ auction_collateral_unit_price, sell the requested amount of the user's collateral to the buyer.
- Else, incrementally lower the auction price and let anybody buy still. The reason for decreasing from a higher price is because of bots and change of collateral price from oracle to avoid any sudden loss. The auction lasts a fixed amount of time (tau) set by Davo governance. The price is recalculated every second of the auction.
- When the auction time limit is reached or the price decrease has reached a certain threshold (the limits are set by Davos governance; currently 40%), let anybody come and restart the auction and get tip+chip for doing it.
- Transfer the price paid in #1.3, in DAVOS, from the buyer's wallet to Davos.
- Exchange ceMATIC for ankrMATIC and send ankrMATIC to the buyer's wallet. Effectively, buyer buys ankrMATIC that they can later exchange for MATIC.
- Cover debt and keep profit (borrowed amount + (borrowing interest + liquidation penalty)).
- Calculate the remainder (price paid - debt - profit). Send the remainder to the user’s wallet.
- Start a Dutch auction: