Transaction Flows
Lenders and Borrowers interacting with MethLab smart contracts.
Vault creation
Lender calls the deployVault
function available in the Factory.sol. Factory internally creates the Lender Vault contract i.e LenderVault.sol and initializes it. Factory also registers the newly created vault in the Registry.sol contract for future references.
Intent creation & Token Transfer
To create an Intent Collection, Lender writes an IntentCollection and calls the createIntentCollection
function on the LenderVault.sol. Once the collection is created, the Lender can transfer the borrow asset to the Vault.sol contract.
Loan Creation
Firstly, the Borrower approves the Vault to use the collateral token. After the approval, the Borrower calls the createLoan
function on the LenderVault.sol. This is followed by Vault transferring the borrow token to the borrower. The Vault now calls the deployLoan
function on the Factory.sol to create a new loan. The Factory contract creates a new loan and initializes it. It also registers the loan with the Registry.sol. Finally, the Vault calls the safeTransfer to transfer collateral from Borrower to the newly created Loan.sol contract.
Repay
To repay the borrow token, the Borrower approves the Loan.sol to use the borrow token. Followed by Borrower calling the repay
function on the Loan.sol. The Loan contract then transfers the collateral token back to the Borrower. At last, the Loan contract calls the safeTransferFrom
to transfer the borrowed assets back to the Vault.
Liquidation
If the Borrower doesn't repay the loan amount, the Lender can liquidate the collateral. The Lender calls the seizeCollateral
function on the Loan.sol. The Loan contract transfers the collateral from the Loan to the LenderVault.sol. The Lender may now withdraw the collateral from the Vault.