Description:
Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/proxy/ERC1967Proxy.sol": {
"content": "// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Proxy.sol)\r
\r
pragma solidity 0.8.11;\r
\r
import "./Proxy.sol";\r
import "../upgradeability/ERC1967Upgrade.sol";\r
\r
/**\r
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an\r
* implementation address that can be changed. This address is stored in storage in the location specified by\r
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the\r
* implementation behind the proxy.\r
*/\r
contract ERC1967Proxy is Proxy, ERC1967Upgrade {\r
/**\r
* @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.\r
*\r
* If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded\r
* function call, and allows initializating the storage of the proxy like a Solidity constructor.\r
*/\r
constructor(address _logic, bytes memory _data) payable {\r
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));\r
_upgradeToAndCall(_logic, _data, false);\r
}\r
\r
/**\r
* @dev Returns the current implementation address.\r
*/\r
function _implementation() internal view virtual override returns (address impl) {\r
return ERC1967Upgrade._getImplementation();\r
}\r
}"
},
"contracts/proxy/Proxy.sol": {
"content": "// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts v4.4.1 (proxy/Proxy.sol)\r
\r
pragma solidity 0.8.11;\r
\r
/**\r
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM\r
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to\r
* be specified by overriding the virtual {_implementation} function.\r
*\r
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a\r
* different contract through the {_delegate} function.\r
*\r
* The success and return data of the delegated call will be returned back to the caller of the proxy.\r
*/\r
abstract contract Proxy {\r
/**\r
* @dev Delegates the current call to `implementation`.\r
*\r
* This function does not return to its internal call site, it will return directly to the external caller.\r
*/\r
function _delegate(address implementation) internal virtual {\r
assembly {\r
// Copy msg.data. We take full control of memory in this inline assembly\r
// block because it will not return to Solidity code. We overwrite the\r
// Solidity scratch pad at memory position 0.\r
calldatacopy(0, 0, calldatasize())\r
\r
// Call the implementation.\r
// out and outsize are 0 because we don't know the size yet.\r
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\r
\r
// Copy the returned data.\r
returndatacopy(0, 0, returndatasize())\r
\r
switch result\r
// delegatecall returns 0 on error.\r
case 0 {\r
revert(0, returndatasize())\r
}\r
default {\r
return(0, returndatasize())\r
}\r
}\r
}\r
\r
/**\r
* @dev This is a virtual function that should be overriden so it returns the address to which the fallback function\r
* and {_fallback} should delegate.\r
*/\r
function _implementation() internal view virtual returns (address);\r
\r
/**\r
* @dev Delegates the current call to the address returned by `_implementation()`.\r
*\r
* This function does not return to its internall call site, it will return directly to the external caller.\r
*/\r
function _fallback() internal virtual {\r
_beforeFallback();\r
_delegate(_implementation());\r
}\r
\r
/**\r
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other\r
* function in the contract matches the call data.\r
*/\r
fallback() external payable virtual {\r
_fallback();\r
}\r
\r
/**\r
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data\r
* is empty.\r
*/\r
receive() external payable virtual {\r
_fallback();\r
}\r
\r
/**\r
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`\r
* call, or as part of the Solidity `fallback` or `receive` functions.\r
*\r
* If overriden should call `super._beforeFallback()`.\r
*/\r
function _beforeFallback() internal virtual {}\r
}"
},
"contracts/upgradeability/draft-IERC1822.sol": {
"content": "// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts v4.x.0 (proxy/ERC1822/IProxiable.sol)\r
\r
pragma solidity 0.8.11;\r
\r
/**\r
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified\r
* proxy whose upgrades are fully controlled by the current implementation.\r
*/\r
interface IERC1822Proxiable {\r
/**\r
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation\r
* address.\r
*\r
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\r
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\r
* function revert if invoked through a proxy.\r
*/\r
function proxiableUUID() external view returns (bytes32);\r
}"
},
"contracts/upgradeability/ERC1967Upgrade.sol": {
"content": "// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol)\r
\r
pragma solidity 0.8.11;\r
\r
import "./draft-IERC1822.sol";\r
import "../util/Address.sol";\r
import "../util/StorageSlot.sol";\r
\r
/**\r
* @dev This abstract contract provides getters and event emitting update functions for\r
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.\r
*\r
* _Available since v4.1._\r
*\r
* @custom:oz-upgrades-unsafe-allow delegatecall\r
*/\r
abstract contract ERC1967Upgrade {\r
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1\r
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;\r
\r
/**\r
* @dev Storage slot with the address of the current implementation.\r
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is\r
* validated in the constructor.\r
*/\r
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\r
\r
/**\r
* @dev Emitted when the implementation is upgraded.\r
*/\r
event Upgraded(address indexed implementation);\r
\r
/**\r
* @dev Returns the current implementation address.\r
*/\r
function _getImplementation() internal view returns (address) {\r
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\r
}\r
\r
/**\r
* @dev Stores a new address in the EIP1967 implementation slot.\r
*/\r
function _setImplementation(address newImplementation) private {\r
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");\r
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\r
}\r
\r
/**\r
* @dev Perform implementation upgrade\r
*\r
* Emits an {Upgraded} event.\r
*/\r
function _upgradeTo(address newImplementation) internal {\r
_setImplementation(newImplementation);\r
emit Upgraded(newImplementation);\r
}\r
\r
/**\r
* @dev Perform implementation upgrade with additional setup call.\r
*\r
* Emits an {Upgraded} event.\r
*/\r
function _upgradeToAndCall(\r
address newImplementation,\r
bytes memory data,\r
bool forceCall\r
) internal {\r
_upgradeTo(newImplementation);\r
if (data.length > 0 || forceCall) {\r
Address.functionDelegateCall(newImplementation, data);\r
}\r
}\r
\r
/**\r
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.\r
*\r
* Emits an {Upgraded} event.\r
*/\r
function _upgradeToAndCallUUPS(\r
address newImplementation,\r
bytes memory data,\r
bool forceCall\r
) internal {\r
// Upgrades from old implementations will perform a rollback test. This test requires the new\r
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing\r
// this special case will break upgrade paths from old UUPS implementation to new ones.\r
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {\r
_setImplementation(newImplementation);\r
} else {\r
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {\r
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");\r
} catch {\r
revert("ERC1967Upgrade: new implementation is not UUPS");\r
}\r
_upgradeToAndCall(newImplementation, data, forceCall);\r
}\r
}\r
\r
uint256[50] private _gap;\r
}"
},
"contracts/util/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\r
// OpenZeppelin Contracts v4.4.0 (utils/Address.sol)\r
\r
pragma solidity 0.8.11;\r
\r
/**\r
* @dev Collection of functions related to the address type\r
*/\r
library Address {\r
/**\r
* @dev Returns true if `account` is a contract.\r
* @dev Forked from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/4961a51cc736c7d4aa9bd2e11e4cbbaff73efee9/contracts/utils/Context.sol\r
* Modifications:\r
* 1. Change solidity version to 0.8.11\r
*\r
* [IMPORTANT]\r
* ====\r
* It is unsafe to assume that an address for which this function returns\r
* false is an externally-owned account (EOA) and not a contract.\r
*\r
* Among others, `isContract` will return false for the following\r
* types of addresses:\r
*\r
* - an externally-owned account\r
* - a contract in construction\r
* - an address where a contract will be created\r
* - an address where a contract lived, but was destroyed\r
* ====\r
*/\r
function isContract(address account) internal view returns (bool) {\r
// This method relies on extcodesize, which returns 0 for contracts in\r
// construction, since the code is only stored at the end of the\r
// constructor execution.\r
\r
uint256 size;\r
assembly {\r
size := extcodesize(account)\r
}\r
return size > 0;\r
}\r
\r
/**\r
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r
* `recipient`, forwarding all available gas and reverting on errors.\r
*\r
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r
* of certain opcodes, possibly making contracts go over the 2300 gas limit\r
* imposed by `transfer`, making them unable to receive funds via\r
* `transfer`. {sendValue} removes this limitation.\r
*\r
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r
*\r
* IMPORTANT: because control is transferred to `recipient`, care must be\r
* taken to not create reentrancy vulnerabilities. Consider using\r
* {ReentrancyGuard} or the\r
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r
*/\r
function sendValue(address payable recipient, uint256 amount) internal {\r
require(address(this).balance >= amount, "Address: insufficient balance");\r
\r
(bool success, ) = recipient.call{value: amount}("");\r
require(success, "Address: unable to send value, recipient may have reverted");\r
}\r
\r
/**\r
* @dev Performs a Solidity function call using a low level `call`. A\r
* plain `call` is an unsafe replacement for a function call: use this\r
* function instead.\r
*\r
* If `target` reverts with a revert reason, it is bubbled up by this\r
* function (like regular Solidity function calls).\r
*\r
* Returns the raw returned data. To convert to the expected return value,\r
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r
*\r
* Requirements:\r
*\r
* - `target` must be a contract.\r
* - calling `target` with `data` must not revert.\r
*\r
* _Available since v3.1._\r
*/\r
function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r
return functionCall(target, data, "Address: low-level call failed");\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r
* `errorMessage` as a fallback revert reason when `target` reverts.\r
*\r
* _Available since v3.1._\r
*/\r
function functionCall(\r
address target,\r
bytes memory data,\r
string memory errorMessage\r
) internal returns (bytes memory) {\r
return functionCallWithValue(target, data, 0, errorMessage);\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
* but also transferring `value` wei to `target`.\r
*\r
* Requirements:\r
*\r
* - the calling contract must have an ETH balance of at least `value`.\r
* - the called Solidity function must be `payable`.\r
*\r
* _Available since v3.1._\r
*/\r
function functionCallWithValue(\r
address target,\r
bytes memory data,\r
uint256 value\r
) internal returns (bytes memory) {\r
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r
* with `errorMessage` as a fallback revert reason when `target` reverts.\r
*\r
* _Available since v3.1._\r
*/\r
function functionCallWithValue(\r
address target,\r
bytes memory data,\r
uint256 value,\r
string memory errorMessage\r
) internal returns (bytes memory) {\r
require(address(this).balance >= value, "Address: insufficient balance for call");\r
require(isContract(target), "Address: call to non-contract");\r
\r
(bool success, bytes memory returndata) = target.call{value: value}(data);\r
return verifyCallResult(success, returndata, errorMessage);\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
* but performing a static call.\r
*\r
* _Available since v3.3._\r
*/\r
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r
return functionStaticCall(target, data, "Address: low-level static call failed");\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
* but performing a static call.\r
*\r
* _Available since v3.3._\r
*/\r
function functionStaticCall(\r
address target,\r
bytes memory data,\r
string memory errorMessage\r
) internal view returns (bytes memory) {\r
require(isContract(target), "Address: static call to non-contract");\r
\r
(bool success, bytes memory returndata) = target.staticcall(data);\r
return verifyCallResult(success, returndata, errorMessage);\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
* but performing a delegate call.\r
*\r
* _Available since v3.4._\r
*/\r
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r
return functionDelegateCall(target, data, "Address: low-level delegate call failed");\r
}\r
\r
/**\r
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r
* but performing a delegate call.\r
*\r
* _Available since v3.4._\r
*/\r
function functionDelegateCall(\r
address target,\r
bytes memory data,\r
string memory errorMessage\r
) internal returns (bytes memory) {\r
require(isContract(target), "Address: delegate call to non-contract");\r
\r
(bool success, bytes memory returndata) = target.delegatecall(data);\r
return verifyCallResult(success, returndata, errorMessage);\r
}\r
\r
/**\r
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\r
* revert reason using the provided one.\r
*\r
* _Available since v4.3._\r
*/\r
function verifyCallResult(\r
bool success,\r
bytes memory returndata,\r
string memory errorMessage\r
) internal pure returns (bytes memory) {\r
if (success) {\r
return returndata;\r
} else {\r
// Look for revert reason and bubble it up if present\r
if (returndata.length > 0) {\r
// The easiest way to bubble the revert reason is using memory via assembly\r
\r
assembly {\r
let returndata_size := mload(returndata)\r
revert(add(32, returndata), returndata_size)\r
}\r
} else {\r
revert(errorMessage);\r
}\r
}\r
}\r
}"
},
"contracts/util/StorageSlot.sol": {
"content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity 0.8.11;\r
\r
/**\r
* @dev Forked from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/4961a51cc736c7d4aa9bd2e11e4cbbaff73efee9/contracts/utils/StorageSlot.sol\r
* Modifications:\r
* 1. Change solidity version to 0.8.11\r
*/\r
/**\r
* @dev Library for reading and writing primitive types to specific storage slots.\r
*\r
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\r
* This library helps with reading and writing to such slots without the need for inline assembly.\r
*\r
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\r
*\r
* Example usage to set ERC1967 implementation slot:\r
* ```\r
* contract ERC1967 {\r
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\r
*\r
* function _getImplementation() internal view returns (address) {\r
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\r
* }\r
*\r
* function _setImplementation(address newImplementation) internal {\r
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");\r
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\r
* }\r
* }\r
* ```\r
*\r
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\r
*/\r
library StorageSlot {\r
struct AddressSlot {\r
address value;\r
}\r
\r
struct BooleanSlot {\r
bool value;\r
}\r
\r
struct Bytes32Slot {\r
bytes32 value;\r
}\r
\r
struct Uint256Slot {\r
uint256 value;\r
}\r
\r
/**\r
* @dev Returns an `AddressSlot` with member `value` located at `slot`.\r
*/\r
function getAddressSlot(bytes32 slot)\r
internal\r
pure\r
returns (AddressSlot storage r)\r
{\r
assembly {\r
r.slot := slot\r
}\r
}\r
\r
/**\r
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.\r
*/\r
function getBooleanSlot(bytes32 slot)\r
internal\r
pure\r
returns (BooleanSlot storage r)\r
{\r
assembly {\r
r.slot := slot\r
}\r
}\r
\r
/**\r
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\r
*/\r
function getBytes32Slot(bytes32 slot)\r
internal\r
pure\r
returns (Bytes32Slot storage r)\r
{\r
assembly {\r
r.slot := slot\r
}\r
}\r
\r
/**\r
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.\r
*/\r
function getUint256Slot(bytes32 slot)\r
internal\r
pure\r
returns (Uint256Slot storage r)\r
{\r
assembly {\r
r.slot := slot\r
}\r
}\r
}\r
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 3000
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}}
Submitted on: 2025-09-17 12:50:12
Comments
Log in to comment.
No comments yet.