Skip to content

Commit

Permalink
[#108] Create use function to check if contract supports interface in…
Browse files Browse the repository at this point in the history
… registry
  • Loading branch information
akshay-ap committed Oct 25, 2023
1 parent dbbafeb commit dfb0e0c
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions contracts/SafeProtocolRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,45 +69,32 @@ contract SafeProtocolRegistry is ISafeProtocolRegistry, Ownable2Step {
revert InvalidModuleType(module, moduleTypes);
}

// Check if module supports expected interface
if (
moduleTypes & MODULE_TYPE_HOOKS == MODULE_TYPE_HOOKS && !IERC165(module).supportsInterface(type(ISafeProtocolHooks).interfaceId)
) {
revert ModuleDoesNotSupportExpectedInterfaceId(module, type(ISafeProtocolHooks).interfaceId);
}

if (
moduleTypes & MODULE_TYPE_PLUGIN == MODULE_TYPE_PLUGIN &&
!IERC165(module).supportsInterface(type(ISafeProtocolPlugin).interfaceId)
) {
revert ModuleDoesNotSupportExpectedInterfaceId(module, type(ISafeProtocolPlugin).interfaceId);
}

if (
moduleTypes & MODULE_TYPE_FUNCTION_HANDLER == MODULE_TYPE_FUNCTION_HANDLER &&
!IERC165(module).supportsInterface(type(ISafeProtocolFunctionHandler).interfaceId)
) {
revert ModuleDoesNotSupportExpectedInterfaceId(module, type(ISafeProtocolFunctionHandler).interfaceId);
}

if (
moduleTypes & MODULE_TYPE_SIGNATURE_VALIDATOR == MODULE_TYPE_SIGNATURE_VALIDATOR &&
!IERC165(module).supportsInterface(type(ISafeProtocolSignatureValidator).interfaceId)
) {
revert ModuleDoesNotSupportExpectedInterfaceId(module, type(ISafeProtocolSignatureValidator).interfaceId);
}

if (
moduleTypes & MODULE_TYPE_SIGNATURE_VALIDATOR_HOOKS == MODULE_TYPE_SIGNATURE_VALIDATOR_HOOKS &&
!IERC165(module).supportsInterface(type(ISafeProtocolSignatureValidatorHooks).interfaceId)
) {
revert ModuleDoesNotSupportExpectedInterfaceId(module, type(ISafeProtocolSignatureValidatorHooks).interfaceId);
}
optionalCheckInterfaceSupport(module, moduleTypes, MODULE_TYPE_PLUGIN, type(ISafeProtocolPlugin).interfaceId);
optionalCheckInterfaceSupport(module, moduleTypes, MODULE_TYPE_FUNCTION_HANDLER, type(ISafeProtocolFunctionHandler).interfaceId);
optionalCheckInterfaceSupport(module, moduleTypes, MODULE_TYPE_HOOKS, type(ISafeProtocolHooks).interfaceId);
optionalCheckInterfaceSupport(
module,
moduleTypes,
MODULE_TYPE_SIGNATURE_VALIDATOR_HOOKS,
type(ISafeProtocolSignatureValidatorHooks).interfaceId
);
optionalCheckInterfaceSupport(
module,
moduleTypes,
MODULE_TYPE_SIGNATURE_VALIDATOR,
type(ISafeProtocolSignatureValidator).interfaceId
);

listedModules[module] = ModuleInfo(uint64(block.timestamp), 0, moduleTypes);
emit ModuleAdded(module);
}

function optionalCheckInterfaceSupport(address module, uint8 moduleTypes, uint8 moduleTypeToCheck, bytes4 interfaceId) internal view {
if (moduleTypes & moduleTypeToCheck == moduleTypeToCheck && !IERC165(module).supportsInterface(interfaceId)) {
revert ModuleDoesNotSupportExpectedInterfaceId(module, interfaceId);
}
}

/**
* @notice Allows only owner to flad a module. Only previously added module can be flagged.
* This function does not permit flagging a module twice.
Expand Down

0 comments on commit dfb0e0c

Please sign in to comment.