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

error NotEnoughFundsToInvest();    // Insufficient funds for investment
error InvalidZeroAddress();         // Zero address provided

Events

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

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 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

_invest

Deposits assets into Yearn vault.

Parameters:

  • amount: Amount to invest

  • minOutputAfterInvestment: 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 liquidated

  • loss: 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