BeefyUSDCeDAIStrategy

Overview

The BeefyUSDCeDAIStrategy contract is a sophisticated strategy that manages USDCe-DAI positions through Gamma's Hypervisor (concentrated liquidity positions) and stakes them in a Beefy Vault. It handles complex liquidity calculations and token conversions through Curve's AtriCrypto zapper.

Constants

address public constant usdce = USDCE_POLYGON;               // USDCe token address
address public constant dai = DAI_POLYGON;                   // DAI token address
uint256 constant _1_USDCE = 1e6;                            // One USDCe unit
uint256 constant _1_DAI = 1 ether;                          // One DAI unit
ICurveAtriCryptoZapper constant zapper =                    // Curve zapper for stable swaps
    ICurveAtriCryptoZapper(CURVE_AAVE_ATRICRYPTO_ZAPPER_POLYGON);

State Variables

IUniProxy public uniProxy;              // Gamma's deposit proxy
IHypervisor public hypervisor;          // Gamma's hypervisor contract

Functions

Initialization Functions

initialize

function initialize(
    IMaxApyVault _vault,
    address[] calldata _keepers,
    bytes32 _strategyName,
    address _strategist,
    IUniProxy _uniProxy,
    IHypervisor _hypervisor,
    IBeefyVault _beefyVault
) public initializer

Initializes the strategy with required components.

Parameters:

  • _vault: MaxApy vault address

  • _keepers: Array of keeper addresses

  • _strategyName: Name of the strategy

  • _strategist: Strategist address

  • _uniProxy: Gamma's UniProxy contract

  • _hypervisor: Gamma's Hypervisor contract

  • _beefyVault: Beefy vault address

Core Functions

calculateUSDCeToSwap

function calculateUSDCeToSwap(uint256 totalUSDCe, uint256 ratio) public view returns (uint256 usdceToSwap)

Calculates optimal USDCe amount to swap for balanced liquidity provision.

Parameters:

  • totalUSDCe: Total USDCe amount

  • ratio: Target ratio

Returns:

  • Amount of USDCe to swap

_invest

function _invest(uint256 amount, uint256 minOutputAfterInvestment) internal override returns (uint256)

Complex investment process:

  1. Calculates optimal token ratio

  2. Swaps portion of USDCe to DAI

  3. Deposits into Gamma Hypervisor

  4. Stakes LP tokens in Beefy

Parameters:

  • amount: Amount to invest

  • minOutputAfterInvestment: Minimum expected shares

Returns:

  • Amount of shares received

_divest

function _divest(uint256 amount) internal override returns (uint256)

Withdrawal process:

  1. Withdraws from Beefy

  2. Removes liquidity from Hypervisor

  3. Converts tokens back to USDCe

Parameters:

  • amount: Amount of Beefy shares to divest

Returns:

  • Amount of USDCe received

Internal View Functions

_shareValue

function _shareValue(uint256 shares) internal view override returns (uint256)

Calculates underlying value including:

  • Base and limit range positions

  • Unused token balances

  • Fee accumulation

_sharesForAmount

function _sharesForAmount(uint256 amount) internal view override returns (uint256)

Calculates shares for amount considering:

  • Current token ratios

  • Liquidity distribution

  • Price calculations

_convertUsdceToDai

function _convertUsdceToDai(uint256 usdceAmount) internal view returns (uint256)

Calculates DAI equivalent of USDCe amount.

Gamma Helper Functions

computeLiquidityFromShares

function computeLiquidityFromShares(int24 tickLower, int24 tickUpper, uint256 shares) internal view returns (uint128)

Calculates liquidity amount for given share position.

getPositionInfo

function getPositionInfo(int24 tickLower, int24 tickUpper) internal view returns (uint128 liquidity, uint128 tokensOwed0, uint128 tokensOwed1)

Retrieves position information including:

  • Current liquidity

  • Accumulated fees

_CalcBurnLiquidity

function _CalcBurnLiquidity(int24 tickLower, int24 tickUpper, uint128 liquidity) public view returns (uint256 amount0, uint256 amount1)

Calculates token amounts from burning liquidity position.

Last updated