Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Rename to Euler Aggregation Vault #35

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IBalanceTracker} from "reward-streams/interfaces/IBalanceTracker.sol";
import {IEulerAggregationLayer} from "./interface/IEulerAggregationLayer.sol";
import {IEulerAggregationVault} from "./interface/IEulerAggregationVault.sol";
import {IWithdrawalQueue} from "./interface/IWithdrawalQueue.sol";
// contracts
import {Dispatch} from "./Dispatch.sol";
Expand All @@ -25,17 +25,17 @@ import {StorageLib, AggregationVaultStorage} from "./lib/StorageLib.sol";
import {ErrorsLib as Errors} from "./lib/ErrorsLib.sol";
import {EventsLib as Events} from "./lib/EventsLib.sol";

/// @title EulerAggregationLayer contract
/// @title EulerAggregationVault contract
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @dev Do NOT use with fee on transfer tokens
/// @dev Do NOT use with rebasing tokens
/// @dev inspired by Yearn v3 ❤️
contract EulerAggregationLayer is
contract EulerAggregationVault is
ERC4626Upgradeable,
AccessControlEnumerableUpgradeable,
Dispatch,
IEulerAggregationLayer
IEulerAggregationVault
{
using SafeERC20 for IERC20;
using SafeCast for uint256;
Expand All @@ -57,7 +57,7 @@ contract EulerAggregationLayer is
Dispatch(_rewardsModule, _hooksModule, _feeModule, _allocationPointsModule)
{}

/// @notice Initialize the EulerAggregationLayer.
/// @notice Initialize the EulerAggregationVault.
/// @param _initParams InitParams struct.
function init(InitParams calldata _initParams) external initializer {
__ERC4626_init_unchained(IERC20(_initParams.asset));
Expand All @@ -70,7 +70,7 @@ contract EulerAggregationLayer is
$.locked = REENTRANCYLOCK__UNLOCKED;
$.withdrawalQueue = _initParams.withdrawalQueuePlugin;
$.rebalancer = _initParams.rebalancerPlugin;
$.strategies[address(0)] = IEulerAggregationLayer.Strategy({
$.strategies[address(0)] = IEulerAggregationVault.Strategy({
allocated: 0,
allocationPoints: _initParams.initialCashAllocationPoints.toUint120(),
active: true,
Expand All @@ -80,7 +80,7 @@ contract EulerAggregationLayer is
$.balanceTracker = _initParams.balanceTracker;

// Setup DEFAULT_ADMIN
_grantRole(DEFAULT_ADMIN_ROLE, _initParams.aggregationLayerOwner);
_grantRole(DEFAULT_ADMIN_ROLE, _initParams.aggregationVaultOwner);

// Setup role admins
_setRoleAdmin(ALLOCATIONS_MANAGER, ALLOCATIONS_MANAGER_ADMIN);
Expand Down Expand Up @@ -209,7 +209,7 @@ contract EulerAggregationLayer is

if (_msgSender() != $.rebalancer) revert Errors.NotRebalancer();

IEulerAggregationLayer.Strategy memory strategyData = $.strategies[_strategy];
IEulerAggregationVault.Strategy memory strategyData = $.strategies[_strategy];

if (_isDeposit) {
// Do required approval (safely) and deposit
Expand Down Expand Up @@ -289,7 +289,7 @@ contract EulerAggregationLayer is
/// @notice Get strategy params.
/// @param _strategy strategy's address
/// @return Strategy struct
function getStrategy(address _strategy) external view returns (IEulerAggregationLayer.Strategy memory) {
function getStrategy(address _strategy) external view returns (IEulerAggregationVault.Strategy memory) {
AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();

return $.strategies[_strategy];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {Rewards} from "./module/Rewards.sol";
import {Hooks} from "./module/Hooks.sol";
import {Fee} from "./module/Fee.sol";
import {WithdrawalQueue} from "../plugin/WithdrawalQueue.sol";
import {EulerAggregationLayer, IEulerAggregationLayer} from "./EulerAggregationLayer.sol";
import {EulerAggregationVault, IEulerAggregationVault} from "./EulerAggregationVault.sol";
// libs
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";

/// @title EulerAggregationLayerFactory contract
/// @title EulerAggregationVaultFactory contract
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
contract EulerAggregationLayerFactory {
contract EulerAggregationVaultFactory {
/// core dependencies
address public immutable balanceTracker;
/// core modules implementations addresses
Expand Down Expand Up @@ -59,8 +59,8 @@ contract EulerAggregationLayerFactory {
/// @param _name Vaut name.
/// @param _symbol Vault symbol.
/// @param _initialCashAllocationPoints The amount of points to initally allocate for cash reserve.
/// @return eulerAggregationLayer The address of the new deployed aggregation layer vault.
function deployEulerAggregationLayer(
/// @return eulerAggregationVault The address of the new deployed aggregation layer vault.
function deployEulerAggregationVault(
address _asset,
string memory _name,
string memory _symbol,
Expand All @@ -76,23 +76,23 @@ contract EulerAggregationLayerFactory {
WithdrawalQueue withdrawalQueue = WithdrawalQueue(Clones.clone(withdrawalQueueImpl));

// deploy new aggregation vault
EulerAggregationLayer eulerAggregationLayer =
new EulerAggregationLayer(rewardsModuleAddr, hooksModuleAddr, feeModuleAddr, allocationpointsModuleAddr);
EulerAggregationVault eulerAggregationVault =
new EulerAggregationVault(rewardsModuleAddr, hooksModuleAddr, feeModuleAddr, allocationpointsModuleAddr);

IEulerAggregationLayer.InitParams memory aggregationVaultInitParams = IEulerAggregationLayer.InitParams({
IEulerAggregationVault.InitParams memory aggregationVaultInitParams = IEulerAggregationVault.InitParams({
balanceTracker: balanceTracker,
withdrawalQueuePlugin: address(withdrawalQueue),
rebalancerPlugin: rebalancer,
aggregationLayerOwner: msg.sender,
aggregationVaultOwner: msg.sender,
asset: _asset,
name: _name,
symbol: _symbol,
initialCashAllocationPoints: _initialCashAllocationPoints
});

withdrawalQueue.init(msg.sender, address(eulerAggregationLayer));
eulerAggregationLayer.init(aggregationVaultInitParams);
withdrawalQueue.init(msg.sender, address(eulerAggregationVault));
eulerAggregationVault.init(aggregationVaultInitParams);

return address(eulerAggregationLayer);
return address(eulerAggregationVault);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

interface IEulerAggregationLayer {
interface IEulerAggregationVault {
/// @dev Struct to pass init() call params.
struct InitParams {
address balanceTracker;
address withdrawalQueuePlugin;
address rebalancerPlugin;
address aggregationLayerOwner;
address aggregationVaultOwner;
address asset;
string name;
string symbol;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/EventsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

library EventsLib {
/// @dev EulerAggregationLayer events
/// @dev EulerAggregationVault events
event Gulp(uint256 interestLeft, uint256 interestSmearEnd);
event AccruePerformanceFee(address indexed feeRecipient, uint256 yield, uint256 feeAssets);
event Rebalance(address indexed strategy, uint256 amountToRebalance, bool isDeposit);
Expand Down
6 changes: 3 additions & 3 deletions src/core/lib/StorageLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity ^0.8.0;

// interfaces
import {IEulerAggregationLayer} from "../interface/IEulerAggregationLayer.sol";
import {IEulerAggregationVault} from "../interface/IEulerAggregationVault.sol";

/// @custom:storage-location erc7201:euler_aggregation_vault.storage.AggregationVault
struct AggregationVaultStorage {
/// Total amount of _asset deposited into EulerAggregationLayer contract
/// Total amount of _asset deposited into EulerAggregationVault contract
uint256 totalAssetsDeposited;
/// Total amount of _asset deposited across all strategies.
uint256 totalAllocated;
Expand All @@ -21,7 +21,7 @@ struct AggregationVaultStorage {
/// Rebalancer plugin address
address rebalancer;
/// Mapping between strategy address and it's allocation config
mapping(address => IEulerAggregationLayer.Strategy) strategies;
mapping(address => IEulerAggregationVault.Strategy) strategies;
/// lastInterestUpdate: last timestamo where interest was updated.
uint40 lastInterestUpdate;
/// interestSmearEnd: timestamp when the smearing of interest end.
Expand Down
8 changes: 4 additions & 4 deletions src/core/module/AllocationPoints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
// interfaces
import {IERC4626} from "@openzeppelin-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {IWithdrawalQueue} from "../interface/IWithdrawalQueue.sol";
import {IEulerAggregationLayer} from "../interface/IEulerAggregationLayer.sol";
import {IEulerAggregationVault} from "../interface/IEulerAggregationVault.sol";
// contracts
import {Shared} from "../common/Shared.sol";
// libs
Expand All @@ -27,7 +27,7 @@ abstract contract AllocationPointsModule is Shared {
AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();

if (_newPoints == 0) revert Errors.InvalidAllocationPoints();
IEulerAggregationLayer.Strategy memory strategyDataCache = $.strategies[_strategy];
IEulerAggregationVault.Strategy memory strategyDataCache = $.strategies[_strategy];

if (!strategyDataCache.active) {
revert Errors.InactiveStrategy();
Expand Down Expand Up @@ -74,7 +74,7 @@ abstract contract AllocationPointsModule is Shared {

_callHooksTarget(ADD_STRATEGY, msg.sender);

$.strategies[_strategy] = IEulerAggregationLayer.Strategy({
$.strategies[_strategy] = IEulerAggregationVault.Strategy({
allocated: 0,
allocationPoints: _allocationPoints.toUint120(),
active: true,
Expand All @@ -96,7 +96,7 @@ abstract contract AllocationPointsModule is Shared {

AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();

IEulerAggregationLayer.Strategy storage strategyStorage = $.strategies[_strategy];
IEulerAggregationVault.Strategy storage strategyStorage = $.strategies[_strategy];

if (!strategyStorage.active) {
revert Errors.AlreadyRemoved();
Expand Down
36 changes: 18 additions & 18 deletions src/plugin/Rebalancer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity ^0.8.0;

// interfaces
import {IEulerAggregationLayer} from "../core/interface/IEulerAggregationLayer.sol";
import {IEulerAggregationVault} from "../core/interface/IEulerAggregationVault.sol";
import {IERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";

/// @title Rebalancer plugin
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice A contract to execute rebalance() on the EulerAggregationLayer.
/// @notice A contract to execute rebalance() on the EulerAggregationVault.
contract Rebalancer {
event ExecuteRebalance(
address indexed curatedVault,
Expand All @@ -19,32 +19,32 @@ contract Rebalancer {
);

/// @notice Rebalance strategies allocation for a specific curated vault.
/// @param _aggregationLayer Aggregation layer vault address.
/// @param _aggregationVault Aggregation layer vault address.
/// @param _strategies Strategies addresses.
function executeRebalance(address _aggregationLayer, address[] calldata _strategies) external {
IEulerAggregationLayer(_aggregationLayer).gulp();
function executeRebalance(address _aggregationVault, address[] calldata _strategies) external {
IEulerAggregationVault(_aggregationVault).gulp();

for (uint256 i; i < _strategies.length; ++i) {
_rebalance(_aggregationLayer, _strategies[i]);
_rebalance(_aggregationVault, _strategies[i]);
}
}

/// @dev If current allocation is greater than target allocation, the aggregator will withdraw the excess assets.
/// If current allocation is less than target allocation, the aggregator will:
/// - Try to deposit the delta, if the cash is not sufficient, deposit all the available cash
/// - If all the available cash is greater than the max deposit, deposit the max deposit
/// @param _aggregationLayer Aggregation layer vault address.
/// @param _aggregationVault Aggregation layer vault address.
/// @param _strategy Strategy address.
function _rebalance(address _aggregationLayer, address _strategy) private {
function _rebalance(address _aggregationVault, address _strategy) private {
if (_strategy == address(0)) {
return; //nothing to rebalance as that's the cash reserve
}

IEulerAggregationLayer.Strategy memory strategyData =
IEulerAggregationLayer(_aggregationLayer).getStrategy(_strategy);
IEulerAggregationVault.Strategy memory strategyData =
IEulerAggregationVault(_aggregationVault).getStrategy(_strategy);

uint256 totalAllocationPointsCache = IEulerAggregationLayer(_aggregationLayer).totalAllocationPoints();
uint256 totalAssetsAllocatableCache = IEulerAggregationLayer(_aggregationLayer).totalAssetsAllocatable();
uint256 totalAllocationPointsCache = IEulerAggregationVault(_aggregationVault).totalAllocationPoints();
uint256 totalAssetsAllocatableCache = IEulerAggregationVault(_aggregationVault).totalAssetsAllocatable();
uint256 targetAllocation =
totalAssetsAllocatableCache * strategyData.allocationPoints / totalAllocationPointsCache;

Expand All @@ -56,7 +56,7 @@ contract Rebalancer {
// Withdraw
amountToRebalance = strategyData.allocated - targetAllocation;

uint256 maxWithdraw = IERC4626(_strategy).maxWithdraw(_aggregationLayer);
uint256 maxWithdraw = IERC4626(_strategy).maxWithdraw(_aggregationVault);
if (amountToRebalance > maxWithdraw) {
amountToRebalance = maxWithdraw;
}
Expand All @@ -65,10 +65,10 @@ contract Rebalancer {
} else if (strategyData.allocated < targetAllocation) {
// Deposit
uint256 targetCash = totalAssetsAllocatableCache
* IEulerAggregationLayer(_aggregationLayer).getStrategy(address(0)).allocationPoints
* IEulerAggregationVault(_aggregationVault).getStrategy(address(0)).allocationPoints
/ totalAllocationPointsCache;
uint256 currentCash =
totalAssetsAllocatableCache - IEulerAggregationLayer(_aggregationLayer).totalAllocated();
totalAssetsAllocatableCache - IEulerAggregationVault(_aggregationVault).totalAllocated();

// Calculate available cash to put in strategies
uint256 cashAvailable = (currentCash > targetCash) ? currentCash - targetCash : 0;
Expand All @@ -78,7 +78,7 @@ contract Rebalancer {
amountToRebalance = cashAvailable;
}

uint256 maxDeposit = IERC4626(_strategy).maxDeposit(_aggregationLayer);
uint256 maxDeposit = IERC4626(_strategy).maxDeposit(_aggregationVault);
if (amountToRebalance > maxDeposit) {
amountToRebalance = maxDeposit;
}
Expand All @@ -90,8 +90,8 @@ contract Rebalancer {
isDeposit = true;
}

IEulerAggregationLayer(_aggregationLayer).rebalance(_strategy, amountToRebalance, isDeposit);
IEulerAggregationVault(_aggregationVault).rebalance(_strategy, amountToRebalance, isDeposit);

emit ExecuteRebalance(_aggregationLayer, _strategy, strategyData.allocated, targetAllocation, amountToRebalance);
emit ExecuteRebalance(_aggregationVault, _strategy, strategyData.allocated, targetAllocation, amountToRebalance);
}
}
8 changes: 4 additions & 4 deletions src/plugin/WithdrawalQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

// interfaces
import {IERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {IEulerAggregationLayer} from "../core/interface/IEulerAggregationLayer.sol";
import {IEulerAggregationVault} from "../core/interface/IEulerAggregationVault.sol";
import {IWithdrawalQueue} from "../core/interface/IWithdrawalQueue.sol";
// contracts
import {AccessControlEnumerableUpgradeable} from
Expand All @@ -14,7 +14,7 @@ import {AccessControlEnumerableUpgradeable} from
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This contract manage the withdrawalQueue aray(add/remove strategy to the queue, re-order queue).
/// Also it handles finishing the withdraw execution flow through the `callWithdrawalQueue()` function
/// that will be called by the EulerAggregationLayer.
/// that will be called by the EulerAggregationVault.
contract WithdrawalQueue is AccessControlEnumerableUpgradeable, IWithdrawalQueue {
error OutOfBounds();
error SameIndexes();
Expand Down Expand Up @@ -132,7 +132,7 @@ contract WithdrawalQueue is AccessControlEnumerableUpgradeable, IWithdrawalQueue
uint256 desiredAssets = _assets - _availableAssets;
uint256 withdrawAmount = (underlyingBalance > desiredAssets) ? desiredAssets : underlyingBalance;

IEulerAggregationLayer(eulerAggregationVaultCached).executeStrategyWithdraw(
IEulerAggregationVault(eulerAggregationVaultCached).executeStrategyWithdraw(
address(strategy), withdrawAmount
);

Expand All @@ -150,7 +150,7 @@ contract WithdrawalQueue is AccessControlEnumerableUpgradeable, IWithdrawalQueue
revert NotEnoughAssets();
}

IEulerAggregationLayer(eulerAggregationVaultCached).executeAggregationVaultWithdraw(
IEulerAggregationVault(eulerAggregationVaultCached).executeAggregationVaultWithdraw(
_caller, _receiver, _owner, _assets, _shares
);
}
Expand Down
Loading
Loading