# Lines of Credit technical details

**`AutomatedLineOfCredit`** is a contract that serves as a lending pool of funds managed by the borrower, who is the sole party who can borrow the funds. The borrower can: borrow funds, repay funds, set `AutomatedLineOfCredit` max size, add/remove deposit strategies, add/remove withdraw strategies, and change the transfer strategy. The borrower can also upgrade the AutomatedLineOfCredit implementation.&#x20;

`AutomatedLineOfCredit` satisfies [ERC-4626](https://ethereum.org/en/developers/docs/standards/tokens/erc-4626/) requirements, meaning it meets all features described [here](https://eips.ethereum.org/EIPS/eip-4626).&#x20;

An audit of `AutomatedLineOfCredit` and `AutomatedLineOfCreditFactory` by g0 Group can be found here: <https://github.com/g0-group/Audits/blob/master/TrueFiDec2022.pdf>

Details on Automated Line of Credit and related contracts can be found in Github below:&#x20;

{% embed url="<https://github.com/TrueFi-Protocol/contracts-beryllium>" %}

## Deployed Contracts

<table data-full-width="false"><thead><tr><th width="377">Contract name</th><th width="164">Network</th><th>Address</th></tr></thead><tbody><tr><td><code>beryllium_automatedLineOfCredit</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0x8626a4234721A605Fc84Bb49d55194869Ae95D98">0x8626a4234721A605Fc84Bb49d55194869Ae95D98</a></td></tr><tr><td><code>beryllium_automatedLineOfCreditFactory</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0x24d00e171Da01124052a4B13931631Ba7482cBB5">0x24d00e171Da01124052a4B13931631Ba7482cBB5</a></td></tr><tr><td><code>beryllium_automatedLineOfCreditFactory_proxy</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0xCA1353dAB799d87D70E3750c2280205A5c8f62e9">0xCA1353dAB799d87D70E3750c2280205A5c8f62e9</a></td></tr><tr><td><code>beryllium_protocolConfig</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0xBC70FE8653D972936507F7306996d8F8E6823482">0xBC70FE8653D972936507F7306996d8F8E6823482</a></td></tr><tr><td><code>beryllium_protocolConfig_proxy</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0x5c67531524201D0a774405827BA4c2DE15781dD0">0x5c67531524201D0a774405827BA4c2DE15781dD0</a></td></tr><tr><td><code>beryllium_depositController</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0xB4C8bfd082a47c008Ce95DD13314105F6C0fe372">0xB4C8bfd082a47c008Ce95DD13314105F6C0fe372</a></td></tr><tr><td><code>beryllium_allowAllLenderVerifier</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0x607CEDb42442E206FAe3E2Cc12AFddD7e12Fdd4F">0x607CEDb42442E206FAe3E2Cc12AFddD7e12Fdd4F</a></td></tr><tr><td><code>beryllium_withdrawController</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0xEe3f9Add26de00FCC02d4BC0E6d0DBEe0e3C25E6">0xEe3f9Add26de00FCC02d4BC0E6d0DBEe0e3C25E6</a></td></tr><tr><td><code>beryllium_openTransferController</code></td><td>Arbitrum One</td><td><a href="https://arbiscan.io/address/0xa1259068Ea5252a307ced730d758c2E8D7ae177f">0xa1259068Ea5252a307ced730d758c2E8D7ae177f</a></td></tr></tbody></table>

## Notes

### AutomatedLineOfCreditFactory

`AutomatedLineOfCreditFactory` serves for deploying new AutomatedLinesOfCredit. All of the `AutomatedLineOfCredit` parameters are chosen by the borrower, except for `ProtocolConfig`.

### Interest rate calculations

When a borrower repays a given amount of borrowed funds, they owe interest. This interest is added to their balance of the outstanding debt. The amount of interest they owe is based on the utilization rate of the funds in the `AutomatedLineOfCredit` at the time they repay a given amount of debt. The interest rate that the Borrower pays on their funds is a function of the utilization of the `AutomatedLineOfCredit`. This function is parameterized by six values which are determined by the borrower when the `AutomatedLineOfCredit` is created:

* A (1) minimum interest rate utilization threshold up to which point the interest rate is equal to the (2) minimum interest rate,
* An (3) optimum utilization rate and (4) optimum interest rate. The interest rate is determined by linearly interpolating between the minimum interest rate and the optimum interest rate when the utilization rate is between the minimum interest rate utilization threshold and the optimum utilization rate,
* A (5) maximum interest rate utilization threshold beyond which the interest rate is equal to the (6) maximum interest rate. The interest rate is determined by linearly interpolating between the optimum interest rate and the maximum interest rate when the utilization rate is between the optimum utilization rate and the maximum interest rate utilization threshold.

The `utilization` of an AutomatedLineOfCredit is equal to:

`(borrowed_funds + unpaid_interest) / value`&#x20;

The `value` of an AutomatedLineOfCredit is equal to:

`liquid_funds_in_ALOC + borrowed_funds + unpaid_interest - unclaimed_fees`

When the *Borrower* borrows from the `AutomatedLineOfCredit`, `utilization` increases. When a Lender deposits into the `AutomatedLineOfCredit`, `utilization` decreases. When a Lender withdraws from the `AutomatedLineOfCredit`, `utilization` increases.&#x20;

### Fees

Whenever an action that changes `AutomatedLineOfCredit` value is performed (`borrow`/`repay`/`deposit`/`mint`/`withdraw`/`redeem`/`updateAndPayFee`), a fee for the TrueFi DAO is calculated and immediately transferred to the TrueFi DAO Treasury address. The fee is deducted from the `AutomatedLineOfCredit` value, so actions like `borrow`/`withdraw`/`redeem` cannot move the funds that are designated as fees. If the accrued fee cannot be repaid at the moment because of the lack of liquidity, additional information about the fee amount is stored in the contract and will be used to make the overdue payment the moment it will be possible.

The `accruedFee` value is equal to:&#x20;

`(current_timestamp - last_update_timestamp) / YEAR * protocol_fee_rate * portfolio_value`&#x20;

\*\*`portfolio_value` does not take into account the interest that has been accrued since the last update.

`protocol_fee_rate` is the rate taken from the `ProtocolConfig` contract the last time an update was made. This means that if the DAO decides to increase the fees, the higher rate will be applied for `accruedFee` calculation since the next update, not the current one.&#x20;

### Deposit / Withdrawal Strategies

Functions enabling Lenders to deposit/withdraw funds to/from the contract can additionally be limited by Deposit/Withdraw Strategy. These strategies (if set), are called with a hook every time a specific action is performed on the contract. The same calldata as for the initial call is passed to them and then the strategy independently decides if this action can or cannot be performed. The strategies might also write some state to themselves on such hooks, but this is not a mandatory behavior.
