> For the complete documentation index, see [llms.txt](https://docs.creditcoop.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.creditcoop.xyz/developers/v1-developer-material/functions-and-methods/lineofcredit.sol.md).

# LineOfCredit.sol

Core functions and methods of LineOfCredit.sol

LineOfCredit.sol is the core contract responsible for:

* Recording credit lines, positions and accounting for Borrowers and Lenders
* Defining Line of Credit terms (Oracle, Arbiter, Borrower, loan duration, interest rate, escrow and spigot collateral)
* Coordinating the Escrow, Spigot, and InterestRateCredit modules
* External calls to Oracle.sol and InterestRateCredit.sol
* Libraries - LineLib.sol, CreditLib.sol, CreditListLib.sol

<details>

<summary>External functions</summary>

```solidity
function init() external virtual returns(LineLib.STATUS)
function addCredit(uint128 drate,uint128 frate,uint256 amount,address token,address lender) external payable override nonReentrant whileActive mutualConsent(lender, borrower) returns (bytes32)
function borrow(bytes32 id, uint256 amount) external override nonReentrant whileActive onlyBorrower returns (bool)
function accrueInterest() external override returns(bool)
function counts() external view returns (uint256, uint256)
function healthcheck() external returns (LineLib.STATUS)
function increaseCredit(bytes32 id, uint256 amount) external payable override nonReentrant whileActive mutualConsentById(id)returns (bool) 
function setRates(bytes32 id,uint128 drate,uint128 frate) external override mutualConsentById(id) returns (bool)
function updateOutstandingDebt() external override returns (uint256, uint256)
function withdraw(bytes32 id, uint256 amount) external override nonReentrant returns (bool)
function depositAndRepay(uint256 amount )external payable override nonReentrant whileBorrowing returns (bool)
function declareInsolvent() external returns (bool)
function depositAndClose() external payable override nonReentrant whileBorrowing onlyBorrower returns (bool)
function close(bytes32 id) external payable override nonReentrant onlyBorrower returns (bool)
```

</details>

<details>

<summary>Methods</summary>

`function init()`: tests that any collateral facility is set up as expected, pointing to the correct address for the Line of Credit. If so, status changes to 'active'.

`function addCredit()`: a Lender deposits for the first time to an active Line of Credit

`function borrow(`): a Borrower draws down from an available credit position

`function accrueInterest()`: updates the amount of Interest Accrued that the Borrower owes

`function counts(`): returns the number of active credit positions within a Line of Credit and the number of credit positions irrespective of status

`function healthcheck()`: returns the status of the Line of Credit

`function increaseCredit()`: an existing Lender deposits additional capital

`function setRates()`: updates the Drawn Rate and the Facility Rate for a credit position

`function updateOutstandingDebt()`: returns total Borrower debt across all Lenders

`function withdraw()`: a Lender withdraws principal and accrued interest

`function depositAndRepay():` anyone can deposit funds to repay a Lender

`function declareInsolvent()`: Arbiter signifies that a Borrower is incapable of repaying debt permanently (used for secured lending)

`function depositAndClose()`: Borrower deposits enough Credit Tokens to repay and close a credit position

`function close()`: deletes a credit position that has already been fully repaid

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.creditcoop.xyz/developers/v1-developer-material/functions-and-methods/lineofcredit.sol.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
