Skip to content

Commit

Permalink
chore: refactor MorphoBlueReallocateTo action contract
Browse files Browse the repository at this point in the history
  • Loading branch information
halaprix committed Dec 2, 2024
1 parent 392e661 commit e50fe2f
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ contract MorphoBlueReallocateTo is Executable {
address public immutable BUNDLER;
ServiceRegistry public immutable registry;

/**
* @notice Constructs the MorphoBlueReallocateTo contract
* @param _registry The address of the ServiceRegistry contract
*/
constructor(address _registry) {
require(_registry != address(0), "MorphoBlueReallocateTo: registry cannot be the zero address");
registry = ServiceRegistry(_registry);
Expand All @@ -24,28 +28,41 @@ contract MorphoBlueReallocateTo is Executable {
}

/**
* @notice Executes the reallocation of liquidity
* @dev Look at UseStore.sol to get additional info on paramsMapping.
*
* @param data Encoded calldata that conforms to the ReallocateToData struct
*/
function execute(bytes calldata data, uint8[] memory) external payable override {
ReallocateToData memory reallocateToData = parseInputs(data);

for (uint256 i = 0; i < reallocateToData.data.length; i++) {
bytes4 selector;
bytes memory _data = reallocateToData.data[i];
assembly {
selector := mload(add(_data, 32))
}
require(selector == REALLOCATE_TO_SELECTOR, "MorphoBluePublicAllocator: invalid selector");
}

_validateReallocateToData(reallocateToData);

IBundler(BUNDLER).multicall(reallocateToData.data);
}

/**
* @notice Parses the input calldata to extract ReallocateToData
* @param _callData The encoded calldata
* @return params The decoded ReallocateToData struct
*/
function parseInputs(
bytes memory _callData
) public pure returns (ReallocateToData memory params) {
return abi.decode(_callData, (ReallocateToData));
}

/**
* @notice Validates the ReallocateToData struct
* @param _reallocateToData The ReallocateToData struct to validate
*/
function _validateReallocateToData(ReallocateToData memory _reallocateToData) internal pure {
for (uint256 i = 0; i < _reallocateToData.data.length; i++) {
bytes4 selector;
bytes memory _data = _reallocateToData.data[i];
assembly {
selector := mload(add(_data, 32))
}
require(selector == REALLOCATE_TO_SELECTOR, "MorphoBlueReallocateTo: invalid selector");
}
}
}

0 comments on commit e50fe2f

Please sign in to comment.