EIP7702Utils.sol 640 B

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