# YearnAaveV3USDTLenderStrategy

## Overview

The YearnAaveV3USDTLenderStrategy contract is a strategy that supplies USDT into a Yearn V3 Vault for AAVE v3 lending. It manages conversions between USDCe and USDT through Curve's AtriCrypto zapper and includes safety margins for liquidations.

## Constants

```solidity
ICurveAtriCryptoZapper constant zapper = ICurveAtriCryptoZapper(CURVE_AAVE_ATRICRYPTO_ZAPPER_POLYGON);  // Curve zapper
address public constant usdt = USDT_POLYGON;                                                              // USDT address
```

## Functions

### Initialization Functions

#### initialize

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

Initializes the strategy and sets up trading limits.

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 with loss calculation.

Parameters:

* `amountNeeded`: Amount to withdraw

Returns:

* `loss`: Amount of realized loss

### View Functions

#### previewLiquidate

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

Simulates withdrawal including losses and conversion rates.

Parameters:

* `requestedAmount`: Amount to withdraw

Returns:

* `liquidatedAmount`: Expected output amount

#### previewLiquidateExact

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

Calculates input needed with 1% safety margin.

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 with safety margin.

Returns:

* Maximum withdrawable amount before losses

### Internal Core Functions

#### \_invest

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

Invests assets by:

1. Converting USDCe to USDT through zapper
2. Depositing USDT into Yearn vault

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 by:

1. Redeeming from Yearn vault
2. Converting USDT to USDCe through zapper

Parameters:

* `shares`: Amount of shares to withdraw

Returns:

* `withdrawn`: Amount of assets received

### Internal View Functions

#### \_shareValue

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

Calculates underlying value including conversion rate.

Parameters:

* `shares`: Share amount

Returns:

* Underlying asset value

#### \_sharesForAmount

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

Calculates shares needed including spot price conversion.

Parameters:

* `amount`: Asset amount

Returns:

* Required shares

#### \_spotPriceDy

```solidity
function _spotPriceDy(uint256 i, uint256 amount) internal view returns (uint256 _spotDy)
```

Calculates spot price conversion without slippage.

Parameters:

* `i`: Direction (1: USDC->USDT, 2: USDT->USDC)
* `amount`: Amount to convert

Returns:

* Converted amount at spot price


---

# 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/polygon-usdc.e/yearn/yearnaavev3usdtlenderstrategy.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.
