diff --git a/packages/dma-contracts/contracts/actions/morpho-blue/MorphoBlueReallocateTo.sol b/packages/dma-contracts/contracts/actions/morpho-blue/MorphoBlueReallocateTo.sol index f151394b0..64aaa6097 100644 --- a/packages/dma-contracts/contracts/actions/morpho-blue/MorphoBlueReallocateTo.sol +++ b/packages/dma-contracts/contracts/actions/morpho-blue/MorphoBlueReallocateTo.sol @@ -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); @@ -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"); + } + } }