# ConvexdETHFrxETHStrategy

## Overview

The ConvexdETHFrxETHStrategy contract is a specialized strategy that supplies ETH into the dETH-frxETH pool in Curve, then stakes the curve LP tokens in Convex to maximize yield. It handles the complex interactions between Curve pools and Convex staking.

## Constants

```solidity
address public constant crv = CRV_MAINNET;             // Ethereum mainnet's CRV Token
address public constant cvx = CVX_MAINNET;             // Ethereum mainnet's CVX Token
address public constant frxETH = FRXETH_MAINNET;       // Ethereum mainnet's frxETH Token
uint256 public constant DETH_FRXETH_CONVEX_POOL_ID = CONVEX_DETH_FRXETH_CONVEX_POOL_ID_MAINNET;  // Convex pool identifier
```

## State Variables

```solidity
IConvexBooster public constant convexBooster;     // Main Convex's deposit contract
IRouter public router;                            // Router for CRV-WETH swaps
ICurveLpPool public constant cvxWethPool;        // CVX-WETH pool in Curve
ICurveLpPool public curveLpPool;                 // Main Curve pool for Strategy
ICurveLpPool public curveEthFrxEthPool;          // Curve's ETH-frxETH pool
```

## Functions

### Initialization Functions

#### constructor

```solidity
constructor() initializer
```

Empty constructor marked as initializer.

#### initialize

```solidity
function initialize(
    IMaxApyVault _vault,
    address[] calldata _keepers,
    bytes32 _strategyName,
    address _strategist,
    ICurveLpPool _curveLpPool,
    ICurveLpPool _curveEthFrxEthPool,
    IRouter _router
) public 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
* `_curveLpPool`: Address of main Curve pool (dETH-frxETH)
* `_curveEthFrxEthPool`: Address of Curve's ETH-frxETH pool
* `_router`: Router address for swaps

### Configuration Functions

#### setRouter

```solidity
function setRouter(address _newRouter) external checkRoles(ADMIN_ROLE)
```

Updates the router used for token swaps.

Parameters:

* `_newRouter`: New router address

### Internal Core Functions

#### \_invest

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

Invests ETH into the Convex pool through a series of steps:

1. Unwraps WETH
2. Swaps ETH for frxETH
3. Adds liquidity to dETH-frxETH pool
4. Stakes LP tokens in Convex

Parameters:

* `amount`: Amount to invest
* `minOutputAfterInvestment`: Minimum expected LP tokens Returns:
* Amount of tokens received in underlying terms

#### \_divest

```solidity
function _divest(uint256 amount) internal override returns (uint256)
```

Withdraws assets from Convex and Curve pools:

1. Withdraws from Convex
2. Removes liquidity from Curve
3. Swaps frxETH back to ETH
4. Wraps ETH to WETH

Parameters:

* `amount`: LP tokens to divest Returns:
* Amount of WETH received

#### \_unwindRewards

```solidity
function _unwindRewards(IConvexRewards rewardPool) internal override
```

Claims and converts reward tokens to underlying asset:

1. Claims CRV and CVX rewards
2. Swaps CRV for WETH
3. Swaps CVX for WETH

Parameters:

* `rewardPool`: Convex rewards pool to claim from

### View Functions

#### previewLiquidate

```solidity
function previewLiquidate(uint256 requestedAmount) public view virtual override returns (uint256)
```

Simulates withdrawal including potential losses.

Parameters:

* `requestedAmount`: Amount to withdraw Returns:
* Expected output amount after losses

### Internal View Functions

#### \_lpPrice

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

Calculates the estimated price for the strategy's Convex LP token.

Returns:

* Estimated LP token price

#### \_crv

```solidity
function _crv() internal pure override returns (address)
```

Returns the CRV token address.

Returns:

* CRV token address

#### \_cvx

```solidity
function _cvx() internal pure override returns (address)
```

Returns the CVX token address.

Returns:

* CVX token address

### Receive Function

```solidity
receive() external payable
```

Enables the contract to receive ETH.

### Simulation Functions

#### \_simulateHarvest

```solidity
function _simulateHarvest() public override
```

Internal simulation function that calculates expected outcomes of harvesting operations including:

1. Investment/divestment amounts
2. Profit/loss calculations
3. Debt management
4. Balance changes


---

# 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/convex/convexdethfrxethstrategy.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.
