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 addressFunctions
Initialization Functions
initialize
function initialize(
IMaxApyVault _vault,
address[] calldata _keepers,
bytes32 _strategyName,
address _strategist,
IYVault _yVault
) public override initializerInitializes 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:
Swapping USDC to LUSD
Depositing LUSD into Yearn vault
Parameters:
amount: Amount to investminOutputAfterInvestment: Minimum expected shares
Returns:
depositedAmount: Amount of tokens received
_divest
function _divest(uint256 shares) internal override returns (uint256 withdrawn)Withdraws assets by:
Withdrawing LUSD from Yearn vault
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 addresstokenOut: Output token addressamountIn: Input amountsecondsAgo: TWAP interval in seconds
Returns:
Estimated output amount
Last updated