AuthorityUtils.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. bytes memory data = abi.encodeCall(IAuthority.canCall, (caller, target, selector));
  18. assembly ("memory-safe") {
  19. mstore(0x00, 0x00)
  20. mstore(0x20, 0x00)
  21. if staticcall(gas(), authority, add(data, 0x20), mload(data), 0x00, 0x40) {
  22. immediate := mload(0x00)
  23. delay := mload(0x20)
  24. // If delay does not fit in a uint32, return 0 (no delay)
  25. // equivalent to: if gt(delay, 0xFFFFFFFF) { delay := 0 }
  26. delay := mul(delay, iszero(shr(32, delay)))
  27. }
  28. }
  29. }
  30. }