BaseYearnV3Strategy
Overview
The BaseYearnV3Strategy contract is the base implementation for strategies interacting with Yearn v3 vaults in the MaxAPY ecosystem. It handles deposits into Yearn vaults, manages share calculations, and provides core functionality for vault interactions.
Constants
No internal constants defined in this contract.
Errors
Events
State Variables
Functions
Initialization Functions
constructor
Empty constructor marked as initializer.
initialize
Initializes the strategy with Yearn components.
Parameters:
_vault
: MaxApy vault address_keepers
: Array of keeper addresses_strategyName
: Name of the strategy_strategist
: Strategist address_yVault
: Yearn vault address
Core Functions
liquidateExact
Withdraws exactly amountNeeded to vault. Can only be called by vault.
Parameters:
amountNeeded
: Amount of underlying asset to withdraw
Returns:
loss
: Amount of loss realized during withdrawal
Configuration Functions
setMaxSingleTrade
Sets the maximum amount allowed for a single trade.
Parameters:
_maxSingleTrade
: New maximum trade size
setMinSingleTrade
Sets the minimum amount required for a single trade.
Parameters:
_minSingleTrade
: New minimum trade size
View Functions
previewLiquidate
Simulates withdrawal including potential losses.
Parameters:
requestedAmount
: Amount requested to withdraw
Returns:
liquidatedAmount
: Expected output amount after losses
previewLiquidateExact
Calculates input amount needed for exact output.
Parameters:
liquidatedAmount
: Desired output amount
Returns:
requestedAmount
: Required input amount
maxLiquidate
Returns maximum withdrawable amount considering potential losses.
Returns:
Maximum amount that can be withdrawn
maxLiquidateExact
Returns maximum withdrawable amount before considering losses.
Returns:
Maximum amount that can be withdrawn before losses
Internal Functions
_prepareReturn
Prepares strategy returns and handles debt repayment.
Parameters:
debtOutstanding
: Amount of debt that needs to be repaidminExpectedBalance
: Minimum balance expected after operation
Returns:
unrealizedProfit
: Amount of profit generatedloss
: Amount of losses incurreddebtPayment
: Amount of debt repaid
_adjustPosition
Adjusts strategy positions based on available capital.
Parameters:
minOutputAfterInvestment
: Minimum expected output after investment
_invest
Deposits assets into Yearn vault.
Parameters:
amount
: Amount to investminOutputAfterInvestment
: Minimum expected shares
Returns:
depositedAmount
: Amount of tokens successfully invested
_divest
Withdraws assets from Yearn vault.
Parameters:
shares
: Amount of shares to withdraw
Returns:
withdrawn
: Amount of assets received
_liquidatePosition
Liquidates position up to requested amount.
Parameters:
amountNeeded
: Amount needed to liquidate
Returns:
liquidatedAmount
: Amount actually liquidatedloss
: Amount of losses incurred
_liquidateAllPositions
Liquidates all positions, used during emergency exit.
Returns:
amountFreed
: Total amount freed from positions
Internal View Functions
_shareValue
Calculates the underlying value of shares.
Parameters:
shares
: Amount of shares to value
Returns:
_assets
: Value in underlying asset terms
_sharesForAmount
Calculates shares needed for a given amount of assets.
Parameters:
amount
: Amount of assets
Returns:
_shares
: Required number of shares
_shareBalance
Returns the strategy's current Yearn vault share balance.
Returns:
_balance
: Current share balance
_estimatedTotalAssets
Calculates total value of all assets under management.
Returns:
Total value of assets in underlying terms
_simulateHarvest
Simulates a harvest operation and reverts with simulation data. Used for testing and verification.
Last updated