From 88daa438f8f5b21b967abb74dd816f2ee8f296c7 Mon Sep 17 00:00:00 2001 From: Haythem Sellami <17862704+haythemsellami@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:11:50 +0300 Subject: [PATCH] remove rebalance hook --- src/Hooks.sol | 7 +++---- src/Rebalancer.sol | 37 ++++++++++++++++++++----------------- test/e2e/HooksE2ETest.t.sol | 6 +++--- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/Hooks.sol b/src/Hooks.sol index 17206686..c107df23 100644 --- a/src/Hooks.sol +++ b/src/Hooks.sol @@ -14,11 +14,10 @@ abstract contract Hooks { uint32 public constant DEPOSIT = 1 << 0; uint32 public constant WITHDRAW = 1 << 1; - uint32 public constant REBALANCE = 1 << 2; - uint32 public constant ADD_STRATEGY = 1 << 3; - uint32 public constant REMOVE_STRATEGY = 1 << 4; + uint32 public constant ADD_STRATEGY = 1 << 2; + uint32 public constant REMOVE_STRATEGY = 1 << 3; - uint32 constant ACTIONS_COUNTER = 1 << 5; + uint32 constant ACTIONS_COUNTER = 1 << 4; /// @dev Contract with hooks implementation address public hookTarget; diff --git a/src/Rebalancer.sol b/src/Rebalancer.sol index 42d99c85..6175a019 100644 --- a/src/Rebalancer.sol +++ b/src/Rebalancer.sol @@ -5,29 +5,40 @@ import {IFourSixTwoSixAgg} from "./interface/IFourSixTwoSixAgg.sol"; import {IERC4626} from "@openzeppelin/token/ERC20/extensions/ERC4626.sol"; contract Rebalancer { - /// @notice Rebalance strategy allocation. - /// @dev This function will first harvest yield, gulps and update interest. - /// @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 + event Rebalance( + address indexed curatedVault, + address indexed strategy, + uint256 currentAllocation, + uint256 targetAllocation, + uint256 amountToRebalance + ); + + /// @notice Rebalance strategy allocation for a specific curated vault. + /// @param _curatedVault Curated vault address. + /// @param _strategy Strategy address. function rebalance(address _curatedVault, address _strategy) external { _rebalance(_curatedVault, _strategy); } + /// @notice Rebalance strategies allocation for a specific curated vault. + /// @param _curatedVault Curated vault address. + /// @param strategies Strategies addresses. function rebalanceMultipleStrategies(address _curatedVault, address[] calldata strategies) external { for (uint256 i; i < strategies.length; ++i) { _rebalance(_curatedVault, strategies[i]); } } + /// @dev This function will first harvest yield, gulps and update interest. + /// @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 function _rebalance(address _curatedVault, address _strategy) private { if (_strategy == address(0)) { return; //nothing to rebalance as that's the cash reserve } - // _callHookTarget(REBALANCE, _msgSender()); - IFourSixTwoSixAgg(_curatedVault).harvest(_strategy); IFourSixTwoSixAgg.Strategy memory strategyData = IFourSixTwoSixAgg(_curatedVault).getStrategy(_strategy); @@ -82,14 +93,6 @@ contract Rebalancer { IFourSixTwoSixAgg(_curatedVault).rebalance(_strategy, amountToRebalance, isDeposit); - // emit Rebalance(_strategy, strategyData.allocated, targetAllocation, amountToRebalance) + emit Rebalance(_curatedVault, _strategy, strategyData.allocated, targetAllocation, amountToRebalance); } - - // /// @notice Rebalance strategy's allocation. - // /// @param _strategy Address of strategy to rebalance. - // function rebalance(address _strategy) external { - // _rebalance(_strategy); - - // _gulp(); - // } } diff --git a/test/e2e/HooksE2ETest.t.sol b/test/e2e/HooksE2ETest.t.sol index 62176738..efff9207 100644 --- a/test/e2e/HooksE2ETest.t.sol +++ b/test/e2e/HooksE2ETest.t.sol @@ -27,7 +27,7 @@ contract HooksE2ETest is FourSixTwoSixAggBase { function testSetHooksConfig() public { uint32 expectedHookedFns = fourSixTwoSixAgg.DEPOSIT() | fourSixTwoSixAgg.WITHDRAW() - | fourSixTwoSixAgg.REBALANCE() | fourSixTwoSixAgg.ADD_STRATEGY() | fourSixTwoSixAgg.REMOVE_STRATEGY(); + | fourSixTwoSixAgg.ADD_STRATEGY() | fourSixTwoSixAgg.REMOVE_STRATEGY(); vm.startPrank(manager); address hooksContract = address(new HooksContract()); @@ -42,7 +42,7 @@ contract HooksE2ETest is FourSixTwoSixAggBase { function testSetHooksConfigWithAddressZero() public { uint32 expectedHookedFns = fourSixTwoSixAgg.DEPOSIT() | fourSixTwoSixAgg.WITHDRAW() - | fourSixTwoSixAgg.REBALANCE() | fourSixTwoSixAgg.ADD_STRATEGY() | fourSixTwoSixAgg.REMOVE_STRATEGY(); + | fourSixTwoSixAgg.ADD_STRATEGY() | fourSixTwoSixAgg.REMOVE_STRATEGY(); vm.startPrank(manager); vm.expectRevert(Hooks.InvalidHooksTarget.selector); @@ -52,7 +52,7 @@ contract HooksE2ETest is FourSixTwoSixAggBase { function testSetHooksConfigWithNotHooksContract() public { uint32 expectedHookedFns = fourSixTwoSixAgg.DEPOSIT() | fourSixTwoSixAgg.WITHDRAW() - | fourSixTwoSixAgg.REBALANCE() | fourSixTwoSixAgg.ADD_STRATEGY() | fourSixTwoSixAgg.REMOVE_STRATEGY(); + | fourSixTwoSixAgg.ADD_STRATEGY() | fourSixTwoSixAgg.REMOVE_STRATEGY(); vm.startPrank(manager); address hooksContract = address(new NotHooksContract());