BaseYearnV2Strategy

Overview

The BaseYearnV2Strategy contract is the base implementation for strategies interacting with Yearn v2 vaults in the MaxAPY ecosystem. It handles deposits into Yearn vaults, manages share calculations, and handles locked profit mechanics.

Constants

uint256 internal constant DEGRADATION_COEFFICIENT = 10 ** 18;  // Coefficient for profit unlocking

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 MinSingleTradeUpdated(uint256 minSingleTrade);
event MaxSingleTradeUpdated(uint256 maxSingleTrade);

State Variables

Functions

Initialization Functions

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

Configuration Functions

setMinSingleTrade

Sets minimum trade size.

Parameters:

  • _minSingleTrade: New minimum trade size

setMaxSingleTrade

Sets maximum trade size.

Parameters:

  • _maxSingleTrade: New maximum trade size

View Functions

previewLiquidate

Simulates withdrawal including losses.

Parameters:

  • requestedAmount: Amount to withdraw

Returns:

  • Expected output amount

previewLiquidateExact

Calculates input needed for exact output.

Parameters:

  • liquidatedAmount: Desired output amount

Returns:

  • Required input amount

maxLiquidate

Returns maximum withdrawable amount after losses.

Returns:

  • Maximum withdrawable amount

maxLiquidateExact

Returns maximum withdrawable amount before losses.

Returns:

  • Maximum withdrawable amount before losses

Internal Functions

_invest

Deposits assets into Yearn vault.

Parameters:

  • amount: Amount to invest

  • minOutputAfterInvestment: Minimum expected shares

Returns:

  • Amount of tokens received

_divest

Withdraws assets from Yearn vault.

Parameters:

  • shares: Amount of shares to withdraw

Returns:

  • Amount of assets received

Internal View Functions

_shareValue

Calculates underlying value of Yearn shares.

Parameters:

  • shares: Amount of shares

Returns:

  • Underlying asset value

_sharesForAmount

Calculates shares needed for given amount.

Parameters:

  • amount: Amount of assets

Returns:

  • Required shares amount

_freeFunds

Calculates available assets in Yearn vault.

Returns:

  • Available funds amount

_calculateLockedProfit

Calculates locked profit in Yearn vault.

Returns:

  • Locked profit amount

_shareBalance

Returns strategy's Yearn share balance.

Returns:

  • Current share balance

_estimatedTotalAssets

Calculates total assets under management.

Returns:

  • Total assets value

Last updated