BaseStrategy
The BaseStrategy
contract serves as the foundation for all strategies in the MaxAPY Protocol. It defines the core functionality and interface strategies that must be adhered to when interacting with the MaxAPY Vault and external protocols. The main purpose of this contract is to provide a standardized way for strategies to manage funds, interact with the vault, and report their performance.
The BaseStrategy
contract includes functions for depositing and withdrawing funds, adjusting positions, liquidating assets, and preparing returns. It also defines the roles and access control mechanisms to ensure that only authorized entities can perform specific actions within the strategy.
By providing a common interface and standardized functionality, the BaseStrategy
contract enables the MaxAPY Protocol to integrate with various strategies seamlessly, promoting modularity, standardization, and security.
The BaseStrategy
was developed, taking into consideration the Yearn v2 base strategy.
Functions
Initialize()
Initializes a new Strategy with the specified vault, keepers, name, and strategist.
Parameters:
_vault
: The address of the MaxApy Vault associated with the strategy
_keepers
: The addresses of the keepers to be granted the keeper role
_strategyName
: The name of the strategy
_strategist
: The address of the strategist
withdrawn()
Tries to withdraw amountNeeded
to vault
. This may only be called by the respective Vault.
Parameters:
amountNeeded
: How much underlyingAsset
to withdraw
Returns:
loss
: Any realized losses
requestWithdraw()
Withdraws exactly amountNeeded
to vault
. This may only be called by the respective Vault.
Parameters:
amountNeeded
: How much underlyingAsset
to withdraw
Returns:
loss
: Any realized losses
harvest()
Harvests the Strategy, but in this case, a percentage of the profit (if any) is reinvested. In the rare case of an emergency shutdown, this will exit the Strategy's position.
Parameters:
minExpectedBalance
: Minimum balance amount of underlyingAsset
expected after performing any strategy unwinding
minOutputAfterInvestment
: Minimum expected output after _invest()
harvestedProfitBPS
: Percentage of the profit to be realized and sent to the vault as net profit
harvester
: Only relevant when the harvest is triggered from the vault, is the address of the user that is enduring the harvest gas cost from the vault and will receive the management fees in return
setEmergencyExit()
Sets the strategy in emergency exit mode.
Parameters:
_emergencyExit
: The new emergency exit value: 1 for inactive, 2 for active
setStrategist()
Sets the strategy's new strategist.
Parameters:
_newStrategist
: The new strategist address
setAutopilot()
Sets the strategy in autopilot mode, meaning that it will be automatically harvested from the vault using the strategy.
Parameters:
_autoPilot
: The new autopilot status: true for active, false for inactive
_adjustPosition()
Performs any adjustments to this Strategy's core position(s) given what change the MaxApy Vault made in the "investable capital" available to the Strategy.
Parameters:
debtOutstanding
: Total principal + interest of debt yet to be paid back
minOutputAfterInvestment
: Minimum expected output after _invest()
(designated in receipt tokens obtained after depositing in a third-party protocol)
_liquidatePosition()
Liquidates up to amountNeeded
of MaxApy Vault's underlyingAsset
of this strategy's positions, regardless of slippage. Any excess will be re-invested with _adjustPosition()
.
Parameters:
amountNeeded
: Amount of MaxApy Vault's underlyingAsset
needed to be liquidated
Returns:
liquidatedAmount
: The actual liquidated amount
loss
: Difference between the expected amount needed to reach amountNeeded
and the actual liquidated amount
_liquidateAllPositions()
Liquidates everything and returns the amount that got freed. This function is used during emergency exit instead of _prepareReturn()
liquidating all of the Strategy's positions back to the MaxApy Vault.
Returns:
amountFreed
: The amount of underlying assets freed
_prepareReturn()
Performs any Strategy unwinding or other calls necessary to capture the "free return" this Strategy has generated since the last time its core position(s) were adjusted.
Parameters:
debtOutstanding
: Outstanding debt of the strategy
minExpectedBalance
: Minimum expected balance of underlying assets after unwinding
harvestedProfitBPS
: Percentage of profits to be harvested (in basis points)
Returns:
realizedProfit
: The realized profit
unrealizedProfit
: The unrealized profit
loss
: The realized losses
debtPayment
: The amount of debt to be paid back to the vault
_underlyingBalance()
Returns the current strategy's balance in underlying tokens.
Returns:
The strategy's balance of underlying tokens
_estimatedTotalAssets()
Returns the real-time estimation of the value in assets held by the strategy.
Returns:
The strategy's total assets (idle + investment positions)
unharvestedAmount()
Returns the real gain/loss from the last harvest.
Returns:
The difference between the current estimated total assets and the last estimated total assets
estimatedTotalAssets()
Provides an accurate estimate of the total amount of assets (principal + return) that this Strategy is currently managing, denominated in terms of underlyingAsset
tokens.
Returns:
The estimated total assets in this Strategy
isActive()
Indicates whether this strategy is currently "active" in that it is managing an active position or will manage a position in the future.
Returns:
True if the strategy is actively managing a position
previewLiquidate()
Calculates the estimated real output of a withdrawal (including losses) for a given requested amount. This function is meant to be called from the vault.
Parameters:
requestedAmount
: The requested amount of underlying assets to withdraw
Returns:
liquidatedAmount
: The estimated output in assets
previewLiquidateExact()
Calculates the estimated requested amount the vault has to request from this strategy actually to get the specified liquidated amount of assets when calling previewWithdraw
. This function is meant to be called from the vault.
Parameters:
liquidatedAmount
: The desired liquidated amount of assets
Returns:
requestedAmount
: The estimated requested amount
maxRequest()
Returns the maximum amount of assets that the strategy can liquidate before realizing losses.
Returns:
The maximum amount of assets that can be requested
maxWithdrawn()
Returns the maximum amount of assets that the strategy can withdraw after losses.
Returns:
The maximum amount of assets that can be withdrawn
Last updated