# YearnAjnaWETHStakingStrategy

## Overview

The YearnAjnaWETHStakingStrategy contract is a strategy that supplies WETH into a Yearn V3 Vault and stakes the vault shares to earn additional AJNA rewards. It manages the conversion of AJNA rewards back to WETH through Uniswap V3.

## Constants

```solidity
address public constant ajna = AJNA_MAINNET;                                   // AJNA token address
IRouter public constant router = IRouter(UNISWAP_V3_ROUTER_MAINNET);          // Uniswap V3 router
IStakingRewardsMulti public constant yearnStakingRewards =                    // Yearn staking rewards contract
    IStakingRewardsMulti(0x0Ed535037c013c3628512980C169Ed59Eb805B49);
```

## State Variables

```solidity
uint256 public minSwapAjna;    // Minimum amount of AJNA to swap
```

## 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,
    IYVaultV3 _yVault
) 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
* `_yVault`: Yearn V3 vault address

### Core Functions

#### liquidateExact

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

Withdraws exact amount to vault and re-stakes any remaining shares.

Parameters:

* `amountNeeded`: Amount to withdraw

Returns:

* `loss`: Amount of realized loss

### Internal Core Functions

#### \_beforePrepareReturn

```solidity
function _beforePrepareReturn() internal override
```

Claims and processes staking rewards before preparing return.

#### \_invest

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

Invests assets and stakes the received shares.

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)
```

Unstakes and withdraws assets from vault.

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

#### \_unwindRewards

```solidity
function _unwindRewards(IStakingRewardsMulti _yearnStakingRewards) internal
```

Claims AJNA rewards and converts them to WETH.

Parameters:

* `_yearnStakingRewards`: Staking rewards contract

### Internal View Functions

#### \_ajnaBalance

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

Returns strategy's AJNA token balance.

Returns:

* Current AJNA balance

#### \_shareBalance

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

Returns strategy's staked vault share balance.

Returns:

* Current staked share balance


---

# 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/yearn/yearnajnawethstakingstrategy.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.
