π€Peer-to-Peer Lending (V1)
Last updated
Last updated
One of the foremost advantages that Decentralized Finance (DeFi) brings to the realm of Peer-to-Peer (P2P) lending and borrowing lies in its trustless essence. By leveraging blockchain technology, DeFi obviates the necessity for third-party mediators, thereby facilitating direct interactions between users. This trustless framework engenders heightened transaction security, privacy, and cost efficiency.
Moreover, DeFi bestows an augmented level of accessibility upon P2P lending and borrowing. By circumventing the prerequisites of a traditional bank account or credit score, DeFi simplifies the process of accessing financial services, transcending geographical or financial constraints. This elevated accessibility has effectively paved the way for financial inclusivity, extending the reach of such services to countless individuals worldwide who were previously excluded from conventional banking channels.
As you might have heard, our first product - P2P lending - is currently live. Try it out here: https://app.cerra.io
We also released the P2P lending Smart contract to the public, making it open source. You can find smart contract code on our Github: https://github.com/cerraio/lending-plutus
We will be open sourcing other system parts, once P2P lending is released to mainnet.
P2P lending consists of 4 main smart contracts/minting policies:
Lending smart contract. Holds all of the loan UTXOs and funds in different states: Created, Active, Liquidateable, Ended, etc. Loan state can be determined from Datum, which specifies assets, timelines, owners and other rules. Contract exposes redeemers for interacting with the loan UTXO.
Factory NFT policy. Ensures validity and non-fungibility of loan/borrow UTXO at lending smart contract address. Is always validated on interaction with the loan/borrow UTXO. Corresponds to borrow/lend NFT.
Borrow NFT policy. Works in tandem with lending smart contract. Is responsible for certain loan lifecycle action validation like creating a loan (minting borrow NFT), or repaying a loan (burning borrow NFT).
Lender NFT policy. Works in tandem with lending smart contract. Is responsible for certain loan lifecycle action validation like creating a loan (minting lender NFT), canceling loan (burning lender NFT) or liquidating an active loan (burning lender NFT).
Smart contract exposes these endpoints (redeemers):
Create loan request - create new loan UTXO with loan amount and loan rules in Datum, mint Factory token, mint lender NFT and send it to the user.
Create borrow request - create new borrow UTXO with collateral amount and loan rules in Datum, mint Factory token, mint borrower NFT and send it to the user.
Cancel loan request - only if not accepted. Burn lender NFT, burn Factory NFT, send all of the funds back to the user.
Cancel borrow request - only if not accepted. Burn borrower NFT, burn Factory NFT, send all of the funds back to the user.
Accept borrow request - accept the loan terms defined in the borrow request UTXO Datum. Mint lender NFT and send it to the user. Send loan amount to smart contract UTXO. Start loan.
Accept loan request - accept the loan terms defined in the loan request UTXO Datum. Mint borrower NFT and send it to the user. Send collateral amount to smart contract UTXO. Send loan amount to the user. Start loan.
Withdraw loan - if some party accepted the borrow request, withdraw the loan amount, as collateral was already deposited when creating a borrow request.
Repay loan - at any given point in time repay a loan with interest. Send loan amount + interest to smart contract, receive collateral back. Burn Borrower NFT.
Collect loan - if loan was successfully repaid before liquidation, collect loan amount + interest and burn Lender NFT.
Liquidate loan on expiration. If the loan was not repaid in time, send collateral to the user, burn Lender NFT.
Liquidate loan on ratio threshold. Provide oracle price reference input for ratio calculation. If the ratio is below 1.05, send collateral to the user, burn Lender NFT.
Loan ownership is determined by bond NFT. Both lender and borrower, once interaction is performed with lending smart contract, receives a bond NFT. This acts as an ownership token of the loan. In case of borrower, borrower bond NFT represents his ownership of collateral and obligations to retrieve it, as well as loan amount and obligations to return it. In case of lender, lender bond NFT represents his ownership to loan amount and interest, and conditional ownership of collateral, in case loan amount is not returned and loan is liquidated.
Both borrower and lender bond NFTs can be traded/transferred, this way allowing to transfer obligations to someone else, as well as creating a secondary bond market. We plan to introduce bond farming, which will grant CERRA rewards for bond NFT staking.
We are also currently developing these additions to the P2P lending smart contract:
Fractional filling. This functionality will allow for multiple lenders/borrowers to fill one lend/borrow request. This will act as a small lending pool with fixed loan duration and interest rate. It will also allow to lend/borrow in smaller amounts and on the other side huge loans can be financed by multiple actors.
3rd party liquidations. Currently, loans can only be liquidated by lenders. This is not extremely convenient, as lenders can miss the opportunity and not react in time. Because of this, we are creating a mechanism for 3rd party to issue a transaction and liquidate any loan, this way receiving a small ADA incentive. We will also be open-sourcing liquidation bot code. Using the bot, any actor will be able to participate in the liquidations and be incentivized by rewards. This will create race conditions, to liquidate a loan first, and receive the ADA reward, so from the platform user's perspective, all of the liquidations will happen instantly.