From e09ae6292ece8093c8fc9abe27002e0158161be3 Mon Sep 17 00:00:00 2001 From: Haythem Sellami <17862704+haythemsellami@users.noreply.github.com> Date: Thu, 27 Jun 2024 19:00:16 +0300 Subject: [PATCH] remove dependency to the EVC --- src/core/EulerAggregationLayer.sol | 8 +------- src/core/EulerAggregationLayerFactory.sol | 4 ---- src/core/common/Shared.sol | 11 ----------- src/core/interface/IEulerAggregationLayer.sol | 1 - src/core/lib/StorageLib.sol | 2 -- src/core/module/AllocationPoints.sol | 4 ++-- src/core/module/Rewards.sol | 7 +++---- test/common/EulerAggregationLayerBase.t.sol | 3 +-- test/e2e/BalanceForwarderE2ETest.t.sol | 1 - 9 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/core/EulerAggregationLayer.sol b/src/core/EulerAggregationLayer.sol index ed321133..fc108298 100644 --- a/src/core/EulerAggregationLayer.sol +++ b/src/core/EulerAggregationLayer.sol @@ -77,7 +77,6 @@ contract EulerAggregationLayer is cap: 0 }); $.totalAllocationPoints = _initParams.initialCashAllocationPoints; - $.evc = _initParams.evc; $.balanceTracker = _initParams.balanceTracker; // Setup DEFAULT_ADMIN @@ -437,7 +436,7 @@ contract EulerAggregationLayer is AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage(); - if ($.totalAssetsDeposited == 0) return; + if (totalSupply() == 0) return; uint256 toGulp = totalAssetsAllocatable() - $.totalAssetsDeposited - $.interestLeft; if (toGulp == 0) return; @@ -592,11 +591,6 @@ contract EulerAggregationLayer is return $.interestLeft * timePassed / totalDuration; } - /// @dev Override for _msgSender() to be aware of the EVC forwarded calls. - function _msgSender() internal view override (ContextUpgradeable, Shared) returns (address) { - return Shared._msgSender(); - } - /// @dev Check if caller is WithdrawalQueue address, if not revert. function _isCallerWithdrawalQueue() internal view { AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage(); diff --git a/src/core/EulerAggregationLayerFactory.sol b/src/core/EulerAggregationLayerFactory.sol index 3d0c06e2..83ea71b3 100644 --- a/src/core/EulerAggregationLayerFactory.sol +++ b/src/core/EulerAggregationLayerFactory.sol @@ -15,7 +15,6 @@ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; /// @author Euler Labs (https://www.eulerlabs.com/) contract EulerAggregationLayerFactory { /// core dependencies - address public immutable evc; address public immutable balanceTracker; /// core modules implementations addresses address public immutable rewardsModuleImpl; @@ -30,7 +29,6 @@ contract EulerAggregationLayerFactory { /// @dev Init params struct. struct FactoryParams { - address evc; address balanceTracker; address rewardsModuleImpl; address hooksModuleImpl; @@ -43,7 +41,6 @@ contract EulerAggregationLayerFactory { /// @notice Constructor. /// @param _factoryParams FactoryParams struct. constructor(FactoryParams memory _factoryParams) { - evc = _factoryParams.evc; balanceTracker = _factoryParams.balanceTracker; rewardsModuleImpl = _factoryParams.rewardsModuleImpl; hooksModuleImpl = _factoryParams.hooksModuleImpl; @@ -83,7 +80,6 @@ contract EulerAggregationLayerFactory { new EulerAggregationLayer(rewardsModuleAddr, hooksModuleAddr, feeModuleAddr, allocationpointsModuleAddr); IEulerAggregationLayer.InitParams memory aggregationVaultInitParams = IEulerAggregationLayer.InitParams({ - evc: evc, balanceTracker: balanceTracker, withdrawalQueuePlugin: address(withdrawalQueue), rebalancerPlugin: rebalancer, diff --git a/src/core/common/Shared.sol b/src/core/common/Shared.sol index cd45771f..c503a595 100644 --- a/src/core/common/Shared.sol +++ b/src/core/common/Shared.sol @@ -38,17 +38,6 @@ contract Shared { $.locked = REENTRANCYLOCK__UNLOCKED; } - function _msgSender() internal view virtual returns (address) { - address sender = msg.sender; - AggregationVaultStorage storage $ = StorageLib._getAggregationVaultStorage(); - - if (sender == address($.evc)) { - (sender,) = IEVC($.evc).getCurrentOnBehalfOfAccount(address(0)); - } - - return sender; - } - function _setHooksConfig(address _hooksTarget, uint32 _hookedFns) internal { if (_hooksTarget != address(0) && IHookTarget(_hooksTarget).isHookTarget() != IHookTarget.isHookTarget.selector) { diff --git a/src/core/interface/IEulerAggregationLayer.sol b/src/core/interface/IEulerAggregationLayer.sol index cbabbb13..f516bee5 100644 --- a/src/core/interface/IEulerAggregationLayer.sol +++ b/src/core/interface/IEulerAggregationLayer.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.0; interface IEulerAggregationLayer { /// @dev Struct to pass init() call params. struct InitParams { - address evc; address balanceTracker; address withdrawalQueuePlugin; address rebalancerPlugin; diff --git a/src/core/lib/StorageLib.sol b/src/core/lib/StorageLib.sol index 4577cc0d..9bc480d8 100644 --- a/src/core/lib/StorageLib.sol +++ b/src/core/lib/StorageLib.sol @@ -6,8 +6,6 @@ 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 EulerAggregationLayer contract uint256 totalAssetsDeposited; /// Total amount of _asset deposited across all strategies. diff --git a/src/core/module/AllocationPoints.sol b/src/core/module/AllocationPoints.sol index 24d34f62..80d5e286 100644 --- a/src/core/module/AllocationPoints.sol +++ b/src/core/module/AllocationPoints.sol @@ -69,7 +69,7 @@ abstract contract AllocationPointsModule is Shared { revert Errors.InvalidStrategyAsset(); } - _callHooksTarget(ADD_STRATEGY, _msgSender()); + _callHooksTarget(ADD_STRATEGY, msg.sender); $.strategies[_strategy] = IEulerAggregationLayer.Strategy({ allocated: 0, @@ -99,7 +99,7 @@ abstract contract AllocationPointsModule is Shared { revert Errors.AlreadyRemoved(); } - _callHooksTarget(REMOVE_STRATEGY, _msgSender()); + _callHooksTarget(REMOVE_STRATEGY, msg.sender); $.totalAllocationPoints -= strategyStorage.allocationPoints; strategyStorage.active = false; diff --git a/src/core/module/Rewards.sol b/src/core/module/Rewards.sol index c5bacc06..ca0ee81f 100644 --- a/src/core/module/Rewards.sol +++ b/src/core/module/Rewards.sol @@ -91,17 +91,16 @@ abstract contract RewardsModule is IBalanceForwarder, Shared { /// @dev Only the authenticated account can enable balance forwarding for itself /// @dev Should call the IBalanceTracker hook with the current account's balance function enableBalanceForwarder() external virtual nonReentrant { - address user = _msgSender(); - uint256 userBalance = IERC20(address(this)).balanceOf(user); + uint256 userBalance = IERC20(address(this)).balanceOf(msg.sender); - _enableBalanceForwarder(user, userBalance); + _enableBalanceForwarder(msg.sender, userBalance); } /// @notice Disables balance forwarding for the authenticated account /// @dev Only the authenticated account can disable balance forwarding for itself /// @dev Should call the IBalanceTracker hook with the account's balance of 0 function disableBalanceForwarder() external virtual nonReentrant { - _disableBalanceForwarder(_msgSender()); + _disableBalanceForwarder(msg.sender); } /// @notice Retrieve the address of rewards contract, tracking changes in account's balances diff --git a/test/common/EulerAggregationLayerBase.t.sol b/test/common/EulerAggregationLayerBase.t.sol index ca699396..159a85ef 100644 --- a/test/common/EulerAggregationLayerBase.t.sol +++ b/test/common/EulerAggregationLayerBase.t.sol @@ -55,7 +55,6 @@ contract EulerAggregationLayerBase is EVaultTestBase { withdrawalQueueImpl = new WithdrawalQueue(); EulerAggregationLayerFactory.FactoryParams memory factoryParams = EulerAggregationLayerFactory.FactoryParams({ - evc: address(evc), balanceTracker: address(0), rewardsModuleImpl: address(rewardsImpl), hooksModuleImpl: address(hooksImpl), @@ -91,7 +90,7 @@ contract EulerAggregationLayerBase is EVaultTestBase { vm.stopPrank(); } - function testInitialParams() public { + function testInitialParams() public view { EulerAggregationLayer.Strategy memory cashReserve = eulerAggregationLayer.getStrategy(address(0)); assertEq(cashReserve.allocated, 0); diff --git a/test/e2e/BalanceForwarderE2ETest.t.sol b/test/e2e/BalanceForwarderE2ETest.t.sol index 25d07165..58537e3d 100644 --- a/test/e2e/BalanceForwarderE2ETest.t.sol +++ b/test/e2e/BalanceForwarderE2ETest.t.sol @@ -26,7 +26,6 @@ contract BalanceForwarderE2ETest is EulerAggregationLayerBase { trackingReward = address(new TrackingRewardStreams(address(evc), 2 weeks)); EulerAggregationLayerFactory.FactoryParams memory factoryParams = EulerAggregationLayerFactory.FactoryParams({ - evc: address(evc), balanceTracker: trackingReward, rewardsModuleImpl: address(rewardsImpl), hooksModuleImpl: address(hooksImpl),