Skip to content

Commit

Permalink
remove rebalance hook
Browse files Browse the repository at this point in the history
  • Loading branch information
haythemsellami committed Jun 12, 2024
1 parent 60356e3 commit 88daa43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
7 changes: 3 additions & 4 deletions src/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 20 additions & 17 deletions src/Rebalancer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
// }
}
6 changes: 3 additions & 3 deletions test/e2e/HooksE2ETest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit 88daa43

Please sign in to comment.