BaseStrategy

Overview

The BaseStrategy is the foundational abstract contract that all MaxApy strategies inherit from. Adapted from Yearn's v2 BaseStrategy, it defines core functionality and interfaces that strategies must implement for interacting with the MaxApy vault and external protocols.

Constants

uint256 public constant ADMIN_ROLE = _ROLE_0;             // Admin role identifier
uint256 public constant EMERGENCY_ADMIN_ROLE = _ROLE_1;   // Emergency admin role identifier
uint256 public constant VAULT_ROLE = _ROLE_2;             // Vault role identifier
uint256 public constant KEEPER_ROLE = _ROLE_3;            // Keeper role identifier
uint256 public constant MAX_BPS = 10_000;                 // Maximum basis points (100%)

Events

event Harvested(uint256 profit, uint256 loss, uint256 debtPayment, uint256 debtOutstanding);
event StrategyEmergencyExitUpdated(address indexed strategy, uint256 emergencyExitStatus);
event StrategistUpdated(address indexed strategy, address newStrategist);
event StrategyAutopilotUpdated(address indexed strategy, bool autoPilotStatus);

State Variables

IMaxApyVault public vault;                  // Associated MaxApy vault
address public underlyingAsset;             // Strategy's underlying asset
uint256 public emergencyExit;               // Emergency shutdown state
bytes32 public strategyName;                // Strategy identifier
address public strategist;                  // Strategy manager address
uint256 public lastEstimatedTotalAssets;    // Last recorded total assets
uint256[20] private __gap;                  // Upgradeability gap

Functions

Initialization Functions

__BaseStrategy_init

Initializes the strategy with necessary components.

Parameters:

  • _vault: MaxApy vault address

  • _keepers: Array of keeper addresses

  • _strategyName: Strategy identifier

  • _strategist: Strategist address

Core Functions

liquidate

Withdraws assets up to requested amount.

Parameters:

  • amountNeeded: Amount of assets to withdraw

Returns:

  • Amount of loss incurred

liquidateExact

Withdraws exact amount of assets.

Parameters:

  • amountNeeded: Exact amount of assets to withdraw

Returns:

  • Amount of loss incurred to achieve exact withdrawal

harvest

Harvests gains and reinvests.

Parameters:

  • minExpectedBalance: Minimum balance expected after operations

  • minOutputAfterInvestment: Minimum expected output from reinvestment

  • harvester: Address to receive management fees

  • deadline: Transaction deadline

Configuration Functions

setEmergencyExit

Sets emergency exit mode.

Parameters:

  • _emergencyExit: Exit mode state (1=inactive, 2=active)

setStrategist

Updates strategist address.

Parameters:

  • _newStrategist: New strategist address

setAutopilot

Enables/disables automated harvesting.

Parameters:

  • _autoPilot: Autopilot state

View Functions

estimatedTotalAssets

Returns total assets under management.

Returns:

  • Current total assets value

isActive

Checks if strategy is actively managing positions.

Returns:

  • True if strategy is active

unharvestedAmount

Calculates unrealized gains/losses since last harvest.

Returns:

  • Net unrealized profit/loss

previewLiquidate

Simulates withdrawal including losses.

Parameters:

  • requestedAmount: Amount to withdraw

Returns:

  • Expected output amount

Required Virtual Functions

These functions must be implemented by inheriting strategies:

Last updated