Co-authored with Rafael Contreras and Ohad Bachner
You might think there are enough protocols to provide collateralized loans in crypto, like Aave, Compound et al. These loans have been designed to protect the lender: they are overcollateralized on liquid assets, meaning that if you want a loan you have to lock a larger amount of another asset than what you are asking, and on top the asset you lock should be very easy to evaluate and sell.
A banker is a fellow who lends you his umbrella when the sun is shining and wants it back the minute it begins to rain.
Source: http://www.twainquotes.com/Banker.html
There are many reasons why people take those kind of loans (capital gain tax avoidance, bull market betting).
But in traditional finance there is also over collaterization of more illiquid assets, like mortgages which rely on easily evaluated assets but not readily sellable.
Now Imagine the collateral is a very illiquid and specialized crypto token / NFT (governance tokens ? sentimental NFTs ?) — it is only valuable to a subset of agents. A member of a DAO that owns these kinds of tokens cannot easily use it as collateral in regular markets.
A DAO might choose to accept it both as an incentive to the member and as a means to collect governance tokens in their own DAO (equivalent to a share buy back in TradFi). The NFT case might look more esoteric, but also imagine a future where the NFTs are linked to other assets beyond digital art (invoices, physical assets).
At Chelo we developed smart contracts to allow DAOs to issue collaterized loans (reverting the collateral to the the DAO in case of default)
A short note before we start: What is a mini DAO?
Mini DAO is a sub DAO of the main DAO. The idea behind this architecture is to make the process more efficient. Only selected members from the DAO will be in the Mini DAO consul and only chosen liquidity will be in the mini DAO treasury.
The best way to explain it will be to give a simple example: suitable for today, Uniswap has 3.6 B $ in treasury and 353.9k DAO members. We cannot expect that all members will vote every loaning, and we don’t want to expose all of the treasury. Mini DAO is solving this problem by selecting only specific members that will control the loan request. As we said, do it more efficiently.
How?
When a Chelo loan is created with collateral it creates a basket NFT(ERC721) (the ‘Collateral’ on the graph above) which holds all the collateral assets (tokens, nfts, etc).
The newly minted basket NFT is transferred to our loan contracts. (Basket NFT — it is a private repository — contact us for access)
If the user repays its loan before the deadline, the basket NFT is sent back automatically to the borrower wallet address (we strongly recommend in this case not to make loans on behalf of third parties as our interface takes the collateral from the sender of the transaction).
Lending Pool: https://github.com/chelofinance/chelo_treasury/blob/prototype/lending/contracts/LendingPool.sol (private repository — contact us for access)
The Collateral Loan smart contract
/// @inheritdoc ILoanManager function createLoanWithCollateral( uint256 principal, uint256 repayment, uint256 duration, uint256 collateralId, uint256 poolId, address borrower ) external onlyOwner returns (LoanMetadata memory loanData) { ILendingPool pool = _pools[poolId]; loanData = LoanMetadata( LoanStatus.Issued, pool, true, collateralId, principal, repayment, 0, duration, block.timestamp + duration, borrower ); assetWrapper.transferFrom(borrower, address(this), collateralId); _createLoan(loanData, pool); }
The function createLoanWithCollateral() is called to create a loan with collateral.
The normal loan settings are passed to it (principal, repayment, duration, borrower, etc) including the collateralID (of our basket asset NFT). Once called, it will transfer the loan to the borrower and send the collateral to our contract.
The Mini DAO
https://github.com/chelofinance/chelo_treasury/tree/prototype/lending/contracts/aragon (private repository — contact us for access)
The Mini DAO needs to approve this loan the same as with normal uncollateralized loans. To withdraw the collateral once a loan is marked as defaulted and the collateral is sent to the Mini DAO, they need to call the function “withdraw(uint bundleId)” in our basket asset nft. That will send the collateral unwrapped to the owner of that bundleID.
The user interface
In the gitbook below we explain how to use the front end we have developed — we strongly suggest that you read the guide from the link as it might change slightly from time to time.
In case of default
In case of default the Mini DAO Needs to call the function markLoanAsDefaulted(ILendingPool pool, uint256 loanId) from our LoanManager.
/// @inheritdoc ILoanManager function markLoanAsDefaulted(ILendingPool pool, uint256 loanId) external onlyOwner { LoanMetadata memory loan = _loans[pool][loanId]; require(loan.status != LoanStatus.Repaid, “LoanManager: Loan already repaid”); require(loan.repaymentDate <= block.timestamp, “LoanManager: Loan timestamp is not finished”); _setLoanStatus(pool, loanId, LoanStatus.Defaulted); if (loan.hasCollateral) { assetWrapper.safeTransferFrom(address(this), owner(), loan.collateralId); } }
They can do this using our user interface by setting a Mini DAO vote to “Mark a loan as defaulted” followed by a successful vote.
The collateral of the loan goes to the wallet of the Mini DAO. If the borrower or any user repays the loan the collateral will still be in control of the Mini DAO.
To move the collateral to the main DAO, the Mini DAO must create another vote with this Open Zeppelin transaction: transferFrom(from, to, tokenId) applied to the basket asset nft. As this vote is approved the NFT will be transferred to the main DAO.
Loan repayment after default
If the borrower does not repay the loan at the loan maturity, the DAO will be able to mark that loan as Defaulted.
If a loan with collateral is marked as defaulted all the collateral is automatically transferred to the Mini DAO (see https://github.com/chelofinance/chelo_treasury/blob/prototype/lending/contracts/LoanManager.sol#L154-L163). (private repository — contact us for access)
Now the Mini DAO will be in control of the collateral, but the borrower can still repay the loan and get in agreement with the Mini DAO. After a loan is marked as defaulted and for some reason the repayment is resolved (the loan does not need to be repaid for this), the Min DAO can mark the loan as *Resolved*, meaning that the debt was resolved by other means. After that will be up to the Mini DAO to return the collateral using their agent application (see https://aragon.org/agent)
Contracts:
API: https://github.com/chelofinance/chelo_treasury/tree/prototype/lending/docs (private repository — contact us for access)
Class diagram:
Meanwhile for more information you can find it on our: