BaseBeefyStrategy

Overview

The BaseBeefyStrategy contract serves as the foundation for strategies that interact with Beefy Finance protocols in the MaxAPY ecosystem. It provides core functionality for depositing assets into Beefy vaults, managing positions, and handling withdrawals.

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

IBeefyVault public beefyVault;        // Beefy vault contract reference
uint256 public maxSingleTrade;        // Maximum size for a single trade
uint256 public minSingleTrade;        // Minimum size for a single trade

Functions

Initialization Functions

initialize

function initialize(
    IMaxApyVault _vault,
    address[] calldata _keepers,
    bytes32 _strategyName,
    address _strategist,
    IBeefyVault _beefyVault
) public virtual initializer

Initializes the strategy with required parameters.

Parameters:

  • _vault: MaxApy vault address

  • _keepers: Array of keeper addresses

  • _strategyName: Name of the strategy

  • _strategist: Strategist address

  • _beefyVault: Beefy vault address

Configuration Functions

setMinSingleTrade

function setMinSingleTrade(uint256 _minSingleTrade) external

Sets minimum trade size for the strategy.

Parameters:

  • _minSingleTrade: New minimum trade size

setMaxSingleTrade

function setMaxSingleTrade(uint256 _maxSingleTrade) external

Sets maximum trade size for the strategy.

Parameters:

  • _maxSingleTrade: New maximum trade size

View Functions

previewLiquidate

function previewLiquidate(uint256 requestedAmount) public view returns (uint256)

Calculates expected output for a withdrawal.

Parameters:

  • requestedAmount: Amount requested to withdraw

Returns:

  • Expected liquidated amount

previewLiquidateExact

function previewLiquidateExact(uint256 liquidatedAmount) public view returns (uint256)

Calculates input needed for desired withdrawal amount.

Parameters:

  • liquidatedAmount: Desired output amount

Returns:

  • Required input amount

maxLiquidate

function maxLiquidate() public view returns (uint256)

Returns maximum amount that can be withdrawn after losses.

Returns:

  • Maximum withdrawable amount

maxLiquidateExact

function maxLiquidateExact() public view returns (uint256)

Returns maximum amount that can be withdrawn before losses.

Returns:

  • Maximum withdrawable amount before losses

Internal Functions

_prepareReturn

function _prepareReturn(
    uint256 debtOutstanding,
    uint256 minExpectedBalance
) internal returns (uint256 unrealizedProfit, uint256 loss, uint256 debtPayment)

Prepares strategy returns and handles profits/losses.

Parameters:

  • debtOutstanding: Outstanding debt amount

  • minExpectedBalance: Minimum expected balance after operations

Returns:

  • unrealizedProfit: Unrealized profit amount

  • loss: Loss amount

  • debtPayment: Debt payment amount

_adjustPosition

function _adjustPosition(uint256, uint256 minOutputAfterInvestment) internal virtual

Adjusts strategy position with available capital.

Parameters:

  • minOutputAfterInvestment: Minimum expected output after investment

_invest

function _invest(uint256 amount, uint256 minOutputAfterInvestment) internal virtual returns (uint256)

Deposits assets into Beefy vault.

Parameters:

  • amount: Amount to invest

  • minOutputAfterInvestment: Minimum expected output

Returns:

  • Amount of tokens received

_divest

function _divest(uint256 shares) internal virtual returns (uint256)

Withdraws assets from Beefy vault.

Parameters:

  • shares: Amount of shares to withdraw

Returns:

  • Amount of underlying assets received

_liquidatePosition

function _liquidatePosition(uint256 amountNeeded) internal returns (uint256 liquidatedAmount, uint256 loss)

Liquidates position to meet withdrawal request.

Parameters:

  • amountNeeded: Amount requested to liquidate

Returns:

  • liquidatedAmount: Amount actually liquidated

  • loss: Any losses incurred

Internal View Functions

_shareValue

function _shareValue(uint256 shares) internal view virtual returns (uint256)

Calculates underlying value of vault shares.

Parameters:

  • shares: Amount of shares

Returns:

  • Underlying asset value

_sharesForAmount

function _sharesForAmount(uint256 amount) internal view virtual returns (uint256)

Calculates shares needed for given amount.

Parameters:

  • amount: Amount of underlying assets

Returns:

  • Required shares amount

_shareBalance

function _shareBalance() internal view returns (uint256)

Returns strategy's Beefy vault share balance.

Returns:

  • Current share balance

_estimatedTotalAssets

function _estimatedTotalAssets() internal view returns (uint256)

Calculates total assets under management.

Returns:

  • Total assets value

Last updated