---
# System prepended metadata

title: p2p-lending

---

# p2p-lending

DNAs:

- Holofuel (in the future maybe other MutualCredit transactors?)
- p2p-lending

## User Stories

Lender: el que hace el prestamo
Borrower: el que recibe el prestamo

- Any lender should be able to create a loan offer
- A lender should be able to cancel their own loan offers
- Any borrower should be able to browse loan offers
- Any borrower should be able to request the lender to accept a loan offer
- A lender should be able to accept a loan offer request and execute the loan
- When the loan is executed:
  - A first transfer (or multiple transfers) of holofuel is made from the lender to the borrower
  - From that point on, every X days, a transfer back is going to be made, of the amount specified in the Repayment.
  - When the debt is repaid fully (taking into account the interest rate), no other transfers are to be made
- The borrower should not be able to borrow any more money until his debts are up to date (?????)

## Structs

```rust
struct Loan {
  loan_offer_address: Address,
  accept_loan_request: Address,
  accept_loan_request_signature: Signature, // This is the signature of the borrower when he made the accept loan request
  timestamp: u64,
  lender: Address,
  borrower: Address,
  amount: u64,
  interest_rate: u64,
  repayment: Repayment,
  holofuel_transactions_addresses: Vec<Address>,
  default_guarantee: Option<Address>
}

struct LoanRepayment {
  loan_address: Address,
  holofuel_transactions_addresses: Vec<Address>,
  repayment_complete: bool
}

struct LoanOffer {
  lender: Address,
  amount: u64,
  interest_rate: u64,
  repayment_method: RepaymentMethod
}

struct AcceptLoanRequest {
  loan_offer_address: Address,
  borrower_address: Address,
  holofuel_requests_addresses: Vec<Address>
}

struct RepaymentMethod {
  days_interval: u64,
  amount: u64
}
```

- Loan is valid only if both from and to addresses signed it


## Sequence diagrams

- Alice creates loan offer
```mermaid
sequenceDiagram

participant AliceUI
participant AliceLending
AliceUI->>AliceLending: create_loan_offer(amount, interest_rate, repayment)
```

- Bob requests loan offer and makes holofuel request

```mermaid
sequenceDiagram

participant BobUI
participant BobLending
participant BobHolofuel
participant AliceLending

BobUI->>BobLending: request_loan(loan_offer_address)
loop For every chunked of transaction
  BobLending->>BobHolofuel: request(alice_address)
  BobHolofuel-->>BobLending: request_address
end
BobLending->>BobLending: create_accept_loan_request(holofuel_requests_addresses)
BobLending->>AliceLending: notify(accept_loan_request_address)
```

- Alice executes the loan

```mermaid
sequenceDiagram

participant AliceUI
participant AliceLending
participant AliceHolofuel
participant BobLending

AliceUI->>AliceLending: execute_loan(accept_loan_request_address)
loop For every request
  AliceLending->>AliceHolofuel: execute(request_address)
  AliceHolofuel-->>AliceLending: transaction_address
end
AliceLending->>AliceLending: create_loan(transactions_addresses)
AliceLending->>BobLending: notify(loan_address)
```
