YearnLUSDStrategy

Overview

The YearnLUSDStrategy contract is a strategy that supplies LUSD into a Yearn V2 Vault to earn yield. It handles conversions between USDC and LUSD through Uniswap V3, using TWAP oracles for price calculations.

Constants

address public constant lusd = LUSD_MAINNET;                                  // LUSD token address
IRouter public constant router = IRouter(UNISWAP_V3_ROUTER_MAINNET);         // Uniswap V3 router
address public constant pool = UNISWAP_V3_USDC_LUSD_POOL_MAINNET;           // USDC-LUSD pool address

Functions

Initialization Functions

initialize

function initialize(
    IMaxApyVault _vault,
    address[] calldata _keepers,
    bytes32 _strategyName,
    address _strategist,
    IYVault _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 V2 vault address

View Functions

previewLiquidate

function previewLiquidate(uint256 requestedAmount) public view virtual override returns (uint256 liquidatedAmount)

Simulates withdrawal with 1% safety margin.

Parameters:

  • requestedAmount: Amount to withdraw

Returns:

  • liquidatedAmount: Expected output amount

previewLiquidateExact

function previewLiquidateExact(uint256 liquidatedAmount) public view virtual override returns (uint256 requestedAmount)

Calculates input needed with 1% buffer.

Parameters:

  • liquidatedAmount: Desired output amount

Returns:

  • requestedAmount: Required input amount

Internal Core Functions

_invest

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

Invests assets by:

  1. Swapping USDC to LUSD

  2. Depositing LUSD into Yearn vault

Parameters:

  • amount: Amount to invest

  • minOutputAfterInvestment: Minimum expected shares

Returns:

  • depositedAmount: Amount of tokens received

_divest

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

Withdraws assets by:

  1. Withdrawing LUSD from Yearn vault

  2. Swapping LUSD to USDC

Parameters:

  • shares: Amount of shares to withdraw

Returns:

  • withdrawn: Amount of assets received

Internal View Functions

_shareValue

function _shareValue(uint256 shares) internal view override returns (uint256)

Calculates underlying value using TWAP oracle.

Parameters:

  • shares: Share amount

Returns:

  • Underlying value

_sharesForAmount

function _sharesForAmount(uint256 amount) internal view override returns (uint256 shares)

Calculates shares needed using TWAP oracle.

Parameters:

  • amount: Asset amount

Returns:

  • Required shares

_lusdBalance

function _lusdBalance() internal view returns (uint256)

Returns strategy's LUSD balance.

Returns:

  • Current LUSD balance

_estimateAmountOut

function _estimateAmountOut(
    address tokenIn,
    address tokenOut,
    uint128 amountIn,
    uint32 secondsAgo
) internal view returns (uint256 amountOut)

Estimates swap output using Uniswap V3 TWAP.

Parameters:

  • tokenIn: Input token address

  • tokenOut: Output token address

  • amountIn: Input amount

  • secondsAgo: TWAP interval in seconds

Returns:

  • Estimated output amount

Last updated