BaseConvexStrategyPolygon
Overview
The BaseConvexStrategyPolygon contract serves as the foundation for Polygon-based strategies that interact with Convex protocols in the MaxAPY ecosystem. This contract provides core functionality for depositing assets, managing rewards, and handling withdrawals on Polygon network.
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
event Invested(address indexed strategy, uint256 amountInvested);
event Divested(address indexed strategy, uint256 amountDivested);
event MaxSingleTradeUpdated(uint256 maxSingleTrade);
event MinSwapCrvUpdated(uint256 newMinSwapCrv);
event RouterUpdated(address newRouter);State Variables
IConvexRewardsPolygon public convexRewardPool; // Main Convex reward contract
address public convexLpToken; // Convex pool's LP token address
address public rewardToken; // Main reward token
uint256 public maxSingleTrade; // Maximum size for a single trade
uint256 public minSwapCrv; // Minimum amount for CRV swapsFunctions
View Functions
stakedBalance
function stakedBalance() external view returns (uint256)Returns the amount of Curve LP tokens staked in Convex.
Returns:
The amount of staked LP tokens
previewLiquidate
function previewLiquidate(uint256 requestedAmount) public view virtual returns (uint256)Calculates estimated withdrawal amount including potential losses.
Parameters:
requestedAmount: The amount of assets requested to withdraw
Returns:
The expected liquidated amount
previewLiquidateExact
function previewLiquidateExact(uint256 liquidatedAmount) public view returns (uint256)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
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
Configuration Functions
setMaxSingleTrade
function setMaxSingleTrade(uint256 _maxSingleTrade) externalSets maximum allowed size for a single trade.
Parameters:
_maxSingleTrade: New maximum trade size
setMinSwapCrv
function setMinSwapCrv(uint256 _minSwapCrv) externalSets minimum amount for CRV token swaps.
Parameters:
_minSwapCrv: New minimum swap amount
Core 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: Amount of debt to be repaidminExpectedBalance: Minimum balance expected after operations
Returns:
unrealizedProfit: Unrealized profit amountloss: Loss amountdebtPayment: Debt payment amount
_adjustPosition
function _adjustPosition(uint256, uint256 minOutputAfterInvestment) internal virtualAdjusts strategy position with available capital.
Parameters:
minOutputAfterInvestment: Minimum expected output after investment
_invest
function _invest(uint256 amount, uint256 minOutputAfterInvestment) internal virtual returns (uint256)Invests assets into Convex pool.
Parameters:
amount: Amount of assets to investminOutputAfterInvestment: Minimum expected output
Returns:
Amount of tokens received
_divest
function _divest(uint256 amount) internal virtual returns (uint256)Withdraws assets from Convex pool.
Parameters:
amount: Amount of LP tokens to withdraw
Returns:
Amount of underlying assets received
Internal Helper Functions
_crvBalance
function _crvBalance() internal view returns (uint256)Returns CRV token balance of strategy.
Returns:
CRV balance
_stakedBalance
function _stakedBalance(IConvexRewardsPolygon rewardPool) internal view returns (uint256)Returns LP tokens staked in Convex.
Parameters:
rewardPool: Convex reward pool address
Returns:
Staked LP token amount
_lpValue
function _lpValue(uint256 lp) internal view returns (uint256)Calculates underlying value of LP tokens.
Parameters:
lp: Amount of LP tokens
Returns:
Underlying value
_lpForAmount
function _lpForAmount(uint256 amount) internal view returns (uint256)Calculates LP tokens needed for underlying amount.
Parameters:
amount: Amount of underlying assets
Returns:
Required LP tokens
Abstract Functions
_lpPrice
function _lpPrice() internal view virtual returns (uint256)Returns estimated price of Convex LP token.
Returns:
LP token price
_estimatedTotalAssets
function _estimatedTotalAssets() internal view returns (uint256)Returns total value of strategy's assets.
Returns:
Total assets value
_crv
function _crv() internal pure virtual returns (address)Returns CRV token address.
Returns:
CRV token address
_unwindRewards
function _unwindRewards(IConvexRewardsPolygon rewardPool) internal virtualClaims and processes rewards from Convex.
Parameters:
rewardPool: Convex reward pool to claim from
Last updated