Skip to main content

Creating and Managing Earn Vaults

Euler Earn makes it easy for DAOs, risk curators, and individuals to create new yield-aggregating vaults. Vaults are deployed using the Euler Earn Factory, which ensures each vault is initialized with the correct parameters and access controls.

Deploying a New Vault

To create a new Earn vault, use the factory contract and specify:

  • The underlying asset (ERC-20 token)
  • Vault name and symbol
  • Initial cash reserve allocation (for instant withdrawals)
  • Yield smearing period (how quickly harvested yield is distributed)
  • Performance fee (optional, up to 50%)
  • Immutability flag (if set, all roles are revoked after deployment)
// Deploy a DAI Earn vault with 30% cash reserve and 2-day smearing
address earnVault = eulerEarnFactory.deployEulerEarn(
DAI_ADDRESS,
"Euler Earn DAI",
"eDAI",
3000, // 30% cash reserve
172800 // 2 days smearing period
);

For a more comprehensive, step-by-step walkthrough and additional best practices, see the Creator Tools guide. The Creator Tools section provides detailed instructions, examples, and advanced tips for deploying, configuring, and managing vaults in a production environment.

Key Processes

Rebalancing

Rebalancing maintains target allocations between strategies:

  1. Calculate target allocation for each strategy: (total allocatable assets * strategy allocation points) / total allocation points
  2. For each strategy:
    • If current allocation < target: Deposit the difference (limited by available cash)
    • If current allocation > target: Withdraw the difference (limited by withdrawable amount)
// Create an array of strategies to rebalance
address[] memory strategiesToRebalance = new address[](2);
strategiesToRebalance[0] = DAI_LENDING_VAULT_ADDRESS;
strategiesToRebalance[1] = DAI_YEARN_VAULT_ADDRESS;

// Trigger rebalancing
IEulerEarn(earnVault).rebalance(strategiesToRebalance);

Harvesting

Harvesting collects yield from all strategies:

  1. Loop through strategies in withdrawal queue order
  2. Calculate yield as: strategy.previewRedeem(shares) - strategy.allocated
  3. Aggregate total yield (positive or negative)
  4. Apply performance fee if yield is positive
  5. If yield is negative, apply loss deduction
// Anyone can trigger harvesting
IEulerEarn(earnVault).harvest();

Interest Smearing

To prevent sudden exchange rate jumps:

  1. Harvested yield is added to a separate accounting variable
  2. Over the configured smearing period, yield is gradually released
  3. The gulp() function triggers distribution of pending interest

Loss Deduction

When a strategy loses value:

  1. First attempt to deduct loss from undistributed interest
  2. If insufficient, socialize the remaining loss among all depositors
  3. This reduces the vault's exchange rate, affecting all depositors equally

Managing Strategies and Allocations

Adding Strategies

// Add a DAI lending vault as a strategy with 5000 allocation points
// The actual percentage depends on total allocation points across all strategies
IEulerEarn(earnVault).addStrategy(
DAI_LENDING_VAULT_ADDRESS,
5000 // allocation points
);

// Add a second strategy with 2000 allocation points
// If total allocation points is 10000, this strategy would get 20% of assets
IEulerEarn(earnVault).addStrategy(
DAI_YEARN_VAULT_ADDRESS,
2000 // allocation points
);

Setting Strategy Caps

// Set maximum allocation caps for strategies
// Note: Caps are not specified in basis points or percentages, but use the same special encoding as EVK vaults. See the EVK docs for details on cap encoding.
IEulerEarn(earnVault).setStrategyCap(DAI_LENDING_VAULT, capValue); // capValue uses special encoding
IEulerEarn(earnVault).setStrategyCap(DAI_YEARN_VAULT, capValue); // capValue uses special encoding

Adjusting Allocations

// Adjust allocation points for existing strategies
// The new percentage will be: newPoints / totalAllocationPoints
IEulerEarn(earnVault).adjustAllocationPoints(DAI_LENDING_VAULT, 6000); // new allocation points

Integration Points

ERC-4626 Compatibility

Euler Earn implements the standard ERC-4626 interface:

// Deposit assets and receive shares
function deposit(uint256 assets, address receiver) external returns (uint256 shares);

// Mint exact shares by providing assets
function mint(uint256 shares, address receiver) external returns (uint256 assets);

// Withdraw exact assets by burning shares
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

// Redeem exact shares for assets
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);

ERC20Votes Support

Native integration with ERC20Votes contract for Compound-like voting and delegation.

Hooks System

Customizable hook system for extending functionality:

  • Before deposits/mints
  • Before withdrawals/redeems
  • Before adding a strategy
  • Before removing a strategy

Rewards Management

Built-in system for handling strategy rewards:

  • Opt in/out of strategy rewards
  • Enable/disable specific reward tokens
  • Claim rewards to designated recipients

Roles and Access Control

Euler Earn uses a robust, modular role-based access control system. Each role is designed for granular, secure management of vault operations. Roles and their permissions are as follows:

  • Default Admin:

    • The top-level admin for the vault. Can assign or revoke any other role, including itself. Has full control over vault governance and access control.
  • Guardian:

    • Can set allocation caps for strategies (limit how much can be allocated to each strategy).
    • Can adjust allocation points (change the target allocation for each strategy).
    • Can set a strategy's status to Emergency (circuit-breaker) or revert it to Active. This is critical for risk management and emergency response.
  • Strategy Operator:

    • Can add new strategies (ERC-4626 vaults) to the Earn vault or remove existing ones. Controls which yield sources are available to the vault.
  • Euler Earn Manager:

    • Can set the performance fee and its recipient.
    • Can opt in/out of strategy rewards, enable/disable/claim rewards.
    • Can set hooks configuration for custom logic.
    • Can skim non-core tokens (not the vault's asset or strategy shares) from the vault to a recipient.
  • Withdrawal Queue Manager:

    • Can reorder the withdrawal queue, optimizing the order in which strategies are tapped for withdrawals and yield harvesting.
  • Rebalancer:

    • Can trigger rebalancing of assets between strategies to maintain target allocations.

Admin Roles: Each of the above roles (except Default Admin) has a corresponding admin role (e.g., GUARDIAN_ADMIN) that can assign or revoke that specific role. This allows for secure delegation and separation of duties.