# SommelierTurboDivEthStrategy

## Overview

The SommelierTurboDivEthStrategy contract is a specialized strategy that supplies tokens into a Sommelier Vault while managing liquidity through Balancer pools. It handles conversions between ETH and rETH using Balancer's stable pools.

## Constants

```solidity
address public constant rEth = RETH_MAINNET;                                       // Ethereum mainnet's rETH Token
address public constant balancerLpPool = 0x1E19CF2D73a72Ef1332C882F20534B6519Be0276;  // Balancer rETH-WETH pool
bytes32 public constant balancerPoolId = 0x1e19cf2d73a72ef1332c882f20534b6519be0276000200000000000000000112;  // Pool ID
IBalancerVault public constant balancerVault = IBalancerVault(BALANCER_VAULT_MAINNET);  // Balancer Vault
```

## Functions

### Constructor

```solidity
constructor() initializer
```

Empty constructor marked as initializer.

### Initialization Functions

### initialize

```solidity
function initialize(
    IMaxApyVault _vault,
    address[] calldata _keepers,
    bytes32 _strategyName,
    address _strategist,
    ICellar _cellar
) public override initializer
```

Initializes the strategy with required components.

Parameters:

* `_vault`: MaxApy vault address
* `_keepers`: Array of keeper addresses
* `_strategyName`: Name of the strategy
* `_strategist`: Strategist address
* `_cellar`: Sommelier cellar address

### Core Functions

### liquidateExact

```solidity
function liquidateExact(uint256 amountNeeded) external override checkRoles(VAULT_ROLE) returns (uint256 loss)
```

Withdraws exactly amountNeeded to vault.

Parameters:

* `amountNeeded`: Amount to withdraw

Returns:

* `loss`: Amount of realized loss

### View Functions

### previewLiquidateExact

```solidity
function previewLiquidateExact(uint256 liquidatedAmount) public view override returns (uint256 requestedAmount)
```

Calculates input needed for exact output.

Parameters:

* `liquidatedAmount`: Desired output amount

Returns:

* `requestedAmount`: Required input amount

### maxLiquidate

```solidity
function maxLiquidate() public view override returns (uint256)
```

Returns maximum withdrawable amount after losses.

Returns:

* Maximum withdrawable amount

### maxLiquidateExact

```solidity
function maxLiquidateExact() public view override returns (uint256)
```

Returns maximum withdrawable amount before losses.

Returns:

* Maximum withdrawable amount before losses

### Internal Core Functions

### \_invest

```solidity
function _invest(uint256 amount, uint256 minOutputAfterInvestment) internal override returns (uint256 depositedAmount)
```

Invests assets in Cellar Vault through Balancer.

Parameters:

* `amount`: Amount to invest
* `minOutputAfterInvestment`: Minimum expected shares

Returns:

* `depositedAmount`: Amount of tokens received

### \_divest

```solidity
function _divest(uint256 shares) internal override returns (uint256 withdrawn)
```

Withdraws assets from Cellar Vault through Balancer.

Parameters:

* `shares`: Amount of shares to withdraw

Returns:

* `withdrawn`: Amount of assets received

### \_liquidatePosition

```solidity
function _liquidatePosition(uint256 amountNeeded) internal override returns (uint256 liquidatedAmount, uint256 loss)
```

Liquidates position up to requested amount.

Parameters:

* `amountNeeded`: Amount to liquidate

Returns:

* `liquidatedAmount`: Amount actually liquidated
* `loss`: Amount of losses incurred

### Internal View Functions

### \_shareValue

```solidity
function _shareValue(uint256 shares) internal view override returns (uint256 _assets)
```

Calculates underlying value of shares.

Parameters:

* `shares`: Amount of shares

Returns:

* `_assets`: Asset value

### \_sharesForAmount

```solidity
function _sharesForAmount(uint256 amount) internal view override returns (uint256 _shares)
```

Calculates shares needed for amount.

Parameters:

* `amount`: Amount of assets

Returns:

* `_shares`: Required shares

### \_shareBalance

```solidity
function _shareBalance() internal view override returns (uint256 _balance)
```

Returns strategy's Cellar share balance.

Returns:

* Current share balance

### \_lpValue

```solidity
function _lpValue(uint256 amount) internal view returns (uint256)
```

Calculates value of LP tokens.

Parameters:

* `amount`: LP token amount

Returns:

* Underlying value

### \_lpPrice

```solidity
function _lpPrice() internal view returns (uint256)
```

Returns Balancer LP token price.

Returns:

* LP token price

### \_lpBalance

```solidity
function _lpBalance() internal view returns (uint256)
```

Returns Balancer LP token balance.

Returns:

* LP token balance

### \_estimatedTotalAssets

```solidity
function _estimatedTotalAssets() internal view virtual override returns (uint256)
```

Calculates total assets under management.

Returns:

* Total assets value

### \_getAssets

```solidity
function _getAssets() internal view returns (IAsset[] memory)
```

Returns ordered array of pool assets.

Returns:

* Array of pool assets

### Internal Helper Functions

### \_joinPool

```solidity
function _joinPool(uint256 _wethIn) internal returns (uint256)
```

Adds single-sided liquidity to Balancer pool.

Parameters:

* `_wethIn`: Amount of WETH to add

Returns:

* Amount of LP tokens minted

### \_exitPool

```solidity
function _exitPool(uint256 _lpTokens) internal returns (uint256)
```

Removes liquidity from Balancer pool.

Parameters:

* `_lpTokens`: Amount of LP tokens to remove

Returns:

* Amount of WETH received


---

# 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://devs.maxapy.io/maxapy-erc4626/strategies/ethereum-weth/sommelier/sommelierturbodivethstrategy.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.
