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
Simulates withdrawal with 1% safety margin.
Parameters:
requestedAmount: Amount to withdraw
Returns:
liquidatedAmount: Expected output amount
previewLiquidateExact
Calculates input needed with 1% buffer.
Parameters:
liquidatedAmount: Desired output amount
Returns:
requestedAmount: Required input amount
Internal Core Functions
_invest
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
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
Calculates underlying value using TWAP oracle.
Parameters:
shares: Share amount
Returns:
Underlying value
_sharesForAmount
Calculates shares needed using TWAP oracle.
Parameters:
amount: Asset amount
Returns:
Required shares
_lusdBalance
Returns strategy's LUSD balance.
Returns:
Current LUSD balance
_estimateAmountOut
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