Borrowing and Lending - AtomicLoans/atomicloans-rfc GitHub Wiki

Borrowing and Lending is done on Atomic Loans using the Funds.sol, Loans.sol and Sales.sol contracts.

  1. Bob starts lending by creating a Loan Fund and depositing stablecoins tokens
  2. Alice requests a loan by providing proof of funds to the agent of Bob, as well as their secret hashes and Bitcoin public key
  3. Bob's agent requests a loan on behalf of the borrower by calling Funds.request. This moves the stablecoin tokens to the Loans contract, and creates a new Loan.
  4. Alice locks her Bitcoin into the Bitcoin Collateral script
  5. Once the Bitcoin transaction has at least 1 confirmation, Bob calls Loan.approve to approve the locking of the collateral
  6. Alice calls Loans.withdraw and reveals Secret A to receive stablecoin tokens.
  7. Alice maintains her collateralization ratio for the duration of the loan, ensuring that the loan doesn't get liquidated by calling Loans.repay for partial repayments when necessary
  8. Before the end of the loan period, Alice calls Loans.repay to repay the entire principal + interest owed in the loan.
  9. Bob accepts the repayment by calling Loans.accept and revealing Secret B

If Bob fails to approve locking of the collateral

  1. Bob or Carol can cancel the loan by calling Loans.cancel which will reveal Secret B or Secret C necessary for unlocking the collateral

If Bob or Carol fails to accept the repayment of the loan

  1. Alice can call Loans.refund to refund the repaid loan amount. Liquidation cannot occur, so instead Alice will simply receive the refundable collateral.

If Alice fails to maintain the minimum collateralization ratio

  1. Dave can call Loans.liquidate to start the Liquidation process