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
Copy 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
Copy 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
Copy 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
Copy function __BaseStrategy_init (
IMaxApyVault _vault ,
address [] calldata _keepers ,
bytes32 _strategyName ,
address _strategist
) internal virtual
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
Copy function liquidate ( uint256 amountNeeded) external virtual returns ( uint256 loss)
Withdraws assets up to requested amount.
Parameters:
amountNeeded
: Amount of assets to withdraw
Returns:
liquidateExact
Copy function liquidateExact ( uint256 amountNeeded) external virtual returns ( uint256 loss)
Withdraws exact amount of assets.
Parameters:
amountNeeded
: Exact amount of assets to withdraw
Returns:
Amount of loss incurred to achieve exact withdrawal
harvest
Copy function harvest (
uint256 minExpectedBalance ,
uint256 minOutputAfterInvestment ,
address harvester ,
uint256 deadline
) external
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
Copy function setEmergencyExit ( uint256 _emergencyExit ) external
Sets emergency exit mode.
Parameters:
_emergencyExit
: Exit mode state (1=inactive, 2=active)
setStrategist
Copy function setStrategist ( address _newStrategist ) external
Updates strategist address.
Parameters:
_newStrategist
: New strategist address
setAutopilot
Copy function setAutopilot ( bool _autoPilot ) external
Enables/disables automated harvesting.
Parameters:
_autoPilot
: Autopilot state
View Functions
estimatedTotalAssets
Copy function estimatedTotalAssets () public view returns ( uint256 )
Returns total assets under management.
Returns:
Current total assets value
isActive
Copy function isActive () public view returns ( bool )
Checks if strategy is actively managing positions.
Returns:
True if strategy is active
unharvestedAmount
Copy function unharvestedAmount () external view virtual returns ( int256 )
Calculates unrealized gains/losses since last harvest.
Returns:
Net unrealized profit/loss
previewLiquidate
Copy function previewLiquidate ( uint256 requestedAmount) public view virtual returns ( uint256 )
Simulates withdrawal including losses.
Parameters:
requestedAmount
: Amount to withdraw
Returns:
Required Virtual Functions
These functions must be implemented by inheriting strategies:
Copy function _adjustPosition ( uint256 debtOutstanding , uint256 minOutputAfterInvestment) internal virtual ;
function _liquidatePosition ( uint256 amountNeeded) internal virtual returns ( uint256 liquidatedAmount , uint256 loss);
function _liquidateAllPositions () internal virtual returns ( uint256 amountFreed);
function _prepareReturn ( uint256 debtOutstanding , uint256 minExpectedBalance) internal virtual returns ( uint256 unrealizedProfit , uint256 loss , uint256 debtPayment);
function _estimatedTotalAssets () internal view virtual returns ( uint256 );
function previewLiquidate ( uint256 requestedAmount) public view virtual returns ( uint256 );
function previewLiquidateExact ( uint256 liquidatedAmount) public view virtual returns ( uint256 );
function maxLiquidate () public view virtual returns ( uint256 );
function maxLiquidateExact () public view virtual returns ( uint256 );