Yearn V3 Framework

As previously discussed, Yearn V3 adopts the "Tokenized Strategy" pattern to streamline strategy implementation. This section provides a detailed explanation of its components.

TokenizedStrategy Implementation

The TokenizedStrategy contract is a single, immutable contract deployed at 0xBB51...feD0, responsible for handling all ERC-4626 functionality across Yearn strategies. Key features include:

  • Accounting and Share Mechanics: Manages ERC-4626 accounting for deposits, withdrawals, and share balances.

  • Profit/Loss Management: Calculates profits and losses while managing fee accrual.

  • Profit Unlocking: Implements profit unlocking mechanisms based on configurable parameters.

  • Pure Logic Contract: Contains no storage and operates purely as a shared logic layer across all strategies.

BaseStrategy Delegation

The BaseStrategy employs a proxy pattern to delegate functionality to the TokenizedStrategy while maintaining isolated storage for each strategy. Key characteristics include:

  • Fallback Delegation: Forwards unimplemented calls to the TokenizedStrategy via fallback.

  • Delegatecall Execution: Executes shared logic in the context of the individual strategy’s storage.

  • Standardized Hooks: Provides predefined hooks for implementing custom logic:

    • _deployFunds: Allocates funds for strategy deployment.

    • _freeFunds: Releases funds for withdrawals.

    • _harvestAndReport: Manages profit reporting and harvesting.

Vault Storage Model

Yearn V3 centralizes strategy storage using the BASE_STRATEGY_STORAGE slot, which contains the StrategyData structure. This structure standardizes storage across all strategies and includes the following fields:

StrategyData Structure

  1. Share and Asset Accounting:

    • ERC20 asset: Underlying token managed by the strategy.

    • uint8 decimals: Precision of the token.

    • uint256 totalSupply: Total number of shares issued.

    • mapping balances: Individual share balances.

    • uint256 totalAssets: Total assets held by the strategy.

  2. Profit Management:

    • uint256 profitUnlockingRate: Unlock rate for profits (per second).

    • uint96 fullProfitUnlockDate: Target date for complete profit unlocking.

    • uint32 profitMaxUnlockTime: Maximum profit unlocking duration.

    • uint16 performanceFee: Percentage of performance fees.

    • address performanceFeeRecipient: Address receiving performance fees.

    • uint96 lastReport: Timestamp of the last report.

  3. Access Control:

    • address management: Current management address.

    • address pendingManagement: Pending management address.

    • address keeper: Keeper address for routine operations.

    • address emergencyAdmin: Emergency administrator address.

  4. Status:

    • uint8 entered: Reentrancy guard state.

    • bool shutdown: Emergency shutdown status.

Each BaseStrategy, including Term Strategy Vaults, maintains an isolated instance of this data structure in the fixed BASE_STRATEGY_STORAGE slot. Logic from the TokenizedStrategy interacts with this storage via delegatecall, ensuring modularity and isolation for all strategies.

Last updated