github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/universal/StorageSetter.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { ISemver } from "src/universal/ISemver.sol"; 5 import { Storage } from "src/libraries/Storage.sol"; 6 7 /// @title StorageSetter 8 /// @notice A simple contract that allows setting arbitrary storage slots. 9 /// WARNING: this contract is not safe to be called by untrusted parties. 10 /// It is only meant as an intermediate step during upgrades. 11 contract StorageSetter is ISemver { 12 /// @notice Represents a storage slot key value pair. 13 struct Slot { 14 bytes32 key; 15 bytes32 value; 16 } 17 18 /// @notice Semantic version. 19 /// @custom:semver 1.2.0 20 string public constant version = "1.2.0"; 21 22 /// @notice Stores a bytes32 `_value` at `_slot`. Any storage slots that 23 /// are packed should be set through this interface. 24 function setBytes32(bytes32 _slot, bytes32 _value) public { 25 Storage.setBytes32(_slot, _value); 26 } 27 28 /// @notice Stores a bytes32 value at each key in `_slots`. 29 function setBytes32(Slot[] calldata slots) public { 30 uint256 length = slots.length; 31 for (uint256 i; i < length; i++) { 32 Storage.setBytes32(slots[i].key, slots[i].value); 33 } 34 } 35 36 /// @notice Retrieves a bytes32 value from `_slot`. 37 function getBytes32(bytes32 _slot) external view returns (bytes32 value_) { 38 value_ = Storage.getBytes32(_slot); 39 } 40 41 /// @notice Stores a uint256 `_value` at `_slot`. 42 function setUint(bytes32 _slot, uint256 _value) public { 43 Storage.setUint(_slot, _value); 44 } 45 46 /// @notice Retrieves a uint256 value from `_slot`. 47 function getUint(bytes32 _slot) external view returns (uint256 value_) { 48 value_ = Storage.getUint(_slot); 49 } 50 51 /// @notice Stores an address `_value` at `_slot`. 52 function setAddress(bytes32 _slot, address _address) public { 53 Storage.setAddress(_slot, _address); 54 } 55 56 /// @notice Retrieves an address value from `_slot`. 57 function getAddress(bytes32 _slot) external view returns (address addr_) { 58 addr_ = Storage.getAddress(_slot); 59 } 60 61 /// @notice Stores a bool `_value` at `_slot`. 62 function setBool(bytes32 _slot, bool _value) public { 63 Storage.setBool(_slot, _value); 64 } 65 66 /// @notice Retrieves a bool value from `_slot`. 67 function getBool(bytes32 _slot) external view returns (bool value_) { 68 value_ = Storage.getBool(_slot); 69 } 70 }