AuthorityUtils.sol 1.1 KB

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