AccessManagedAdapter.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {AccessManaged} from "../AccessManaged.sol";
  4. import {Address} from "../../../utils/Address.sol";
  5. /**
  6. * @dev This contract can be used to migrate existing {Ownable} or {AccessControl} contracts into an {AccessManager}
  7. * system.
  8. *
  9. * Ownable contracts can have their ownership transferred to an instance of this adapter. AccessControl contracts can
  10. * grant all roles to the adapter, while ideally revoking them from all other accounts. Subsequently, the permissions
  11. * for those contracts can be managed centrally and with function granularity in the {AccessManager} instance the
  12. * adapter is connected to.
  13. *
  14. * Permissioned interactions with thus migrated contracts must go through the adapter's {relay} function and will
  15. * proceed if the function is allowed for the caller in the AccessManager instance.
  16. */
  17. contract AccessManagedAdapter is AccessManaged {
  18. error AccessManagedAdapterUnauthorizedSelfRelay();
  19. /**
  20. * @dev Initializes an adapter connected to an AccessManager instance.
  21. */
  22. constructor(address initialAuthority) AccessManaged(initialAuthority) {}
  23. /**
  24. * @dev Relays a function call to the target contract. The call will be relayed if the AccessManager allows the
  25. * caller access to this function in the target contract, i.e. if the caller is a member of the group that is
  26. * allowed for the function.
  27. */
  28. function relay(address target, bytes calldata data) external payable {
  29. if (target == address(this)) {
  30. revert AccessManagedAdapterUnauthorizedSelfRelay();
  31. }
  32. _checkCanCall(_msgSender(), target, bytes4(data[0:4]));
  33. Address.functionCallWithValue(target, data, msg.value);
  34. }
  35. }