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.
No internal constants defined in this contract.
Copy error NotEnoughFundsToInvest (); // Insufficient funds for investment
error InvalidZeroAddress (); // Zero address provided
Copy event Invested ( address indexed strategy , uint256 amountInvested );
event Divested ( address indexed strategy , uint256 requestedShares , uint256 amountDivested );
event MaxSingleTradeUpdated ( uint256 maxSingleTrade );
event MinSingleTradeUpdated ( uint256 minSingleTrade ); State Variables
Initialization Functions
Empty constructor marked as initializer.
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
Withdraws exactly amountNeeded to vault. Can only be called by vault.
amountNeeded: Amount of underlying asset to withdraw
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
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
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
Prepares strategy returns and handles debt repayment.
Parameters:
debtOutstanding: Amount of debt that needs to be repaid
minExpectedBalance: Minimum balance expected after operation
Returns:
unrealizedProfit: Amount of profit generated
loss: Amount of losses incurred
debtPayment: Amount of debt repaid
_adjustPosition
Adjusts strategy positions based on available capital.
Parameters:
minOutputAfterInvestment: Minimum expected output after investment
Deposits assets into Yearn vault.
Parameters:
minOutputAfterInvestment: Minimum expected shares
Returns:
depositedAmount: Amount of tokens successfully invested
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 liquidated
loss: Amount of losses incurred
_liquidateAllPositions
Liquidates all positions, used during emergency exit.
Returns:
amountFreed: Total amount freed from positions
Internal View Functions
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:
Returns:
_shares: Required number of shares
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.