Skip to main content

Integration guide

This guide provides developers with information on how to integrate with the Euler Earn protocol, including deploying new vaults, managing strategies, and interacting with existing vaults.

Deploying an Earn vault

To deploy a new Euler Earn vault, use the EulerEarnFactory contract:

function deployEulerEarn(
address _asset,
string memory _name,
string memory _symbol,
uint256 _initialCashAllocationPoints,
uint24 _smearingPeriod
) external returns (address);

Parameters:

  • _asset: The address of the underlying ERC-20 token
  • _name: The name for the vault shares token (e.g., "Euler Earn DAI")
  • _symbol: The symbol for the vault shares token (e.g., "eDAI")
  • _initialCashAllocationPoints: Initial allocation points for the cash reserve
  • _smearingPeriod: The period (in seconds) over which harvested yield is distributed

Example:

// 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
);

Managing strategies

Adding strategies

Once a vault is deployed, you can add strategies to it. Only addresses with the STRATEGY_OPERATOR role can add strategies:

function addStrategy(address _strategy, uint256 _allocationPoints) external;

Parameters:

  • _strategy: The address of the ERC-4626 strategy vault
  • _allocationPoints: The allocation points to assign to this strategy

Example:

// Add a DAI lending vault as a strategy with 50% allocation
IEulerEarn(earnVault).addStrategy(
DAI_LENDING_VAULT_ADDRESS,
5000 // 50% allocation
);

// Add a second strategy with 20% allocation
IEulerEarn(earnVault).addStrategy(
DAI_YEARN_VAULT_ADDRESS,
2000 // 20% allocation
);

Adjusting allocation points

The GUARDIAN role can adjust allocation points for existing strategies:

function adjustAllocationPoints(address _strategy, uint256 _newPoints) external;

Setting strategy caps

The GUARDIAN role can set maximum caps for strategies:

function setStrategyCap(address _strategy, uint16 _cap) external;

The cap is a percentage (0-10000) representing the maximum percentage of total assets that can be allocated to this strategy.

Removing strategies

The STRATEGY_OPERATOR role can remove strategies that have zero allocation:

function removeStrategy(address _strategy) external;

Rebalancing

The REBALANCER role can trigger rebalancing to reallocate funds between strategies:

function rebalance(address[] calldata _strategies) external;

Example:

// 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

Anyone can trigger harvesting of yields from strategies:

function harvest() external;

Harvesting has a 1-day cooldown period, except when called directly (not via withdraw/redeem).

ERC-4626 interface

As an ERC-4626 vault, Euler Earn implements the standard deposit, withdraw, mint, and redeem functions:

// 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);

Working with existing vaults

Finding vaults

To find existing Euler Earn vaults, use these factory methods:

// Get the number of deployed vaults
function getEulerEarnVaultsListLength() external view returns (uint256);

// Get a specific vault by index
function eulerEarnVaults(uint256 index) external view returns (address);

// Get a slice of the deployed vaults
function getEulerEarnVaultsListSlice(uint256 _start, uint256 _end)
external view returns (address[] memory);

// Verify if an address is a valid Euler Earn vault
function isValidDeployment(address _earnVaultAddress) external view returns (bool);

Vault information

To get information about a specific vault:

// Total assets in the vault (including allocated to strategies)
function totalAssets() external view returns (uint256);

// Assets allocated to strategies (excluding cash reserve)
function totalAllocated() external view returns (uint256);

// Total user deposits
function totalAssetsDeposited() external view returns (uint256);

// Amount available for allocation
function totalAssetsAllocatable() external view returns (uint256);

// Get specific strategy information
function getStrategy(address _strategy) external view returns (Strategy memory);

// Get the withdrawal queue
function withdrawalQueue() external view returns (address[] memory);

// Performance fee configuration
function performanceFeeConfig() external view returns (address, uint96);

Example integration flow

Here's a complete example of deploying and configuring an Earn vault:

// 1. Deploy the vault
address earnVault = eulerEarnFactory.deployEulerEarn(
USDC_ADDRESS,
"Euler Earn USDC",
"eUSDC",
2000, // 20% cash reserve
86400 // 1 day smearing period
);

// 2. Add strategies
IEulerEarn(earnVault).addStrategy(USDC_LENDING_VAULT, 5000); // 50%
IEulerEarn(earnVault).addStrategy(USDC_STABLE_YIELD_VAULT, 3000); // 30%

// 3. Set strategy caps
IEulerEarn(earnVault).setStrategyCap(USDC_LENDING_VAULT, 7000); // max 70%
IEulerEarn(earnVault).setStrategyCap(USDC_STABLE_YIELD_VAULT, 5000); // max 50%

// 4. Configure performance fee
IEulerEarn(earnVault).setPerformanceFee(1000); // 10%
IEulerEarn(earnVault).setFeeRecipient(FEE_COLLECTOR_ADDRESS);

// 5. Trigger initial rebalance
address[] memory strategies = new address[](2);
strategies[0] = USDC_LENDING_VAULT;
strategies[1] = USDC_STABLE_YIELD_VAULT;
IEulerEarn(earnVault).rebalance(strategies);

For a comprehensive overview of security considerations when working with Euler Earn, please see the Security section.