🐸
maxAPY for Devs
  • maxAPY ERC7540
    • MetaVault
      • Introduction
      • Architecture
      • Core Operations
      • State Management & Operations
      • Asset Management
      • Settlement Mechanics
      • Withdrawal Queue Mechanics
      • Deployed Addresses
  • Periphery
    • Hurdle Rate Oracle
    • SharePriceOracle
    • Deployed Addresses
  • maxAPY ERC4626
    • Introduction
    • Architecture
    • Vault
      • MaxApyFactory
      • MaxApyRouter
      • MaxApyVault
    • Periphery
      • MaxApyHarvester
    • Base Strategies
      • BaseStrategy
      • BaseSommelierStrategy
      • BaseYearnV3Strategy
      • BaseYearnV2Strategy
      • BaseConvexStrategy
      • BaseConvexStrategyPolygon
      • BaseBeefyStrategy
      • BaseHopStrategy
      • BaseBeefyCurveStrategy
    • Strategies
      • Ethereum - WETH
        • Convex
          • ConvexdETHFrxETHStrategy
        • Sommelier
          • SommelierMorphoEthMaximizerStrategy
          • SommelierStEthDepositTurboStEthStrategy
          • SommelierTurboDivEthStrategy
          • SommelierTurboEEthV2Strategy
          • SommelierTurboEthXStrategy
          • SommelierTurboEzEthStrategy
          • SommelierTurboRsEthStrategy
          • SommelierTurboStEthStrategy
          • SommelierTurboSwEthStrategy
        • Yearn
          • YearnAaveV3WETHLenderStrategy
          • YearnAjnaWETHStakingStrategy
          • YearnCompoundV3WETHLenderStrategy
          • YearnV3WETH2Strategy
          • YearnV3WETHStrategy
          • YearnWETHStrategy
      • Ethereum - USDC
        • Convex
          • ConvexCrvUSDWethCollateralStrategy
        • Sommelier
          • SommelierTurboGHOStrategy
        • Yearn
          • YearnAjnaDAIStakingStrategy
          • YearnDAIStrategy
          • YearnLUSDStrategy
          • YearnUSDCStrategy
          • YearnUSDTStrategy
      • Polygon - WETH
        • Hop
          • HopETHStrategy
      • Polygon - USDC.e
        • Convex
          • ConvexUSDCCrvUSDStrategy
          • ConvexUSDTCrvUSDStrategy
        • Beefy
          • BeefyCrvUSDUSDCeStrategy
          • BeefyMaiUSDCeStrategy
          • BeefyUSDCeDAIStrategy
        • Yearn
          • YearnAaveV3USDTLenderStrategy
          • YearnAjnaUSDCStrategy
          • YearnCompoundUSDCeLenderStrategy
          • YearnDAILenderStrategy
          • YearnDAIStrategy
          • YearnMaticUSDCStakingStrategy
          • YearnUSDCeLenderStrategy
          • YearnUSDCeStrategy
          • YearnUSDTStrategy
    • Subgraph
      • Overview
      • Schema
      • Query Guide
Powered by GitBook
On this page
  • Overview
  • Errors
  • Events
  • State Variables
  • Functions
  • View Functions
  • stakedBalance
  • previewLiquidate
  • previewLiquidateExact
  • maxLiquidate
  • maxLiquidateExact
  • Configuration Functions
  • setMaxSingleTrade
  • setMinSwapCrv
  • Core Internal Functions
  • _prepareReturn
  • _adjustPosition
  • _invest
  • _divest
  • Internal Helper Functions
  • _crvBalance
  • _stakedBalance
  • _lpValue
  • _lpForAmount
  • Abstract Functions
  • _lpPrice
  • _estimatedTotalAssets
  • _crv
  • _unwindRewards
  1. maxAPY ERC4626
  2. Base Strategies

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 swap

Events

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 swaps

Functions

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) external

Sets maximum allowed size for a single trade.

Parameters:

  • _maxSingleTrade: New maximum trade size

setMinSwapCrv

function setMinSwapCrv(uint256 _minSwapCrv) external

Sets 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 repaid

  • minExpectedBalance: Minimum balance expected after operations

Returns:

  • unrealizedProfit: Unrealized profit amount

  • loss: Loss amount

  • debtPayment: Debt payment amount

_adjustPosition

function _adjustPosition(uint256, uint256 minOutputAfterInvestment) internal virtual

Adjusts 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 invest

  • minOutputAfterInvestment: 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 virtual

Claims and processes rewards from Convex.

Parameters:

  • rewardPool: Convex reward pool to claim from

PreviousBaseConvexStrategyNextBaseBeefyStrategy

Last updated 6 months ago