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 #31

Merged
merged 2 commits into from
Jun 27, 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
11 changes: 8 additions & 3 deletions src/Dispatch.sol → src/core/Dispatch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

//contracts
import {Shared} from "./Shared.sol";
import {Shared} from "./common/Shared.sol";
import {HooksModule} from "./module/Hooks.sol";
import {RewardsModule} from "./module/Rewards.sol";

Expand All @@ -17,6 +17,11 @@ abstract contract Dispatch is RewardsModule, HooksModule {
address public immutable MODULE_FEE;
address public immutable MODULE_ALLOCATION_POINTS;

/// @dev Constructor.
/// @param _rewardsModule Address of Rewards module.
/// @param _hooksModule Address of Hooks module.
/// @param _feeModule Address of Fee module.
/// @param _allocationPointsModule Address of AllocationPoints module.
constructor(address _rewardsModule, address _hooksModule, address _feeModule, address _allocationPointsModule)
Shared()
{
Expand All @@ -29,10 +34,10 @@ abstract contract Dispatch is RewardsModule, HooksModule {
// Modifier proxies the function call to a module and low-level returns the result
modifier use(address module) {
_; // when using the modifier, it is assumed the function body is empty.
delegateToModule(module);
_delegateToModule(module);
}

function delegateToModule(address module) private {
function _delegateToModule(address module) private {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), module, 0, calldatasize(), 0, 0)
Expand Down
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 {IAggregationLayerVault} from "./interface/IAggregationLayerVault.sol";
import {IEulerAggregationLayer} from "./interface/IEulerAggregationLayer.sol";
import {IWithdrawalQueue} from "./interface/IWithdrawalQueue.sol";
// contracts
import {Dispatch} from "./Dispatch.sol";
Expand All @@ -15,7 +15,7 @@ import {
} from "@openzeppelin-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {AccessControlEnumerableUpgradeable} from
"@openzeppelin-upgradeable/access/extensions/AccessControlEnumerableUpgradeable.sol";
import {Shared} from "./Shared.sol";
import {Shared} from "./common/Shared.sol";
import {ContextUpgradeable} from "@openzeppelin-upgradeable/utils/ContextUpgradeable.sol";
// libs
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.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 AggregationLayerVault contract
/// @title EulerAggregationLayer 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 AggregationLayerVault is
contract EulerAggregationLayer is
ERC4626Upgradeable,
AccessControlEnumerableUpgradeable,
Dispatch,
IAggregationLayerVault
IEulerAggregationLayer
{
using SafeERC20 for IERC20;
using SafeCast for uint256;
Expand All @@ -59,7 +59,7 @@ contract AggregationLayerVault is
Dispatch(_rewardsModule, _hooksModule, _feeModule, _allocationPointsModule)
{}

/// @notice Initialize the AggregationLayerVault.
/// @notice Initialize the EulerAggregationLayer.
/// @param _initParams InitParams struct.
function init(InitParams calldata _initParams) external initializer {
__ERC4626_init_unchained(IERC20(_initParams.asset));
Expand All @@ -69,8 +69,8 @@ contract AggregationLayerVault is

AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();
$.locked = REENTRANCYLOCK__UNLOCKED;
$.withdrawalQueue = _initParams.withdrawalQueuePeriphery;
$.strategies[address(0)] = IAggregationLayerVault.Strategy({
$.withdrawalQueue = _initParams.withdrawalQueuePlugin;
$.strategies[address(0)] = IEulerAggregationLayer.Strategy({
allocated: 0,
allocationPoints: _initParams.initialCashAllocationPoints.toUint120(),
active: true,
Expand All @@ -82,15 +82,16 @@ contract AggregationLayerVault is

// Setup DEFAULT_ADMIN
_grantRole(DEFAULT_ADMIN_ROLE, _initParams.aggregationVaultOwner);
// By default, the Rebalancer contract is assigned the REBALANCER role
_grantRole(REBALANCER, _initParams.rebalancerPerihpery);

// Setup role admins
_setRoleAdmin(ALLOCATIONS_MANAGER, ALLOCATIONS_MANAGER_ADMIN);
_setRoleAdmin(STRATEGY_ADDER, STRATEGY_ADDER_ADMIN);
_setRoleAdmin(STRATEGY_REMOVER, STRATEGY_REMOVER_ADMIN);
_setRoleAdmin(AGGREGATION_VAULT_MANAGER, AGGREGATION_VAULT_MANAGER_ADMIN);
_setRoleAdmin(REBALANCER, REBALANCER_ADMIN);

// By default, the Rebalancer contract is assigned the REBALANCER role
_grantRole(REBALANCER, _initParams.rebalancerPlugin);
}

/// @dev See {FeeModule-setFeeRecipient}.
Expand Down Expand Up @@ -189,7 +190,7 @@ contract AggregationLayerVault is
{
AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();

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

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

return $.strategies[_strategy];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ pragma solidity ^0.8.0;
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 {AggregationLayerVault, IAggregationLayerVault} from "./AggregationLayerVault.sol";
import {WithdrawalQueue} from "../plugin/WithdrawalQueue.sol";
import {EulerAggregationLayer, IEulerAggregationLayer} from "./EulerAggregationLayer.sol";
// libs
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";

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

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

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

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

return address(aggregationLayerVault);
return address(eulerAggregationLayer);
}
}
6 changes: 3 additions & 3 deletions src/Shared.sol → src/core/common/Shared.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ pragma solidity ^0.8.0;
import {IEVC} from "ethereum-vault-connector/utils/EVCUtil.sol";
import {IHookTarget} from "evk/src/interfaces/IHookTarget.sol";
// libs
import {StorageLib, AggregationVaultStorage} from "./lib/StorageLib.sol";
import {HooksLib} from "./lib/HooksLib.sol";
import {ErrorsLib as Errors} from "./lib/ErrorsLib.sol";
import {StorageLib, AggregationVaultStorage} from "../lib/StorageLib.sol";
import {HooksLib} from "../lib/HooksLib.sol";
import {ErrorsLib as Errors} from "../lib/ErrorsLib.sol";

/// @title Shared contract
/// @custom:security-contact [email protected]
Expand Down
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 IAggregationLayerVault {
interface IEulerAggregationLayer {
/// @dev Struct to pass init() call params.
struct InitParams {
address evc;
address balanceTracker;
address withdrawalQueuePeriphery;
address rebalancerPerihpery;
address withdrawalQueuePlugin;
address rebalancerPlugin;
address aggregationVaultOwner;
address asset;
string name;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/EventsLib.sol → 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 AggregationLayerVault events
/// @dev EulerAggregationLayer 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
File renamed without changes.
11 changes: 3 additions & 8 deletions src/lib/StorageLib.sol → src/core/lib/StorageLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity ^0.8.0;

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

/// @custom:storage-location erc7201:euler_aggregation_vault.storage.AggregationVault
struct AggregationVaultStorage {
/// EVC address
address evc;
/// Total amount of _asset deposited into AggregationLayerVault contract
/// Total amount of _asset deposited into EulerAggregationLayer contract
uint256 totalAssetsDeposited;
/// Total amount of _asset deposited across all strategies.
uint256 totalAllocated;
Expand All @@ -21,9 +21,7 @@ struct AggregationVaultStorage {
/// Withdrawal queue contract's address
address withdrawalQueue;
/// Mapping between strategy address and it's allocation config
mapping(address => IAggregationLayerVault.Strategy) strategies;


mapping(address => IEulerAggregationLayer.Strategy) strategies;
/// lastInterestUpdate: last timestamo where interest was updated.
uint40 lastInterestUpdate;
/// interestSmearEnd: timestamp when the smearing of interest end.
Expand All @@ -32,13 +30,10 @@ struct AggregationVaultStorage {
uint168 interestLeft;
/// locked: if locked or not for update.
uint8 locked;

/// Address of balance tracker contract for reward streams integration.
address balanceTracker;
/// A mapping to check if a user address enabled balance forwarding for reward streams integration.
mapping(address => bool) isBalanceForwarderEnabled;


/// @dev storing the hooks target and kooked functions.
uint256 hooksConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity ^0.8.0;
// interfaces
import {IERC4626} from "@openzeppelin-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {IWithdrawalQueue} from "../interface/IWithdrawalQueue.sol";
import {IAggregationLayerVault} from "../interface/IAggregationLayerVault.sol";
import {IEulerAggregationLayer} from "../interface/IEulerAggregationLayer.sol";
// contracts
import {Shared} from "../Shared.sol";
import {Shared} from "../common/Shared.sol";
// libs
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {StorageLib, AggregationVaultStorage} from "../lib/StorageLib.sol";
Expand All @@ -26,7 +26,7 @@ abstract contract AllocationPointsModule is Shared {
function adjustAllocationPoints(address _strategy, uint256 _newPoints) external virtual nonReentrant {
AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();

IAggregationLayerVault.Strategy memory strategyDataCache = $.strategies[_strategy];
IEulerAggregationLayer.Strategy memory strategyDataCache = $.strategies[_strategy];

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

_callHooksTarget(ADD_STRATEGY, _msgSender());

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

AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage();

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

if (!strategyStorage.active) {
revert Errors.AlreadyRemoved();
Expand Down
2 changes: 1 addition & 1 deletion src/module/Fee.sol → src/core/module/Fee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {IBalanceTracker} from "reward-streams/interfaces/IBalanceTracker.sol";
import {IRewardStreams} from "reward-streams/interfaces/IRewardStreams.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// contracts
import {Shared} from "../Shared.sol";
import {Shared} from "../common/Shared.sol";
// libs
import {StorageLib, AggregationVaultStorage} from "../lib/StorageLib.sol";
import {ErrorsLib as Errors} from "../lib/ErrorsLib.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/module/Hooks.sol → src/core/module/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
// interfaces
import {IHookTarget} from "evk/src/interfaces/IHookTarget.sol";
// contracts
import {Shared} from "../Shared.sol";
import {Shared} from "../common/Shared.sol";
// libs
import {StorageLib, AggregationVaultStorage} from "../lib/StorageLib.sol";
import {HooksLib} from "../lib/HooksLib.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/module/Rewards.sol → src/core/module/Rewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {IBalanceTracker} from "reward-streams/interfaces/IBalanceTracker.sol";
import {IRewardStreams} from "reward-streams/interfaces/IRewardStreams.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// contracts
import {Shared} from "../Shared.sol";
import {Shared} from "../common/Shared.sol";
// libs
import {StorageLib, AggregationVaultStorage} from "../lib/StorageLib.sol";
import {ErrorsLib as Errors} from "../lib/ErrorsLib.sol";
Expand Down
20 changes: 10 additions & 10 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 {IAggregationLayerVault} from "../interface/IAggregationLayerVault.sol";
import {IEulerAggregationLayer} from "../core/interface/IEulerAggregationLayer.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 AggregationLayerVault.
/// @notice A contract to execute rebalance() on the EulerAggregationLayer.
/// @dev Usually this contract will hold the `REBALANCER` role.
contract Rebalancer {
event ExecuteRebalance(
Expand All @@ -23,7 +23,7 @@ contract Rebalancer {
/// @param _curatedVault Curated vault address.
/// @param _strategies Strategies addresses.
function executeRebalance(address _curatedVault, address[] calldata _strategies) external {
IAggregationLayerVault(_curatedVault).gulp();
IEulerAggregationLayer(_curatedVault).gulp();

for (uint256 i; i < _strategies.length; ++i) {
_rebalance(_curatedVault, _strategies[i]);
Expand All @@ -41,11 +41,11 @@ contract Rebalancer {
return; //nothing to rebalance as that's the cash reserve
}

IAggregationLayerVault.Strategy memory strategyData =
IAggregationLayerVault(_curatedVault).getStrategy(_strategy);
IEulerAggregationLayer.Strategy memory strategyData =
IEulerAggregationLayer(_curatedVault).getStrategy(_strategy);

uint256 totalAllocationPointsCache = IAggregationLayerVault(_curatedVault).totalAllocationPoints();
uint256 totalAssetsAllocatableCache = IAggregationLayerVault(_curatedVault).totalAssetsAllocatable();
uint256 totalAllocationPointsCache = IEulerAggregationLayer(_curatedVault).totalAllocationPoints();
uint256 totalAssetsAllocatableCache = IEulerAggregationLayer(_curatedVault).totalAssetsAllocatable();
uint256 targetAllocation =
totalAssetsAllocatableCache * strategyData.allocationPoints / totalAllocationPointsCache;

Expand All @@ -66,9 +66,9 @@ contract Rebalancer {
} else if (strategyData.allocated < targetAllocation) {
// Deposit
uint256 targetCash = totalAssetsAllocatableCache
* IAggregationLayerVault(_curatedVault).getStrategy(address(0)).allocationPoints
* IEulerAggregationLayer(_curatedVault).getStrategy(address(0)).allocationPoints
/ totalAllocationPointsCache;
uint256 currentCash = totalAssetsAllocatableCache - IAggregationLayerVault(_curatedVault).totalAllocated();
uint256 currentCash = totalAssetsAllocatableCache - IEulerAggregationLayer(_curatedVault).totalAllocated();

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

IAggregationLayerVault(_curatedVault).rebalance(_strategy, amountToRebalance, isDeposit);
IEulerAggregationLayer(_curatedVault).rebalance(_strategy, amountToRebalance, isDeposit);

emit ExecuteRebalance(_curatedVault, _strategy, strategyData.allocated, targetAllocation, amountToRebalance);
}
Expand Down
Loading
Loading