BaseConvexStrategy
Overview
The BaseConvexStrategy contract serves as the foundation for strategies that interact with Convex protocols in the MaxAPY ecosystem. It provides the core functionality for depositing assets into Convex pools, managing rewards, and handling withdrawals.
Constants
uint256 internal constant DEGRADATION_COEFFICIENT = 10 ** 18;Errors
error ConvexPoolShutdown(); // Convex pool has been shut down
error InvalidCoinIndex(); // Invalid coin index provided
error NotEnoughFundsToInvest(); // Insufficient funds for investment
error InvalidZeroAddress(); // Zero address provided
error CurveWithdrawAdminFeesFailed(); // Failed to withdraw admin fees
error InvalidHarvestedProfit(); // Invalid profit amount reported
error MinOutputAmountNotReached(); // Minimum output not achieved
error InvalidZeroAmount(); // Zero amount provided
error MinExpectedBalanceAfterSwapNotReached(); // Minimum balance not reached after swapEvents
State Variables
Functions
View Functions
stakedBalance
Returns the amount of Curve LP tokens staked in Convex.
Returns:
The amount of staked LP tokens
previewLiquidate
Calculates estimated withdrawal amount including potential losses.
Parameters:
requestedAmount: The amount of assets requested to withdraw
Returns:
The expected liquidated amount
previewLiquidateExact
Calculates the amount needed to request for desired withdrawal amount.
Parameters:
liquidatedAmount: The desired amount to receive
Returns:
The amount that needs to be requested
maxLiquidate
Returns maximum amount that can be withdrawn after losses.
Returns:
Maximum withdrawable amount
maxLiquidateExact
Returns maximum amount that can be withdrawn before losses.
Returns:
Maximum withdrawable amount before losses
Configuration Functions
setMaxSingleTrade
Sets maximum allowed size for a single trade.
Parameters:
_maxSingleTrade: New maximum trade size
setMinSwapCrv
Sets minimum amount for CRV token swaps.
Parameters:
_minSwapCrv: New minimum swap amount
setMinSwapCvx
Sets minimum amount for CVX token swaps.
Parameters:
_minSwapCvx: New minimum swap amount
Core Internal Functions
_prepareReturn
Prepares strategy returns and handles profits/losses.
Parameters:
debtOutstanding: Amount of debt to be repaidminExpectedBalance: Minimum balance expected after operations
Returns:
unrealizedProfit: Unrealized profit amountloss: Loss amountdebtPayment: Debt payment amount
_adjustPosition
Adjusts strategy position with available capital.
Parameters:
minOutputAfterInvestment: Minimum expected output after investment
_invest
Invests assets into Convex pool.
Parameters:
amount: Amount of assets to investminOutputAfterInvestment: Minimum expected output
Returns:
Amount of tokens received
_divest
Withdraws assets from Convex pool.
Parameters:
amount: Amount of LP tokens to withdraw
Returns:
Amount of underlying assets received
Internal View Functions
_cvxBalance
Returns CVX token balance of strategy.
Returns:
CVX balance
_crvBalance
Returns CRV token balance of strategy.
Returns:
CRV balance
_stakedBalance
Returns LP tokens staked in Convex.
Parameters:
rewardPool: Convex reward pool address
Returns:
Staked LP token amount
_lpValue
Calculates underlying value of LP tokens.
Parameters:
lp: Amount of LP tokens
Returns:
Underlying value
_lpForAmount
Calculates LP tokens needed for underlying amount.
Parameters:
amount: Amount of underlying assets
Returns:
Required LP tokens
Abstract Functions
_lpPrice
Returns estimated price of Convex LP token.
Returns:
LP token price
_estimatedTotalAssets
Returns total value of strategy's assets.
Returns:
Total assets value
_crv
Returns CRV token address.
Returns:
CRV token address
_cvx
Returns CVX token address.
Returns:
CVX token address
Last updated