smart-contract-fiesta
/
organized_contracts
/00
/001617dde8a3547413b539024dd311eaa114dd79560fbc1fd3b30af91cf2ac23
/ERC1967Upgrade.sol
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023. | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.7; | |
abstract contract ERC1967Upgrade { | |
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 | |
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; | |
/** | |
* @dev Storage slot with the address of the current implementation. | |
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is | |
* validated in the constructor. | |
*/ | |
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; | |
/** | |
* @dev Emitted when the implementation is upgraded. | |
*/ | |
event Upgraded(address indexed implementation); | |
/** | |
* @dev Returns the current implementation address. | |
*/ | |
function _getImplementation() internal view returns (address) { | |
return getAddressSlot(_IMPLEMENTATION_SLOT).value; | |
} | |
/** | |
* @dev Stores a new address in the EIP1967 implementation slot. | |
*/ | |
function _setImplementation(address newImplementation) private { | |
// require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); | |
getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; | |
} | |
/** | |
* @dev Perform implementation upgrade | |
* | |
* Emits an {Upgraded} event. | |
*/ | |
function _upgradeTo(address newImplementation) internal { | |
_setImplementation(newImplementation); | |
emit Upgraded(newImplementation); | |
} | |
/** | |
* @dev Perform implementation upgrade with additional setup call. | |
* | |
* Emits an {Upgraded} event. | |
*/ | |
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal { | |
_upgradeTo(newImplementation); | |
// if (data.length > 0 || forceCall) { | |
// functionDelegateCall(newImplementation, data, "Address: low-level delegate call failed"); | |
// } | |
} | |
struct AddressSlot { | |
address value; | |
} | |
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { | |
/// @solidity memory-safe-assembly | |
assembly { | |
r.slot := slot | |
} | |
} | |
} |