# EtherFiLibrary

[Git Source](https://github.com/Ion-Protocol/ion-protocol/blob/88cc595825f1dc2eb738fb93e172a3e8ab7a5c43/src/libraries/lrt/EtherFiLibrary.sol)

A helper library for EtherFi-related conversions.

### [Functions](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#functions" id="functions"></a>

#### [getEthAmountInForLstAmountOut](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#getethamountinforlstamountout" id="getethamountinforlstamountout"></a>

Returns the amount of ETH required to obtain a given amount of weETH.

*Performing the calculations seems to potentially yield a rounding error of 1-2 wei. In order to ensure that the correct value is returned, both versions are tested and the correct one is returned. Should a correct version ever not be found, any contracts using the library should halt execution.*

```
function getEthAmountInForLstAmountOut(IWeEth weEth, uint256 lrtAmount) internal view returns (uint256);
```

**Parameters**

| Name        | Type      | Description                     |
| ----------- | --------- | ------------------------------- |
| `weEth`     | `IWeEth`  | contract.                       |
| `lrtAmount` | `uint256` | Desired amount of weETH. \[WAD] |

**Returns**

| Name     | Type      | Description                                                        |
| -------- | --------- | ------------------------------------------------------------------ |
| `<none>` | `uint256` | Amount of ETH required to obtain the given amount of weETH. \[WAD] |

#### [getLstAmountOutForEthAmountIn](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#getlstamountoutforethamountin" id="getlstamountoutforethamountin"></a>

Returns the amount of weETH that will be obtained from a given amount of ETH.

```
function getLstAmountOutForEthAmountIn(IWeEth weEth, uint256 ethAmount) internal view returns (uint256);
```

**Parameters**

| Name        | Type      | Description                      |
| ----------- | --------- | -------------------------------- |
| `weEth`     | `IWeEth`  | contract.                        |
| `ethAmount` | `uint256` | Amount of ETH to deposit. \[WAD] |

**Returns**

| Name     | Type      | Description                                   |
| -------- | --------- | --------------------------------------------- |
| `<none>` | `uint256` | Amount of weETH that will be obtained. \[WAD] |

#### [\_getLstAmountOutForEthAmountIn](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#getlstamountoutforethamountin" id="getlstamountoutforethamountin"></a>

An internal helper function to calculate the amount of weETH that will be obtained from a given amount of ETH.

*This is useful if the function arguments are already known so that additional external calls can be avoided.*

```
function _getLstAmountOutForEthAmountIn(
    uint256 totalPooledEther,
    uint256 totalShares,
    uint256 ethAmount
)
    internal
    pure
    returns (uint256);
```

**Parameters**

| Name               | Type      | Description                                     |
| ------------------ | --------- | ----------------------------------------------- |
| `totalPooledEther` | `uint256` | Total pooled ether in the Ether Fi pool. \[WAD] |
| `totalShares`      | `uint256` | Total amount of minted shares. \[WAD]           |
| `ethAmount`        | `uint256` | Amount of ETH to deposit. \[WAD]                |

**Returns**

| Name     | Type      | Description                                   |
| -------- | --------- | --------------------------------------------- |
| `<none>` | `uint256` | Amount of weETH that will be obtained. \[WAD] |

#### [depositForLrt](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#depositforlrt" id="depositforlrt"></a>

Deposits a given amount of ETH into the Ether Fi pool and then uses the received eETH to mint weETH.

```
function depositForLrt(IWeEth weEth, uint256 ethAmount) internal returns (uint256);
```

**Parameters**

| Name        | Type      | Description                      |
| ----------- | --------- | -------------------------------- |
| `weEth`     | `IWeEth`  | contract.                        |
| `ethAmount` | `uint256` | Amount of ETH to deposit. \[WAD] |

**Returns**

| Name     | Type      | Description                               |
| -------- | --------- | ----------------------------------------- |
| `<none>` | `uint256` | Amount of weETH that was obtained. \[WAD] |

#### [\_sharesForAmount](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#sharesforamount" id="sharesforamount"></a>

An internal helper function to calculate the amount of shares from amount.

*Useful for avoiding external calls when the function arguments are already known.*

```
function _sharesForAmount(
    uint256 totalPooledEther,
    uint256 totalShares,
    uint256 _depositAmount
)
    internal
    pure
    returns (uint256);
```

**Parameters**

| Name               | Type      | Description                                     |
| ------------------ | --------- | ----------------------------------------------- |
| `totalPooledEther` | `uint256` | Total pooled ether in the Ether Fi pool. \[WAD] |
| `totalShares`      | `uint256` | Total amount of minted shares. \[WAD]           |
| `_depositAmount`   | `uint256` | Amount of ETH. \[WAD]                           |

#### [\_amountForShares](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#amountforshares" id="amountforshares"></a>

An internal helper function to calculate the amount from given amount of shares.

*Useful for avoiding external calls when the function arguments are already known.*

```
function _amountForShares(
    uint256 totalPooledEther,
    uint256 totalShares,
    uint256 _shares
)
    internal
    pure
    returns (uint256);
```

**Parameters**

| Name               | Type      | Description                                     |
| ------------------ | --------- | ----------------------------------------------- |
| `totalPooledEther` | `uint256` | Total pooled ether in the Ether Fi pool. \[WAD] |
| `totalShares`      | `uint256` | Total amount of minted shares. \[WAD]           |
| `_shares`          | `uint256` | Amount of shares. \[WAD]                        |

### [Errors](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#errors" id="errors"></a>

#### [NoAmountInFound](https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/broken-reference) <a href="#noamountinfound" id="noamountinfound"></a>

```
error NoAmountInFound();
```


---

# Agent Instructions: 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:

```
GET https://docs.ionprotocol.io/devs/smart-contract-architecture/libraries/lrt/etherfilibrary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
