# Introduction

The <mark style="color:red;">**`PeerProtocol`**</mark> contract is a smart contract that allows borrowers to request loans from the contract and allows the contract owner to approve or reject these loan requests. It also allows borrowers to make payments towards their outstanding loan balances and allows the contract owner to update the default status of a borrower if they fail to make timely payments.

This contract was built using the Solidity programming language and is designed to be deployed on the Ethereum blockchain. It makes use of several common Ethereum patterns and features, such as function modifiers, require statements, and mappings, in order to implement its functionality.

Overall, the purpose of this contract is to provide a decentralized, transparent, and secure way for borrowers and lenders to interact and manage loans using stablecoins. It allows borrowers to access loans quickly and easily and allows lenders to manage their lending portfolio and assess the creditworthiness of potential borrowers.

I hope this introduction is helpful and gives you a better understanding of the <mark style="color:red;">**`PeerProtocol`**</mark> contract. Let me know if you have any further questions.

The contract has a number of variables that store information about the loans and borrowers, including the outstanding loan balances, default status, and various loan terms such as the lending rate, interest rate, and loan period. It also has several functions for interacting with the contract, such as:

## <mark style="color:red;">**`constructor`**</mark>

```solidity
constructor() public {
    owner = msg.sender;
}
```

This is the constructor function for the contract, which is called when the contract is deployed to the Ethereum network. It initializes the contract and sets the **`owner`** variable to the address of the contract deployer.

## <mark style="color:red;">**`approveLending`**</mark>

```solidity
function approveLending(address borrower, uint amount) public onlyOwner {
    require(amount > 0, "Must approve a positive amount of stable coins for lending");
    require(loanAmount >= amount, "Not enough stable coins available for lending");
    balances[borrower] += amount;
    loanAmount -= amount;
}
```

This function allows the contract owner to approve a request for a loan. It takes an **`address`** parameter representing the borrower, and a **`uint`** parameter representing the amount of stable coins to be lent. It updates the **`balances`** mapping to reflect the new loan, and reduces the **`loanAmount`** variable by the amount of the loan.

## <mark style="color:red;">**`repayEarly`**</mark>

```solidity
function repayEarly(address borrower) public {
    require(balances[borrower] > 0, "No outstanding balance to repay");
    uint balance = balances[borrower];
    uint interest = balance.mul(interestRate / 100);
    uint totalDue = balance.add(interest);
    totalDue = totalDue.mul((100 - earlyRepaymentDiscount) / 100);
    balances[borrower] = 0;
    loanAmount += totalDue;
}
```

This function first checks that the borrower has an outstanding **`balance`** to repay, and then calculates the<mark style="color:red;">`totalDue`</mark> by adding the <mark style="color:red;">**`interest`**</mark> to the <mark style="color:red;">**`balance`**</mark>. It then applies the <mark style="color:red;">**`earlyRepaymentDiscount`**</mark> , if applicable, by multiplying the <mark style="color:red;">**`totalDue`**</mark> by a percentage that is equal to 100 minus the <mark style="color:red;">**`earlyRepaymentDiscount`**</mark>. Finally, it sets the borrower's balance to 0 and adds the <mark style="color:red;">**`totalDue`**</mark> to the <mark style="color:red;">**`loanAmount`**</mark>.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.peerhive.app/tech-stack-and-smart-contract/introduction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
