IAuthority.sol 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. /**
  4. * @dev Standard interface for permissioning originally defined in Dappsys.
  5. */
  6. interface IAuthority {
  7. /**
  8. * @dev Returns true if the caller can invoke on a target the function identified by a function selector.
  9. */
  10. function canCall(address caller, address target, bytes4 selector) external view returns (bool allowed);
  11. }
  12. /**
  13. * @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility
  14. * for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.
  15. * This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.
  16. */
  17. function safeCanCall(
  18. address authority,
  19. address caller,
  20. address target,
  21. bytes4 selector
  22. ) view returns (bool allowed, uint32 delay) {
  23. (bool success, bytes memory data) = authority.staticcall(
  24. abi.encodeCall(IAuthority.canCall, (caller, target, selector))
  25. );
  26. if (success) {
  27. if (data.length >= 0x40) {
  28. (allowed, delay) = abi.decode(data, (bool, uint32));
  29. } else if (data.length >= 0x20) {
  30. allowed = abi.decode(data, (bool));
  31. }
  32. }
  33. return (allowed, delay);
  34. }