Skip to content

Commit

Permalink
remove dependency to the EVC
Browse files Browse the repository at this point in the history
  • Loading branch information
haythemsellami committed Jun 27, 2024
1 parent b146b63 commit e09ae62
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 34 deletions.
8 changes: 1 addition & 7 deletions src/core/EulerAggregationLayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ contract EulerAggregationLayer is
cap: 0
});
$.totalAllocationPoints = _initParams.initialCashAllocationPoints;
$.evc = _initParams.evc;
$.balanceTracker = _initParams.balanceTracker;

// Setup DEFAULT_ADMIN
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions src/core/EulerAggregationLayerFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +29,6 @@ contract EulerAggregationLayerFactory {

/// @dev Init params struct.
struct FactoryParams {
address evc;
address balanceTracker;
address rewardsModuleImpl;
address hooksModuleImpl;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions src/core/common/Shared.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion src/core/interface/IEulerAggregationLayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/core/lib/StorageLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/core/module/AllocationPoints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/core/module/Rewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/common/EulerAggregationLayerBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion test/e2e/BalanceForwarderE2ETest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit e09ae62

Please sign in to comment.