# LLAMMA and Controller

> import DocCard, { DocCardGrid } from '@site/src/components/DocCard'

# LLAMMA and Controller

:::vyper[`AMM.vy` & `Controller.vy`]

The source code for both contracts, `AMM.vy` and `Controller.vy`, can be found on [GitHub](https://github.com/curvefi/curve-stablecoin/tree/lending/contracts). The contracts are written using [Vyper](https://github.com/vyperlang/vyper) version `0.3.10`.

:::

Llamalend uses **Controller V3** — the same blueprint that powers the latest crvUSD mint markets (weETH, cbBTC, LBTC). The Controller and AMM contracts originated in the crvUSD system and were extended for lending use. For a full version history including the evolution from crvUSD V1 through V3, see the [crvUSD Overview](../../crvusd/overview.md#controller--amm-versions).

Because Curve Lending operates very similarly to the system for minting crvUSD, both `Controller.vy` and `AMM.vy` can be used for lending markets. To ensure full compatibility with both systems, **several modifications were made in V3**:

<DocCardGrid>
  <DocCard title="AMM.vy (LLAMMA)" icon="vyper" link="../../crvusd/amm" linkText="Full LLAMMA Documentation">

The core contract `AMM.vy` (LLAMMA) **remains exactly the same** as in the crvUSD system. No changes were needed for lending.

  </DocCard>
  <DocCard title="Controller.vy" icon="vyper" link="../../crvusd/controller" linkText="Full Controller Documentation">

The Controller has been modified for lending with changes to **token decimal handling**, **fee collection**, and **ETH transfer behavior**.

  </DocCard>
</DocCardGrid>

---

## Changes to Controller.vy

The changes made to the codebase of the Controller contract are mainly under-the-hood changes, which do not significantly affect how users interact with the contract. External functions like `create_loan`, `repay`, etc., work the same way as before.

*The following changes have been made:*

- The Controller now has the **ability to handle not only 18-digit tokens** (like crvUSD) but also **tokens with any number of digits**. For this, there were multiple changes to **ensure rounding always rounds up in favor of the existing borrowers**.

- The **`collect_fees()` method will not work in lending**. Admin fees are set to zero, and all the interest will go to the vault depositors. Moreover, AMM admin fees cannot be charged: their claim would fail too. The system is designed to make money on fees generated by crvUSD itself.

- The contract that creates the Controller has `collateral_token()` and `borrowed_token()` public methods instead of a `stablecoin()` method. This keeps the code clean and understandable when a stablecoin is collateral, not the borrowed asset. However, compatibility with the `stablecoin()` method is preserved.

- **Transfers of native ETH are removed for safety**. To enhance safety with unknown variables, automatic wrapping of ETH is disabled permanently.
