EIP7702Utils.sol 726 B

123456789101112131415161718192021
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.4.0-rc.0) (account/utils/EIP7702Utils.sol)
  3. pragma solidity ^0.8.20;
  4. /**
  5. * @dev Library with common EIP-7702 utility functions.
  6. *
  7. * See https://eips.ethereum.org/EIPS/eip-7702[ERC-7702].
  8. */
  9. library EIP7702Utils {
  10. bytes3 internal constant EIP7702_PREFIX = 0xef0100;
  11. /**
  12. * @dev Returns the address of the delegate if `account` as an EIP-7702 delegation setup, or address(0) otherwise.
  13. */
  14. function fetchDelegate(address account) internal view returns (address) {
  15. bytes23 delegation = bytes23(account.code);
  16. return bytes3(delegation) == EIP7702_PREFIX ? address(bytes20(delegation << 24)) : address(0);
  17. }
  18. }