> For the complete documentation index, see [llms.txt](https://lucia-protocol.gitbook.io/lucia-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lucia-protocol.gitbook.io/lucia-protocol/barns-and-sheds.md).

# Barns and Sheds

Within the LUCIA Protocol, "Barns" serve as the umbrella structure housing an array of collateralized assets, commonly known as "Sheds." Each Shed acts as an individual vault where users can manage their loans and collateral assets. These Sheds are further grouped into different Barns based on the type of collateral, thus minimizing risk by segregating asset classes. In essence, Sheds parallel the concept of Collateralized Debt Positions (CDPs) in traditional DeFi frameworks.

**Balances in the Shed**

Each Shed encapsulates two primary balances:

1. The collateral asset (denoted as *C*, e.g., USDT)
2. The debt balance (denoted as *D*, typically denominated in our native stablecoin, LUCI)

We can define the Collateral-to-Debt ratio (CDR) as:

<figure><img src="/files/eAlD0fTtn4kuuOsStG2k" alt=""><figcaption></figcaption></figure>

**Managing Balances**

Users have the ability to actively manage their Sheds by altering these balances. They can deposit or withdraw collateral, as well as repay portions of their debt. Let's denote:

* 𝛥C as the change in collateral
* 𝛥D as the change in debt

The new CDR after any changes is calculated as:&#x20;

<figure><img src="/files/V5GiYZuBI4ch31Q3Rh2a" alt=""><figcaption></figcaption></figure>

**Closing Sheds**

Users can also opt to liquidate their Sheds, which are essentially their Collateralized Debt Positions (CDPs). When a user decides to liquidate a Shed, the necessary step involves completely repaying their associated LUCI token debt — designated as (*D*).  By repaying the LUCI debt in its entirety and thereby reducing *D* to zero, the CDR essentially becomes undefined—formally represented as:

<figure><img src="/files/grSkDpLMWFgSgRiMyP4B" alt=""><figcaption></figcaption></figure>

The act of making *D* zero doesn't just render CDR mathematically indeterminate, but also triggers an automatic release of the user's initially staked collateral. This collateral, previously locked to secure the borrowed amount, is fully returned to the user, effectively 'zeroing out' their financial obligations within that particular Shed. The modular and compartmentalized architecture of Barns and Sheds within the LUCIA Protocol offers both flexibility and risk minimization. By providing detailed insights into each Shed's *CDR*, users are empowered to make informed decisions about their loans and collateral, thereby enriching the overall lending and borrowing experience.


---

# 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://lucia-protocol.gitbook.io/lucia-protocol/barns-and-sheds.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.
