github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/test/mocks/EIP1967Helper.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity ^0.8.0;
     3  
     4  import { Vm } from "forge-std/Vm.sol";
     5  
     6  /// @title EIP1967Helper
     7  /// @dev Testing library to help with reading EIP 1967 variables from state
     8  library EIP1967Helper {
     9      /// @notice The storage slot that holds the address of a proxy implementation.
    10      /// @dev `bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)`
    11      bytes32 internal constant PROXY_IMPLEMENTATION_ADDRESS =
    12          0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
    13  
    14      /// @notice The storage slot that holds the address of the owner.
    15      /// @dev `bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)`
    16      bytes32 internal constant PROXY_OWNER_ADDRESS = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
    17  
    18      Vm internal constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
    19  
    20      function getAdmin(address _proxy) internal view returns (address) {
    21          return address(uint160(uint256(vm.load(address(_proxy), PROXY_OWNER_ADDRESS))));
    22      }
    23  
    24      function getImplementation(address _proxy) internal view returns (address) {
    25          return address(uint160(uint256(vm.load(address(_proxy), PROXY_IMPLEMENTATION_ADDRESS))));
    26      }
    27  }