Blitz Match (P2P) Borrowing & Lending
MYSO's v2 Peer-to-Peer system is a decentralized lending platform that enables lenders to offer loans to borrowers on a peer-to-peer basis. It is built on the Ethereum blockchain and consists of several smart contracts that work together to facilitate the lending process. The core components of the system are the Address Registry, Borrower Gateway, Lender Vault Factory, Lender Vault Implementation, and Quote Handler contracts.

Core Contract Overview
Address Registry: The Address Registry contract serves as a central registry for storing addresses of various system components and their associated metadata. It provides functions to register and retrieve addresses for different entities, such as the borrower gateway, lender vaults, and whitelisted compartments. The Address Registry ensures that all contracts within the lending system can easily discover and interact with one another.
Lender Vault Factory: The Lender Vault Factory contract is responsible for creating and deploying individual Lender Vault instances. Lender Vaults are used to store and manage funds provided by lenders. The Lender Vault Factory ensures that each Lender Vault is uniquely identified and associated with the respective lender. It also provides functions to create and retrieve Lender Vaults based on specific requirements and parameters.
Lender Vault: The Lender Vault Implementation contract implements the logic and functionality for managing funds in a Lender Vault. It handles operations such as accepting deposits from lenders, lending funds to borrowers, unlocking collateral, and processing repayments. The Lender Vault also comes with severall access management features, allowing vault owners to transfer the vault's ownership if needed as well as allowing them to add 3rd party signers to a vault to delegate the process of creating, managing and updating loan quotes.
Quote Handler: The Quote Handler contract facilitates the management and validation of on-chain and off-chain quotes used in the lending system. It allows lenders to add, update, delete, and validate loan quotes. The Quote Handler verifies the correctness, authenticity, and integrity of quotes that are submitted to the system by lenders and consumed by borrowers. It ensures that only quotes that belong to registered lender vaults can be consumed and that they comply with token whitelisting rules, signature requirements etc.
Borrower Gateway: The Borrower Gateway contract acts as the primary entry point for borrowers to interact with the peer-to-peer lending system. It provides functions for borrowers to consume available on-chain and off-chain loan quotes, and routes a borrower's loan request to a given target lender vault. The Borrower Gateway validates and processes loan requests, ensuring that they meet the system's requirements and are valid.
Peripheral Contracts
In addition to the core contracts, the MYSO v2 peer-to-peer lending system involves peripheral contracts that enhance its functionality and connectivity. These contracts include Compartment Contracts, Oracles, and Callbacks. Note that all these contracts are optional and not necessarily needed to interact with the system.
Compartment Contracts: Compartment contracts provide a dedicated space for borrowers to store collateral during the loan duration. They allow segregated safekeeping of collateral assets and enable seamless accounting of collateral management (e.g., in case of rebasing tokens). The borrower's collateral is locked within a compartment contract until the loan is fully repaid or the collateral is otherwise released to the given lender. These contracts are created and managed by the Lender Vault Implementation contract, ensuring a secure and transparent lending process.
Callbacks: Callback contracts are mechanisms utilized by the lending system to enable communication and interaction with external contracts or systems. For example, when a loan repayment is made, a callback function may be invoked to notify an external accounting system or update a credit score. Callbacks enhance the system's interoperability, allowing it to integrate with external systems and leverage their functionalities to enhance the overall lending process.
Oracles: Optionally, lenders can use oracles to offer loans at constant LTVs without having to actively update loan quotes as collateral prices change. The Quote Handler contract interacts with oracles to validate and calculate loan quotes, ensuring accurate and reliable lending terms.
Main User Flows
Lenders
Lender Registration: Lenders begin by interacting with the Lender Vault Factory contract. They create their own Lender Vault instance within the lending system by deploying a new Lender Vault contract.
Funds Deposit: Once the Lender Vault is created, lenders can deposit funds into it. They transfer their desired amount of funds to the Lender Vault, by virtue of a standard ERC20 transfer (no prior approval needed).
Quote Submission: Lenders can then proceed to provide quotes for potential borrowers. They interact with the Quote Handler contract to add on-chain and/or off-chain quotes. On-chain quotes are registered directly on the blockchain, while off-chain quotes may involve external data or off-chain calculations.
Quote Validation: The Quote Handler validates the authenticity and integrity of the quotes provided by lenders. It ensures that the quotes comply with the system's rules, whitelisting requirements, and validation checks. This step verifies the accuracy and reliability of the quotes.
Withdraw Funds: Lenders can at any time withdraw all of their "freely available" funds from the vault. By "freely available" funds we refer to all the vault's token balances that aren't earmarked as locked collateral from borrowers. Note that whenever a borrower consumes a lender's loan offer then their given vault's loan token balance decreases (i.e., by the given loan amount) and their vault's collateral token balance increases accordingly (i.e., by the given collateral pledge amount). Conversely, if a borrower repays then the vault's loan token will increase again (i.e., by the principal and given interest amount) and the vault's collateral token decrease (i.e., the borrower reclaims their collateral from the vault). If a borrower doesn't repay in time lenders can proceed to "unlock" the corresponding and previously earmarked collateral and then withdraw it to their wallet.
Borrowers
Loan Selection: Borrowers access the Borrower Gateway, which serves as the main "point of contact" for borrowers within the lending system. They can freely browse and select from all available loan options.
Quote Consumption: Once a suitable quote is selected, borrowers provide the chosen quote to the Borrower Gateway for further processing. The Borrower Gateway acts as an intermediary, facilitating the consumption of the selected quote.
Loan Approval: The lending system processes the loan request based on the provided quote, collateral, and borrower's information. If the loan request meets the required criteria, the loan is approved, and the necessary funds are transferred to the borrower.
Loan Repayment: Borrowers are responsible for repaying their loans according to the agreed-upon terms. They have the right -but not the obligation- to repay their loan (Zero-Liquidation Loan). Borrowers submit repayment requests through the Borrower Gateway, where they then get routed to the given Lender Vault Implementation contract, ensuring accurate tracking and management of repayments.
Last updated