> 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/spigotedline.sol.md).

# SpigotedLine.sol

Core functions and methods of SpigotedLine.sol

* An integration between [Spigot.sol](/developers/v1-developer-material/functions-and-methods/spigot.sol.md) and [LineOfCredit.sol](/developers/v1-developer-material/functions-and-methods/lineofcredit.sol.md).
* It owns the Spigot so it's important that it can properly manage and call Spigot.sol and doesn't lose ownership unless `releaseSpigot()` successfully executes.
* Manages a Spigot's configuration based on the health status of a Line of Credit
* Trades Revenue Tokens for Credit Tokens owed to lenders using 0x protocol
* Stores excess revenue or trade slippage in `unused` tokens for later use in repayment
* Allows Borrowers to clawback escrowed tokens if a Line is fully repaid
* Allows liquidating `unused` or the Spigot itself if a Line's status is LIQUIDATABLE
* External calls to - 0x protocol,[ Spigot.sol](/developers/v1-developer-material/functions-and-methods/spigot.sol.md)
* Libraries -[ LineLib.sol](https://github.com/BobZedF/Gitbooktest/blob/main/developers/functions-and-methods/broken-reference/README.md), SpigotedLineLib.sol

<details>

<summary>External Functions</summary>

```solidity
function claimAndRepay(address claimToken, bytes calldata zeroExTradeData)external whileBorrowing nonReentrant returns (uint256)function claimAndTrade(address claimToken, bytes calldata zeroExTradeData)external whileBorrowing nonReentrant returns (uint256)
function unused(address token) external view returns (uint256)
function useAndRepay(uint256 amount) external whileBorrowing returns(bool)
function updateWhitelist(bytes4 func, bool allowed)external returns (bool)
function releaseSpigot(address to) external returns (bool)
function sweep(address to, address token) external nonReentrant returns (uint256)
```

</details>

#### SpigotedLine Methods

Many of the features of the Spigoted Line of Credit product depend on and call Spigot.sol. Read this in conjunction with methods for that contract, the Glossary and further product information herein.

| Function            | SpigotedLine Method                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `claimAndRepay()`   | <p>Claims Revenue Tokens from the Spigot, trades them for Credit Tokens via a Dex and makes the Credit Tokens available to Lender withdraw.<br></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `claimAndTrade()`   | <p>Claims Revenue Tokens from the Spigot and trades them for Credit Tokens via a Dex.<br><br>The newly exchanged Credit Tokens are held in 'unusedTokens' ready for a Lender to using useAndRepay() and withdraw().<br><br>This feature allows a Borrower to take advantage of an increase in the relative value of the Revenue Token compared to the Credit Token and to in effect use less Revenue Tokens to repay the same amount of debt.<br></p><p>The system ensures that the first Credit Token in the repayment queue is the one being bought.<br><br>A Line can have multiple Credit Tokens being lent out/borrowed and multiple Revenue Tokens being escrowed to repay the debt.<br></p> |
| `unused()`          | <p>Returns the amount of Credit Tokens that have been bought with Revenue Tokens from the Spigot and which haven't yet been withdrawn by a Lender or otherwise used by the Borrower to repay.<br></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `useAndRepay()`     | <p>Allows a Lender or a Borrower to use Credit Tokens (that have already been claimed/traded) from 'unusedTokens' in order to repay debt.<br></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `updateWhitelist()` | <p>Sets or updates the whitelisted functions that a Borrower \[as Operator] is allowed to perform on its Revenue Contracts so that it can still use those contracts whilst providing Revenue Tokens to repay credit. Only callable by an Arbiter.<br></p>                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `releaseSpigot()`   | <p>Transfers ownership of the entire Spigot from the Line of Credit to either the Borrower (if a Line of Credit has been been fully repaid) or to the Arbiter (if the Line of Credit is liquidatable).<br></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `sweep()`           | <p>After a loan has been repaid, sends any remaining Revenue Tokens or Credit Tokens to the Borrower.<br><br>In case of a Borrower default however (loan status = liquidatable), this function serves as a liquidation mechanism that is called in an effort to increase the Lenders' recovery rate and reduce the "loss given default (LGD)"</p><p><br></p>                                                                                                                                                                                                                                                                                                                                       |

\`\`


---

# 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/spigotedline.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.
