AuthorityUtils.sol 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.0.0) (access/manager/AuthorityUtils.sol)
  3. pragma solidity ^0.8.20;
  4. import {IAuthority} from "./IAuthority.sol";
  5. library AuthorityUtils {
  6. /**
  7. * @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility
  8. * for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.
  9. * This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.
  10. */
  11. function canCallWithDelay(
  12. address authority,
  13. address caller,
  14. address target,
  15. bytes4 selector
  16. ) internal view returns (bool immediate, uint32 delay) {
  17. (bool success, bytes memory data) = authority.staticcall(
  18. abi.encodeCall(IAuthority.canCall, (caller, target, selector))
  19. );
  20. if (success) {
  21. if (data.length >= 0x40) {
  22. (immediate, delay) = abi.decode(data, (bool, uint32));
  23. } else if (data.length >= 0x20) {
  24. immediate = abi.decode(data, (bool));
  25. }
  26. }
  27. return (immediate, delay);
  28. }
  29. }